as_tokendef.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. /*
  2. AngelCode Scripting Library
  3. Copyright (c) 2003-2019 Andreas Jonsson
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any
  6. damages arising from the use of this software.
  7. Permission is granted to anyone to use this software for any
  8. purpose, including commercial applications, and to alter it and
  9. redistribute it freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you
  11. must not claim that you wrote the original software. If you use
  12. this software in a product, an acknowledgment in the product
  13. documentation would be appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and
  15. must not be misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source
  17. distribution.
  18. The original version of this library can be located at:
  19. http://www.angelcode.com/angelscript/
  20. Andreas Jonsson
  21. andreas@angelcode.com
  22. */
  23. //
  24. // as_tokendef.h
  25. //
  26. // Definitions for tokens identifiable by the tokenizer
  27. //
  28. #ifndef AS_TOKENDEF_H
  29. #define AS_TOKENDEF_H
  30. #include "as_config.h"
  31. BEGIN_AS_NAMESPACE
  32. enum eTokenType
  33. {
  34. ttUnrecognizedToken,
  35. ttEnd, // End of file
  36. // White space and comments
  37. ttWhiteSpace, // ' ', '\t', '\r', '\n', UTF8 byte-order-mark
  38. ttOnelineComment, // // \n
  39. ttMultilineComment, // /* */
  40. // Atoms
  41. ttIdentifier, // abc123
  42. ttIntConstant, // 1234
  43. ttFloatConstant, // 12.34e56f
  44. ttDoubleConstant, // 12.34e56
  45. ttStringConstant, // "123"
  46. ttMultilineStringConstant, //
  47. ttHeredocStringConstant, // """text"""
  48. ttNonTerminatedStringConstant, // "123
  49. ttBitsConstant, // 0xFFFF
  50. // Math operators
  51. ttPlus, // +
  52. ttMinus, // -
  53. ttStar, // *
  54. ttSlash, // /
  55. ttPercent, // %
  56. ttStarStar, // **
  57. ttHandle, // @
  58. ttAddAssign, // +=
  59. ttSubAssign, // -=
  60. ttMulAssign, // *=
  61. ttDivAssign, // /=
  62. ttModAssign, // %=
  63. ttPowAssign, // **=
  64. ttOrAssign, // |=
  65. ttAndAssign, // &=
  66. ttXorAssign, // ^=
  67. ttShiftLeftAssign, // <<=
  68. ttShiftRightLAssign, // >>=
  69. ttShiftRightAAssign, // >>>=
  70. ttInc, // ++
  71. ttDec, // --
  72. ttDot, // .
  73. ttScope, // ::
  74. // Statement tokens
  75. ttAssignment, // =
  76. ttEndStatement, // ;
  77. ttListSeparator, // ,
  78. ttStartStatementBlock, // {
  79. ttEndStatementBlock, // }
  80. ttOpenParanthesis, // (
  81. ttCloseParanthesis, // )
  82. ttOpenBracket, // [
  83. ttCloseBracket, // ]
  84. ttAmp, // &
  85. // Bitwise operators
  86. ttBitOr, // |
  87. ttBitNot, // ~
  88. ttBitXor, // ^
  89. ttBitShiftLeft, // <<
  90. ttBitShiftRight, // >> // TODO: In Java this is the arithmetical shift
  91. ttBitShiftRightArith, // >>> // TODO: In Java this is the logical shift
  92. // Compare operators
  93. ttEqual, // ==
  94. ttNotEqual, // !=
  95. ttLessThan, // <
  96. ttGreaterThan, // >
  97. ttLessThanOrEqual, // <=
  98. ttGreaterThanOrEqual, // >=
  99. ttQuestion, // ?
  100. ttColon, // :
  101. // Reserved keywords
  102. ttIf, // if
  103. ttElse, // else
  104. ttFor, // for
  105. ttWhile, // while
  106. ttBool, // bool
  107. ttFuncDef, // funcdef
  108. ttImport, // import
  109. ttInt, // int
  110. ttInt8, // int8
  111. ttInt16, // int16
  112. ttInt64, // int64
  113. ttInterface, // interface
  114. ttIs, // is
  115. ttNotIs, // !is
  116. ttUInt, // uint
  117. ttUInt8, // uint8
  118. ttUInt16, // uint16
  119. ttUInt64, // uint64
  120. ttFloat, // float
  121. ttVoid, // void
  122. ttTrue, // true
  123. ttFalse, // false
  124. ttReturn, // return
  125. ttNot, // not
  126. ttAnd, // and, &&
  127. ttOr, // or, ||
  128. ttXor, // xor, ^^
  129. ttBreak, // break
  130. ttContinue, // continue
  131. ttConst, // const
  132. ttDo, // do
  133. ttDouble, // double
  134. ttSwitch, // switch
  135. ttCase, // case
  136. ttDefault, // default
  137. ttIn, // in
  138. ttOut, // out
  139. ttInOut, // inout
  140. ttNull, // null
  141. ttClass, // class
  142. ttTypedef, // typedef
  143. ttEnum, // enum
  144. ttCast, // cast
  145. ttPrivate, // private
  146. ttProtected, // protected
  147. ttNamespace, // namespace
  148. ttMixin, // mixin
  149. ttAuto, // auto
  150. ttTry, // try
  151. ttCatch // catch
  152. };
  153. struct sTokenWord
  154. {
  155. const char *word;
  156. size_t wordLength;
  157. eTokenType tokenType;
  158. };
  159. #define asTokenDef(str, tok) {str, sizeof(str)-1, tok}
  160. sTokenWord const tokenWords[] =
  161. {
  162. asTokenDef("+" , ttPlus),
  163. asTokenDef("+=" , ttAddAssign),
  164. asTokenDef("++" , ttInc),
  165. asTokenDef("-" , ttMinus),
  166. asTokenDef("-=" , ttSubAssign),
  167. asTokenDef("--" , ttDec),
  168. asTokenDef("*" , ttStar),
  169. asTokenDef("*=" , ttMulAssign),
  170. asTokenDef("/" , ttSlash),
  171. asTokenDef("/=" , ttDivAssign),
  172. asTokenDef("%" , ttPercent),
  173. asTokenDef("%=" , ttModAssign),
  174. asTokenDef("**" , ttStarStar),
  175. asTokenDef("**=" , ttPowAssign),
  176. asTokenDef("=" , ttAssignment),
  177. asTokenDef("==" , ttEqual),
  178. asTokenDef("." , ttDot),
  179. asTokenDef("|" , ttBitOr),
  180. asTokenDef("|=" , ttOrAssign),
  181. asTokenDef("||" , ttOr),
  182. asTokenDef("&" , ttAmp),
  183. asTokenDef("&=" , ttAndAssign),
  184. asTokenDef("&&" , ttAnd),
  185. asTokenDef("^" , ttBitXor),
  186. asTokenDef("^=" , ttXorAssign),
  187. asTokenDef("^^" , ttXor),
  188. asTokenDef("<" , ttLessThan),
  189. asTokenDef("<=" , ttLessThanOrEqual),
  190. asTokenDef("<<" , ttBitShiftLeft),
  191. asTokenDef("<<=" , ttShiftLeftAssign),
  192. asTokenDef(">" , ttGreaterThan),
  193. asTokenDef(">=" , ttGreaterThanOrEqual),
  194. asTokenDef(">>" , ttBitShiftRight),
  195. asTokenDef(">>=" , ttShiftRightLAssign),
  196. asTokenDef(">>>" , ttBitShiftRightArith),
  197. asTokenDef(">>>=" , ttShiftRightAAssign),
  198. asTokenDef("~" , ttBitNot),
  199. asTokenDef(";" , ttEndStatement),
  200. asTokenDef("," , ttListSeparator),
  201. asTokenDef("{" , ttStartStatementBlock),
  202. asTokenDef("}" , ttEndStatementBlock),
  203. asTokenDef("(" , ttOpenParanthesis),
  204. asTokenDef(")" , ttCloseParanthesis),
  205. asTokenDef("[" , ttOpenBracket),
  206. asTokenDef("]" , ttCloseBracket),
  207. asTokenDef("?" , ttQuestion),
  208. asTokenDef(":" , ttColon),
  209. asTokenDef("::" , ttScope),
  210. asTokenDef("!" , ttNot),
  211. asTokenDef("!=" , ttNotEqual),
  212. asTokenDef("!is" , ttNotIs),
  213. asTokenDef("@" , ttHandle),
  214. asTokenDef("and" , ttAnd),
  215. asTokenDef("auto" , ttAuto),
  216. asTokenDef("bool" , ttBool),
  217. asTokenDef("break" , ttBreak),
  218. asTokenDef("case" , ttCase),
  219. asTokenDef("cast" , ttCast),
  220. asTokenDef("catch" , ttCatch),
  221. asTokenDef("class" , ttClass),
  222. asTokenDef("const" , ttConst),
  223. asTokenDef("continue" , ttContinue),
  224. asTokenDef("default" , ttDefault),
  225. asTokenDef("do" , ttDo),
  226. #ifdef AS_USE_DOUBLE_AS_FLOAT
  227. asTokenDef("double" , ttFloat),
  228. #else
  229. asTokenDef("double" , ttDouble),
  230. #endif
  231. asTokenDef("else" , ttElse),
  232. asTokenDef("enum" , ttEnum),
  233. asTokenDef("false" , ttFalse),
  234. asTokenDef("float" , ttFloat),
  235. asTokenDef("for" , ttFor),
  236. asTokenDef("funcdef" , ttFuncDef),
  237. asTokenDef("if" , ttIf),
  238. asTokenDef("import" , ttImport),
  239. asTokenDef("in" , ttIn),
  240. asTokenDef("inout" , ttInOut),
  241. asTokenDef("int" , ttInt),
  242. asTokenDef("int8" , ttInt8),
  243. asTokenDef("int16" , ttInt16),
  244. asTokenDef("int32" , ttInt),
  245. asTokenDef("int64" , ttInt64),
  246. asTokenDef("interface" , ttInterface),
  247. asTokenDef("is" , ttIs),
  248. asTokenDef("mixin" , ttMixin),
  249. asTokenDef("namespace" , ttNamespace),
  250. asTokenDef("not" , ttNot),
  251. asTokenDef("null" , ttNull),
  252. asTokenDef("or" , ttOr),
  253. asTokenDef("out" , ttOut),
  254. asTokenDef("private" , ttPrivate),
  255. asTokenDef("protected" , ttProtected),
  256. asTokenDef("return" , ttReturn),
  257. asTokenDef("switch" , ttSwitch),
  258. asTokenDef("true" , ttTrue),
  259. asTokenDef("try" , ttTry),
  260. asTokenDef("typedef" , ttTypedef),
  261. asTokenDef("uint" , ttUInt),
  262. asTokenDef("uint8" , ttUInt8),
  263. asTokenDef("uint16" , ttUInt16),
  264. asTokenDef("uint32" , ttUInt),
  265. asTokenDef("uint64" , ttUInt64),
  266. asTokenDef("void" , ttVoid),
  267. asTokenDef("while" , ttWhile),
  268. asTokenDef("xor" , ttXor),
  269. };
  270. const unsigned int numTokenWords = sizeof(tokenWords)/sizeof(sTokenWord);
  271. const char * const whiteSpace = " \t\r\n";
  272. // Some keywords that are not considered tokens by the parser
  273. // These only have meaning in specific situations. Outside these
  274. // situations they are treated as normal identifiers.
  275. const char * const THIS_TOKEN = "this";
  276. const char * const FROM_TOKEN = "from";
  277. const char * const SUPER_TOKEN = "super";
  278. const char * const SHARED_TOKEN = "shared";
  279. const char * const FINAL_TOKEN = "final";
  280. const char * const OVERRIDE_TOKEN = "override";
  281. const char * const GET_TOKEN = "get";
  282. const char * const SET_TOKEN = "set";
  283. const char * const ABSTRACT_TOKEN = "abstract";
  284. const char * const FUNCTION_TOKEN = "function";
  285. const char * const IF_HANDLE_TOKEN = "if_handle_then_const";
  286. const char * const EXTERNAL_TOKEN = "external";
  287. const char * const EXPLICIT_TOKEN = "explicit";
  288. const char * const PROPERTY_TOKEN = "property";
  289. END_AS_NAMESPACE
  290. #endif