token_registry.def 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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(AndKeyword, "and")
  105. CARBON_KEYWORD_TOKEN(AsmKeyword, "asm")
  106. CARBON_KEYWORD_TOKEN(BreakKeyword, "break")
  107. CARBON_KEYWORD_TOKEN(CatchKeyword, "catch")
  108. CARBON_KEYWORD_TOKEN(ClassKeyword, "class")
  109. CARBON_KEYWORD_TOKEN(ContinueKeyword, "continue")
  110. CARBON_KEYWORD_TOKEN(ElseKeyword, "else")
  111. CARBON_KEYWORD_TOKEN(EnumKeyword, "enum")
  112. CARBON_KEYWORD_TOKEN(ExternKeyword, "extern")
  113. CARBON_KEYWORD_TOKEN(FinalKeyword, "final")
  114. CARBON_KEYWORD_TOKEN(FixKeyword, "fix")
  115. CARBON_KEYWORD_TOKEN(FnKeyword, "fn")
  116. CARBON_KEYWORD_TOKEN(ForKeyword, "for")
  117. CARBON_KEYWORD_TOKEN(GuardKeyword, "guard")
  118. CARBON_KEYWORD_TOKEN(IfKeyword, "if")
  119. CARBON_KEYWORD_TOKEN(InlineKeyword, "inline")
  120. CARBON_KEYWORD_TOKEN(InoutKeyword, "inout")
  121. CARBON_KEYWORD_TOKEN(InterfaceKeyword, "interface")
  122. CARBON_KEYWORD_TOKEN(InternalKeyword, "internal")
  123. CARBON_KEYWORD_TOKEN(LetKeyword, "let")
  124. CARBON_KEYWORD_TOKEN(LoopKeyword, "loop")
  125. CARBON_KEYWORD_TOKEN(MatchKeyword, "match")
  126. CARBON_KEYWORD_TOKEN(NotKeyword, "not")
  127. CARBON_KEYWORD_TOKEN(OrKeyword, "or")
  128. CARBON_KEYWORD_TOKEN(OutKeyword, "out")
  129. CARBON_KEYWORD_TOKEN(PrivateKeyword, "private")
  130. CARBON_KEYWORD_TOKEN(ProtectedKeyword, "protected")
  131. CARBON_KEYWORD_TOKEN(PublicKeyword, "public")
  132. CARBON_KEYWORD_TOKEN(RefKeyword, "ref")
  133. CARBON_KEYWORD_TOKEN(ReturnKeyword, "return")
  134. CARBON_KEYWORD_TOKEN(StaticKeyword, "static")
  135. CARBON_KEYWORD_TOKEN(StructKeyword, "struct")
  136. CARBON_KEYWORD_TOKEN(ThrowKeyword, "throw")
  137. CARBON_KEYWORD_TOKEN(TryKeyword, "try")
  138. CARBON_KEYWORD_TOKEN(UnderscoreKeyword, "_")
  139. CARBON_KEYWORD_TOKEN(VarKeyword, "var")
  140. CARBON_KEYWORD_TOKEN(VirtualKeyword, "virtual")
  141. CARBON_KEYWORD_TOKEN(WhileKeyword, "while")
  142. CARBON_KEYWORD_TOKEN(XorKeyword, "xor")
  143. // clang-format on
  144. #undef CARBON_KEYWORD_TOKEN
  145. CARBON_TOKEN(Identifier)
  146. CARBON_TOKEN(IntegerLiteral)
  147. CARBON_TOKEN(RealLiteral)
  148. CARBON_TOKEN(StringLiteral)
  149. CARBON_TOKEN(IntegerTypeLiteral)
  150. CARBON_TOKEN(UnsignedIntegerTypeLiteral)
  151. CARBON_TOKEN(FloatingPointTypeLiteral)
  152. CARBON_TOKEN(Error)
  153. CARBON_TOKEN(EndOfFile)
  154. #undef CARBON_TOKEN