ada.go

  1package a
  2
  3import (
  4	. "github.com/alecthomas/chroma" // nolint
  5	"github.com/alecthomas/chroma/lexers/internal"
  6)
  7
  8// Ada lexer.
  9var Ada = internal.Register(MustNewLexer(
 10	&Config{
 11		Name:            "Ada",
 12		Aliases:         []string{"ada", "ada95", "ada2005"},
 13		Filenames:       []string{"*.adb", "*.ads", "*.ada"},
 14		MimeTypes:       []string{"text/x-ada"},
 15		CaseInsensitive: true,
 16	},
 17	Rules{
 18		"root": {
 19			{`[^\S\n]+`, Text, nil},
 20			{`--.*?\n`, CommentSingle, nil},
 21			{`[^\S\n]+`, Text, nil},
 22			{`function|procedure|entry`, KeywordDeclaration, Push("subprogram")},
 23			{`(subtype|type)(\s+)(\w+)`, ByGroups(KeywordDeclaration, Text, KeywordType), Push("type_def")},
 24			{`task|protected`, KeywordDeclaration, nil},
 25			{`(subtype)(\s+)`, ByGroups(KeywordDeclaration, Text), nil},
 26			{`(end)(\s+)`, ByGroups(KeywordReserved, Text), Push("end")},
 27			{`(pragma)(\s+)(\w+)`, ByGroups(KeywordReserved, Text, CommentPreproc), nil},
 28			{`(true|false|null)\b`, KeywordConstant, nil},
 29			{Words(``, `\b`, `Address`, `Byte`, `Boolean`, `Character`, `Controlled`, `Count`, `Cursor`, `Duration`, `File_Mode`, `File_Type`, `Float`, `Generator`, `Integer`, `Long_Float`, `Long_Integer`, `Long_Long_Float`, `Long_Long_Integer`, `Natural`, `Positive`, `Reference_Type`, `Short_Float`, `Short_Integer`, `Short_Short_Float`, `Short_Short_Integer`, `String`, `Wide_Character`, `Wide_String`), KeywordType, nil},
 30			{`(and(\s+then)?|in|mod|not|or(\s+else)|rem)\b`, OperatorWord, nil},
 31			{`generic|private`, KeywordDeclaration, nil},
 32			{`package`, KeywordDeclaration, Push("package")},
 33			{`array\b`, KeywordReserved, Push("array_def")},
 34			{`(with|use)(\s+)`, ByGroups(KeywordNamespace, Text), Push("import")},
 35			{`(\w+)(\s*)(:)(\s*)(constant)`, ByGroups(NameConstant, Text, Punctuation, Text, KeywordReserved), nil},
 36			{`<<\w+>>`, NameLabel, nil},
 37			{`(\w+)(\s*)(:)(\s*)(declare|begin|loop|for|while)`, ByGroups(NameLabel, Text, Punctuation, Text, KeywordReserved), nil},
 38			{Words(`\b`, `\b`, `abort`, `abs`, `abstract`, `accept`, `access`, `aliased`, `all`, `array`, `at`, `begin`, `body`, `case`, `constant`, `declare`, `delay`, `delta`, `digits`, `do`, `else`, `elsif`, `end`, `entry`, `exception`, `exit`, `interface`, `for`, `goto`, `if`, `is`, `limited`, `loop`, `new`, `null`, `of`, `or`, `others`, `out`, `overriding`, `pragma`, `protected`, `raise`, `range`, `record`, `renames`, `requeue`, `return`, `reverse`, `select`, `separate`, `subtype`, `synchronized`, `task`, `tagged`, `terminate`, `then`, `type`, `until`, `when`, `while`, `xor`), KeywordReserved, nil},
 39			{`"[^"]*"`, LiteralString, nil},
 40			Include("attribute"),
 41			Include("numbers"),
 42			{`'[^']'`, LiteralStringChar, nil},
 43			{`(\w+)(\s*|[(,])`, ByGroups(Name, UsingSelf("root")), nil},
 44			{`(<>|=>|:=|[()|:;,.'])`, Punctuation, nil},
 45			{`[*<>+=/&-]`, Operator, nil},
 46			{`\n+`, Text, nil},
 47		},
 48		"numbers": {
 49			{`[0-9_]+#[0-9a-f]+#`, LiteralNumberHex, nil},
 50			{`[0-9_]+\.[0-9_]*`, LiteralNumberFloat, nil},
 51			{`[0-9_]+`, LiteralNumberInteger, nil},
 52		},
 53		"attribute": {
 54			{`(')(\w+)`, ByGroups(Punctuation, NameAttribute), nil},
 55		},
 56		"subprogram": {
 57			{`\(`, Punctuation, Push("#pop", "formal_part")},
 58			{`;`, Punctuation, Pop(1)},
 59			{`is\b`, KeywordReserved, Pop(1)},
 60			{`"[^"]+"|\w+`, NameFunction, nil},
 61			Include("root"),
 62		},
 63		"end": {
 64			{`(if|case|record|loop|select)`, KeywordReserved, nil},
 65			{`"[^"]+"|[\w.]+`, NameFunction, nil},
 66			{`\s+`, Text, nil},
 67			{`;`, Punctuation, Pop(1)},
 68		},
 69		"type_def": {
 70			{`;`, Punctuation, Pop(1)},
 71			{`\(`, Punctuation, Push("formal_part")},
 72			{`with|and|use`, KeywordReserved, nil},
 73			{`array\b`, KeywordReserved, Push("#pop", "array_def")},
 74			{`record\b`, KeywordReserved, Push("record_def")},
 75			{`(null record)(;)`, ByGroups(KeywordReserved, Punctuation), Pop(1)},
 76			Include("root"),
 77		},
 78		"array_def": {
 79			{`;`, Punctuation, Pop(1)},
 80			{`(\w+)(\s+)(range)`, ByGroups(KeywordType, Text, KeywordReserved), nil},
 81			Include("root"),
 82		},
 83		"record_def": {
 84			{`end record`, KeywordReserved, Pop(1)},
 85			Include("root"),
 86		},
 87		"import": {
 88			{`[\w.]+`, NameNamespace, Pop(1)},
 89			Default(Pop(1)),
 90		},
 91		"formal_part": {
 92			{`\)`, Punctuation, Pop(1)},
 93			{`\w+`, NameVariable, nil},
 94			{`,|:[^=]`, Punctuation, nil},
 95			{`(in|not|null|out|access)\b`, KeywordReserved, nil},
 96			Include("root"),
 97		},
 98		"package": {
 99			{`body`, KeywordDeclaration, nil},
100			{`is\s+new|renames`, KeywordReserved, nil},
101			{`is`, KeywordReserved, Pop(1)},
102			{`;`, Punctuation, Pop(1)},
103			{`\(`, Punctuation, Push("package_instantiation")},
104			{`([\w.]+)`, NameClass, nil},
105			Include("root"),
106		},
107		"package_instantiation": {
108			{`("[^"]+"|\w+)(\s+)(=>)`, ByGroups(NameVariable, Text, Punctuation), nil},
109			{`[\w.\'"]`, Text, nil},
110			{`\)`, Punctuation, Pop(1)},
111			Include("root"),
112		},
113	},
114))