immunio 1.2.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (291) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -5
  3. data/ext/immunio/Rakefile +14 -6
  4. data/lib/immunio/context.rb +2 -0
  5. data/lib/immunio/plugins/action_view.rb +7 -668
  6. data/lib/immunio/plugins/action_view/action_view.rb +22 -0
  7. data/lib/immunio/plugins/action_view/active_support_hash.rb +29 -0
  8. data/lib/immunio/plugins/action_view/cache_store.rb +24 -0
  9. data/lib/immunio/plugins/action_view/erubi.rb +38 -0
  10. data/lib/immunio/plugins/action_view/erubis.rb +39 -0
  11. data/lib/immunio/plugins/action_view/fragment_caching.rb +29 -0
  12. data/lib/immunio/plugins/action_view/haml.rb +46 -0
  13. data/lib/immunio/plugins/action_view/slim.rb +42 -0
  14. data/lib/immunio/plugins/action_view/template.rb +431 -0
  15. data/lib/immunio/plugins/action_view/template_rendering.rb +45 -0
  16. data/lib/immunio/plugins/http_tracker.rb +2 -0
  17. data/lib/immunio/plugins/io.rb +34 -0
  18. data/lib/immunio/version.rb +1 -1
  19. data/lua-hooks/Makefile +36 -9
  20. data/lua-hooks/ext/luajit/COPYRIGHT +1 -1
  21. data/lua-hooks/ext/luajit/Makefile +22 -15
  22. data/lua-hooks/ext/luajit/README +2 -2
  23. data/lua-hooks/ext/luajit/doc/bluequad-print.css +1 -1
  24. data/lua-hooks/ext/luajit/doc/bluequad.css +1 -1
  25. data/lua-hooks/ext/luajit/doc/changes.html +69 -3
  26. data/lua-hooks/ext/luajit/doc/contact.html +10 -3
  27. data/lua-hooks/ext/luajit/doc/ext_c_api.html +2 -2
  28. data/lua-hooks/ext/luajit/doc/ext_ffi.html +2 -2
  29. data/lua-hooks/ext/luajit/doc/ext_ffi_api.html +2 -2
  30. data/lua-hooks/ext/luajit/doc/ext_ffi_semantics.html +3 -4
  31. data/lua-hooks/ext/luajit/doc/ext_ffi_tutorial.html +2 -2
  32. data/lua-hooks/ext/luajit/doc/ext_jit.html +3 -3
  33. data/lua-hooks/ext/luajit/doc/ext_profiler.html +2 -2
  34. data/lua-hooks/ext/luajit/doc/extensions.html +47 -20
  35. data/lua-hooks/ext/luajit/doc/faq.html +2 -2
  36. data/lua-hooks/ext/luajit/doc/install.html +74 -45
  37. data/lua-hooks/ext/luajit/doc/luajit.html +5 -5
  38. data/lua-hooks/ext/luajit/doc/running.html +3 -3
  39. data/lua-hooks/ext/luajit/doc/status.html +13 -8
  40. data/lua-hooks/ext/luajit/dynasm/dasm_arm.h +1 -1
  41. data/lua-hooks/ext/luajit/dynasm/dasm_arm.lua +1 -1
  42. data/lua-hooks/ext/luajit/dynasm/dasm_arm64.h +1 -1
  43. data/lua-hooks/ext/luajit/dynasm/dasm_arm64.lua +1 -1
  44. data/lua-hooks/ext/luajit/dynasm/dasm_mips.h +8 -5
  45. data/lua-hooks/ext/luajit/dynasm/dasm_mips.lua +66 -11
  46. data/lua-hooks/ext/luajit/dynasm/dasm_mips64.lua +12 -0
  47. data/lua-hooks/ext/luajit/dynasm/dasm_ppc.h +1 -1
  48. data/lua-hooks/ext/luajit/dynasm/dasm_ppc.lua +1 -1
  49. data/lua-hooks/ext/luajit/dynasm/dasm_proto.h +1 -1
  50. data/lua-hooks/ext/luajit/dynasm/dasm_x64.lua +1 -1
  51. data/lua-hooks/ext/luajit/dynasm/dasm_x86.h +1 -1
  52. data/lua-hooks/ext/luajit/dynasm/dasm_x86.lua +5 -1
  53. data/lua-hooks/ext/luajit/dynasm/dynasm.lua +2 -2
  54. data/lua-hooks/ext/luajit/etc/luajit.1 +1 -1
  55. data/lua-hooks/ext/luajit/etc/luajit.pc +1 -1
  56. data/lua-hooks/ext/luajit/src/Makefile +15 -11
  57. data/lua-hooks/ext/luajit/src/Makefile.dep +16 -16
  58. data/lua-hooks/ext/luajit/src/host/buildvm.c +2 -2
  59. data/lua-hooks/ext/luajit/src/host/buildvm.h +1 -1
  60. data/lua-hooks/ext/luajit/src/host/buildvm_asm.c +9 -4
  61. data/lua-hooks/ext/luajit/src/host/buildvm_fold.c +2 -2
  62. data/lua-hooks/ext/luajit/src/host/buildvm_lib.c +1 -1
  63. data/lua-hooks/ext/luajit/src/host/buildvm_libbc.h +14 -3
  64. data/lua-hooks/ext/luajit/src/host/buildvm_peobj.c +27 -3
  65. data/lua-hooks/ext/luajit/src/host/genlibbc.lua +1 -1
  66. data/lua-hooks/ext/luajit/src/host/genminilua.lua +6 -5
  67. data/lua-hooks/ext/luajit/src/host/minilua.c +1 -1
  68. data/lua-hooks/ext/luajit/src/jit/bc.lua +1 -1
  69. data/lua-hooks/ext/luajit/src/jit/bcsave.lua +8 -8
  70. data/lua-hooks/ext/luajit/src/jit/dis_arm.lua +2 -2
  71. data/lua-hooks/ext/luajit/src/jit/dis_arm64.lua +1216 -0
  72. data/lua-hooks/ext/luajit/src/jit/dis_arm64be.lua +12 -0
  73. data/lua-hooks/ext/luajit/src/jit/dis_mips.lua +35 -20
  74. data/lua-hooks/ext/luajit/src/jit/dis_mips64.lua +17 -0
  75. data/lua-hooks/ext/luajit/src/jit/dis_mips64el.lua +17 -0
  76. data/lua-hooks/ext/luajit/src/jit/dis_mipsel.lua +1 -1
  77. data/lua-hooks/ext/luajit/src/jit/dis_ppc.lua +2 -2
  78. data/lua-hooks/ext/luajit/src/jit/dis_x64.lua +1 -1
  79. data/lua-hooks/ext/luajit/src/jit/dis_x86.lua +7 -4
  80. data/lua-hooks/ext/luajit/src/jit/dump.lua +17 -12
  81. data/lua-hooks/ext/luajit/src/jit/p.lua +3 -2
  82. data/lua-hooks/ext/luajit/src/jit/v.lua +2 -2
  83. data/lua-hooks/ext/luajit/src/jit/zone.lua +1 -1
  84. data/lua-hooks/ext/luajit/src/lauxlib.h +14 -20
  85. data/lua-hooks/ext/luajit/src/lib_aux.c +38 -27
  86. data/lua-hooks/ext/luajit/src/lib_base.c +12 -5
  87. data/lua-hooks/ext/luajit/src/lib_bit.c +1 -1
  88. data/lua-hooks/ext/luajit/src/lib_debug.c +5 -5
  89. data/lua-hooks/ext/luajit/src/lib_ffi.c +2 -2
  90. data/lua-hooks/ext/luajit/src/lib_init.c +16 -16
  91. data/lua-hooks/ext/luajit/src/lib_io.c +6 -7
  92. data/lua-hooks/ext/luajit/src/lib_jit.c +14 -4
  93. data/lua-hooks/ext/luajit/src/lib_math.c +1 -5
  94. data/lua-hooks/ext/luajit/src/lib_os.c +1 -1
  95. data/lua-hooks/ext/luajit/src/lib_package.c +14 -23
  96. data/lua-hooks/ext/luajit/src/lib_string.c +1 -5
  97. data/lua-hooks/ext/luajit/src/lib_table.c +21 -1
  98. data/lua-hooks/ext/luajit/src/lj.supp +3 -3
  99. data/lua-hooks/ext/luajit/src/lj_alloc.c +174 -83
  100. data/lua-hooks/ext/luajit/src/lj_api.c +97 -18
  101. data/lua-hooks/ext/luajit/src/lj_arch.h +54 -22
  102. data/lua-hooks/ext/luajit/src/lj_asm.c +172 -53
  103. data/lua-hooks/ext/luajit/src/lj_asm.h +1 -1
  104. data/lua-hooks/ext/luajit/src/lj_asm_arm.h +19 -16
  105. data/lua-hooks/ext/luajit/src/lj_asm_arm64.h +2022 -0
  106. data/lua-hooks/ext/luajit/src/lj_asm_mips.h +564 -158
  107. data/lua-hooks/ext/luajit/src/lj_asm_ppc.h +19 -18
  108. data/lua-hooks/ext/luajit/src/lj_asm_x86.h +578 -92
  109. data/lua-hooks/ext/luajit/src/lj_bc.c +1 -1
  110. data/lua-hooks/ext/luajit/src/lj_bc.h +1 -1
  111. data/lua-hooks/ext/luajit/src/lj_bcdump.h +1 -1
  112. data/lua-hooks/ext/luajit/src/lj_bcread.c +1 -1
  113. data/lua-hooks/ext/luajit/src/lj_bcwrite.c +1 -1
  114. data/lua-hooks/ext/luajit/src/lj_buf.c +1 -1
  115. data/lua-hooks/ext/luajit/src/lj_buf.h +1 -1
  116. data/lua-hooks/ext/luajit/src/lj_carith.c +1 -1
  117. data/lua-hooks/ext/luajit/src/lj_carith.h +1 -1
  118. data/lua-hooks/ext/luajit/src/lj_ccall.c +172 -7
  119. data/lua-hooks/ext/luajit/src/lj_ccall.h +21 -5
  120. data/lua-hooks/ext/luajit/src/lj_ccallback.c +71 -17
  121. data/lua-hooks/ext/luajit/src/lj_ccallback.h +1 -1
  122. data/lua-hooks/ext/luajit/src/lj_cconv.c +4 -2
  123. data/lua-hooks/ext/luajit/src/lj_cconv.h +1 -1
  124. data/lua-hooks/ext/luajit/src/lj_cdata.c +7 -5
  125. data/lua-hooks/ext/luajit/src/lj_cdata.h +1 -1
  126. data/lua-hooks/ext/luajit/src/lj_clib.c +5 -5
  127. data/lua-hooks/ext/luajit/src/lj_clib.h +1 -1
  128. data/lua-hooks/ext/luajit/src/lj_cparse.c +11 -6
  129. data/lua-hooks/ext/luajit/src/lj_cparse.h +1 -1
  130. data/lua-hooks/ext/luajit/src/lj_crecord.c +70 -14
  131. data/lua-hooks/ext/luajit/src/lj_crecord.h +1 -1
  132. data/lua-hooks/ext/luajit/src/lj_ctype.c +1 -1
  133. data/lua-hooks/ext/luajit/src/lj_ctype.h +8 -8
  134. data/lua-hooks/ext/luajit/src/lj_debug.c +1 -1
  135. data/lua-hooks/ext/luajit/src/lj_debug.h +1 -1
  136. data/lua-hooks/ext/luajit/src/lj_def.h +6 -9
  137. data/lua-hooks/ext/luajit/src/lj_dispatch.c +3 -3
  138. data/lua-hooks/ext/luajit/src/lj_dispatch.h +2 -1
  139. data/lua-hooks/ext/luajit/src/lj_emit_arm.h +5 -4
  140. data/lua-hooks/ext/luajit/src/lj_emit_arm64.h +419 -0
  141. data/lua-hooks/ext/luajit/src/lj_emit_mips.h +100 -20
  142. data/lua-hooks/ext/luajit/src/lj_emit_ppc.h +4 -4
  143. data/lua-hooks/ext/luajit/src/lj_emit_x86.h +116 -25
  144. data/lua-hooks/ext/luajit/src/lj_err.c +34 -13
  145. data/lua-hooks/ext/luajit/src/lj_err.h +1 -1
  146. data/lua-hooks/ext/luajit/src/lj_errmsg.h +1 -1
  147. data/lua-hooks/ext/luajit/src/lj_ff.h +1 -1
  148. data/lua-hooks/ext/luajit/src/lj_ffrecord.c +58 -49
  149. data/lua-hooks/ext/luajit/src/lj_ffrecord.h +1 -1
  150. data/lua-hooks/ext/luajit/src/lj_frame.h +33 -6
  151. data/lua-hooks/ext/luajit/src/lj_func.c +4 -2
  152. data/lua-hooks/ext/luajit/src/lj_func.h +1 -1
  153. data/lua-hooks/ext/luajit/src/lj_gc.c +16 -7
  154. data/lua-hooks/ext/luajit/src/lj_gc.h +1 -1
  155. data/lua-hooks/ext/luajit/src/lj_gdbjit.c +31 -1
  156. data/lua-hooks/ext/luajit/src/lj_gdbjit.h +1 -1
  157. data/lua-hooks/ext/luajit/src/lj_ir.c +69 -96
  158. data/lua-hooks/ext/luajit/src/lj_ir.h +29 -18
  159. data/lua-hooks/ext/luajit/src/lj_ircall.h +24 -30
  160. data/lua-hooks/ext/luajit/src/lj_iropt.h +9 -9
  161. data/lua-hooks/ext/luajit/src/lj_jit.h +67 -9
  162. data/lua-hooks/ext/luajit/src/lj_lex.c +1 -1
  163. data/lua-hooks/ext/luajit/src/lj_lex.h +1 -1
  164. data/lua-hooks/ext/luajit/src/lj_lib.c +1 -1
  165. data/lua-hooks/ext/luajit/src/lj_lib.h +1 -1
  166. data/lua-hooks/ext/luajit/src/lj_load.c +1 -1
  167. data/lua-hooks/ext/luajit/src/lj_mcode.c +11 -10
  168. data/lua-hooks/ext/luajit/src/lj_mcode.h +1 -1
  169. data/lua-hooks/ext/luajit/src/lj_meta.c +1 -1
  170. data/lua-hooks/ext/luajit/src/lj_meta.h +1 -1
  171. data/lua-hooks/ext/luajit/src/lj_obj.c +1 -1
  172. data/lua-hooks/ext/luajit/src/lj_obj.h +7 -3
  173. data/lua-hooks/ext/luajit/src/lj_opt_dce.c +1 -1
  174. data/lua-hooks/ext/luajit/src/lj_opt_fold.c +84 -17
  175. data/lua-hooks/ext/luajit/src/lj_opt_loop.c +1 -1
  176. data/lua-hooks/ext/luajit/src/lj_opt_mem.c +3 -3
  177. data/lua-hooks/ext/luajit/src/lj_opt_narrow.c +24 -22
  178. data/lua-hooks/ext/luajit/src/lj_opt_sink.c +11 -6
  179. data/lua-hooks/ext/luajit/src/lj_opt_split.c +11 -2
  180. data/lua-hooks/ext/luajit/src/lj_parse.c +9 -7
  181. data/lua-hooks/ext/luajit/src/lj_parse.h +1 -1
  182. data/lua-hooks/ext/luajit/src/lj_profile.c +1 -1
  183. data/lua-hooks/ext/luajit/src/lj_profile.h +1 -1
  184. data/lua-hooks/ext/luajit/src/lj_record.c +201 -117
  185. data/lua-hooks/ext/luajit/src/lj_record.h +1 -1
  186. data/lua-hooks/ext/luajit/src/lj_snap.c +72 -26
  187. data/lua-hooks/ext/luajit/src/lj_snap.h +1 -1
  188. data/lua-hooks/ext/luajit/src/lj_state.c +6 -6
  189. data/lua-hooks/ext/luajit/src/lj_state.h +2 -2
  190. data/lua-hooks/ext/luajit/src/lj_str.c +1 -1
  191. data/lua-hooks/ext/luajit/src/lj_str.h +1 -1
  192. data/lua-hooks/ext/luajit/src/lj_strfmt.c +7 -3
  193. data/lua-hooks/ext/luajit/src/lj_strfmt.h +1 -1
  194. data/lua-hooks/ext/luajit/src/lj_strfmt_num.c +4 -3
  195. data/lua-hooks/ext/luajit/src/lj_strscan.c +1 -1
  196. data/lua-hooks/ext/luajit/src/lj_strscan.h +1 -1
  197. data/lua-hooks/ext/luajit/src/lj_tab.c +1 -2
  198. data/lua-hooks/ext/luajit/src/lj_tab.h +1 -1
  199. data/lua-hooks/ext/luajit/src/lj_target.h +3 -3
  200. data/lua-hooks/ext/luajit/src/lj_target_arm.h +1 -1
  201. data/lua-hooks/ext/luajit/src/lj_target_arm64.h +239 -7
  202. data/lua-hooks/ext/luajit/src/lj_target_mips.h +111 -22
  203. data/lua-hooks/ext/luajit/src/lj_target_ppc.h +1 -1
  204. data/lua-hooks/ext/luajit/src/lj_target_x86.h +21 -4
  205. data/lua-hooks/ext/luajit/src/lj_trace.c +63 -18
  206. data/lua-hooks/ext/luajit/src/lj_trace.h +2 -1
  207. data/lua-hooks/ext/luajit/src/lj_traceerr.h +1 -1
  208. data/lua-hooks/ext/luajit/src/lj_udata.c +1 -1
  209. data/lua-hooks/ext/luajit/src/lj_udata.h +1 -1
  210. data/lua-hooks/ext/luajit/src/lj_vm.h +5 -1
  211. data/lua-hooks/ext/luajit/src/lj_vmevent.c +1 -1
  212. data/lua-hooks/ext/luajit/src/lj_vmevent.h +1 -1
  213. data/lua-hooks/ext/luajit/src/lj_vmmath.c +1 -1
  214. data/lua-hooks/ext/luajit/src/ljamalg.c +1 -1
  215. data/lua-hooks/ext/luajit/src/lua.h +9 -1
  216. data/lua-hooks/ext/luajit/src/luaconf.h +3 -7
  217. data/lua-hooks/ext/luajit/src/luajit.c +69 -54
  218. data/lua-hooks/ext/luajit/src/luajit.h +4 -4
  219. data/lua-hooks/ext/luajit/src/lualib.h +1 -1
  220. data/lua-hooks/ext/luajit/src/msvcbuild.bat +12 -4
  221. data/lua-hooks/ext/luajit/src/vm_arm.dasc +1 -1
  222. data/lua-hooks/ext/luajit/src/vm_arm64.dasc +255 -32
  223. data/lua-hooks/ext/luajit/src/vm_mips.dasc +26 -23
  224. data/lua-hooks/ext/luajit/src/vm_mips64.dasc +5062 -0
  225. data/lua-hooks/ext/luajit/src/vm_ppc.dasc +1 -1
  226. data/lua-hooks/ext/luajit/src/vm_x64.dasc +24 -25
  227. data/lua-hooks/ext/luajit/src/vm_x86.dasc +77 -4
  228. data/lua-hooks/libluahooks.darwin.a +0 -0
  229. data/lua-hooks/libluahooks.linux.a +0 -0
  230. data/lua-hooks/options.mk +1 -1
  231. metadata +37 -77
  232. data/lua-hooks/ext/all.c +0 -69
  233. data/lua-hooks/ext/libinjection/COPYING +0 -37
  234. data/lua-hooks/ext/libinjection/libinjection.h +0 -65
  235. data/lua-hooks/ext/libinjection/libinjection_html5.c +0 -847
  236. data/lua-hooks/ext/libinjection/libinjection_html5.h +0 -54
  237. data/lua-hooks/ext/libinjection/libinjection_sqli.c +0 -2301
  238. data/lua-hooks/ext/libinjection/libinjection_sqli.h +0 -295
  239. data/lua-hooks/ext/libinjection/libinjection_sqli_data.h +0 -9349
  240. data/lua-hooks/ext/libinjection/libinjection_xss.c +0 -531
  241. data/lua-hooks/ext/libinjection/libinjection_xss.h +0 -21
  242. data/lua-hooks/ext/libinjection/lualib.c +0 -145
  243. data/lua-hooks/ext/libinjection/module.mk +0 -5
  244. data/lua-hooks/ext/lpeg/HISTORY +0 -96
  245. data/lua-hooks/ext/lpeg/lpcap.c +0 -537
  246. data/lua-hooks/ext/lpeg/lpcap.h +0 -56
  247. data/lua-hooks/ext/lpeg/lpcode.c +0 -1014
  248. data/lua-hooks/ext/lpeg/lpcode.h +0 -40
  249. data/lua-hooks/ext/lpeg/lpeg-128.gif +0 -0
  250. data/lua-hooks/ext/lpeg/lpeg.html +0 -1445
  251. data/lua-hooks/ext/lpeg/lpprint.c +0 -244
  252. data/lua-hooks/ext/lpeg/lpprint.h +0 -36
  253. data/lua-hooks/ext/lpeg/lptree.c +0 -1303
  254. data/lua-hooks/ext/lpeg/lptree.h +0 -82
  255. data/lua-hooks/ext/lpeg/lptypes.h +0 -149
  256. data/lua-hooks/ext/lpeg/lpvm.c +0 -364
  257. data/lua-hooks/ext/lpeg/lpvm.h +0 -58
  258. data/lua-hooks/ext/lpeg/makefile +0 -55
  259. data/lua-hooks/ext/lpeg/module.mk +0 -6
  260. data/lua-hooks/ext/lpeg/re.html +0 -498
  261. data/lua-hooks/ext/lua-cmsgpack/.gitignore +0 -13
  262. data/lua-hooks/ext/lua-cmsgpack/CMakeLists.txt +0 -45
  263. data/lua-hooks/ext/lua-cmsgpack/README.md +0 -115
  264. data/lua-hooks/ext/lua-cmsgpack/lua_cmsgpack.c +0 -970
  265. data/lua-hooks/ext/lua-cmsgpack/module.mk +0 -2
  266. data/lua-hooks/ext/lua-cmsgpack/test.lua +0 -570
  267. data/lua-hooks/ext/lua-snapshot/LICENSE +0 -7
  268. data/lua-hooks/ext/lua-snapshot/Makefile +0 -12
  269. data/lua-hooks/ext/lua-snapshot/README.md +0 -18
  270. data/lua-hooks/ext/lua-snapshot/dump.lua +0 -15
  271. data/lua-hooks/ext/lua-snapshot/module.mk +0 -2
  272. data/lua-hooks/ext/lua-snapshot/snapshot.c +0 -462
  273. data/lua-hooks/ext/luautf8/README.md +0 -152
  274. data/lua-hooks/ext/luautf8/lutf8lib.c +0 -1274
  275. data/lua-hooks/ext/luautf8/module.mk +0 -2
  276. data/lua-hooks/ext/luautf8/unidata.h +0 -3064
  277. data/lua-hooks/ext/module.mk +0 -15
  278. data/lua-hooks/ext/modules.h +0 -17
  279. data/lua-hooks/ext/perf/luacpu.c +0 -114
  280. data/lua-hooks/ext/perf/lualoadavg.c +0 -40
  281. data/lua-hooks/ext/perf/luameminfo.c +0 -38
  282. data/lua-hooks/ext/perf/luaoslib.c +0 -203
  283. data/lua-hooks/ext/perf/module.mk +0 -5
  284. data/lua-hooks/ext/sha1/luasha1.c +0 -74
  285. data/lua-hooks/ext/sha1/module.mk +0 -5
  286. data/lua-hooks/ext/sha1/sha1.c +0 -145
  287. data/lua-hooks/ext/sha2/luasha256.c +0 -77
  288. data/lua-hooks/ext/sha2/module.mk +0 -5
  289. data/lua-hooks/ext/sha2/sha256.c +0 -196
  290. data/lua-hooks/ext/sysutils/lua_utils.c +0 -56
  291. data/lua-hooks/ext/sysutils/module.mk +0 -2
@@ -1,58 +0,0 @@
1
- /*
2
- ** $Id: lpvm.h,v 1.3 2014/02/21 13:06:41 roberto Exp $
3
- */
4
-
5
- #if !defined(lpvm_h)
6
- #define lpvm_h
7
-
8
- #include "lpcap.h"
9
-
10
-
11
- /* Virtual Machine's instructions */
12
- typedef enum Opcode {
13
- IAny, /* if no char, fail */
14
- IChar, /* if char != aux, fail */
15
- ISet, /* if char not in buff, fail */
16
- ITestAny, /* in no char, jump to 'offset' */
17
- ITestChar, /* if char != aux, jump to 'offset' */
18
- ITestSet, /* if char not in buff, jump to 'offset' */
19
- ISpan, /* read a span of chars in buff */
20
- IBehind, /* walk back 'aux' characters (fail if not possible) */
21
- IRet, /* return from a rule */
22
- IEnd, /* end of pattern */
23
- IChoice, /* stack a choice; next fail will jump to 'offset' */
24
- IJmp, /* jump to 'offset' */
25
- ICall, /* call rule at 'offset' */
26
- IOpenCall, /* call rule number 'key' (must be closed to a ICall) */
27
- ICommit, /* pop choice and jump to 'offset' */
28
- IPartialCommit, /* update top choice to current position and jump */
29
- IBackCommit, /* "fails" but jump to its own 'offset' */
30
- IFailTwice, /* pop one choice and then fail */
31
- IFail, /* go back to saved state on choice and jump to saved offset */
32
- IGiveup, /* internal use */
33
- IFullCapture, /* complete capture of last 'off' chars */
34
- IOpenCapture, /* start a capture */
35
- ICloseCapture,
36
- ICloseRunTime
37
- } Opcode;
38
-
39
-
40
-
41
- typedef union Instruction {
42
- struct Inst {
43
- byte code;
44
- byte aux;
45
- short key;
46
- } i;
47
- int offset;
48
- byte buff[1];
49
- } Instruction;
50
-
51
-
52
- void printpatt (Instruction *p, int n);
53
- const char *match (lua_State *L, const char *o, const char *s, const char *e,
54
- Instruction *op, Capture *capture, int ptop);
55
-
56
-
57
- #endif
58
-
@@ -1,55 +0,0 @@
1
- LIBNAME = lpeg
2
- LUADIR = ../lua/
3
-
4
- COPT = -O2
5
- # COPT = -DLPEG_DEBUG -g
6
-
7
- CWARNS = -Wall -Wextra -pedantic \
8
- -Waggregate-return \
9
- -Wcast-align \
10
- -Wcast-qual \
11
- -Wdisabled-optimization \
12
- -Wpointer-arith \
13
- -Wshadow \
14
- -Wsign-compare \
15
- -Wundef \
16
- -Wwrite-strings \
17
- -Wbad-function-cast \
18
- -Wdeclaration-after-statement \
19
- -Wmissing-prototypes \
20
- -Wnested-externs \
21
- -Wstrict-prototypes \
22
- # -Wunreachable-code \
23
-
24
-
25
- CFLAGS = $(CWARNS) $(COPT) -std=c99 -I$(LUADIR) -fPIC
26
- CC = gcc
27
-
28
- FILES = lpvm.o lpcap.o lptree.o lpcode.o lpprint.o
29
-
30
- # For Linux
31
- linux:
32
- make lpeg.so "DLLFLAGS = -shared -fPIC"
33
-
34
- # For Mac OS
35
- macosx:
36
- make lpeg.so "DLLFLAGS = -bundle -undefined dynamic_lookup"
37
-
38
- lpeg.so: $(FILES)
39
- env $(CC) $(DLLFLAGS) $(FILES) -o lpeg.so
40
-
41
- $(FILES): makefile
42
-
43
- test: test.lua re.lua lpeg.so
44
- ./test.lua
45
-
46
- clean:
47
- rm -f $(FILES) lpeg.so
48
-
49
-
50
- lpcap.o: lpcap.c lpcap.h lptypes.h
51
- lpcode.o: lpcode.c lptypes.h lpcode.h lptree.h lpvm.h lpcap.h
52
- lpprint.o: lpprint.c lptypes.h lpprint.h lptree.h lpvm.h lpcap.h
53
- lptree.o: lptree.c lptypes.h lpcap.h lpcode.h lptree.h lpvm.h lpprint.h
54
- lpvm.o: lpvm.c lpcap.h lptypes.h lpvm.h lpprint.h lptree.h
55
-
@@ -1,6 +0,0 @@
1
- SRC += \
2
- ext/lpeg/lpcap.c \
3
- ext/lpeg/lpcode.c \
4
- ext/lpeg/lpprint.c \
5
- ext/lpeg/lptree.c \
6
- ext/lpeg/lpvm.c
@@ -1,498 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
- <html>
4
- <head>
5
- <title>LPeg.re - Regex syntax for LPEG</title>
6
- <link rel="stylesheet"
7
- href="http://www.inf.puc-rio.br/~roberto/lpeg/doc.css"
8
- type="text/css"/>
9
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
10
- </head>
11
- <body>
12
-
13
- <!-- $Id: re.html,v 1.24 2016/09/20 17:41:27 roberto Exp $ -->
14
-
15
- <div id="container">
16
-
17
- <div id="product">
18
- <div id="product_logo">
19
- <a href="http://www.inf.puc-rio.br/~roberto/lpeg/">
20
- <img alt="LPeg logo" src="lpeg-128.gif"/>
21
- </a>
22
- </div>
23
- <div id="product_name"><big><strong>LPeg.re</strong></big></div>
24
- <div id="product_description">
25
- Regex syntax for LPEG
26
- </div>
27
- </div> <!-- id="product" -->
28
-
29
- <div id="main">
30
-
31
- <div id="navigation">
32
- <h1>re</h1>
33
-
34
- <ul>
35
- <li><a href="#basic">Basic Constructions</a></li>
36
- <li><a href="#func">Functions</a></li>
37
- <li><a href="#ex">Some Examples</a></li>
38
- <li><a href="#license">License</a></li>
39
- </ul>
40
- </li>
41
- </ul>
42
- </div> <!-- id="navigation" -->
43
-
44
- <div id="content">
45
-
46
- <h2><a name="basic"></a>The <code>re</code> Module</h2>
47
-
48
- <p>
49
- The <code>re</code> module
50
- (provided by file <code>re.lua</code> in the distribution)
51
- supports a somewhat conventional regex syntax
52
- for pattern usage within <a href="lpeg.html">LPeg</a>.
53
- </p>
54
-
55
- <p>
56
- The next table summarizes <code>re</code>'s syntax.
57
- A <code>p</code> represents an arbitrary pattern;
58
- <code>num</code> represents a number (<code>[0-9]+</code>);
59
- <code>name</code> represents an identifier
60
- (<code>[a-zA-Z][a-zA-Z0-9_]*</code>).
61
- Constructions are listed in order of decreasing precedence.
62
- <table border="1">
63
- <tbody><tr><td><b>Syntax</b></td><td><b>Description</b></td></tr>
64
- <tr><td><code>( p )</code></td> <td>grouping</td></tr>
65
- <tr><td><code>'string'</code></td> <td>literal string</td></tr>
66
- <tr><td><code>"string"</code></td> <td>literal string</td></tr>
67
- <tr><td><code>[class]</code></td> <td>character class</td></tr>
68
- <tr><td><code>.</code></td> <td>any character</td></tr>
69
- <tr><td><code>%name</code></td>
70
- <td>pattern <code>defs[name]</code> or a pre-defined pattern</td></tr>
71
- <tr><td><code>name</code></td><td>non terminal</td></tr>
72
- <tr><td><code>&lt;name&gt;</code></td><td>non terminal</td></tr>
73
- <tr><td><code>{}</code></td> <td>position capture</td></tr>
74
- <tr><td><code>{ p }</code></td> <td>simple capture</td></tr>
75
- <tr><td><code>{: p :}</code></td> <td>anonymous group capture</td></tr>
76
- <tr><td><code>{:name: p :}</code></td> <td>named group capture</td></tr>
77
- <tr><td><code>{~ p ~}</code></td> <td>substitution capture</td></tr>
78
- <tr><td><code>{| p |}</code></td> <td>table capture</td></tr>
79
- <tr><td><code>=name</code></td> <td>back reference
80
- </td></tr>
81
- <tr><td><code>p ?</code></td> <td>optional match</td></tr>
82
- <tr><td><code>p *</code></td> <td>zero or more repetitions</td></tr>
83
- <tr><td><code>p +</code></td> <td>one or more repetitions</td></tr>
84
- <tr><td><code>p^num</code></td> <td>exactly <code>n</code> repetitions</td></tr>
85
- <tr><td><code>p^+num</code></td>
86
- <td>at least <code>n</code> repetitions</td></tr>
87
- <tr><td><code>p^-num</code></td>
88
- <td>at most <code>n</code> repetitions</td></tr>
89
- <tr><td><code>p -&gt; 'string'</code></td> <td>string capture</td></tr>
90
- <tr><td><code>p -&gt; "string"</code></td> <td>string capture</td></tr>
91
- <tr><td><code>p -&gt; num</code></td> <td>numbered capture</td></tr>
92
- <tr><td><code>p -&gt; name</code></td> <td>function/query/string capture
93
- equivalent to <code>p / defs[name]</code></td></tr>
94
- <tr><td><code>p =&gt; name</code></td> <td>match-time capture
95
- equivalent to <code>lpeg.Cmt(p, defs[name])</code></td></tr>
96
- <tr><td><code>& p</code></td> <td>and predicate</td></tr>
97
- <tr><td><code>! p</code></td> <td>not predicate</td></tr>
98
- <tr><td><code>p1 p2</code></td> <td>concatenation</td></tr>
99
- <tr><td><code>p1 / p2</code></td> <td>ordered choice</td></tr>
100
- <tr><td>(<code>name &lt;- p</code>)<sup>+</sup></td> <td>grammar</td></tr>
101
- </tbody></table>
102
- <p>
103
- Any space appearing in a syntax description can be
104
- replaced by zero or more space characters and Lua-style comments
105
- (<code>--</code> until end of line).
106
- </p>
107
-
108
- <p>
109
- Character classes define sets of characters.
110
- An initial <code>^</code> complements the resulting set.
111
- A range <em>x</em><code>-</code><em>y</em> includes in the set
112
- all characters with codes between the codes of <em>x</em> and <em>y</em>.
113
- A pre-defined class <code>%</code><em>name</em> includes all
114
- characters of that class.
115
- A simple character includes itself in the set.
116
- The only special characters inside a class are <code>^</code>
117
- (special only if it is the first character);
118
- <code>]</code>
119
- (can be included in the set as the first character,
120
- after the optional <code>^</code>);
121
- <code>%</code> (special only if followed by a letter);
122
- and <code>-</code>
123
- (can be included in the set as the first or the last character).
124
- </p>
125
-
126
- <p>
127
- Currently the pre-defined classes are similar to those from the
128
- Lua's string library
129
- (<code>%a</code> for letters,
130
- <code>%A</code> for non letters, etc.).
131
- There is also a class <code>%nl</code>
132
- containing only the newline character,
133
- which is particularly handy for grammars written inside long strings,
134
- as long strings do not interpret escape sequences like <code>\n</code>.
135
- </p>
136
-
137
-
138
- <h2><a name="func">Functions</a></h2>
139
-
140
- <h3><code>re.compile (string, [, defs])</code></h3>
141
- <p>
142
- Compiles the given string and
143
- returns an equivalent LPeg pattern.
144
- The given string may define either an expression or a grammar.
145
- The optional <code>defs</code> table provides extra Lua values
146
- to be used by the pattern.
147
- </p>
148
-
149
- <h3><code>re.find (subject, pattern [, init])</code></h3>
150
- <p>
151
- Searches the given pattern in the given subject.
152
- If it finds a match,
153
- returns the index where this occurrence starts and
154
- the index where it ends.
155
- Otherwise, returns nil.
156
- </p>
157
-
158
- <p>
159
- An optional numeric argument <code>init</code> makes the search
160
- starts at that position in the subject string.
161
- As usual in Lua libraries,
162
- a negative value counts from the end.
163
- </p>
164
-
165
- <h3><code>re.gsub (subject, pattern, replacement)</code></h3>
166
- <p>
167
- Does a <em>global substitution</em>,
168
- replacing all occurrences of <code>pattern</code>
169
- in the given <code>subject</code> by <code>replacement</code>.
170
-
171
- <h3><code>re.match (subject, pattern)</code></h3>
172
- <p>
173
- Matches the given pattern against the given subject,
174
- returning all captures.
175
- </p>
176
-
177
- <h3><code>re.updatelocale ()</code></h3>
178
- <p>
179
- Updates the pre-defined character classes to the current locale.
180
- </p>
181
-
182
-
183
- <h2><a name="ex">Some Examples</a></h2>
184
-
185
- <h3>A complete simple program</h3>
186
- <p>
187
- The next code shows a simple complete Lua program using
188
- the <code>re</code> module:
189
- </p>
190
- <pre class="example">
191
- local re = require"re"
192
-
193
- -- find the position of the first numeral in a string
194
- print(re.find("the number 423 is odd", "[0-9]+")) --&gt; 12 14
195
-
196
- -- returns all words in a string
197
- print(re.match("the number 423 is odd", "({%a+} / .)*"))
198
- --&gt; the number is odd
199
-
200
- -- returns the first numeral in a string
201
- print(re.match("the number 423 is odd", "s <- {%d+} / . s"))
202
- --&gt; 423
203
-
204
- print(re.gsub("hello World", "[aeiou]", "."))
205
- --&gt; h.ll. W.rld
206
- </pre>
207
-
208
-
209
- <h3>Balanced parentheses</h3>
210
- <p>
211
- The following call will produce the same pattern produced by the
212
- Lua expression in the
213
- <a href="lpeg.html#balanced">balanced parentheses</a> example:
214
- </p>
215
- <pre class="example">
216
- b = re.compile[[ balanced &lt;- "(" ([^()] / balanced)* ")" ]]
217
- </pre>
218
-
219
- <h3>String reversal</h3>
220
- <p>
221
- The next example reverses a string:
222
- </p>
223
- <pre class="example">
224
- rev = re.compile[[ R &lt;- (!.) -&gt; '' / ({.} R) -&gt; '%2%1']]
225
- print(rev:match"0123456789") --&gt; 9876543210
226
- </pre>
227
-
228
- <h3>CSV decoder</h3>
229
- <p>
230
- The next example replicates the <a href="lpeg.html#CSV">CSV decoder</a>:
231
- </p>
232
- <pre class="example">
233
- record = re.compile[[
234
- record &lt;- {| field (',' field)* |} (%nl / !.)
235
- field &lt;- escaped / nonescaped
236
- nonescaped &lt;- { [^,"%nl]* }
237
- escaped &lt;- '"' {~ ([^"] / '""' -&gt; '"')* ~} '"'
238
- ]]
239
- </pre>
240
-
241
- <h3>Lua's long strings</h3>
242
- <p>
243
- The next example matches Lua long strings:
244
- </p>
245
- <pre class="example">
246
- c = re.compile([[
247
- longstring &lt;- ('[' {:eq: '='* :} '[' close)
248
- close &lt;- ']' =eq ']' / . close
249
- ]])
250
-
251
- print(c:match'[==[]]===]]]]==]===[]') --&gt; 17
252
- </pre>
253
-
254
- <h3>Abstract Syntax Trees</h3>
255
- <p>
256
- This example shows a simple way to build an
257
- abstract syntax tree (AST) for a given grammar.
258
- To keep our example simple,
259
- let us consider the following grammar
260
- for lists of names:
261
- </p>
262
- <pre class="example">
263
- p = re.compile[[
264
- listname &lt;- (name s)*
265
- name &lt;- [a-z][a-z]*
266
- s &lt;- %s*
267
- ]]
268
- </pre>
269
- <p>
270
- Now, we will add captures to build a corresponding AST.
271
- As a first step, the pattern will build a table to
272
- represent each non terminal;
273
- terminals will be represented by their corresponding strings:
274
- </p>
275
- <pre class="example">
276
- c = re.compile[[
277
- listname &lt;- {| (name s)* |}
278
- name &lt;- {| {[a-z][a-z]*} |}
279
- s &lt;- %s*
280
- ]]
281
- </pre>
282
- <p>
283
- Now, a match against <code>"hi hello bye"</code>
284
- results in the table
285
- <code>{{"hi"}, {"hello"}, {"bye"}}</code>.
286
- </p>
287
- <p>
288
- For such a simple grammar,
289
- this AST is more than enough;
290
- actually, the tables around each single name
291
- are already overkilling.
292
- More complex grammars,
293
- however, may need some more structure.
294
- Specifically,
295
- it would be useful if each table had
296
- a <code>tag</code> field telling what non terminal
297
- that table represents.
298
- We can add such a tag using
299
- <a href="lpeg.html#cap-g">named group captures</a>:
300
- </p>
301
- <pre class="example">
302
- x = re.compile[[
303
- listname <- {| {:tag: '' -> 'list':} (name s)* |}
304
- name <- {| {:tag: '' -> 'id':} {[a-z][a-z]*} |}
305
- s <- ' '*
306
- ]]
307
- </pre>
308
- <p>
309
- With these group captures,
310
- a match against <code>"hi hello bye"</code>
311
- results in the following table:
312
- </p>
313
- <pre class="example">
314
- {tag="list",
315
- {tag="id", "hi"},
316
- {tag="id", "hello"},
317
- {tag="id", "bye"}
318
- }
319
- </pre>
320
-
321
-
322
- <h3>Indented blocks</h3>
323
- <p>
324
- This example breaks indented blocks into tables,
325
- respecting the indentation:
326
- </p>
327
- <pre class="example">
328
- p = re.compile[[
329
- block &lt;- {| {:ident:' '*:} line
330
- ((=ident !' ' line) / &(=ident ' ') block)* |}
331
- line &lt;- {[^%nl]*} %nl
332
- ]]
333
- </pre>
334
- <p>
335
- As an example,
336
- consider the following text:
337
- </p>
338
- <pre class="example">
339
- t = p:match[[
340
- first line
341
- subline 1
342
- subline 2
343
- second line
344
- third line
345
- subline 3.1
346
- subline 3.1.1
347
- subline 3.2
348
- ]]
349
- </pre>
350
- <p>
351
- The resulting table <code>t</code> will be like this:
352
- </p>
353
- <pre class="example">
354
- {'first line'; {'subline 1'; 'subline 2'; ident = ' '};
355
- 'second line';
356
- 'third line'; { 'subline 3.1'; {'subline 3.1.1'; ident = ' '};
357
- 'subline 3.2'; ident = ' '};
358
- ident = ''}
359
- </pre>
360
-
361
- <h3>Macro expander</h3>
362
- <p>
363
- This example implements a simple macro expander.
364
- Macros must be defined as part of the pattern,
365
- following some simple rules:
366
- </p>
367
- <pre class="example">
368
- p = re.compile[[
369
- text &lt;- {~ item* ~}
370
- item &lt;- macro / [^()] / '(' item* ')'
371
- arg &lt;- ' '* {~ (!',' item)* ~}
372
- args &lt;- '(' arg (',' arg)* ')'
373
- -- now we define some macros
374
- macro &lt;- ('apply' args) -&gt; '%1(%2)'
375
- / ('add' args) -&gt; '%1 + %2'
376
- / ('mul' args) -&gt; '%1 * %2'
377
- ]]
378
-
379
- print(p:match"add(mul(a,b), apply(f,x))") --&gt; a * b + f(x)
380
- </pre>
381
- <p>
382
- A <code>text</code> is a sequence of items,
383
- wherein we apply a substitution capture to expand any macros.
384
- An <code>item</code> is either a macro,
385
- any character different from parentheses,
386
- or a parenthesized expression.
387
- A macro argument (<code>arg</code>) is a sequence
388
- of items different from a comma.
389
- (Note that a comma may appear inside an item,
390
- e.g., inside a parenthesized expression.)
391
- Again we do a substitution capture to expand any macro
392
- in the argument before expanding the outer macro.
393
- <code>args</code> is a list of arguments separated by commas.
394
- Finally we define the macros.
395
- Each macro is a string substitution;
396
- it replaces the macro name and its arguments by its corresponding string,
397
- with each <code>%</code><em>n</em> replaced by the <em>n</em>-th argument.
398
- </p>
399
-
400
- <h3>Patterns</h3>
401
- <p>
402
- This example shows the complete syntax
403
- of patterns accepted by <code>re</code>.
404
- </p>
405
- <pre class="example">
406
- p = [=[
407
-
408
- pattern &lt;- exp !.
409
- exp &lt;- S (grammar / alternative)
410
-
411
- alternative &lt;- seq ('/' S seq)*
412
- seq &lt;- prefix*
413
- prefix &lt;- '&amp;' S prefix / '!' S prefix / suffix
414
- suffix &lt;- primary S (([+*?]
415
- / '^' [+-]? num
416
- / '-&gt;' S (string / '{}' / name)
417
- / '=&gt;' S name) S)*
418
-
419
- primary &lt;- '(' exp ')' / string / class / defined
420
- / '{:' (name ':')? exp ':}'
421
- / '=' name
422
- / '{}'
423
- / '{~' exp '~}'
424
- / '{' exp '}'
425
- / '.'
426
- / name S !arrow
427
- / '&lt;' name '&gt;' -- old-style non terminals
428
-
429
- grammar &lt;- definition+
430
- definition &lt;- name S arrow exp
431
-
432
- class &lt;- '[' '^'? item (!']' item)* ']'
433
- item &lt;- defined / range / .
434
- range &lt;- . '-' [^]]
435
-
436
- S &lt;- (%s / '--' [^%nl]*)* -- spaces and comments
437
- name &lt;- [A-Za-z][A-Za-z0-9_]*
438
- arrow &lt;- '&lt;-'
439
- num &lt;- [0-9]+
440
- string &lt;- '"' [^"]* '"' / "'" [^']* "'"
441
- defined &lt;- '%' name
442
-
443
- ]=]
444
-
445
- print(re.match(p, p)) -- a self description must match itself
446
- </pre>
447
-
448
-
449
-
450
- <h2><a name="license">License</a></h2>
451
-
452
- <p>
453
- Copyright &copy; 2008-2015 Lua.org, PUC-Rio.
454
- </p>
455
- <p>
456
- Permission is hereby granted, free of charge,
457
- to any person obtaining a copy of this software and
458
- associated documentation files (the "Software"),
459
- to deal in the Software without restriction,
460
- including without limitation the rights to use,
461
- copy, modify, merge, publish, distribute, sublicense,
462
- and/or sell copies of the Software,
463
- and to permit persons to whom the Software is
464
- furnished to do so,
465
- subject to the following conditions:
466
- </p>
467
-
468
- <p>
469
- The above copyright notice and this permission notice
470
- shall be included in all copies or substantial portions of the Software.
471
- </p>
472
-
473
- <p>
474
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
475
- EXPRESS OR IMPLIED,
476
- INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
477
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
478
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
479
- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
480
- TORT OR OTHERWISE, ARISING FROM,
481
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
482
- THE SOFTWARE.
483
- </p>
484
-
485
- </div> <!-- id="content" -->
486
-
487
- </div> <!-- id="main" -->
488
-
489
- <div id="about">
490
- <p><small>
491
- $Id: re.html,v 1.24 2016/09/20 17:41:27 roberto Exp $
492
- </small></p>
493
- </div> <!-- id="about" -->
494
-
495
- </div> <!-- id="container" -->
496
-
497
- </body>
498
- </html>