token_registry.def 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // Note that this is an X-macro header.
  6. //
  7. // It does not use `#include` guards, and instead is designed to be `#include`ed
  8. // after some set of x-macros are defined in order for its inclusion to expand
  9. // to the desired output.
  10. //
  11. // The viable X-macros to define prior to including the header are:
  12. //
  13. // - `CARBON_TOKEN`
  14. // - `CARBON_SYMBOL_TOKEN`
  15. // - `CARBON_OPENING_GROUP_SYMBOL_TOKEN`
  16. // - `CARBON_CLOSING_GROUP_SYMBOL_TOKEN`
  17. // - `CARBON_KEYWORD_TOKEN`
  18. //
  19. // This tree represents the subset relationship between these macros.
  20. //
  21. // Regardless of which of these macros is defined prior to inclusion, all of the
  22. // definitions will be removed at the end of including this file to clean up the
  23. // set of defined macros.
  24. #ifndef CARBON_TOKEN
  25. #define CARBON_TOKEN(Name)
  26. #endif
  27. #ifndef CARBON_SYMBOL_TOKEN
  28. #define CARBON_SYMBOL_TOKEN(Name, Spelling) CARBON_TOKEN(Name)
  29. #endif
  30. // Note that symbols need to be ordered from longest to shortest to effectively
  31. // provide max-munch lexing.
  32. // clang-format off
  33. CARBON_SYMBOL_TOKEN(GreaterGreaterEqual, ">>=")
  34. CARBON_SYMBOL_TOKEN(LessEqualGreater, "<=>")
  35. CARBON_SYMBOL_TOKEN(LessLessEqual, "<<=")
  36. CARBON_SYMBOL_TOKEN(AmpEqual, "&=")
  37. CARBON_SYMBOL_TOKEN(CaretEqual, "^=")
  38. CARBON_SYMBOL_TOKEN(ColonEqual, ":=")
  39. CARBON_SYMBOL_TOKEN(EqualEqual, "==")
  40. CARBON_SYMBOL_TOKEN(EqualGreater, "=>")
  41. CARBON_SYMBOL_TOKEN(ExclaimEqual, "!=")
  42. CARBON_SYMBOL_TOKEN(GreaterEqual, ">=")
  43. CARBON_SYMBOL_TOKEN(GreaterGreater, ">>")
  44. CARBON_SYMBOL_TOKEN(LessEqual, "<=")
  45. CARBON_SYMBOL_TOKEN(LessGreater, "<>")
  46. CARBON_SYMBOL_TOKEN(LessLess, "<<")
  47. CARBON_SYMBOL_TOKEN(LessMinus, "<-")
  48. CARBON_SYMBOL_TOKEN(MinusEqual, "-=")
  49. CARBON_SYMBOL_TOKEN(MinusGreater, "->")
  50. CARBON_SYMBOL_TOKEN(MinusMinus, "--")
  51. CARBON_SYMBOL_TOKEN(PercentEqual, "%=")
  52. CARBON_SYMBOL_TOKEN(PipeEqual, "|=")
  53. CARBON_SYMBOL_TOKEN(PlusEqual, "+=")
  54. CARBON_SYMBOL_TOKEN(PlusPlus, "++")
  55. CARBON_SYMBOL_TOKEN(SlashEqual, "/=")
  56. CARBON_SYMBOL_TOKEN(StarEqual, "*=")
  57. CARBON_SYMBOL_TOKEN(TildeEqual, "~=")
  58. CARBON_SYMBOL_TOKEN(Amp, "&")
  59. CARBON_SYMBOL_TOKEN(At, "@")
  60. CARBON_SYMBOL_TOKEN(Backslash, "\\")
  61. CARBON_SYMBOL_TOKEN(Caret, "^")
  62. CARBON_SYMBOL_TOKEN(Colon, ":")
  63. CARBON_SYMBOL_TOKEN(Comma, ",")
  64. CARBON_SYMBOL_TOKEN(Equal, "=")
  65. CARBON_SYMBOL_TOKEN(Exclaim, "!")
  66. CARBON_SYMBOL_TOKEN(Greater, ">")
  67. CARBON_SYMBOL_TOKEN(Less, "<")
  68. CARBON_SYMBOL_TOKEN(Minus, "-")
  69. CARBON_SYMBOL_TOKEN(Percent, "%")
  70. CARBON_SYMBOL_TOKEN(Period, ".")
  71. CARBON_SYMBOL_TOKEN(Pipe, "|")
  72. CARBON_SYMBOL_TOKEN(Plus, "+")
  73. CARBON_SYMBOL_TOKEN(Question, "?")
  74. CARBON_SYMBOL_TOKEN(Semi, ";")
  75. CARBON_SYMBOL_TOKEN(Slash, "/")
  76. CARBON_SYMBOL_TOKEN(Star, "*")
  77. CARBON_SYMBOL_TOKEN(Tilde, "~")
  78. // clang-format on
  79. #ifndef CARBON_OPENING_GROUP_SYMBOL_TOKEN
  80. #define CARBON_OPENING_GROUP_SYMBOL_TOKEN(Name, Spelling, ClosingName) \
  81. CARBON_SYMBOL_TOKEN(Name, Spelling)
  82. #endif
  83. // clang-format on
  84. CARBON_OPENING_GROUP_SYMBOL_TOKEN(OpenParen, "(", CloseParen)
  85. CARBON_OPENING_GROUP_SYMBOL_TOKEN(OpenCurlyBrace, "{", CloseCurlyBrace)
  86. CARBON_OPENING_GROUP_SYMBOL_TOKEN(OpenSquareBracket, "[", CloseSquareBracket)
  87. // clang-format off
  88. #undef CARBON_OPENING_GROUP_SYMBOL_TOKEN
  89. #ifndef CARBON_CLOSING_GROUP_SYMBOL_TOKEN
  90. #define CARBON_CLOSING_GROUP_SYMBOL_TOKEN(Name, Spelling, OpeningName) \
  91. CARBON_SYMBOL_TOKEN(Name, Spelling)
  92. #endif
  93. // clang-format on
  94. CARBON_CLOSING_GROUP_SYMBOL_TOKEN(CloseParen, ")", OpenParen)
  95. CARBON_CLOSING_GROUP_SYMBOL_TOKEN(CloseCurlyBrace, "}", OpenCurlyBrace)
  96. CARBON_CLOSING_GROUP_SYMBOL_TOKEN(CloseSquareBracket, "]", OpenSquareBracket)
  97. // clang-format off
  98. #undef CARBON_CLOSING_GROUP_SYMBOL_TOKEN
  99. #undef CARBON_SYMBOL_TOKEN
  100. #ifndef CARBON_KEYWORD_TOKEN
  101. #define CARBON_KEYWORD_TOKEN(Name, Spelling) CARBON_TOKEN(Name)
  102. #endif
  103. // clang-format off
  104. CARBON_KEYWORD_TOKEN(Abstract, "abstract")
  105. CARBON_KEYWORD_TOKEN(Addr, "addr")
  106. CARBON_KEYWORD_TOKEN(Alias, "alias")
  107. CARBON_KEYWORD_TOKEN(And, "and")
  108. CARBON_KEYWORD_TOKEN(Api, "api")
  109. CARBON_KEYWORD_TOKEN(As, "as")
  110. CARBON_KEYWORD_TOKEN(Auto, "auto")
  111. CARBON_KEYWORD_TOKEN(Base, "base")
  112. CARBON_KEYWORD_TOKEN(Break, "break")
  113. CARBON_KEYWORD_TOKEN(Case, "case")
  114. CARBON_KEYWORD_TOKEN(Class, "class")
  115. CARBON_KEYWORD_TOKEN(Constraint, "constraint")
  116. CARBON_KEYWORD_TOKEN(Continue, "continue")
  117. CARBON_KEYWORD_TOKEN(Default, "default")
  118. CARBON_KEYWORD_TOKEN(Else, "else")
  119. CARBON_KEYWORD_TOKEN(Extends, "extends")
  120. CARBON_KEYWORD_TOKEN(External, "external")
  121. CARBON_KEYWORD_TOKEN(Final, "final")
  122. CARBON_KEYWORD_TOKEN(Fn, "fn")
  123. CARBON_KEYWORD_TOKEN(For, "for")
  124. CARBON_KEYWORD_TOKEN(Friend, "friend")
  125. CARBON_KEYWORD_TOKEN(If, "if")
  126. CARBON_KEYWORD_TOKEN(Impl, "impl")
  127. CARBON_KEYWORD_TOKEN(Import, "import")
  128. CARBON_KEYWORD_TOKEN(Interface, "interface")
  129. CARBON_KEYWORD_TOKEN(Is, "is")
  130. CARBON_KEYWORD_TOKEN(Let, "let")
  131. CARBON_KEYWORD_TOKEN(Library, "library")
  132. CARBON_KEYWORD_TOKEN(Match, "match")
  133. CARBON_KEYWORD_TOKEN(Namespace, "namespace")
  134. CARBON_KEYWORD_TOKEN(Not, "not")
  135. CARBON_KEYWORD_TOKEN(Observe, "observe")
  136. CARBON_KEYWORD_TOKEN(Or, "or")
  137. CARBON_KEYWORD_TOKEN(Override, "override")
  138. CARBON_KEYWORD_TOKEN(Package, "package")
  139. CARBON_KEYWORD_TOKEN(Partial, "partial")
  140. CARBON_KEYWORD_TOKEN(Private, "private")
  141. CARBON_KEYWORD_TOKEN(Protected, "protected")
  142. CARBON_KEYWORD_TOKEN(Return, "return")
  143. CARBON_KEYWORD_TOKEN(Returned, "returned")
  144. CARBON_KEYWORD_TOKEN(Then, "then")
  145. // Underscore is tokenized as a keyword because it's part of identifiers.
  146. CARBON_KEYWORD_TOKEN(Underscore, "_")
  147. CARBON_KEYWORD_TOKEN(Var, "var")
  148. CARBON_KEYWORD_TOKEN(Virtual, "virtual")
  149. CARBON_KEYWORD_TOKEN(Where, "where")
  150. CARBON_KEYWORD_TOKEN(While, "while")
  151. // TODO: In use by precedence.cpp, but not standardized.
  152. CARBON_KEYWORD_TOKEN(Xor, "xor")
  153. // clang-format on
  154. #undef CARBON_KEYWORD_TOKEN
  155. CARBON_TOKEN(Identifier)
  156. CARBON_TOKEN(IntegerLiteral)
  157. CARBON_TOKEN(RealLiteral)
  158. CARBON_TOKEN(StringLiteral)
  159. CARBON_TOKEN(IntegerTypeLiteral)
  160. CARBON_TOKEN(UnsignedIntegerTypeLiteral)
  161. CARBON_TOKEN(FloatingPointTypeLiteral)
  162. CARBON_TOKEN(Error)
  163. CARBON_TOKEN(EndOfFile)
  164. #undef CARBON_TOKEN