token_kind.def 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. // This is an X-macro header. It does not use `#include` guards, and instead is
  6. // designed to be `#include`ed after the x-macro is defined in order for its
  7. // inclusion to expand to the desired output. Macro definitions are cleaned up
  8. // at the end of this file.
  9. //
  10. // Supported x-macros are:
  11. // - CARBON_TOKEN(Name)
  12. // Defines a token. Used directly when a token needs custom parsing, such as
  13. // integer literals.
  14. // - CARBON_SYMBOL_TOKEN(Name, Spelling)
  15. // Defines a symbol which has the provided spelling, such as `*`. Spellings
  16. // must be unique.
  17. // - CARBON_OPENING_GROUP_SYMBOL_TOKEN(Name, Spelling, ClosingName)
  18. // - CARBON_CLOSING_GROUP_SYMBOL_TOKEN(Name, Spelling, OpeningName)
  19. // These two macros together define matches opening and closing symbols,
  20. // such as `(` and `)`, and create an association between the two.
  21. // - CARBON_KEYWORD_TOKEN(Name, Spelling)
  22. // Defines a keyword which has the provided spelling, such as `if`.
  23. // Spellings must be unique.
  24. //
  25. // This tree represents the subset relationship between these macros, where if a
  26. // specific x-macro isn't defined, it'll fall back to the parent macro.
  27. #ifndef CARBON_TOKEN
  28. #define CARBON_TOKEN(Name)
  29. #endif
  30. #ifndef CARBON_SYMBOL_TOKEN
  31. #define CARBON_SYMBOL_TOKEN(Name, Spelling) CARBON_TOKEN(Name)
  32. #endif
  33. // Note that symbols need to be ordered from longest to shortest to effectively
  34. // provide max-munch lexing.
  35. // clang-format off
  36. CARBON_SYMBOL_TOKEN(GreaterGreaterEqual, ">>=")
  37. CARBON_SYMBOL_TOKEN(LessEqualGreater, "<=>")
  38. CARBON_SYMBOL_TOKEN(LessLessEqual, "<<=")
  39. CARBON_SYMBOL_TOKEN(AmpEqual, "&=")
  40. CARBON_SYMBOL_TOKEN(CaretEqual, "^=")
  41. CARBON_SYMBOL_TOKEN(ColonEqual, ":=")
  42. CARBON_SYMBOL_TOKEN(ColonExclaim, ":!")
  43. CARBON_SYMBOL_TOKEN(EqualEqual, "==")
  44. CARBON_SYMBOL_TOKEN(EqualGreater, "=>")
  45. CARBON_SYMBOL_TOKEN(ExclaimEqual, "!=")
  46. CARBON_SYMBOL_TOKEN(GreaterEqual, ">=")
  47. CARBON_SYMBOL_TOKEN(GreaterGreater, ">>")
  48. CARBON_SYMBOL_TOKEN(LessEqual, "<=")
  49. CARBON_SYMBOL_TOKEN(LessGreater, "<>")
  50. CARBON_SYMBOL_TOKEN(LessLess, "<<")
  51. CARBON_SYMBOL_TOKEN(LessMinus, "<-")
  52. CARBON_SYMBOL_TOKEN(MinusEqual, "-=")
  53. CARBON_SYMBOL_TOKEN(MinusGreater, "->")
  54. CARBON_SYMBOL_TOKEN(MinusMinus, "--")
  55. CARBON_SYMBOL_TOKEN(PercentEqual, "%=")
  56. CARBON_SYMBOL_TOKEN(PipeEqual, "|=")
  57. CARBON_SYMBOL_TOKEN(PlusEqual, "+=")
  58. CARBON_SYMBOL_TOKEN(PlusPlus, "++")
  59. CARBON_SYMBOL_TOKEN(SlashEqual, "/=")
  60. CARBON_SYMBOL_TOKEN(StarEqual, "*=")
  61. CARBON_SYMBOL_TOKEN(TildeEqual, "~=")
  62. CARBON_SYMBOL_TOKEN(Amp, "&")
  63. CARBON_SYMBOL_TOKEN(At, "@")
  64. CARBON_SYMBOL_TOKEN(Backslash, "\\")
  65. CARBON_SYMBOL_TOKEN(Caret, "^")
  66. CARBON_SYMBOL_TOKEN(Colon, ":")
  67. CARBON_SYMBOL_TOKEN(Comma, ",")
  68. CARBON_SYMBOL_TOKEN(Equal, "=")
  69. CARBON_SYMBOL_TOKEN(Exclaim, "!")
  70. CARBON_SYMBOL_TOKEN(Greater, ">")
  71. CARBON_SYMBOL_TOKEN(Less, "<")
  72. CARBON_SYMBOL_TOKEN(Minus, "-")
  73. CARBON_SYMBOL_TOKEN(Percent, "%")
  74. CARBON_SYMBOL_TOKEN(Period, ".")
  75. CARBON_SYMBOL_TOKEN(Pipe, "|")
  76. CARBON_SYMBOL_TOKEN(Plus, "+")
  77. CARBON_SYMBOL_TOKEN(Question, "?")
  78. CARBON_SYMBOL_TOKEN(Semi, ";")
  79. CARBON_SYMBOL_TOKEN(Slash, "/")
  80. CARBON_SYMBOL_TOKEN(Star, "*")
  81. CARBON_SYMBOL_TOKEN(Tilde, "~")
  82. // clang-format on
  83. #ifndef CARBON_OPENING_GROUP_SYMBOL_TOKEN
  84. #define CARBON_OPENING_GROUP_SYMBOL_TOKEN(Name, Spelling, ClosingName) \
  85. CARBON_SYMBOL_TOKEN(Name, Spelling)
  86. #endif
  87. CARBON_OPENING_GROUP_SYMBOL_TOKEN(OpenParen, "(", CloseParen)
  88. CARBON_OPENING_GROUP_SYMBOL_TOKEN(OpenCurlyBrace, "{", CloseCurlyBrace)
  89. CARBON_OPENING_GROUP_SYMBOL_TOKEN(OpenSquareBracket, "[", CloseSquareBracket)
  90. #undef CARBON_OPENING_GROUP_SYMBOL_TOKEN
  91. #ifndef CARBON_CLOSING_GROUP_SYMBOL_TOKEN
  92. #define CARBON_CLOSING_GROUP_SYMBOL_TOKEN(Name, Spelling, OpeningName) \
  93. CARBON_SYMBOL_TOKEN(Name, Spelling)
  94. #endif
  95. CARBON_CLOSING_GROUP_SYMBOL_TOKEN(CloseParen, ")", OpenParen)
  96. CARBON_CLOSING_GROUP_SYMBOL_TOKEN(CloseCurlyBrace, "}", OpenCurlyBrace)
  97. CARBON_CLOSING_GROUP_SYMBOL_TOKEN(CloseSquareBracket, "]", OpenSquareBracket)
  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(Impls, "impls")
  128. CARBON_KEYWORD_TOKEN(Import, "import")
  129. CARBON_KEYWORD_TOKEN(In, "in")
  130. CARBON_KEYWORD_TOKEN(Interface, "interface")
  131. CARBON_KEYWORD_TOKEN(Is, "is")
  132. CARBON_KEYWORD_TOKEN(Let, "let")
  133. CARBON_KEYWORD_TOKEN(Library, "library")
  134. CARBON_KEYWORD_TOKEN(Match, "match")
  135. CARBON_KEYWORD_TOKEN(Namespace, "namespace")
  136. CARBON_KEYWORD_TOKEN(Not, "not")
  137. CARBON_KEYWORD_TOKEN(Observe, "observe")
  138. CARBON_KEYWORD_TOKEN(Or, "or")
  139. CARBON_KEYWORD_TOKEN(Override, "override")
  140. CARBON_KEYWORD_TOKEN(Package, "package")
  141. CARBON_KEYWORD_TOKEN(Partial, "partial")
  142. CARBON_KEYWORD_TOKEN(Private, "private")
  143. CARBON_KEYWORD_TOKEN(Protected, "protected")
  144. CARBON_KEYWORD_TOKEN(Return, "return")
  145. CARBON_KEYWORD_TOKEN(Returned, "returned")
  146. CARBON_KEYWORD_TOKEN(SelfTypeIdentifier, "Self")
  147. CARBON_KEYWORD_TOKEN(SelfValueIdentifier, "self")
  148. // TODO: Although we provide a String type literal, it's not standardized.
  149. CARBON_KEYWORD_TOKEN(StringTypeLiteral, "String")
  150. CARBON_KEYWORD_TOKEN(Template, "template")
  151. CARBON_KEYWORD_TOKEN(Then, "then")
  152. // Underscore is tokenized as a keyword because it's part of identifiers.
  153. CARBON_KEYWORD_TOKEN(Underscore, "_")
  154. CARBON_KEYWORD_TOKEN(Var, "var")
  155. CARBON_KEYWORD_TOKEN(Virtual, "virtual")
  156. CARBON_KEYWORD_TOKEN(Where, "where")
  157. CARBON_KEYWORD_TOKEN(While, "while")
  158. // TODO: In use by precedence.cpp, but not standardized.
  159. CARBON_KEYWORD_TOKEN(Xor, "xor")
  160. // clang-format on
  161. #undef CARBON_KEYWORD_TOKEN
  162. CARBON_TOKEN(Identifier)
  163. CARBON_TOKEN(IntegerLiteral)
  164. CARBON_TOKEN(RealLiteral)
  165. CARBON_TOKEN(StringLiteral)
  166. CARBON_TOKEN(IntegerTypeLiteral)
  167. CARBON_TOKEN(UnsignedIntegerTypeLiteral)
  168. CARBON_TOKEN(FloatingPointTypeLiteral)
  169. CARBON_TOKEN(Error)
  170. CARBON_TOKEN(EndOfFile)
  171. #undef CARBON_TOKEN