...

Source file src/github.com/alecthomas/chroma/lexers/a/ada.go

Documentation: github.com/alecthomas/chroma/lexers/a

     1  package a
     2  
     3  import (
     4  	. "github.com/alecthomas/chroma" // nolint
     5  	"github.com/alecthomas/chroma/lexers/internal"
     6  )
     7  
     8  // Ada lexer.
     9  var Ada = internal.Register(MustNewLazyLexer(
    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  	adaRules,
    18  ))
    19  
    20  func adaRules() Rules {
    21  	return Rules{
    22  		"root": {
    23  			{`[^\S\n]+`, Text, nil},
    24  			{`--.*?\n`, CommentSingle, nil},
    25  			{`[^\S\n]+`, Text, nil},
    26  			{`function|procedure|entry`, KeywordDeclaration, Push("subprogram")},
    27  			{`(subtype|type)(\s+)(\w+)`, ByGroups(KeywordDeclaration, Text, KeywordType), Push("type_def")},
    28  			{`task|protected`, KeywordDeclaration, nil},
    29  			{`(subtype)(\s+)`, ByGroups(KeywordDeclaration, Text), nil},
    30  			{`(end)(\s+)`, ByGroups(KeywordReserved, Text), Push("end")},
    31  			{`(pragma)(\s+)(\w+)`, ByGroups(KeywordReserved, Text, CommentPreproc), nil},
    32  			{`(true|false|null)\b`, KeywordConstant, nil},
    33  			{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},
    34  			{`(and(\s+then)?|in|mod|not|or(\s+else)|rem)\b`, OperatorWord, nil},
    35  			{`generic|private`, KeywordDeclaration, nil},
    36  			{`package`, KeywordDeclaration, Push("package")},
    37  			{`array\b`, KeywordReserved, Push("array_def")},
    38  			{`(with|use)(\s+)`, ByGroups(KeywordNamespace, Text), Push("import")},
    39  			{`(\w+)(\s*)(:)(\s*)(constant)`, ByGroups(NameConstant, Text, Punctuation, Text, KeywordReserved), nil},
    40  			{`<<\w+>>`, NameLabel, nil},
    41  			{`(\w+)(\s*)(:)(\s*)(declare|begin|loop|for|while)`, ByGroups(NameLabel, Text, Punctuation, Text, KeywordReserved), nil},
    42  			{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},
    43  			{`"[^"]*"`, LiteralString, nil},
    44  			Include("attribute"),
    45  			Include("numbers"),
    46  			{`'[^']'`, LiteralStringChar, nil},
    47  			{`(\w+)(\s*|[(,])`, ByGroups(Name, UsingSelf("root")), nil},
    48  			{`(<>|=>|:=|[()|:;,.'])`, Punctuation, nil},
    49  			{`[*<>+=/&-]`, Operator, nil},
    50  			{`\n+`, Text, nil},
    51  		},
    52  		"numbers": {
    53  			{`[0-9_]+#[0-9a-f]+#`, LiteralNumberHex, nil},
    54  			{`[0-9_]+\.[0-9_]*`, LiteralNumberFloat, nil},
    55  			{`[0-9_]+`, LiteralNumberInteger, nil},
    56  		},
    57  		"attribute": {
    58  			{`(')(\w+)`, ByGroups(Punctuation, NameAttribute), nil},
    59  		},
    60  		"subprogram": {
    61  			{`\(`, Punctuation, Push("#pop", "formal_part")},
    62  			{`;`, Punctuation, Pop(1)},
    63  			{`is\b`, KeywordReserved, Pop(1)},
    64  			{`"[^"]+"|\w+`, NameFunction, nil},
    65  			Include("root"),
    66  		},
    67  		"end": {
    68  			{`(if|case|record|loop|select)`, KeywordReserved, nil},
    69  			{`"[^"]+"|[\w.]+`, NameFunction, nil},
    70  			{`\s+`, Text, nil},
    71  			{`;`, Punctuation, Pop(1)},
    72  		},
    73  		"type_def": {
    74  			{`;`, Punctuation, Pop(1)},
    75  			{`\(`, Punctuation, Push("formal_part")},
    76  			{`with|and|use`, KeywordReserved, nil},
    77  			{`array\b`, KeywordReserved, Push("#pop", "array_def")},
    78  			{`record\b`, KeywordReserved, Push("record_def")},
    79  			{`(null record)(;)`, ByGroups(KeywordReserved, Punctuation), Pop(1)},
    80  			Include("root"),
    81  		},
    82  		"array_def": {
    83  			{`;`, Punctuation, Pop(1)},
    84  			{`(\w+)(\s+)(range)`, ByGroups(KeywordType, Text, KeywordReserved), nil},
    85  			Include("root"),
    86  		},
    87  		"record_def": {
    88  			{`end record`, KeywordReserved, Pop(1)},
    89  			Include("root"),
    90  		},
    91  		"import": {
    92  			{`[\w.]+`, NameNamespace, Pop(1)},
    93  			Default(Pop(1)),
    94  		},
    95  		"formal_part": {
    96  			{`\)`, Punctuation, Pop(1)},
    97  			{`\w+`, NameVariable, nil},
    98  			{`,|:[^=]`, Punctuation, nil},
    99  			{`(in|not|null|out|access)\b`, KeywordReserved, nil},
   100  			Include("root"),
   101  		},
   102  		"package": {
   103  			{`body`, KeywordDeclaration, nil},
   104  			{`is\s+new|renames`, KeywordReserved, nil},
   105  			{`is`, KeywordReserved, Pop(1)},
   106  			{`;`, Punctuation, Pop(1)},
   107  			{`\(`, Punctuation, Push("package_instantiation")},
   108  			{`([\w.]+)`, NameClass, nil},
   109  			Include("root"),
   110  		},
   111  		"package_instantiation": {
   112  			{`("[^"]+"|\w+)(\s+)(=>)`, ByGroups(NameVariable, Text, Punctuation), nil},
   113  			{`[\w.\'"]`, Text, nil},
   114  			{`\)`, Punctuation, Pop(1)},
   115  			Include("root"),
   116  		},
   117  	}
   118  }
   119  

View as plain text