dub 0.2.2 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of dub might be problematic. Click here for more details.

Files changed (277) hide show
  1. data/History.txt +92 -0
  2. data/LICENSE +20 -0
  3. data/README.rdoc +115 -0
  4. data/Rakefile +59 -0
  5. data/dub.gemspec +197 -0
  6. data/lib/dub/argument.rb +286 -0
  7. data/lib/dub/entities_unescape.rb +9 -0
  8. data/lib/dub/function.rb +177 -0
  9. data/lib/dub/function_group.rb +72 -0
  10. data/lib/dub/generator.rb +15 -0
  11. data/lib/dub/group.rb +20 -0
  12. data/lib/dub/klass.rb +338 -0
  13. data/lib/dub/lua/class.cpp.erb +114 -0
  14. data/lib/dub/lua/class_gen.rb +96 -0
  15. data/lib/dub/lua/function.cpp.erb +15 -0
  16. data/lib/dub/lua/function_gen.rb +329 -0
  17. data/lib/dub/lua/group.cpp.erb +9 -0
  18. data/lib/dub/lua/lua_cpp_helper.cpp +259 -0
  19. data/lib/dub/lua/lua_cpp_helper.h +219 -0
  20. data/lib/dub/lua/lua_object.cpp +158 -0
  21. data/lib/dub/lua/lua_object.h +69 -0
  22. data/lib/dub/lua/namespace.cpp.erb +42 -0
  23. data/lib/dub/lua/namespace_gen.rb +69 -0
  24. data/lib/dub/lua.rb +24 -0
  25. data/lib/dub/member_extraction.rb +128 -0
  26. data/lib/dub/namespace.rb +295 -0
  27. data/lib/dub/opts_parser.rb +30 -0
  28. data/lib/dub/parser.rb +46 -0
  29. data/lib/dub/templates/lua_template.erb +21 -0
  30. data/lib/dub/version.rb +3 -0
  31. data/lib/dub.rb +24 -20
  32. data/test/argument_test.rb +581 -0
  33. data/test/fixtures/app/CMakeLists.txt +54 -0
  34. data/test/fixtures/app/Doxyfile +1600 -0
  35. data/test/fixtures/app/bindings/all_lua.cpp +299 -0
  36. data/test/fixtures/app/include/matrix.h +283 -0
  37. data/test/fixtures/app/make_lua_bindings.rb +13 -0
  38. data/test/fixtures/app/vendor/lua/CMakeLists.txt +25 -0
  39. data/test/fixtures/app/vendor/lua/COPYRIGHT +34 -0
  40. data/test/fixtures/app/vendor/lua/HISTORY +183 -0
  41. data/test/fixtures/app/vendor/lua/INSTALL +99 -0
  42. data/test/fixtures/app/vendor/lua/Makefile +183 -0
  43. data/test/fixtures/app/vendor/lua/README +37 -0
  44. data/test/fixtures/app/vendor/lua/lapi.c +1080 -0
  45. data/test/fixtures/app/vendor/lua/lapi.h +16 -0
  46. data/test/fixtures/app/vendor/lua/lauxlib.c +653 -0
  47. data/test/fixtures/app/vendor/lua/lauxlib.h +174 -0
  48. data/test/fixtures/app/vendor/lua/lbaselib.c +643 -0
  49. data/test/fixtures/app/vendor/lua/lcode.c +839 -0
  50. data/test/fixtures/app/vendor/lua/lcode.h +76 -0
  51. data/test/fixtures/app/vendor/lua/ldblib.c +397 -0
  52. data/test/fixtures/app/vendor/lua/ldebug.c +622 -0
  53. data/test/fixtures/app/vendor/lua/ldebug.h +33 -0
  54. data/test/fixtures/app/vendor/lua/ldo.c +516 -0
  55. data/test/fixtures/app/vendor/lua/ldo.h +57 -0
  56. data/test/fixtures/app/vendor/lua/ldump.c +164 -0
  57. data/test/fixtures/app/vendor/lua/lfunc.c +174 -0
  58. data/test/fixtures/app/vendor/lua/lfunc.h +34 -0
  59. data/test/fixtures/app/vendor/lua/lgc.c +711 -0
  60. data/test/fixtures/app/vendor/lua/lgc.h +110 -0
  61. data/test/fixtures/app/vendor/lua/liblua.a +0 -0
  62. data/test/fixtures/app/vendor/lua/linit.c +38 -0
  63. data/test/fixtures/app/vendor/lua/liolib.c +532 -0
  64. data/test/fixtures/app/vendor/lua/llex.c +461 -0
  65. data/test/fixtures/app/vendor/lua/llex.h +81 -0
  66. data/test/fixtures/app/vendor/lua/llimits.h +128 -0
  67. data/test/fixtures/app/vendor/lua/lmathlib.c +263 -0
  68. data/test/fixtures/app/vendor/lua/lmem.c +86 -0
  69. data/test/fixtures/app/vendor/lua/lmem.h +49 -0
  70. data/test/fixtures/app/vendor/lua/loadlib.c +664 -0
  71. data/test/fixtures/app/vendor/lua/lobject.c +214 -0
  72. data/test/fixtures/app/vendor/lua/lobject.h +381 -0
  73. data/test/fixtures/app/vendor/lua/lopcodes.c +102 -0
  74. data/test/fixtures/app/vendor/lua/lopcodes.h +268 -0
  75. data/test/fixtures/app/vendor/lua/loslib.c +244 -0
  76. data/test/fixtures/app/vendor/lua/lparser.c +1337 -0
  77. data/test/fixtures/app/vendor/lua/lparser.h +82 -0
  78. data/test/fixtures/app/vendor/lua/lstate.c +214 -0
  79. data/test/fixtures/app/vendor/lua/lstate.h +168 -0
  80. data/test/fixtures/app/vendor/lua/lstring.c +111 -0
  81. data/test/fixtures/app/vendor/lua/lstring.h +31 -0
  82. data/test/fixtures/app/vendor/lua/lstrlib.c +868 -0
  83. data/test/fixtures/app/vendor/lua/ltable.c +588 -0
  84. data/test/fixtures/app/vendor/lua/ltable.h +40 -0
  85. data/test/fixtures/app/vendor/lua/ltablib.c +278 -0
  86. data/test/fixtures/app/vendor/lua/ltm.c +75 -0
  87. data/test/fixtures/app/vendor/lua/ltm.h +54 -0
  88. data/test/fixtures/app/vendor/lua/lua.c +695 -0
  89. data/test/fixtures/app/vendor/lua/lua.h +385 -0
  90. data/test/fixtures/app/vendor/lua/lua_dub_helper.h +77 -0
  91. data/test/fixtures/app/vendor/lua/luac +0 -0
  92. data/test/fixtures/app/vendor/lua/luac.c +200 -0
  93. data/test/fixtures/app/vendor/lua/luaconf.h +762 -0
  94. data/test/fixtures/app/vendor/lua/lualib.h +53 -0
  95. data/test/fixtures/app/vendor/lua/lundump.c +223 -0
  96. data/test/fixtures/app/vendor/lua/lundump.h +36 -0
  97. data/test/fixtures/app/vendor/lua/lvm.c +765 -0
  98. data/test/fixtures/app/vendor/lua/lvm.h +36 -0
  99. data/test/fixtures/app/vendor/lua/lzio.c +82 -0
  100. data/test/fixtures/app/vendor/lua/lzio.h +67 -0
  101. data/test/fixtures/app/vendor/lua/matrix.h +102 -0
  102. data/test/fixtures/app/vendor/lua/print.c +227 -0
  103. data/test/fixtures/app/vendor/lua/test/README +26 -0
  104. data/test/fixtures/app/vendor/lua/test/bisect.lua +27 -0
  105. data/test/fixtures/app/vendor/lua/test/cf.lua +16 -0
  106. data/test/fixtures/app/vendor/lua/test/echo.lua +5 -0
  107. data/test/fixtures/app/vendor/lua/test/env.lua +7 -0
  108. data/test/fixtures/app/vendor/lua/test/factorial.lua +32 -0
  109. data/test/fixtures/app/vendor/lua/test/fib.lua +40 -0
  110. data/test/fixtures/app/vendor/lua/test/fibfor.lua +13 -0
  111. data/test/fixtures/app/vendor/lua/test/globals.lua +13 -0
  112. data/test/fixtures/app/vendor/lua/test/hello.lua +3 -0
  113. data/test/fixtures/app/vendor/lua/test/life.lua +111 -0
  114. data/test/fixtures/app/vendor/lua/test/luac.lua +7 -0
  115. data/test/fixtures/app/vendor/lua/test/printf.lua +7 -0
  116. data/test/fixtures/app/vendor/lua/test/readonly.lua +12 -0
  117. data/test/fixtures/app/vendor/lua/test/sieve.lua +29 -0
  118. data/test/fixtures/app/vendor/lua/test/sort.lua +66 -0
  119. data/test/fixtures/app/vendor/lua/test/table.lua +12 -0
  120. data/test/fixtures/app/vendor/lua/test/trace-calls.lua +32 -0
  121. data/test/fixtures/app/vendor/lua/test/trace-globals.lua +38 -0
  122. data/test/fixtures/app/vendor/lua/test/xd.lua +14 -0
  123. data/test/fixtures/app/xml/classdub_1_1_base.xml +85 -0
  124. data/test/fixtures/app/xml/classdub_1_1_custom_destructor.xml +67 -0
  125. data/test/fixtures/app/xml/classdub_1_1_deletable_out_of_lua.xml +43 -0
  126. data/test/fixtures/app/xml/classdub_1_1_matrix.xml +482 -0
  127. data/test/fixtures/app/xml/classdub_1_1_no_destructor.xml +49 -0
  128. data/test/fixtures/app/xml/classdub_1_1_priv_sub_base.xml +89 -0
  129. data/test/fixtures/app/xml/classdub_1_1_private_constr.xml +68 -0
  130. data/test/fixtures/app/xml/classdub_1_1_static_constr.xml +69 -0
  131. data/test/fixtures/app/xml/classdub_1_1_sub_base.xml +89 -0
  132. data/test/fixtures/app/xml/classdub_1_1_t_mat.xml +252 -0
  133. data/test/fixtures/app/xml/combine.xslt +15 -0
  134. data/test/fixtures/app/xml/compound.xsd +814 -0
  135. data/test/fixtures/app/xml/dir_53661a2bdeb1d55e60581a7e15deb763.xml +12 -0
  136. data/test/fixtures/app/xml/index.xml +91 -0
  137. data/test/fixtures/app/xml/index.xsd +66 -0
  138. data/test/fixtures/app/xml/matrix_8h.xml +310 -0
  139. data/test/fixtures/app/xml/namespacedub.xml +48 -0
  140. data/test/fixtures/classcv_1_1_mat.xml +1996 -0
  141. data/test/fixtures/classcv_1_1_point__.xml +341 -0
  142. data/test/fixtures/classcv_1_1_scalar__.xml +269 -0
  143. data/test/fixtures/classcv_1_1_size__.xml +270 -0
  144. data/test/fixtures/dummy_class.cpp.erb +1 -0
  145. data/test/fixtures/dummy_function.cpp.erb +1 -0
  146. data/test/fixtures/group___magic_type.xml +406 -0
  147. data/test/fixtures/namespacecv.xml +12659 -0
  148. data/test/function_group_test.rb +43 -0
  149. data/test/function_test.rb +405 -0
  150. data/test/group_test.rb +241 -0
  151. data/test/helper.rb +34 -0
  152. data/test/klass_test.rb +551 -0
  153. data/test/lua_function_gen_test.rb +242 -0
  154. data/test/namespace_test.rb +220 -0
  155. data/test/parser_test.rb +36 -0
  156. metadata +229 -272
  157. checksums.yaml +0 -7
  158. data/lib/open_api_sdk/analytics.rb +0 -99
  159. data/lib/open_api_sdk/domains.rb +0 -353
  160. data/lib/open_api_sdk/dub.rb +0 -88
  161. data/lib/open_api_sdk/links.rb +0 -766
  162. data/lib/open_api_sdk/metatags.rb +0 -54
  163. data/lib/open_api_sdk/models/operations/bulkcreatelinks_response.rb +0 -60
  164. data/lib/open_api_sdk/models/operations/bulkupdatelinks_requestbody.rb +0 -27
  165. data/lib/open_api_sdk/models/operations/bulkupdatelinks_response.rb +0 -60
  166. data/lib/open_api_sdk/models/operations/color.rb +0 -24
  167. data/lib/open_api_sdk/models/operations/createdomain_requestbody.rb +0 -33
  168. data/lib/open_api_sdk/models/operations/createdomain_response.rb +0 -60
  169. data/lib/open_api_sdk/models/operations/createlink_requestbody.rb +0 -95
  170. data/lib/open_api_sdk/models/operations/createlink_response.rb +0 -60
  171. data/lib/open_api_sdk/models/operations/createtag_requestbody.rb +0 -32
  172. data/lib/open_api_sdk/models/operations/createtag_response.rb +0 -60
  173. data/lib/open_api_sdk/models/operations/data.rb +0 -83
  174. data/lib/open_api_sdk/models/operations/deletedomain_request.rb +0 -24
  175. data/lib/open_api_sdk/models/operations/deletedomain_response.rb +0 -60
  176. data/lib/open_api_sdk/models/operations/deletedomain_responsebody.rb +0 -24
  177. data/lib/open_api_sdk/models/operations/deletelink_request.rb +0 -24
  178. data/lib/open_api_sdk/models/operations/deletelink_response.rb +0 -60
  179. data/lib/open_api_sdk/models/operations/deletelink_responsebody.rb +0 -24
  180. data/lib/open_api_sdk/models/operations/event.rb +0 -21
  181. data/lib/open_api_sdk/models/operations/getlinkinfo_request.rb +0 -33
  182. data/lib/open_api_sdk/models/operations/getlinkinfo_response.rb +0 -60
  183. data/lib/open_api_sdk/models/operations/getlinks_request.rb +0 -51
  184. data/lib/open_api_sdk/models/operations/getlinks_response.rb +0 -60
  185. data/lib/open_api_sdk/models/operations/getlinkscount_request.rb +0 -48
  186. data/lib/open_api_sdk/models/operations/getlinkscount_response.rb +0 -60
  187. data/lib/open_api_sdk/models/operations/getmetatags_request.rb +0 -24
  188. data/lib/open_api_sdk/models/operations/getmetatags_response.rb +0 -33
  189. data/lib/open_api_sdk/models/operations/getmetatags_responsebody.rb +0 -30
  190. data/lib/open_api_sdk/models/operations/getqrcode_request.rb +0 -39
  191. data/lib/open_api_sdk/models/operations/getqrcode_response.rb +0 -60
  192. data/lib/open_api_sdk/models/operations/gettags_response.rb +0 -60
  193. data/lib/open_api_sdk/models/operations/getworkspace_request.rb +0 -24
  194. data/lib/open_api_sdk/models/operations/getworkspace_response.rb +0 -60
  195. data/lib/open_api_sdk/models/operations/groupby.rb +0 -28
  196. data/lib/open_api_sdk/models/operations/interval.rb +0 -25
  197. data/lib/open_api_sdk/models/operations/level.rb +0 -21
  198. data/lib/open_api_sdk/models/operations/listdomains_response.rb +0 -60
  199. data/lib/open_api_sdk/models/operations/paymentprocessor.rb +0 -20
  200. data/lib/open_api_sdk/models/operations/requestbody.rb +0 -95
  201. data/lib/open_api_sdk/models/operations/retrieveanalytics_request.rb +0 -81
  202. data/lib/open_api_sdk/models/operations/retrieveanalytics_response.rb +0 -60
  203. data/lib/open_api_sdk/models/operations/sort.rb +0 -20
  204. data/lib/open_api_sdk/models/operations/trackcustomer_requestbody.rb +0 -33
  205. data/lib/open_api_sdk/models/operations/trackcustomer_response.rb +0 -60
  206. data/lib/open_api_sdk/models/operations/trackcustomer_responsebody.rb +0 -33
  207. data/lib/open_api_sdk/models/operations/tracklead_requestbody.rb +0 -42
  208. data/lib/open_api_sdk/models/operations/tracklead_response.rb +0 -60
  209. data/lib/open_api_sdk/models/operations/tracklead_responsebody.rb +0 -42
  210. data/lib/open_api_sdk/models/operations/tracksale_requestbody.rb +0 -42
  211. data/lib/open_api_sdk/models/operations/tracksale_response.rb +0 -60
  212. data/lib/open_api_sdk/models/operations/tracksale_responsebody.rb +0 -42
  213. data/lib/open_api_sdk/models/operations/updatedomain_request.rb +0 -27
  214. data/lib/open_api_sdk/models/operations/updatedomain_requestbody.rb +0 -33
  215. data/lib/open_api_sdk/models/operations/updatedomain_response.rb +0 -60
  216. data/lib/open_api_sdk/models/operations/updatelink_request.rb +0 -27
  217. data/lib/open_api_sdk/models/operations/updatelink_requestbody.rb +0 -95
  218. data/lib/open_api_sdk/models/operations/updatelink_response.rb +0 -60
  219. data/lib/open_api_sdk/models/operations/updatetag_color.rb +0 -24
  220. data/lib/open_api_sdk/models/operations/updatetag_request.rb +0 -27
  221. data/lib/open_api_sdk/models/operations/updatetag_requestbody.rb +0 -32
  222. data/lib/open_api_sdk/models/operations/updatetag_response.rb +0 -60
  223. data/lib/open_api_sdk/models/operations/updateworkspace_request.rb +0 -27
  224. data/lib/open_api_sdk/models/operations/updateworkspace_requestbody.rb +0 -27
  225. data/lib/open_api_sdk/models/operations/updateworkspace_response.rb +0 -60
  226. data/lib/open_api_sdk/models/operations/upsertlink_requestbody.rb +0 -95
  227. data/lib/open_api_sdk/models/operations/upsertlink_response.rb +0 -60
  228. data/lib/open_api_sdk/models/operations.rb +0 -74
  229. data/lib/open_api_sdk/models/shared/badrequest.rb +0 -24
  230. data/lib/open_api_sdk/models/shared/code.rb +0 -18
  231. data/lib/open_api_sdk/models/shared/color.rb +0 -24
  232. data/lib/open_api_sdk/models/shared/conflict.rb +0 -24
  233. data/lib/open_api_sdk/models/shared/conflict_code.rb +0 -18
  234. data/lib/open_api_sdk/models/shared/conflict_error.rb +0 -30
  235. data/lib/open_api_sdk/models/shared/countrycode.rb +0 -267
  236. data/lib/open_api_sdk/models/shared/domains.rb +0 -27
  237. data/lib/open_api_sdk/models/shared/domainschema.rb +0 -48
  238. data/lib/open_api_sdk/models/shared/error.rb +0 -30
  239. data/lib/open_api_sdk/models/shared/forbidden.rb +0 -24
  240. data/lib/open_api_sdk/models/shared/forbidden_code.rb +0 -18
  241. data/lib/open_api_sdk/models/shared/forbidden_error.rb +0 -30
  242. data/lib/open_api_sdk/models/shared/geo.rb +0 -771
  243. data/lib/open_api_sdk/models/shared/internalservererror.rb +0 -24
  244. data/lib/open_api_sdk/models/shared/internalservererror_code.rb +0 -18
  245. data/lib/open_api_sdk/models/shared/internalservererror_error.rb +0 -30
  246. data/lib/open_api_sdk/models/shared/inviteexpired.rb +0 -24
  247. data/lib/open_api_sdk/models/shared/inviteexpired_code.rb +0 -18
  248. data/lib/open_api_sdk/models/shared/inviteexpired_error.rb +0 -30
  249. data/lib/open_api_sdk/models/shared/linkgeotargeting.rb +0 -771
  250. data/lib/open_api_sdk/models/shared/linkschema.rb +0 -142
  251. data/lib/open_api_sdk/models/shared/notfound.rb +0 -24
  252. data/lib/open_api_sdk/models/shared/notfound_code.rb +0 -18
  253. data/lib/open_api_sdk/models/shared/notfound_error.rb +0 -30
  254. data/lib/open_api_sdk/models/shared/plan.rb +0 -24
  255. data/lib/open_api_sdk/models/shared/ratelimitexceeded.rb +0 -24
  256. data/lib/open_api_sdk/models/shared/ratelimitexceeded_code.rb +0 -18
  257. data/lib/open_api_sdk/models/shared/ratelimitexceeded_error.rb +0 -30
  258. data/lib/open_api_sdk/models/shared/role.rb +0 -19
  259. data/lib/open_api_sdk/models/shared/security.rb +0 -24
  260. data/lib/open_api_sdk/models/shared/tagschema.rb +0 -30
  261. data/lib/open_api_sdk/models/shared/unauthorized.rb +0 -24
  262. data/lib/open_api_sdk/models/shared/unauthorized_code.rb +0 -18
  263. data/lib/open_api_sdk/models/shared/unauthorized_error.rb +0 -30
  264. data/lib/open_api_sdk/models/shared/unprocessableentity.rb +0 -24
  265. data/lib/open_api_sdk/models/shared/unprocessableentity_code.rb +0 -18
  266. data/lib/open_api_sdk/models/shared/unprocessableentity_error.rb +0 -30
  267. data/lib/open_api_sdk/models/shared/users.rb +0 -24
  268. data/lib/open_api_sdk/models/shared/workspaceschema.rb +0 -81
  269. data/lib/open_api_sdk/models/shared.rb +0 -49
  270. data/lib/open_api_sdk/qr_codes.rb +0 -97
  271. data/lib/open_api_sdk/sdkconfiguration.rb +0 -52
  272. data/lib/open_api_sdk/tags.rb +0 -272
  273. data/lib/open_api_sdk/track.rb +0 -276
  274. data/lib/open_api_sdk/utils/metadata_fields.rb +0 -150
  275. data/lib/open_api_sdk/utils/t.rb +0 -59
  276. data/lib/open_api_sdk/utils/utils.rb +0 -772
  277. data/lib/open_api_sdk/workspaces.rb +0 -192
@@ -0,0 +1,461 @@
1
+ /*
2
+ ** $Id: llex.c,v 2.20 2006/03/09 18:14:31 roberto Exp $
3
+ ** Lexical Analyzer
4
+ ** See Copyright Notice in lua.h
5
+ */
6
+
7
+
8
+ #include <ctype.h>
9
+ #include <locale.h>
10
+ #include <string.h>
11
+
12
+ #define llex_c
13
+ #define LUA_CORE
14
+
15
+ #include "lua.h"
16
+
17
+ #include "ldo.h"
18
+ #include "llex.h"
19
+ #include "lobject.h"
20
+ #include "lparser.h"
21
+ #include "lstate.h"
22
+ #include "lstring.h"
23
+ #include "ltable.h"
24
+ #include "lzio.h"
25
+
26
+
27
+
28
+ #define next(ls) (ls->current = zgetc(ls->z))
29
+
30
+
31
+
32
+
33
+ #define currIsNewline(ls) (ls->current == '\n' || ls->current == '\r')
34
+
35
+
36
+ /* ORDER RESERVED */
37
+ const char *const luaX_tokens [] = {
38
+ "and", "break", "do", "else", "elseif",
39
+ "end", "false", "for", "function", "if",
40
+ "in", "local", "nil", "not", "or", "repeat",
41
+ "return", "then", "true", "until", "while",
42
+ "..", "...", "==", ">=", "<=", "~=",
43
+ "<number>", "<name>", "<string>", "<eof>",
44
+ NULL
45
+ };
46
+
47
+
48
+ #define save_and_next(ls) (save(ls, ls->current), next(ls))
49
+
50
+
51
+ static void save (LexState *ls, int c) {
52
+ Mbuffer *b = ls->buff;
53
+ if (b->n + 1 > b->buffsize) {
54
+ size_t newsize;
55
+ if (b->buffsize >= MAX_SIZET/2)
56
+ luaX_lexerror(ls, "lexical element too long", 0);
57
+ newsize = b->buffsize * 2;
58
+ luaZ_resizebuffer(ls->L, b, newsize);
59
+ }
60
+ b->buffer[b->n++] = cast(char, c);
61
+ }
62
+
63
+
64
+ void luaX_init (lua_State *L) {
65
+ int i;
66
+ for (i=0; i<NUM_RESERVED; i++) {
67
+ TString *ts = luaS_new(L, luaX_tokens[i]);
68
+ luaS_fix(ts); /* reserved words are never collected */
69
+ lua_assert(strlen(luaX_tokens[i])+1 <= TOKEN_LEN);
70
+ ts->tsv.reserved = cast_byte(i+1); /* reserved word */
71
+ }
72
+ }
73
+
74
+
75
+ #define MAXSRC 80
76
+
77
+
78
+ const char *luaX_token2str (LexState *ls, int token) {
79
+ if (token < FIRST_RESERVED) {
80
+ lua_assert(token == cast(unsigned char, token));
81
+ return (iscntrl(token)) ? luaO_pushfstring(ls->L, "char(%d)", token) :
82
+ luaO_pushfstring(ls->L, "%c", token);
83
+ }
84
+ else
85
+ return luaX_tokens[token-FIRST_RESERVED];
86
+ }
87
+
88
+
89
+ static const char *txtToken (LexState *ls, int token) {
90
+ switch (token) {
91
+ case TK_NAME:
92
+ case TK_STRING:
93
+ case TK_NUMBER:
94
+ save(ls, '\0');
95
+ return luaZ_buffer(ls->buff);
96
+ default:
97
+ return luaX_token2str(ls, token);
98
+ }
99
+ }
100
+
101
+
102
+ void luaX_lexerror (LexState *ls, const char *msg, int token) {
103
+ char buff[MAXSRC];
104
+ luaO_chunkid(buff, getstr(ls->source), MAXSRC);
105
+ msg = luaO_pushfstring(ls->L, "%s:%d: %s", buff, ls->linenumber, msg);
106
+ if (token)
107
+ luaO_pushfstring(ls->L, "%s near " LUA_QS, msg, txtToken(ls, token));
108
+ luaD_throw(ls->L, LUA_ERRSYNTAX);
109
+ }
110
+
111
+
112
+ void luaX_syntaxerror (LexState *ls, const char *msg) {
113
+ luaX_lexerror(ls, msg, ls->t.token);
114
+ }
115
+
116
+
117
+ TString *luaX_newstring (LexState *ls, const char *str, size_t l) {
118
+ lua_State *L = ls->L;
119
+ TString *ts = luaS_newlstr(L, str, l);
120
+ TValue *o = luaH_setstr(L, ls->fs->h, ts); /* entry for `str' */
121
+ if (ttisnil(o))
122
+ setbvalue(o, 1); /* make sure `str' will not be collected */
123
+ return ts;
124
+ }
125
+
126
+
127
+ static void inclinenumber (LexState *ls) {
128
+ int old = ls->current;
129
+ lua_assert(currIsNewline(ls));
130
+ next(ls); /* skip `\n' or `\r' */
131
+ if (currIsNewline(ls) && ls->current != old)
132
+ next(ls); /* skip `\n\r' or `\r\n' */
133
+ if (++ls->linenumber >= MAX_INT)
134
+ luaX_syntaxerror(ls, "chunk has too many lines");
135
+ }
136
+
137
+
138
+ void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) {
139
+ ls->decpoint = '.';
140
+ ls->L = L;
141
+ ls->lookahead.token = TK_EOS; /* no look-ahead token */
142
+ ls->z = z;
143
+ ls->fs = NULL;
144
+ ls->linenumber = 1;
145
+ ls->lastline = 1;
146
+ ls->source = source;
147
+ luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER); /* initialize buffer */
148
+ next(ls); /* read first char */
149
+ }
150
+
151
+
152
+
153
+ /*
154
+ ** =======================================================
155
+ ** LEXICAL ANALYZER
156
+ ** =======================================================
157
+ */
158
+
159
+
160
+
161
+ static int check_next (LexState *ls, const char *set) {
162
+ if (!strchr(set, ls->current))
163
+ return 0;
164
+ save_and_next(ls);
165
+ return 1;
166
+ }
167
+
168
+
169
+ static void buffreplace (LexState *ls, char from, char to) {
170
+ size_t n = luaZ_bufflen(ls->buff);
171
+ char *p = luaZ_buffer(ls->buff);
172
+ while (n--)
173
+ if (p[n] == from) p[n] = to;
174
+ }
175
+
176
+
177
+ static void trydecpoint (LexState *ls, SemInfo *seminfo) {
178
+ /* format error: try to update decimal point separator */
179
+ struct lconv *cv = localeconv();
180
+ char old = ls->decpoint;
181
+ ls->decpoint = (cv ? cv->decimal_point[0] : '.');
182
+ buffreplace(ls, old, ls->decpoint); /* try updated decimal separator */
183
+ if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) {
184
+ /* format error with correct decimal point: no more options */
185
+ buffreplace(ls, ls->decpoint, '.'); /* undo change (for error message) */
186
+ luaX_lexerror(ls, "malformed number", TK_NUMBER);
187
+ }
188
+ }
189
+
190
+
191
+ /* LUA_NUMBER */
192
+ static void read_numeral (LexState *ls, SemInfo *seminfo) {
193
+ lua_assert(isdigit(ls->current));
194
+ do {
195
+ save_and_next(ls);
196
+ } while (isdigit(ls->current) || ls->current == '.');
197
+ if (check_next(ls, "Ee")) /* `E'? */
198
+ check_next(ls, "+-"); /* optional exponent sign */
199
+ while (isalnum(ls->current) || ls->current == '_')
200
+ save_and_next(ls);
201
+ save(ls, '\0');
202
+ buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */
203
+ if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) /* format error? */
204
+ trydecpoint(ls, seminfo); /* try to update decimal point separator */
205
+ }
206
+
207
+
208
+ static int skip_sep (LexState *ls) {
209
+ int count = 0;
210
+ int s = ls->current;
211
+ lua_assert(s == '[' || s == ']');
212
+ save_and_next(ls);
213
+ while (ls->current == '=') {
214
+ save_and_next(ls);
215
+ count++;
216
+ }
217
+ return (ls->current == s) ? count : (-count) - 1;
218
+ }
219
+
220
+
221
+ static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) {
222
+ int cont = 0;
223
+ (void)(cont); /* avoid warnings when `cont' is not used */
224
+ save_and_next(ls); /* skip 2nd `[' */
225
+ if (currIsNewline(ls)) /* string starts with a newline? */
226
+ inclinenumber(ls); /* skip it */
227
+ for (;;) {
228
+ switch (ls->current) {
229
+ case EOZ:
230
+ luaX_lexerror(ls, (seminfo) ? "unfinished long string" :
231
+ "unfinished long comment", TK_EOS);
232
+ break; /* to avoid warnings */
233
+ #if defined(LUA_COMPAT_LSTR)
234
+ case '[': {
235
+ if (skip_sep(ls) == sep) {
236
+ save_and_next(ls); /* skip 2nd `[' */
237
+ cont++;
238
+ #if LUA_COMPAT_LSTR == 1
239
+ if (sep == 0)
240
+ luaX_lexerror(ls, "nesting of [[...]] is deprecated", '[');
241
+ #endif
242
+ }
243
+ break;
244
+ }
245
+ #endif
246
+ case ']': {
247
+ if (skip_sep(ls) == sep) {
248
+ save_and_next(ls); /* skip 2nd `]' */
249
+ #if defined(LUA_COMPAT_LSTR) && LUA_COMPAT_LSTR == 2
250
+ cont--;
251
+ if (sep == 0 && cont >= 0) break;
252
+ #endif
253
+ goto endloop;
254
+ }
255
+ break;
256
+ }
257
+ case '\n':
258
+ case '\r': {
259
+ save(ls, '\n');
260
+ inclinenumber(ls);
261
+ if (!seminfo) luaZ_resetbuffer(ls->buff); /* avoid wasting space */
262
+ break;
263
+ }
264
+ default: {
265
+ if (seminfo) save_and_next(ls);
266
+ else next(ls);
267
+ }
268
+ }
269
+ } endloop:
270
+ if (seminfo)
271
+ seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + (2 + sep),
272
+ luaZ_bufflen(ls->buff) - 2*(2 + sep));
273
+ }
274
+
275
+
276
+ static void read_string (LexState *ls, int del, SemInfo *seminfo) {
277
+ save_and_next(ls);
278
+ while (ls->current != del) {
279
+ switch (ls->current) {
280
+ case EOZ:
281
+ luaX_lexerror(ls, "unfinished string", TK_EOS);
282
+ continue; /* to avoid warnings */
283
+ case '\n':
284
+ case '\r':
285
+ luaX_lexerror(ls, "unfinished string", TK_STRING);
286
+ continue; /* to avoid warnings */
287
+ case '\\': {
288
+ int c;
289
+ next(ls); /* do not save the `\' */
290
+ switch (ls->current) {
291
+ case 'a': c = '\a'; break;
292
+ case 'b': c = '\b'; break;
293
+ case 'f': c = '\f'; break;
294
+ case 'n': c = '\n'; break;
295
+ case 'r': c = '\r'; break;
296
+ case 't': c = '\t'; break;
297
+ case 'v': c = '\v'; break;
298
+ case '\n': /* go through */
299
+ case '\r': save(ls, '\n'); inclinenumber(ls); continue;
300
+ case EOZ: continue; /* will raise an error next loop */
301
+ default: {
302
+ if (!isdigit(ls->current))
303
+ save_and_next(ls); /* handles \\, \", \', and \? */
304
+ else { /* \xxx */
305
+ int i = 0;
306
+ c = 0;
307
+ do {
308
+ c = 10*c + (ls->current-'0');
309
+ next(ls);
310
+ } while (++i<3 && isdigit(ls->current));
311
+ if (c > UCHAR_MAX)
312
+ luaX_lexerror(ls, "escape sequence too large", TK_STRING);
313
+ save(ls, c);
314
+ }
315
+ continue;
316
+ }
317
+ }
318
+ save(ls, c);
319
+ next(ls);
320
+ continue;
321
+ }
322
+ default:
323
+ save_and_next(ls);
324
+ }
325
+ }
326
+ save_and_next(ls); /* skip delimiter */
327
+ seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + 1,
328
+ luaZ_bufflen(ls->buff) - 2);
329
+ }
330
+
331
+
332
+ static int llex (LexState *ls, SemInfo *seminfo) {
333
+ luaZ_resetbuffer(ls->buff);
334
+ for (;;) {
335
+ switch (ls->current) {
336
+ case '\n':
337
+ case '\r': {
338
+ inclinenumber(ls);
339
+ continue;
340
+ }
341
+ case '-': {
342
+ next(ls);
343
+ if (ls->current != '-') return '-';
344
+ /* else is a comment */
345
+ next(ls);
346
+ if (ls->current == '[') {
347
+ int sep = skip_sep(ls);
348
+ luaZ_resetbuffer(ls->buff); /* `skip_sep' may dirty the buffer */
349
+ if (sep >= 0) {
350
+ read_long_string(ls, NULL, sep); /* long comment */
351
+ luaZ_resetbuffer(ls->buff);
352
+ continue;
353
+ }
354
+ }
355
+ /* else short comment */
356
+ while (!currIsNewline(ls) && ls->current != EOZ)
357
+ next(ls);
358
+ continue;
359
+ }
360
+ case '[': {
361
+ int sep = skip_sep(ls);
362
+ if (sep >= 0) {
363
+ read_long_string(ls, seminfo, sep);
364
+ return TK_STRING;
365
+ }
366
+ else if (sep == -1) return '[';
367
+ else luaX_lexerror(ls, "invalid long string delimiter", TK_STRING);
368
+ }
369
+ case '=': {
370
+ next(ls);
371
+ if (ls->current != '=') return '=';
372
+ else { next(ls); return TK_EQ; }
373
+ }
374
+ case '<': {
375
+ next(ls);
376
+ if (ls->current != '=') return '<';
377
+ else { next(ls); return TK_LE; }
378
+ }
379
+ case '>': {
380
+ next(ls);
381
+ if (ls->current != '=') return '>';
382
+ else { next(ls); return TK_GE; }
383
+ }
384
+ case '~': {
385
+ next(ls);
386
+ if (ls->current != '=') return '~';
387
+ else { next(ls); return TK_NE; }
388
+ }
389
+ case '"':
390
+ case '\'': {
391
+ read_string(ls, ls->current, seminfo);
392
+ return TK_STRING;
393
+ }
394
+ case '.': {
395
+ save_and_next(ls);
396
+ if (check_next(ls, ".")) {
397
+ if (check_next(ls, "."))
398
+ return TK_DOTS; /* ... */
399
+ else return TK_CONCAT; /* .. */
400
+ }
401
+ else if (!isdigit(ls->current)) return '.';
402
+ else {
403
+ read_numeral(ls, seminfo);
404
+ return TK_NUMBER;
405
+ }
406
+ }
407
+ case EOZ: {
408
+ return TK_EOS;
409
+ }
410
+ default: {
411
+ if (isspace(ls->current)) {
412
+ lua_assert(!currIsNewline(ls));
413
+ next(ls);
414
+ continue;
415
+ }
416
+ else if (isdigit(ls->current)) {
417
+ read_numeral(ls, seminfo);
418
+ return TK_NUMBER;
419
+ }
420
+ else if (isalpha(ls->current) || ls->current == '_') {
421
+ /* identifier or reserved word */
422
+ TString *ts;
423
+ do {
424
+ save_and_next(ls);
425
+ } while (isalnum(ls->current) || ls->current == '_');
426
+ ts = luaX_newstring(ls, luaZ_buffer(ls->buff),
427
+ luaZ_bufflen(ls->buff));
428
+ if (ts->tsv.reserved > 0) /* reserved word? */
429
+ return ts->tsv.reserved - 1 + FIRST_RESERVED;
430
+ else {
431
+ seminfo->ts = ts;
432
+ return TK_NAME;
433
+ }
434
+ }
435
+ else {
436
+ int c = ls->current;
437
+ next(ls);
438
+ return c; /* single-char tokens (+ - / ...) */
439
+ }
440
+ }
441
+ }
442
+ }
443
+ }
444
+
445
+
446
+ void luaX_next (LexState *ls) {
447
+ ls->lastline = ls->linenumber;
448
+ if (ls->lookahead.token != TK_EOS) { /* is there a look-ahead token? */
449
+ ls->t = ls->lookahead; /* use this one */
450
+ ls->lookahead.token = TK_EOS; /* and discharge it */
451
+ }
452
+ else
453
+ ls->t.token = llex(ls, &ls->t.seminfo); /* read next token */
454
+ }
455
+
456
+
457
+ void luaX_lookahead (LexState *ls) {
458
+ lua_assert(ls->lookahead.token == TK_EOS);
459
+ ls->lookahead.token = llex(ls, &ls->lookahead.seminfo);
460
+ }
461
+
@@ -0,0 +1,81 @@
1
+ /*
2
+ ** $Id: llex.h,v 1.58 2006/03/23 18:23:32 roberto Exp $
3
+ ** Lexical Analyzer
4
+ ** See Copyright Notice in lua.h
5
+ */
6
+
7
+ #ifndef llex_h
8
+ #define llex_h
9
+
10
+ #include "lobject.h"
11
+ #include "lzio.h"
12
+
13
+
14
+ #define FIRST_RESERVED 257
15
+
16
+ /* maximum length of a reserved word */
17
+ #define TOKEN_LEN (sizeof("function")/sizeof(char))
18
+
19
+
20
+ /*
21
+ * WARNING: if you change the order of this enumeration,
22
+ * grep "ORDER RESERVED"
23
+ */
24
+ enum RESERVED {
25
+ /* terminal symbols denoted by reserved words */
26
+ TK_AND = FIRST_RESERVED, TK_BREAK,
27
+ TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION,
28
+ TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT,
29
+ TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE,
30
+ /* other terminal symbols */
31
+ TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_NUMBER,
32
+ TK_NAME, TK_STRING, TK_EOS
33
+ };
34
+
35
+ /* number of reserved words */
36
+ #define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1))
37
+
38
+
39
+ /* array with token `names' */
40
+ LUAI_DATA const char *const luaX_tokens [];
41
+
42
+
43
+ typedef union {
44
+ lua_Number r;
45
+ TString *ts;
46
+ } SemInfo; /* semantics information */
47
+
48
+
49
+ typedef struct Token {
50
+ int token;
51
+ SemInfo seminfo;
52
+ } Token;
53
+
54
+
55
+ typedef struct LexState {
56
+ int current; /* current character (charint) */
57
+ int linenumber; /* input line counter */
58
+ int lastline; /* line of last token `consumed' */
59
+ Token t; /* current token */
60
+ Token lookahead; /* look ahead token */
61
+ struct FuncState *fs; /* `FuncState' is private to the parser */
62
+ struct lua_State *L;
63
+ ZIO *z; /* input stream */
64
+ Mbuffer *buff; /* buffer for tokens */
65
+ TString *source; /* current source name */
66
+ char decpoint; /* locale decimal point */
67
+ } LexState;
68
+
69
+
70
+ LUAI_FUNC void luaX_init (lua_State *L);
71
+ LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z,
72
+ TString *source);
73
+ LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l);
74
+ LUAI_FUNC void luaX_next (LexState *ls);
75
+ LUAI_FUNC void luaX_lookahead (LexState *ls);
76
+ LUAI_FUNC void luaX_lexerror (LexState *ls, const char *msg, int token);
77
+ LUAI_FUNC void luaX_syntaxerror (LexState *ls, const char *s);
78
+ LUAI_FUNC const char *luaX_token2str (LexState *ls, int token);
79
+
80
+
81
+ #endif
@@ -0,0 +1,128 @@
1
+ /*
2
+ ** $Id: llimits.h,v 1.69 2005/12/27 17:12:00 roberto Exp $
3
+ ** Limits, basic types, and some other `installation-dependent' definitions
4
+ ** See Copyright Notice in lua.h
5
+ */
6
+
7
+ #ifndef llimits_h
8
+ #define llimits_h
9
+
10
+
11
+ #include <limits.h>
12
+ #include <stddef.h>
13
+
14
+
15
+ #include "lua.h"
16
+
17
+
18
+ typedef LUAI_UINT32 lu_int32;
19
+
20
+ typedef LUAI_UMEM lu_mem;
21
+
22
+ typedef LUAI_MEM l_mem;
23
+
24
+
25
+
26
+ /* chars used as small naturals (so that `char' is reserved for characters) */
27
+ typedef unsigned char lu_byte;
28
+
29
+
30
+ #define MAX_SIZET ((size_t)(~(size_t)0)-2)
31
+
32
+ #define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2)
33
+
34
+
35
+ #define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */
36
+
37
+ /*
38
+ ** conversion of pointer to integer
39
+ ** this is for hashing only; there is no problem if the integer
40
+ ** cannot hold the whole pointer value
41
+ */
42
+ #define IntPoint(p) ((unsigned int)(lu_mem)(p))
43
+
44
+
45
+
46
+ /* type to ensure maximum alignment */
47
+ typedef LUAI_USER_ALIGNMENT_T L_Umaxalign;
48
+
49
+
50
+ /* result of a `usual argument conversion' over lua_Number */
51
+ typedef LUAI_UACNUMBER l_uacNumber;
52
+
53
+
54
+ /* internal assertions for in-house debugging */
55
+ #ifdef lua_assert
56
+
57
+ #define check_exp(c,e) (lua_assert(c), (e))
58
+ #define api_check(l,e) lua_assert(e)
59
+
60
+ #else
61
+
62
+ #define lua_assert(c) ((void)0)
63
+ #define check_exp(c,e) (e)
64
+ #define api_check luai_apicheck
65
+
66
+ #endif
67
+
68
+
69
+ #ifndef UNUSED
70
+ #define UNUSED(x) ((void)(x)) /* to avoid warnings */
71
+ #endif
72
+
73
+
74
+ #ifndef cast
75
+ #define cast(t, exp) ((t)(exp))
76
+ #endif
77
+
78
+ #define cast_byte(i) cast(lu_byte, (i))
79
+ #define cast_num(i) cast(lua_Number, (i))
80
+ #define cast_int(i) cast(int, (i))
81
+
82
+
83
+
84
+ /*
85
+ ** type for virtual-machine instructions
86
+ ** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h)
87
+ */
88
+ typedef lu_int32 Instruction;
89
+
90
+
91
+
92
+ /* maximum stack for a Lua function */
93
+ #define MAXSTACK 250
94
+
95
+
96
+
97
+ /* minimum size for the string table (must be power of 2) */
98
+ #ifndef MINSTRTABSIZE
99
+ #define MINSTRTABSIZE 32
100
+ #endif
101
+
102
+
103
+ /* minimum size for string buffer */
104
+ #ifndef LUA_MINBUFFER
105
+ #define LUA_MINBUFFER 32
106
+ #endif
107
+
108
+
109
+ #ifndef lua_lock
110
+ #define lua_lock(L) ((void) 0)
111
+ #define lua_unlock(L) ((void) 0)
112
+ #endif
113
+
114
+ #ifndef luai_threadyield
115
+ #define luai_threadyield(L) {lua_unlock(L); lua_lock(L);}
116
+ #endif
117
+
118
+
119
+ /*
120
+ ** macro to control inclusion of some hard tests on stack reallocation
121
+ */
122
+ #ifndef HARDSTACKTESTS
123
+ #define condhardstacktests(x) ((void)0)
124
+ #else
125
+ #define condhardstacktests(x) x
126
+ #endif
127
+
128
+ #endif