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.

antlr.go 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package a
  2. import (
  3. . "github.com/alecthomas/chroma" // nolint
  4. "github.com/alecthomas/chroma/lexers/internal"
  5. )
  6. // ANTLR lexer.
  7. var ANTLR = internal.Register(MustNewLexer(
  8. &Config{
  9. Name: "ANTLR",
  10. Aliases: []string{"antlr"},
  11. Filenames: []string{},
  12. MimeTypes: []string{},
  13. },
  14. Rules{
  15. "whitespace": {
  16. {`\s+`, TextWhitespace, nil},
  17. },
  18. "comments": {
  19. {`//.*$`, Comment, nil},
  20. {`/\*(.|\n)*?\*/`, Comment, nil},
  21. },
  22. "root": {
  23. Include("whitespace"),
  24. Include("comments"),
  25. {`(lexer|parser|tree)?(\s*)(grammar\b)(\s*)([A-Za-z]\w*)(;)`, ByGroups(Keyword, TextWhitespace, Keyword, TextWhitespace, NameClass, Punctuation), nil},
  26. {`options\b`, Keyword, Push("options")},
  27. {`tokens\b`, Keyword, Push("tokens")},
  28. {`(scope)(\s*)([A-Za-z]\w*)(\s*)(\{)`, ByGroups(Keyword, TextWhitespace, NameVariable, TextWhitespace, Punctuation), Push("action")},
  29. {`(catch|finally)\b`, Keyword, Push("exception")},
  30. {`(@[A-Za-z]\w*)(\s*)(::)?(\s*)([A-Za-z]\w*)(\s*)(\{)`, ByGroups(NameLabel, TextWhitespace, Punctuation, TextWhitespace, NameLabel, TextWhitespace, Punctuation), Push("action")},
  31. {`((?:protected|private|public|fragment)\b)?(\s*)([A-Za-z]\w*)(!)?`, ByGroups(Keyword, TextWhitespace, NameLabel, Punctuation), Push("rule-alts", "rule-prelims")},
  32. },
  33. "exception": {
  34. {`\n`, TextWhitespace, Pop(1)},
  35. {`\s`, TextWhitespace, nil},
  36. Include("comments"),
  37. {`\[`, Punctuation, Push("nested-arg-action")},
  38. {`\{`, Punctuation, Push("action")},
  39. },
  40. "rule-prelims": {
  41. Include("whitespace"),
  42. Include("comments"),
  43. {`returns\b`, Keyword, nil},
  44. {`\[`, Punctuation, Push("nested-arg-action")},
  45. {`\{`, Punctuation, Push("action")},
  46. {`(throws)(\s+)([A-Za-z]\w*)`, ByGroups(Keyword, TextWhitespace, NameLabel), nil},
  47. {`(,)(\s*)([A-Za-z]\w*)`, ByGroups(Punctuation, TextWhitespace, NameLabel), nil},
  48. {`options\b`, Keyword, Push("options")},
  49. {`(scope)(\s+)(\{)`, ByGroups(Keyword, TextWhitespace, Punctuation), Push("action")},
  50. {`(scope)(\s+)([A-Za-z]\w*)(\s*)(;)`, ByGroups(Keyword, TextWhitespace, NameLabel, TextWhitespace, Punctuation), nil},
  51. {`(@[A-Za-z]\w*)(\s*)(\{)`, ByGroups(NameLabel, TextWhitespace, Punctuation), Push("action")},
  52. {`:`, Punctuation, Pop(1)},
  53. },
  54. "rule-alts": {
  55. Include("whitespace"),
  56. Include("comments"),
  57. {`options\b`, Keyword, Push("options")},
  58. {`:`, Punctuation, nil},
  59. {`'(\\\\|\\'|[^'])*'`, LiteralString, nil},
  60. {`"(\\\\|\\"|[^"])*"`, LiteralString, nil},
  61. {`<<([^>]|>[^>])>>`, LiteralString, nil},
  62. {`\$?[A-Z_]\w*`, NameConstant, nil},
  63. {`\$?[a-z_]\w*`, NameVariable, nil},
  64. {`(\+|\||->|=>|=|\(|\)|\.\.|\.|\?|\*|\^|!|\#|~)`, Operator, nil},
  65. {`,`, Punctuation, nil},
  66. {`\[`, Punctuation, Push("nested-arg-action")},
  67. {`\{`, Punctuation, Push("action")},
  68. {`;`, Punctuation, Pop(1)},
  69. },
  70. "tokens": {
  71. Include("whitespace"),
  72. Include("comments"),
  73. {`\{`, Punctuation, nil},
  74. {`([A-Z]\w*)(\s*)(=)?(\s*)(\'(?:\\\\|\\\'|[^\']*)\')?(\s*)(;)`, ByGroups(NameLabel, TextWhitespace, Punctuation, TextWhitespace, LiteralString, TextWhitespace, Punctuation), nil},
  75. {`\}`, Punctuation, Pop(1)},
  76. },
  77. "options": {
  78. Include("whitespace"),
  79. Include("comments"),
  80. {`\{`, Punctuation, nil},
  81. {`([A-Za-z]\w*)(\s*)(=)(\s*)([A-Za-z]\w*|\'(?:\\\\|\\\'|[^\']*)\'|[0-9]+|\*)(\s*)(;)`, ByGroups(NameVariable, TextWhitespace, Punctuation, TextWhitespace, Text, TextWhitespace, Punctuation), nil},
  82. {`\}`, Punctuation, Pop(1)},
  83. },
  84. "action": {
  85. {`([^${}\'"/\\]+|"(\\\\|\\"|[^"])*"|'(\\\\|\\'|[^'])*'|//.*$\n?|/\*(.|\n)*?\*/|/(?!\*)(\\\\|\\/|[^/])*/|\\(?!%)|/)+`, Other, nil},
  86. {`(\\)(%)`, ByGroups(Punctuation, Other), nil},
  87. {`(\$[a-zA-Z]+)(\.?)(text|value)?`, ByGroups(NameVariable, Punctuation, NameProperty), nil},
  88. {`\{`, Punctuation, Push()},
  89. {`\}`, Punctuation, Pop(1)},
  90. },
  91. "nested-arg-action": {
  92. {`([^$\[\]\'"/]+|"(\\\\|\\"|[^"])*"|'(\\\\|\\'|[^'])*'|//.*$\n?|/\*(.|\n)*?\*/|/(?!\*)(\\\\|\\/|[^/])*/|/)+`, Other, nil},
  93. {`\[`, Punctuation, Push()},
  94. {`\]`, Punctuation, Pop(1)},
  95. {`(\$[a-zA-Z]+)(\.?)(text|value)?`, ByGroups(NameVariable, Punctuation, NameProperty), nil},
  96. {`(\\\\|\\\]|\\\[|[^\[\]])+`, Other, nil},
  97. },
  98. },
  99. ))