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.

ada.go 4.7KB

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