You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ballerina.go 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package b
  2. import (
  3. . "github.com/alecthomas/chroma" // nolint
  4. "github.com/alecthomas/chroma/lexers/internal"
  5. )
  6. // Ballerina lexer.
  7. var Ballerina = internal.Register(MustNewLexer(
  8. &Config{
  9. Name: "Ballerina",
  10. Aliases: []string{"ballerina"},
  11. Filenames: []string{"*.bal"},
  12. MimeTypes: []string{"text/x-ballerina"},
  13. DotAll: true,
  14. },
  15. Rules{
  16. "root": {
  17. {`[^\S\n]+`, Text, nil},
  18. {`//.*?\n`, CommentSingle, nil},
  19. {`/\*.*?\*/`, CommentMultiline, nil},
  20. {`(break|catch|continue|done|else|finally|foreach|forever|fork|if|lock|match|return|throw|transaction|try|while)\b`, Keyword, nil},
  21. {`((?:(?:[^\W\d]|\$)[\w.\[\]$<>]*\s+)+?)((?:[^\W\d]|\$)[\w$]*)(\s*)(\()`, ByGroups(UsingSelf("root"), NameFunction, Text, Operator), nil},
  22. {`@[^\W\d][\w.]*`, NameDecorator, nil},
  23. {`(annotation|bind|but|endpoint|error|function|object|private|public|returns|service|type|var|with|worker)\b`, KeywordDeclaration, nil},
  24. {`(boolean|byte|decimal|float|int|json|map|nil|record|string|table|xml)\b`, KeywordType, nil},
  25. {`(true|false|null)\b`, KeywordConstant, nil},
  26. {`(import)(\s+)`, ByGroups(KeywordNamespace, Text), Push("import")},
  27. {`"(\\\\|\\"|[^"])*"`, LiteralString, nil},
  28. {`'\\.'|'[^\\]'|'\\u[0-9a-fA-F]{4}'`, LiteralStringChar, nil},
  29. {`(\.)((?:[^\W\d]|\$)[\w$]*)`, ByGroups(Operator, NameAttribute), nil},
  30. {`^\s*([^\W\d]|\$)[\w$]*:`, NameLabel, nil},
  31. {`([^\W\d]|\$)[\w$]*`, Name, nil},
  32. {`([0-9][0-9_]*\.([0-9][0-9_]*)?|\.[0-9][0-9_]*)([eE][+\-]?[0-9][0-9_]*)?[fFdD]?|[0-9][eE][+\-]?[0-9][0-9_]*[fFdD]?|[0-9]([eE][+\-]?[0-9][0-9_]*)?[fFdD]|0[xX]([0-9a-fA-F][0-9a-fA-F_]*\.?|([0-9a-fA-F][0-9a-fA-F_]*)?\.[0-9a-fA-F][0-9a-fA-F_]*)[pP][+\-]?[0-9][0-9_]*[fFdD]?`, LiteralNumberFloat, nil},
  33. {`0[xX][0-9a-fA-F][0-9a-fA-F_]*[lL]?`, LiteralNumberHex, nil},
  34. {`0[bB][01][01_]*[lL]?`, LiteralNumberBin, nil},
  35. {`0[0-7_]+[lL]?`, LiteralNumberOct, nil},
  36. {`0|[1-9][0-9_]*[lL]?`, LiteralNumberInteger, nil},
  37. {`[~^*!%&\[\](){}<>|+=:;,./?-]`, Operator, nil},
  38. {`\n`, Text, nil},
  39. },
  40. "import": {
  41. {`[\w.]+`, NameNamespace, Pop(1)},
  42. },
  43. },
  44. ))