rattler 0.4.2 → 0.5.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.
Files changed (347) hide show
  1. data/README.rdoc +9 -3
  2. data/features/command_line/dest_option.feature +1 -1
  3. data/features/command_line/lib_option.feature +2 -2
  4. data/features/command_line/output_option.feature +2 -2
  5. data/features/command_line/parser_generator.feature +3 -3
  6. data/features/grammar/any_character.feature +0 -4
  7. data/features/grammar/back_reference.feature +0 -4
  8. data/features/grammar/character_class.feature +0 -4
  9. data/features/grammar/comments.feature +0 -4
  10. data/features/grammar/e_symbol.feature +18 -0
  11. data/features/grammar/eof.feature +0 -4
  12. data/features/grammar/fail.feature +0 -4
  13. data/features/grammar/list_matching.feature +52 -3
  14. data/features/grammar/literal.feature +0 -4
  15. data/features/grammar/negative_lookahead.feature +0 -4
  16. data/features/grammar/negative_semantic_predicate.feature +99 -0
  17. data/features/grammar/node_action.feature +17 -4
  18. data/features/grammar/nonterminal.feature +3 -7
  19. data/features/grammar/one_or_more.feature +0 -4
  20. data/features/grammar/optional.feature +0 -4
  21. data/features/grammar/ordered_choice.feature +0 -4
  22. data/features/grammar/positive_lookahead.feature +0 -4
  23. data/features/grammar/positive_semantic_predicate.feature +99 -0
  24. data/features/grammar/posix_class.feature +3 -6
  25. data/features/grammar/repeat.feature +50 -0
  26. data/features/grammar/sequence.feature +0 -4
  27. data/features/grammar/side_effect.feature +81 -0
  28. data/features/grammar/skip_operator.feature +2 -5
  29. data/features/grammar/start_rule.feature +1 -5
  30. data/features/grammar/symantic_action.feature +9 -4
  31. data/features/grammar/token.feature +0 -4
  32. data/features/grammar/whitespace.feature +0 -4
  33. data/features/grammar/word_literal.feature +0 -4
  34. data/features/grammar/zero_or_more.feature +0 -4
  35. data/features/step_definitions/grammar_steps.rb +5 -1
  36. data/lib/rattler/back_end/optimizer.rb +1 -0
  37. data/lib/rattler/back_end/optimizer/reduce_repeat_match.rb +20 -8
  38. data/lib/rattler/back_end/optimizer/simplify_redundant_repeat.rb +10 -7
  39. data/lib/rattler/back_end/optimizer/specialize_repeat.rb +40 -0
  40. data/lib/rattler/back_end/parser_generator.rb +11 -6
  41. data/lib/rattler/back_end/parser_generator/delegating_generator.rb +20 -0
  42. data/lib/rattler/back_end/parser_generator/e_symbol_generator.rb +52 -0
  43. data/lib/rattler/back_end/parser_generator/eof_generator.rb +58 -0
  44. data/lib/rattler/back_end/parser_generator/expr_generator.rb +6 -2
  45. data/lib/rattler/back_end/parser_generator/gen_method_names.rb +15 -5
  46. data/lib/rattler/back_end/parser_generator/general_list_generator.rb +194 -0
  47. data/lib/rattler/back_end/parser_generator/general_repeat_generator.rb +177 -0
  48. data/lib/rattler/back_end/parser_generator/label_generator.rb +4 -1
  49. data/lib/rattler/back_end/parser_generator/list0_generating.rb +36 -0
  50. data/lib/rattler/back_end/parser_generator/list1_generating.rb +30 -0
  51. data/lib/rattler/back_end/parser_generator/list_generator.rb +16 -20
  52. data/lib/rattler/back_end/parser_generator/one_or_more_generating.rb +25 -0
  53. data/lib/rattler/back_end/parser_generator/{optional_generator.rb → optional_generating.rb} +66 -81
  54. data/lib/rattler/back_end/parser_generator/predicate_propogating.rb +4 -4
  55. data/lib/rattler/back_end/parser_generator/repeat_generator.rb +53 -0
  56. data/lib/rattler/back_end/parser_generator/skip_propogating.rb +2 -2
  57. data/lib/rattler/back_end/parser_generator/sub_generating.rb +16 -18
  58. data/lib/rattler/back_end/parser_generator/token_propogating.rb +1 -1
  59. data/lib/rattler/back_end/parser_generator/zero_or_more_generating.rb +31 -0
  60. data/lib/rattler/grammar/grammar_parser.rb +20 -0
  61. data/lib/rattler/grammar/metagrammar.rb +131 -13
  62. data/lib/rattler/grammar/rattler.rtlr +25 -12
  63. data/lib/rattler/parsers.rb +9 -5
  64. data/lib/rattler/parsers/assert_code.rb +31 -0
  65. data/lib/rattler/parsers/atomic.rb +19 -0
  66. data/lib/rattler/parsers/direct_action.rb +12 -4
  67. data/lib/rattler/parsers/disallow_code.rb +31 -0
  68. data/lib/rattler/parsers/dispatch_action.rb +3 -2
  69. data/lib/rattler/parsers/e_symbol.rb +47 -0
  70. data/lib/rattler/parsers/effect_code.rb +31 -0
  71. data/lib/rattler/parsers/eof.rb +6 -13
  72. data/lib/rattler/parsers/list_parser.rb +33 -14
  73. data/lib/rattler/parsers/match.rb +1 -6
  74. data/lib/rattler/parsers/parser_dsl.rb +78 -35
  75. data/lib/rattler/parsers/predicate.rb +1 -4
  76. data/lib/rattler/parsers/repeat.rb +76 -0
  77. data/lib/rattler/parsers/semantic_assert.rb +19 -0
  78. data/lib/rattler/parsers/semantic_disallow.rb +19 -0
  79. data/lib/rattler/parsers/side_effect.rb +19 -0
  80. data/lib/rattler/parsers/skip.rb +1 -9
  81. data/lib/rattler/parsers/token.rb +1 -6
  82. data/lib/rattler/util/graphviz/node_builder.rb +6 -3
  83. data/spec/rattler/back_end/assert_compiler_examples.rb +187 -0
  84. data/spec/rattler/back_end/direct_action_compiler_examples.rb +227 -0
  85. data/spec/rattler/back_end/disallow_compiler_examples.rb +187 -0
  86. data/spec/rattler/back_end/dispatch_action_compiler_examples.rb +225 -0
  87. data/spec/rattler/back_end/optimizer/reduce_repeat_match_spec.rb +45 -33
  88. data/spec/rattler/back_end/optimizer/simplify_redundant_repeat_spec.rb +32 -172
  89. data/spec/rattler/back_end/parser_generator/e_symbol_generator_spec.rb +149 -0
  90. data/spec/rattler/back_end/parser_generator/eof_generator_spec.rb +152 -0
  91. data/spec/rattler/back_end/parser_generator/label_generator_spec.rb +4 -4
  92. data/spec/rattler/back_end/parser_generator/list0_generator_examples.rb +322 -0
  93. data/spec/rattler/back_end/parser_generator/list1_generator_examples.rb +343 -0
  94. data/spec/rattler/back_end/parser_generator/list_generator_spec.rb +597 -140
  95. data/spec/rattler/back_end/parser_generator/one_or_more_generator_examples.rb +292 -0
  96. data/spec/rattler/back_end/parser_generator/optional_generator_examples.rb +233 -0
  97. data/spec/rattler/back_end/parser_generator/repeat_generator_spec.rb +281 -0
  98. data/spec/rattler/back_end/parser_generator/zero_or_more_generator_examples.rb +277 -0
  99. data/spec/rattler/back_end/semantic_assert_compiler_examples.rb +152 -0
  100. data/spec/rattler/back_end/semantic_disallow_compiler_examples.rb +152 -0
  101. data/spec/rattler/back_end/shared_compiler_examples.rb +106 -651
  102. data/spec/rattler/back_end/side_effect_compiler_examples.rb +227 -0
  103. data/spec/rattler/back_end/skip_compiler_examples.rb +161 -0
  104. data/spec/rattler/back_end/token_compiler_examples.rb +262 -0
  105. data/spec/rattler/grammar/grammar_parser_spec.rb +302 -23
  106. data/spec/rattler/parsers/apply_spec.rb +6 -0
  107. data/spec/rattler/parsers/assert_spec.rb +18 -7
  108. data/spec/rattler/parsers/back_reference_spec.rb +9 -0
  109. data/spec/rattler/parsers/choice_spec.rb +36 -21
  110. data/spec/rattler/parsers/direct_action_spec.rb +76 -36
  111. data/spec/rattler/parsers/disallow_spec.rb +18 -7
  112. data/spec/rattler/parsers/dispatch_action_spec.rb +128 -22
  113. data/spec/rattler/parsers/e_symbol_spec.rb +30 -0
  114. data/spec/rattler/parsers/eof_spec.rb +15 -6
  115. data/spec/rattler/parsers/label_spec.rb +15 -2
  116. data/spec/rattler/parsers/list_parser_spec.rb +187 -0
  117. data/spec/rattler/parsers/match_spec.rb +16 -7
  118. data/spec/rattler/parsers/parser_dsl_spec.rb +82 -23
  119. data/spec/rattler/parsers/repeat_spec.rb +233 -0
  120. data/spec/rattler/parsers/semantic_assert_spec.rb +83 -0
  121. data/spec/rattler/parsers/semantic_disallow_spec.rb +83 -0
  122. data/spec/rattler/parsers/sequence_spec.rb +34 -20
  123. data/spec/rattler/parsers/side_effect_spec.rb +214 -0
  124. data/spec/rattler/parsers/skip_spec.rb +17 -6
  125. data/spec/rattler_spec.rb +2 -0
  126. data/spec/support/compiler_spec_helper.rb +8 -0
  127. metadata +156 -447
  128. data/bin/rtlr.compiled.rbc +0 -201
  129. data/features/step_definitions/cli_steps.rbc +0 -149
  130. data/features/step_definitions/grammar_steps.rbc +0 -1211
  131. data/features/support/env.rbc +0 -389
  132. data/lib/rattler.rbc +0 -1231
  133. data/lib/rattler/back_end.rbc +0 -286
  134. data/lib/rattler/back_end/compiler.rbc +0 -1394
  135. data/lib/rattler/back_end/optimizer.rbc +0 -2000
  136. data/lib/rattler/back_end/optimizer/composite_reducing.rbc +0 -337
  137. data/lib/rattler/back_end/optimizer/flatten_choice.rbc +0 -443
  138. data/lib/rattler/back_end/optimizer/flatten_sequence.rbc +0 -827
  139. data/lib/rattler/back_end/optimizer/flattening.rbc +0 -570
  140. data/lib/rattler/back_end/optimizer/inline_regular_rules.rbc +0 -691
  141. data/lib/rattler/back_end/optimizer/join_match_capturing_sequence.rbc +0 -1299
  142. data/lib/rattler/back_end/optimizer/join_match_choice.rbc +0 -523
  143. data/lib/rattler/back_end/optimizer/join_match_matching_sequence.rbc +0 -619
  144. data/lib/rattler/back_end/optimizer/join_match_sequence.rbc +0 -174
  145. data/lib/rattler/back_end/optimizer/join_predicate_bare_match.rbc +0 -1505
  146. data/lib/rattler/back_end/optimizer/join_predicate_match.rbc +0 -174
  147. data/lib/rattler/back_end/optimizer/join_predicate_nested_match.rbc +0 -620
  148. data/lib/rattler/back_end/optimizer/join_predicate_or_bare_match.rbc +0 -1502
  149. data/lib/rattler/back_end/optimizer/join_predicate_or_match.rbc +0 -174
  150. data/lib/rattler/back_end/optimizer/join_predicate_or_nested_match.rbc +0 -616
  151. data/lib/rattler/back_end/optimizer/match_joining.rbc +0 -1454
  152. data/lib/rattler/back_end/optimizer/optimization.rbc +0 -1366
  153. data/lib/rattler/back_end/optimizer/optimization_context.rbc +0 -1386
  154. data/lib/rattler/back_end/optimizer/optimization_sequence.rbc +0 -520
  155. data/lib/rattler/back_end/optimizer/optimize_children.rbc +0 -793
  156. data/lib/rattler/back_end/optimizer/reduce_repeat_match.rbc +0 -788
  157. data/lib/rattler/back_end/optimizer/remove_meaningless_wrapper.rbc +0 -508
  158. data/lib/rattler/back_end/optimizer/simplify_redundant_repeat.rbc +0 -807
  159. data/lib/rattler/back_end/optimizer/simplify_token_match.rbc +0 -561
  160. data/lib/rattler/back_end/parser_generator.rbc +0 -1326
  161. data/lib/rattler/back_end/parser_generator/apply_generator.rbc +0 -2148
  162. data/lib/rattler/back_end/parser_generator/assert_generator.rbc +0 -1967
  163. data/lib/rattler/back_end/parser_generator/back_reference_generator.rbc +0 -1665
  164. data/lib/rattler/back_end/parser_generator/choice_generator.rbc +0 -2793
  165. data/lib/rattler/back_end/parser_generator/direct_action_generator.rbc +0 -1071
  166. data/lib/rattler/back_end/parser_generator/disallow_generator.rbc +0 -1967
  167. data/lib/rattler/back_end/parser_generator/dispatch_action_generator.rbc +0 -1071
  168. data/lib/rattler/back_end/parser_generator/expr_generator.rbc +0 -2295
  169. data/lib/rattler/back_end/parser_generator/fail_generator.rbc +0 -1216
  170. data/lib/rattler/back_end/parser_generator/gen_method_names.rbc +0 -296
  171. data/lib/rattler/back_end/parser_generator/group_match.rbc +0 -612
  172. data/lib/rattler/back_end/parser_generator/group_match_generator.rbc +0 -1647
  173. data/lib/rattler/back_end/parser_generator/label_generator.rbc +0 -1401
  174. data/lib/rattler/back_end/parser_generator/list1_generator.rb +0 -54
  175. data/lib/rattler/back_end/parser_generator/list1_generator.rbc +0 -1237
  176. data/lib/rattler/back_end/parser_generator/list_generating.rb +0 -71
  177. data/lib/rattler/back_end/parser_generator/list_generating.rbc +0 -1900
  178. data/lib/rattler/back_end/parser_generator/list_generator.rbc +0 -1068
  179. data/lib/rattler/back_end/parser_generator/match_generator.rbc +0 -1743
  180. data/lib/rattler/back_end/parser_generator/nested.rbc +0 -496
  181. data/lib/rattler/back_end/parser_generator/one_or_more_generator.rb +0 -56
  182. data/lib/rattler/back_end/parser_generator/one_or_more_generator.rbc +0 -1277
  183. data/lib/rattler/back_end/parser_generator/optional_generator.rbc +0 -2025
  184. data/lib/rattler/back_end/parser_generator/predicate_propogating.rbc +0 -648
  185. data/lib/rattler/back_end/parser_generator/repeat_generating.rb +0 -57
  186. data/lib/rattler/back_end/parser_generator/repeat_generating.rbc +0 -1549
  187. data/lib/rattler/back_end/parser_generator/rule_generator.rbc +0 -1239
  188. data/lib/rattler/back_end/parser_generator/rule_set_generator.rbc +0 -2641
  189. data/lib/rattler/back_end/parser_generator/sequence_generator.rbc +0 -4867
  190. data/lib/rattler/back_end/parser_generator/skip_generator.rbc +0 -1278
  191. data/lib/rattler/back_end/parser_generator/skip_propogating.rbc +0 -432
  192. data/lib/rattler/back_end/parser_generator/sub_generating.rbc +0 -2785
  193. data/lib/rattler/back_end/parser_generator/token_generator.rbc +0 -755
  194. data/lib/rattler/back_end/parser_generator/token_propogating.rbc +0 -324
  195. data/lib/rattler/back_end/parser_generator/top_level.rbc +0 -352
  196. data/lib/rattler/back_end/parser_generator/zero_or_more_generator.rb +0 -53
  197. data/lib/rattler/back_end/parser_generator/zero_or_more_generator.rbc +0 -1111
  198. data/lib/rattler/back_end/ruby_generator.rbc +0 -1841
  199. data/lib/rattler/grammar.rbc +0 -557
  200. data/lib/rattler/grammar/analysis.rbc +0 -1944
  201. data/lib/rattler/grammar/grammar.rbc +0 -1090
  202. data/lib/rattler/grammar/grammar_dsl.rbc +0 -1401
  203. data/lib/rattler/grammar/grammar_parser.rbc +0 -2096
  204. data/lib/rattler/grammar/metagrammar.rbc +0 -11014
  205. data/lib/rattler/parsers.rbc +0 -1006
  206. data/lib/rattler/parsers/action_code.rbc +0 -1577
  207. data/lib/rattler/parsers/apply.rbc +0 -562
  208. data/lib/rattler/parsers/assert.rbc +0 -378
  209. data/lib/rattler/parsers/back_reference.rbc +0 -871
  210. data/lib/rattler/parsers/choice.rbc +0 -607
  211. data/lib/rattler/parsers/combinator_parser.rbc +0 -612
  212. data/lib/rattler/parsers/combining.rbc +0 -570
  213. data/lib/rattler/parsers/direct_action.rbc +0 -1472
  214. data/lib/rattler/parsers/disallow.rbc +0 -379
  215. data/lib/rattler/parsers/dispatch_action.rbc +0 -2078
  216. data/lib/rattler/parsers/eof.rbc +0 -567
  217. data/lib/rattler/parsers/fail.rbc +0 -745
  218. data/lib/rattler/parsers/label.rbc +0 -749
  219. data/lib/rattler/parsers/list.rbc +0 -292
  220. data/lib/rattler/parsers/list0.rb +0 -26
  221. data/lib/rattler/parsers/list0.rbc +0 -292
  222. data/lib/rattler/parsers/list1.rb +0 -26
  223. data/lib/rattler/parsers/list1.rbc +0 -305
  224. data/lib/rattler/parsers/list_parser.rbc +0 -886
  225. data/lib/rattler/parsers/match.rbc +0 -621
  226. data/lib/rattler/parsers/node_code.rbc +0 -1064
  227. data/lib/rattler/parsers/one_or_more.rb +0 -47
  228. data/lib/rattler/parsers/one_or_more.rbc +0 -475
  229. data/lib/rattler/parsers/optional.rb +0 -42
  230. data/lib/rattler/parsers/optional.rbc +0 -450
  231. data/lib/rattler/parsers/parser.rbc +0 -994
  232. data/lib/rattler/parsers/parser_dsl.rbc +0 -4765
  233. data/lib/rattler/parsers/predicate.rbc +0 -490
  234. data/lib/rattler/parsers/rule.rbc +0 -777
  235. data/lib/rattler/parsers/rule_set.rbc +0 -1438
  236. data/lib/rattler/parsers/sequence.rbc +0 -1040
  237. data/lib/rattler/parsers/skip.rbc +0 -613
  238. data/lib/rattler/parsers/token.rbc +0 -457
  239. data/lib/rattler/parsers/zero_or_more.rb +0 -40
  240. data/lib/rattler/parsers/zero_or_more.rbc +0 -462
  241. data/lib/rattler/runner.rbc +0 -3813
  242. data/lib/rattler/runtime.rbc +0 -370
  243. data/lib/rattler/runtime/extended_packrat_parser.rbc +0 -2351
  244. data/lib/rattler/runtime/packrat_parser.rbc +0 -1390
  245. data/lib/rattler/runtime/parse_failure.rbc +0 -909
  246. data/lib/rattler/runtime/parse_node.rbc +0 -1007
  247. data/lib/rattler/runtime/parser.rbc +0 -2267
  248. data/lib/rattler/runtime/parser_helper.rbc +0 -337
  249. data/lib/rattler/runtime/recursive_descent_parser.rbc +0 -942
  250. data/lib/rattler/util.rbc +0 -286
  251. data/lib/rattler/util/graphviz.rbc +0 -327
  252. data/lib/rattler/util/graphviz/node_builder.rbc +0 -2207
  253. data/lib/rattler/util/line_counter.rbc +0 -988
  254. data/lib/rattler/util/node.rbc +0 -2393
  255. data/lib/rattler/util/parser_spec_helper.rbc +0 -2533
  256. data/spec/rattler/back_end/compiler_spec.rbc +0 -1187
  257. data/spec/rattler/back_end/optimizer/flatten_choice_spec.rbc +0 -2093
  258. data/spec/rattler/back_end/optimizer/flatten_sequence_spec.rbc +0 -4055
  259. data/spec/rattler/back_end/optimizer/inline_regular_rules_spec.rbc +0 -2345
  260. data/spec/rattler/back_end/optimizer/join_match_capturing_sequence_spec.rbc +0 -7006
  261. data/spec/rattler/back_end/optimizer/join_match_choice_spec.rbc +0 -3252
  262. data/spec/rattler/back_end/optimizer/join_match_matching_sequence_spec.rbc +0 -3681
  263. data/spec/rattler/back_end/optimizer/join_predicate_bare_match_spec.rbc +0 -5603
  264. data/spec/rattler/back_end/optimizer/join_predicate_nested_match_spec.rbc +0 -5232
  265. data/spec/rattler/back_end/optimizer/join_predicate_or_bare_match_spec.rbc +0 -4272
  266. data/spec/rattler/back_end/optimizer/join_predicate_or_nested_match_spec.rbc +0 -4342
  267. data/spec/rattler/back_end/optimizer/reduce_repeat_match_spec.rbc +0 -2960
  268. data/spec/rattler/back_end/optimizer/simplify_redundant_repeat_spec.rbc +0 -6929
  269. data/spec/rattler/back_end/optimizer/simplify_token_match_spec.rbc +0 -2327
  270. data/spec/rattler/back_end/optimizer_spec.rbc +0 -372
  271. data/spec/rattler/back_end/parser_generator/apply_generator_spec.rbc +0 -4710
  272. data/spec/rattler/back_end/parser_generator/assert_generator_spec.rbc +0 -4697
  273. data/spec/rattler/back_end/parser_generator/back_reference_generator_spec.rbc +0 -4855
  274. data/spec/rattler/back_end/parser_generator/choice_generator_spec.rbc +0 -5350
  275. data/spec/rattler/back_end/parser_generator/direct_action_generator_spec.rbc +0 -4737
  276. data/spec/rattler/back_end/parser_generator/disallow_generator_spec.rbc +0 -4697
  277. data/spec/rattler/back_end/parser_generator/dispatch_action_generator_spec.rbc +0 -4731
  278. data/spec/rattler/back_end/parser_generator/fail_generator_spec.rbc +0 -2115
  279. data/spec/rattler/back_end/parser_generator/group_match_generator_spec.rbc +0 -4195
  280. data/spec/rattler/back_end/parser_generator/group_match_spec.rbc +0 -1414
  281. data/spec/rattler/back_end/parser_generator/label_generator_spec.rbc +0 -4696
  282. data/spec/rattler/back_end/parser_generator/list1_generator_spec.rb +0 -309
  283. data/spec/rattler/back_end/parser_generator/list1_generator_spec.rbc +0 -5213
  284. data/spec/rattler/back_end/parser_generator/list_generator_spec.rbc +0 -5179
  285. data/spec/rattler/back_end/parser_generator/match_generator_spec.rbc +0 -4681
  286. data/spec/rattler/back_end/parser_generator/one_or_more_generator_spec.rb +0 -259
  287. data/spec/rattler/back_end/parser_generator/one_or_more_generator_spec.rbc +0 -4957
  288. data/spec/rattler/back_end/parser_generator/optional_generator_spec.rb +0 -190
  289. data/spec/rattler/back_end/parser_generator/optional_generator_spec.rbc +0 -4704
  290. data/spec/rattler/back_end/parser_generator/rule_generator_spec.rbc +0 -545
  291. data/spec/rattler/back_end/parser_generator/rule_set_generator_spec.rbc +0 -1110
  292. data/spec/rattler/back_end/parser_generator/sequence_generator_spec.rbc +0 -5453
  293. data/spec/rattler/back_end/parser_generator/skip_generator_spec.rbc +0 -4691
  294. data/spec/rattler/back_end/parser_generator/token_generator_spec.rbc +0 -4691
  295. data/spec/rattler/back_end/parser_generator/zero_or_more_generator_spec.rb +0 -244
  296. data/spec/rattler/back_end/parser_generator/zero_or_more_generator_spec.rbc +0 -4924
  297. data/spec/rattler/back_end/ruby_generator_spec.rbc +0 -2460
  298. data/spec/rattler/back_end/shared_compiler_examples.rbc +0 -41886
  299. data/spec/rattler/grammar/analysis_spec.rbc +0 -4365
  300. data/spec/rattler/grammar/grammar_parser_spec.rbc +0 -10344
  301. data/spec/rattler/grammar/grammar_spec.rbc +0 -1701
  302. data/spec/rattler/parsers/action_code_spec.rbc +0 -4674
  303. data/spec/rattler/parsers/apply_spec.rbc +0 -851
  304. data/spec/rattler/parsers/assert_spec.rbc +0 -752
  305. data/spec/rattler/parsers/back_reference_spec.rbc +0 -1002
  306. data/spec/rattler/parsers/choice_spec.rbc +0 -1696
  307. data/spec/rattler/parsers/combinator_parser_spec.rbc +0 -361
  308. data/spec/rattler/parsers/direct_action_spec.rbc +0 -5222
  309. data/spec/rattler/parsers/disallow_spec.rbc +0 -752
  310. data/spec/rattler/parsers/dispatch_action_spec.rbc +0 -3033
  311. data/spec/rattler/parsers/eof_spec.rbc +0 -728
  312. data/spec/rattler/parsers/fail_spec.rbc +0 -548
  313. data/spec/rattler/parsers/label_spec.rbc +0 -1091
  314. data/spec/rattler/parsers/list0_spec.rb +0 -82
  315. data/spec/rattler/parsers/list0_spec.rbc +0 -2308
  316. data/spec/rattler/parsers/list1_spec.rb +0 -82
  317. data/spec/rattler/parsers/list1_spec.rbc +0 -2287
  318. data/spec/rattler/parsers/list_spec.rbc +0 -2308
  319. data/spec/rattler/parsers/match_spec.rbc +0 -780
  320. data/spec/rattler/parsers/node_code_spec.rbc +0 -1754
  321. data/spec/rattler/parsers/one_or_more_spec.rb +0 -64
  322. data/spec/rattler/parsers/one_or_more_spec.rbc +0 -1698
  323. data/spec/rattler/parsers/optional_spec.rb +0 -64
  324. data/spec/rattler/parsers/optional_spec.rbc +0 -1717
  325. data/spec/rattler/parsers/parser_dsl_spec.rbc +0 -10150
  326. data/spec/rattler/parsers/rule_set_spec.rbc +0 -1060
  327. data/spec/rattler/parsers/sequence_spec.rbc +0 -2899
  328. data/spec/rattler/parsers/skip_spec.rbc +0 -753
  329. data/spec/rattler/parsers/token_spec.rbc +0 -1511
  330. data/spec/rattler/parsers/zero_or_more_spec.rb +0 -64
  331. data/spec/rattler/parsers/zero_or_more_spec.rbc +0 -1719
  332. data/spec/rattler/runtime/extended_packrat_parser_spec.rbc +0 -1341
  333. data/spec/rattler/runtime/packrat_parser_spec.rbc +0 -210
  334. data/spec/rattler/runtime/parse_failure_spec.rbc +0 -2244
  335. data/spec/rattler/runtime/parse_node_spec.rbc +0 -2008
  336. data/spec/rattler/runtime/parser_spec.rbc +0 -2757
  337. data/spec/rattler/runtime/recursive_descent_parser_spec.rbc +0 -210
  338. data/spec/rattler/runtime/shared_parser_examples.rbc +0 -2567
  339. data/spec/rattler/util/graphviz/node_builder_spec.rbc +0 -3439
  340. data/spec/rattler/util/line_counter_spec.rbc +0 -2272
  341. data/spec/rattler/util/node_spec.rbc +0 -15023
  342. data/spec/rattler_spec.rbc +0 -1591
  343. data/spec/spec_helper.rbc +0 -336
  344. data/spec/support/combinator_parser_spec_helper.rbc +0 -1284
  345. data/spec/support/compiler_spec_helper.rbc +0 -1941
  346. data/spec/support/parser_generator_spec_helper.rbc +0 -718
  347. data/spec/support/runtime_parser_spec_helper.rbc +0 -313
@@ -3,10 +3,6 @@ Feature: One-Or-More
3
3
  The "+" operator following an expression means to match one or more times,
4
4
  i.e. match repeatedly and succeed if input was matched at least once.
5
5
 
6
- In order to define an expression that matches one or more times
7
- As a language designer
8
- I want to use a "one-or-more" postfix operator in my grammar
9
-
10
6
  Scenario Outline: Capturing Expression
11
7
  Given a grammar with:
12
8
  """
@@ -3,10 +3,6 @@ Feature: Optional Operator
3
3
  The "?" operator following an expression makes the it optional, meaning it
4
4
  succeeds even if no input is matched.
5
5
 
6
- In order to define an expression that matches optionally
7
- As a language designer
8
- I want to use an "optional" postfix operator in my grammar
9
-
10
6
  Scenario Outline: Capturing Expression
11
7
  Given a grammar with:
12
8
  """
@@ -4,10 +4,6 @@ Feature: Ordered Choice Expressions
4
4
  and it means to try each sub-expression in order until one matches, and fail
5
5
  if none of the sub-expressions match.
6
6
 
7
- In order to define multiple alternatives for an expression
8
- As a language designer
9
- I want to use ordered choice expressions in my grammar
10
-
11
7
  Scenario Outline: Parsing
12
8
  Given a grammar with:
13
9
  """
@@ -4,10 +4,6 @@ Feature: Positive Lookahead Operator
4
4
  would match here but never consume any input. This is known as zero-width
5
5
  positive lookahead.
6
6
 
7
- In order to define zero-width positive lookahead expressions
8
- As a language designer
9
- I want to use the positive lookahead operator in my grammar
10
-
11
7
  Scenario Outline: Parsing
12
8
  Given a grammar with:
13
9
  """
@@ -0,0 +1,99 @@
1
+ Feature: Positive Semantic Predicates
2
+
3
+ A positive semantic predicate can be defined by placing a "&" in front of a
4
+ semantic action. If the action results in a true value the parse succeeds,
5
+ otherwise the parse fails.
6
+
7
+ Scenario Outline: Single token
8
+ Given a grammar with:
9
+ """
10
+ expr <- @DIGIT+ &{|s| s.to_i > 20 }
11
+ """
12
+ When I parse <input>
13
+ Then the parse result should be <result>
14
+
15
+ Examples:
16
+ | input | result |
17
+ | "42" | "42" |
18
+ | "17" | FAIL |
19
+
20
+ Scenario Outline: Sequence
21
+ Given a grammar with:
22
+ """
23
+ %whitespace SPACE*
24
+ expr <- @DIGIT+ @DIGIT+ &{|a,b| a.to_i < b.to_i }
25
+ """
26
+ When I parse <input>
27
+ Then the parse result should be <result>
28
+
29
+ Examples:
30
+ | input | result |
31
+ | "3 16" | ["3", "16"] |
32
+ | "16 3" | FAIL |
33
+
34
+ Scenario Outline: Sequence with non-capturing expressions
35
+ Given a grammar with:
36
+ """
37
+ expr <- ~"(" @DIGIT+ ~">" @DIGIT+ ~")" &{|a,b| a.to_i > b.to_i }
38
+ """
39
+ When I parse <input>
40
+ Then the parse result should be <result>
41
+
42
+ Examples:
43
+ | input | result |
44
+ | "(23>17)" | ["23", "17"] |
45
+ | "(17>23)" | FAIL |
46
+
47
+ Scenario Outline: Sequence with labeled expressions
48
+ Given a grammar with:
49
+ """
50
+ expr <- "(" left:@DIGIT+ "<" right:@DIGIT+ ")" &{ left.to_i < right.to_i }
51
+ """
52
+ When I parse <input>
53
+ Then the parse result should be <result>
54
+
55
+ Examples:
56
+ | input | result |
57
+ | "(17<23)" | ["(", "17", "<", "23", ")"] |
58
+ | "(23<17)" | FAIL |
59
+
60
+ Scenario Outline: Single token using "_"
61
+ Given a grammar with:
62
+ """
63
+ expr <- @DIGIT+ &{ _.to_i > 20 }
64
+ """
65
+ When I parse <input>
66
+ Then the parse result should be <result>
67
+
68
+ Examples:
69
+ | input | result |
70
+ | "42" | "42" |
71
+ | "17" | FAIL |
72
+
73
+ Scenario Outline: Sequence using "_"
74
+ Given a grammar with:
75
+ """
76
+ %whitespace SPACE*
77
+ expr <- @DIGIT+ @DIGIT+ &{ _[0].to_i < _[1].to_i }
78
+ """
79
+ When I parse <input>
80
+ Then the parse result should be <result>
81
+
82
+ Examples:
83
+ | input | result |
84
+ | "3 16" | ["3", "16"] |
85
+ | "16 3" | FAIL |
86
+
87
+ Scenario Outline: Sequence using "_" as a parameter name
88
+ Given a grammar with:
89
+ """
90
+ %whitespace SPACE*
91
+ expr <- @DIGIT+ @DIGIT+ &{|_| _.to_i < 20 }
92
+ """
93
+ When I parse <input>
94
+ Then the parse result should be <result>
95
+
96
+ Examples:
97
+ | input | result |
98
+ | "3 16" | ["3", "16"] |
99
+ | "42 7" | FAIL |
@@ -18,11 +18,7 @@ Feature: POSIX Character Classes
18
18
  SPACE - Whitespace characters
19
19
  UPPER - Uppercase characters
20
20
  XDIGIT - Hexadecimal digits
21
- WORD - Alphanumeric characters plus "_" (Ruby 1.9 only)
22
-
23
- In order to write more consistent and readable grammars
24
- As a language designer
25
- I want to use POSIX character classes in my grammar
21
+ WORD - Alphanumeric characters plus "_"
26
22
 
27
23
  Scenario: ALNUM
28
24
  Given a grammar with:
@@ -70,4 +66,5 @@ Feature: POSIX Character Classes
70
66
  expr <- UPPER+
71
67
  """
72
68
  When I parse "ABCdef"
73
- Then the parse result should be ["A", "B", "C"]
69
+ Then the parse result should be ["A", "B", "C"]
70
+
@@ -0,0 +1,50 @@
1
+ Feature: Generalized Repeat
2
+
3
+ Repetition counts or ranges can be used for generalized repeat expressions.
4
+ A count by itself means to match the preceding expression exactly that many
5
+ times. A range can be written with ".." between the lower and upper bounds.
6
+ The upper bound is optional.
7
+
8
+ Scenario Outline: Range
9
+ Given a grammar with:
10
+ """
11
+ expr <- ALPHA 2..4
12
+ """
13
+ When I parse <input>
14
+ Then the parse result should be <result>
15
+ And the parse position should be <pos>
16
+
17
+ Examples:
18
+ | input | result | pos |
19
+ | "abc" | ["a", "b", "c"] | 3 |
20
+ | "abcde" | ["a", "b", "c", "d"] | 4 |
21
+ | "a" | FAIL | 0 |
22
+
23
+ Scenario Outline: Lower bound only
24
+ Given a grammar with:
25
+ """
26
+ expr <- ALPHA 2..
27
+ """
28
+ When I parse <input>
29
+ Then the parse result should be <result>
30
+ And the parse position should be <pos>
31
+
32
+ Examples:
33
+ | input | result | pos |
34
+ | "abc" | ["a", "b", "c"] | 3 |
35
+ | "abcde" | ["a", "b", "c", "d", "e"] | 5 |
36
+ | "a" | FAIL | 0 |
37
+
38
+ Scenario Outline: Specific count
39
+ Given a grammar with:
40
+ """
41
+ expr <- ALPHA 2
42
+ """
43
+ When I parse <input>
44
+ Then the parse result should be <result>
45
+ And the parse position should be <pos>
46
+
47
+ Examples:
48
+ | input | result | pos |
49
+ | "abc" | ["a", "b"] | 2 |
50
+ | "a" | FAIL | 0 |
@@ -3,10 +3,6 @@ Feature: Sequence Expressions
3
3
  A sequence expression is a series of sub-expressions and it means to match
4
4
  all of the sub-expressions in sequence, otherwise fail and consume no input.
5
5
 
6
- In order to define an expression as a sequence of sub-expressions
7
- As a language designer
8
- I want to use sequence expressions in my grammar
9
-
10
6
  Scenario Outline: Parsing
11
7
  Given a grammar with:
12
8
  """
@@ -0,0 +1,81 @@
1
+ Feature: Semantic side-effects
2
+
3
+ A semantic side-effect can be defined by placing a "~" in front of a symantic
4
+ action. The expression is evaulated for effect and always succeeds with no
5
+ parse result.
6
+
7
+ Scenario: Single token
8
+ Given a grammar with:
9
+ """
10
+ expr <- @DIGIT+ ~{|s| $x = s.to_i }
11
+ """
12
+ When I parse "42 "
13
+ Then the parse result should be "42"
14
+ And $x should be 42
15
+
16
+ Scenario: Sequence
17
+ Given a grammar with:
18
+ """
19
+ %whitespace SPACE*
20
+ expr <- @DIGIT+ @DIGIT+ ~{|a,b| $x = a.to_i * b.to_i }
21
+ """
22
+ When I parse "3 16"
23
+ Then the parse result should be ["3", "16"]
24
+ And $x should be 48
25
+
26
+ Scenario: Sequence with non-capturing expressions
27
+ Given a grammar with:
28
+ """
29
+ expr <- ~"(" @DIGIT+ ~"+" @DIGIT+ ~")" ~{|a,b| $x = a.to_i + b.to_i }
30
+ """
31
+ When I parse "(23+17)"
32
+ Then the parse result should be ["23", "17"]
33
+ And $x should be 40
34
+
35
+ Scenario: Sequence with labeled expressions
36
+ Given a grammar with:
37
+ """
38
+ expr <- "(" l:@DIGIT+ "+" r:@DIGIT+ ")" ~{ $x = l.to_i + r.to_i }
39
+ """
40
+ When I parse "(17+29)"
41
+ Then the parse result should be ["(", "17", "+", "29", ")"]
42
+ And $x should be 46
43
+
44
+ Scenario: Single token using "_"
45
+ Given a grammar with:
46
+ """
47
+ expr <- @DIGIT+ ~{ $x = _.to_i }
48
+ """
49
+ When I parse "23"
50
+ Then the parse result should be "23"
51
+ And $x should be 23
52
+
53
+ Scenario: Sequence using "_"
54
+ Given a grammar with:
55
+ """
56
+ %whitespace SPACE*
57
+ expr <- @DIGIT+ @DIGIT+ ~{ $x = _.reverse }
58
+ """
59
+ When I parse "3 16"
60
+ Then the parse result should be ["3", "16"]
61
+ And $x should be ["16", "3"]
62
+
63
+ Scenario: Sequence using "_" as a parameter name
64
+ Given a grammar with:
65
+ """
66
+ %whitespace SPACE*
67
+ expr <- @DIGIT+ @DIGIT+ ~{|_| $x = _.to_i }
68
+ """
69
+ When I parse "3 16"
70
+ Then the parse result should be ["3", "16"]
71
+ And $x should be 3
72
+
73
+ Scenario: Lone action
74
+ Given a grammar with:
75
+ """
76
+ expr <- ~{ $x = 42 }
77
+ """
78
+ When I parse "anything"
79
+ Then the parse result should be true
80
+ And $x should be 42
81
+ And the parse position should be 0
@@ -2,10 +2,6 @@ Feature: Skip Operator
2
2
 
3
3
  The "~" operator before an expression means to match but ignore the result.
4
4
 
5
- In order to match syntax without it being included in the parse results
6
- As a language designer
7
- I want to use a "skip" prefix operator in my grammar
8
-
9
5
  Scenario: Sequence with skipped sub-expressions
10
6
  Given a grammar with:
11
7
  """
@@ -21,4 +17,5 @@ Feature: Skip Operator
21
17
  """
22
18
  When I parse "if "
23
19
  Then the parse result should be true
24
- And the parse position should be 2
20
+ And the parse position should be 2
21
+
@@ -2,10 +2,6 @@ Feature: Start Rule
2
2
 
3
3
  The first rule defined in a grammar is the start rule.
4
4
 
5
- In order to make my grammars readable
6
- As a language designer
7
- I want to give my start rule a meaningful name
8
-
9
5
  Scenario Outline: Default Start Rule
10
6
  Given a grammar with:
11
7
  """
@@ -18,4 +14,4 @@ Feature: Start Rule
18
14
  Examples:
19
15
  | input | result |
20
16
  | "42a" | "42" |
21
- | "foo" | FAIL |
17
+ | "foo" | FAIL |
@@ -8,10 +8,6 @@ Feature: Symantic Actions
8
8
  are simply ignored. Labeled parse results can be refered to as identifiers in
9
9
  the action. The special identifier "_" refers to the entire parse results.
10
10
 
11
- In order to add simple symantics to parse results
12
- As a language designer
13
- I want to use symantic actions in my grammar
14
-
15
11
  Scenario: Single token
16
12
  Given a grammar with:
17
13
  """
@@ -70,3 +66,12 @@ Feature: Symantic Actions
70
66
  """
71
67
  When I parse "3 16"
72
68
  Then the parse result should be 3
69
+
70
+ Scenario: Lone action
71
+ Given a grammar with:
72
+ """
73
+ default <- { 42 }
74
+ """
75
+ When I parse "anything"
76
+ Then the parse result should be 42
77
+ And the parse position should be 0
@@ -5,10 +5,6 @@ Feature: Token Operator
5
5
  automatically skipped. The expression becomes atomic, so any defined
6
6
  whitespace will be automatically skipped before the token.
7
7
 
8
- In order to match arbitrarily complex expressions as tokens
9
- As a language designer
10
- I want to use a "token" prefix operator in my grammar
11
-
12
8
  Scenario: Nested sequences and repeats
13
9
  Given a grammar with:
14
10
  """
@@ -6,10 +6,6 @@ Feature: Whitespace
6
6
  form defines whitespace for expressions in the block, otherwise it is defined
7
7
  for the rest of the grammar.
8
8
 
9
- In order to focus on the structure of my language
10
- As a language designer
11
- I want to specify whitespace in my grammar once and only once
12
-
13
9
  Scenario: Block form
14
10
  Given a grammar with:
15
11
  """
@@ -6,10 +6,6 @@ Feature: Word Literal Expressions
6
6
  word character can be defined using the %word_character directive. By default
7
7
  a word charactacter is an alphanumeric character or the underscore character.
8
8
 
9
- In order to define keywords
10
- As a language designer
11
- I want to use word literals in my grammar
12
-
13
9
  Scenario Outline: Default word character definition
14
10
  Given a grammar with:
15
11
  """
@@ -3,10 +3,6 @@ Feature: Zero-Or-More
3
3
  The "*" operator following an expression means to match zero or more times,
4
4
  i.e. match repeatedly and succeed even if no input was matched.
5
5
 
6
- In order to define an expression that matches zero or more times
7
- As a language designer
8
- I want to use a "zero-or-more" postfix operator in my grammar
9
-
10
6
  Scenario Outline: Capturing Expression
11
7
  Given a grammar with:
12
8
  """
@@ -36,4 +36,8 @@ end
36
36
 
37
37
  Then /failure position should be (.+)$/ do |expr|
38
38
  @parser.failure.pos.should == eval(expr, TOPLEVEL_BINDING)
39
- end
39
+ end
40
+
41
+ Then /^\$x should be (.+)$/ do |expr|
42
+ $x.should == eval(expr, TOPLEVEL_BINDING)
43
+ end
@@ -76,6 +76,7 @@ module Rattler::BackEnd
76
76
  autoload :OptimizationSequence, 'rattler/back_end/optimizer/optimization_sequence'
77
77
  autoload :OptimizeChildren, 'rattler/back_end/optimizer/optimize_children'
78
78
  autoload :InlineRegularRules, 'rattler/back_end/optimizer/inline_regular_rules'
79
+ autoload :SpecializeRepeat, 'rattler/back_end/optimizer/specialize_repeat'
79
80
  autoload :SimplifyRedundantRepeat, 'rattler/back_end/optimizer/simplify_redundant_repeat'
80
81
  autoload :RemoveMeaninglessWrapper, 'rattler/back_end/optimizer/remove_meaningless_wrapper'
81
82
  autoload :SimplifyTokenMatch, 'rattler/back_end/optimizer/simplify_token_match'
@@ -20,10 +20,8 @@ module Rattler::BackEnd::Optimizer
20
20
 
21
21
  def _applies_to?(parser, context)
22
22
  context.matching? and
23
- case parser
24
- when ZeroOrMore, OneOrMore, Optional
25
- parser.child.is_a?(Match)
26
- end
23
+ parser.is_a? Repeat and
24
+ parser.child.is_a? Match
27
25
  end
28
26
 
29
27
  def _apply(parser, context)
@@ -33,10 +31,24 @@ module Rattler::BackEnd::Optimizer
33
31
  private
34
32
 
35
33
  def suffix(parser)
36
- case parser
37
- when ZeroOrMore then '*'
38
- when OneOrMore then '+'
39
- when Optional then '?'
34
+ if parser.zero_or_more?
35
+ '*'
36
+ elsif parser.one_or_more?
37
+ '+'
38
+ elsif parser.optional?
39
+ '?'
40
+ else
41
+ general_suffix parser.lower_bound, parser.upper_bound
42
+ end
43
+ end
44
+
45
+ def general_suffix(lower_bound, upper_bound)
46
+ if lower_bound == upper_bound
47
+ "{#{lower_bound}}"
48
+ elsif !upper_bound
49
+ "{#{lower_bound},}"
50
+ else
51
+ "{#{lower_bound},#{upper_bound}}"
40
52
  end
41
53
  end
42
54