antlr.go

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