rattler 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,281 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
2
+ require File.expand_path(File.dirname(__FILE__) + '/zero_or_more_generator_examples')
3
+ require File.expand_path(File.dirname(__FILE__) + '/one_or_more_generator_examples')
4
+ require File.expand_path(File.dirname(__FILE__) + '/optional_generator_examples')
5
+
6
+ include Rattler::BackEnd::ParserGenerator
7
+ include Rattler::Parsers
8
+
9
+ describe RepeatGenerator do
10
+
11
+ include ParserGeneratorSpecHelper
12
+
13
+ let(:repeat) { Repeat[nested, *bounds] }
14
+
15
+ it_behaves_like 'a zero-or-more generator'
16
+ it_behaves_like 'a one-or-more generator'
17
+ it_behaves_like 'an optional generator'
18
+
19
+ describe '#gen_basic' do
20
+
21
+ context 'with an upper bound' do
22
+
23
+ let(:bounds) { [2, 4] }
24
+ let(:nested) { Match[/w+/] }
25
+
26
+ context 'when nested' do
27
+ it 'generates nested repeat matching code' do
28
+ nested_code {|g| g.gen_basic repeat }.should == (<<-CODE).strip
29
+ begin
30
+ a = []
31
+ rp = @scanner.pos
32
+ while r = @scanner.scan(/\w+/)
33
+ a << r
34
+ break if a.size >= 4
35
+ end
36
+ if a.size >= 2
37
+ a
38
+ else
39
+ @scanner.pos = rp
40
+ false
41
+ end
42
+ end
43
+ CODE
44
+ end
45
+ end
46
+
47
+ context 'when top-level' do
48
+ it 'generates nested repeat matching code' do
49
+ top_level_code {|g| g.gen_basic repeat }.should == (<<-CODE).strip
50
+ a = []
51
+ rp = @scanner.pos
52
+ while r = @scanner.scan(/\w+/)
53
+ a << r
54
+ break if a.size >= 4
55
+ end
56
+ if a.size >= 2
57
+ a
58
+ else
59
+ @scanner.pos = rp
60
+ false
61
+ end
62
+ CODE
63
+ end
64
+ end
65
+ end
66
+
67
+ context 'with no upper bound' do
68
+
69
+ let(:bounds) { [2, nil] }
70
+ let(:nested) { Match[/w+/] }
71
+
72
+ context 'when nested' do
73
+ it 'generates nested repeat matching code' do
74
+ nested_code {|g| g.gen_basic repeat }.should == (<<-CODE).strip
75
+ begin
76
+ a = []
77
+ rp = @scanner.pos
78
+ while r = @scanner.scan(/\w+/)
79
+ a << r
80
+ end
81
+ if a.size >= 2
82
+ a
83
+ else
84
+ @scanner.pos = rp
85
+ false
86
+ end
87
+ end
88
+ CODE
89
+ end
90
+ end
91
+
92
+ context 'when top-level' do
93
+ it 'generates nested repeat matching code' do
94
+ top_level_code {|g| g.gen_basic repeat }.should == (<<-CODE).strip
95
+ a = []
96
+ rp = @scanner.pos
97
+ while r = @scanner.scan(/\w+/)
98
+ a << r
99
+ end
100
+ if a.size >= 2
101
+ a
102
+ else
103
+ @scanner.pos = rp
104
+ false
105
+ end
106
+ CODE
107
+ end
108
+ end
109
+ end
110
+ end
111
+
112
+ describe '#gen_assert' do
113
+
114
+ let(:bounds) { [2, 4] }
115
+ let(:nested) { Match[/w+/] }
116
+
117
+ context 'when nested' do
118
+ it 'generates nested repeat positive lookahead code' do
119
+ nested_code {|g| g.gen_assert repeat }.should == (<<-CODE).strip
120
+ begin
121
+ c = 0
122
+ rp = @scanner.pos
123
+ while @scanner.skip(/\w+/)
124
+ c += 1
125
+ break if c >= 2
126
+ end
127
+ @scanner.pos = rp
128
+ (c >= 2)
129
+ end
130
+ CODE
131
+ end
132
+ end
133
+
134
+ context 'when top-level' do
135
+ it 'generates top level repeat positive lookahead code' do
136
+ top_level_code {|g| g.gen_assert repeat }.should == (<<-CODE).strip
137
+ c = 0
138
+ rp = @scanner.pos
139
+ while @scanner.skip(/\w+/)
140
+ c += 1
141
+ break if c >= 2
142
+ end
143
+ @scanner.pos = rp
144
+ (c >= 2)
145
+ CODE
146
+ end
147
+ end
148
+ end
149
+
150
+ describe '#gen_disallow' do
151
+
152
+ let(:bounds) { [2, 4] }
153
+ let(:nested) { Match[/w+/] }
154
+
155
+ context 'when nested' do
156
+ it 'generates nested repeat negative lookahead code' do
157
+ nested_code {|g| g.gen_disallow repeat }.should == (<<-CODE).strip
158
+ begin
159
+ c = 0
160
+ rp = @scanner.pos
161
+ while @scanner.skip(/\w+/)
162
+ c += 1
163
+ break if c >= 2
164
+ end
165
+ @scanner.pos = rp
166
+ (c < 2)
167
+ end
168
+ CODE
169
+ end
170
+ end
171
+
172
+ context 'when top-level' do
173
+ it 'generates top level repeat negative lookahead code' do
174
+ top_level_code {|g| g.gen_disallow repeat }.should == (<<-CODE).strip
175
+ c = 0
176
+ rp = @scanner.pos
177
+ while @scanner.skip(/\w+/)
178
+ c += 1
179
+ break if c >= 2
180
+ end
181
+ @scanner.pos = rp
182
+ (c < 2)
183
+ CODE
184
+ end
185
+ end
186
+ end
187
+
188
+ describe '#gen_skip' do
189
+
190
+ context 'with an upper bound' do
191
+
192
+ let(:bounds) { [2, 4] }
193
+ let(:nested) { Match[/w+/] }
194
+
195
+ context 'when nested' do
196
+ it 'generates nested repeat skipping code' do
197
+ nested_code {|g| g.gen_skip repeat }.should == (<<-CODE).strip
198
+ begin
199
+ c = 0
200
+ rp = @scanner.pos
201
+ while @scanner.skip(/w+/)
202
+ c += 1
203
+ break if c >= 4
204
+ end
205
+ if c >= 2
206
+ true
207
+ else
208
+ @scanner.pos = rp
209
+ false
210
+ end
211
+ end
212
+ CODE
213
+ end
214
+ end
215
+
216
+ context 'when top-level' do
217
+ it 'generates top level repeat skipping code' do
218
+ top_level_code {|g| g.gen_skip repeat }.should == (<<-CODE).strip
219
+ c = 0
220
+ rp = @scanner.pos
221
+ while @scanner.skip(/w+/)
222
+ c += 1
223
+ break if c >= 4
224
+ end
225
+ if c >= 2
226
+ true
227
+ else
228
+ @scanner.pos = rp
229
+ false
230
+ end
231
+ CODE
232
+ end
233
+ end
234
+ end
235
+
236
+ context 'with no upper bound' do
237
+
238
+ let(:bounds) { [2, nil] }
239
+ let(:nested) { Match[/w+/] }
240
+
241
+ context 'when nested' do
242
+ it 'generates nested repeat skipping code' do
243
+ nested_code {|g| g.gen_skip repeat }.should == (<<-CODE).strip
244
+ begin
245
+ c = 0
246
+ rp = @scanner.pos
247
+ while @scanner.skip(/w+/)
248
+ c += 1
249
+ end
250
+ if c >= 2
251
+ true
252
+ else
253
+ @scanner.pos = rp
254
+ false
255
+ end
256
+ end
257
+ CODE
258
+ end
259
+ end
260
+
261
+ context 'when top-level' do
262
+ it 'generates top level repeat skipping code' do
263
+ top_level_code {|g| g.gen_skip repeat }.should == (<<-CODE).strip
264
+ c = 0
265
+ rp = @scanner.pos
266
+ while @scanner.skip(/w+/)
267
+ c += 1
268
+ end
269
+ if c >= 2
270
+ true
271
+ else
272
+ @scanner.pos = rp
273
+ false
274
+ end
275
+ CODE
276
+ end
277
+ end
278
+ end
279
+ end
280
+
281
+ end
@@ -0,0 +1,277 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
2
+
3
+ shared_examples_for 'a zero-or-more generator' do
4
+
5
+ let(:bounds) { [0, nil] }
6
+ let(:nested) { Match[/w+/] }
7
+
8
+ describe '#gen_basic' do
9
+
10
+ let(:nested) { Choice[Match[/[[:alpha:]]/], Match[/[[:digit:]]/]] }
11
+
12
+ context 'given a repeat with zero-or-more bounds' do
13
+
14
+ context 'when nested' do
15
+ it 'generates nested zero-or-more matching code' do
16
+ nested_code {|g| g.gen_basic repeat }.
17
+ should == (<<-CODE).strip
18
+ begin
19
+ a = []
20
+ while r = begin
21
+ @scanner.scan(/[[:alpha:]]/) ||
22
+ @scanner.scan(/[[:digit:]]/)
23
+ end
24
+ a << r
25
+ end
26
+ a
27
+ end
28
+ CODE
29
+ end
30
+ end
31
+
32
+ context 'when top-level' do
33
+ it 'generates top level zero-or-more matching code' do
34
+ top_level_code {|g| g.gen_basic repeat }.
35
+ should == (<<-CODE).strip
36
+ a = []
37
+ while r = begin
38
+ @scanner.scan(/[[:alpha:]]/) ||
39
+ @scanner.scan(/[[:digit:]]/)
40
+ end
41
+ a << r
42
+ end
43
+ a
44
+ CODE
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ describe '#gen_assert' do
51
+
52
+ context 'given a repeat with zero-or-more bounds' do
53
+
54
+ context 'when nested' do
55
+ it 'generates "true"' do
56
+ nested_code {|g| g.gen_assert repeat }.should == 'true'
57
+ end
58
+ end
59
+
60
+ context 'when top-level' do
61
+ it 'generates "true"' do
62
+ top_level_code {|g| g.gen_assert repeat }.should == 'true'
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+ describe '#gen_disallow' do
69
+
70
+ context 'given a repeat with zero-or-more bounds' do
71
+
72
+ context 'when nested' do
73
+ it 'generates "false"' do
74
+ nested_code {|g| g.gen_disallow repeat }.should == 'false'
75
+ end
76
+ end
77
+
78
+ context 'when top-level' do
79
+ it 'generates "false"' do
80
+ top_level_code {|g| g.gen_disallow repeat }.should == 'false'
81
+ end
82
+ end
83
+ end
84
+ end
85
+
86
+ describe '#gen_dispatch_action' do
87
+
88
+ let(:nested) { Match[/w+/] }
89
+ let(:code) { NodeCode.new('Word', 'parsed') }
90
+
91
+ context 'given a repeat with zero-or-more bounds' do
92
+
93
+ context 'when nested' do
94
+ it 'generates nested zero-or-more matching code with a dispatch action' do
95
+ nested_code {|g| g.gen_dispatch_action repeat, code }.
96
+ should == (<<-CODE).strip
97
+ begin
98
+ a = []
99
+ while r = @scanner.scan(/w+/)
100
+ a << r
101
+ end
102
+ Word.parsed(select_captures(a))
103
+ end
104
+ CODE
105
+ end
106
+ end
107
+
108
+ context 'when top-level' do
109
+ it 'generates top level zero-or-more matching code with a dispatch action' do
110
+ top_level_code {|g| g.gen_dispatch_action repeat, code }.
111
+ should == (<<-CODE).strip
112
+ a = []
113
+ while r = @scanner.scan(/w+/)
114
+ a << r
115
+ end
116
+ Word.parsed(select_captures(a))
117
+ CODE
118
+ end
119
+ end
120
+ end
121
+ end
122
+
123
+ describe '#gen_direct_action' do
124
+
125
+ let(:nested) { Match[/w+/] }
126
+ let(:code) { ActionCode.new('|_| _.size') }
127
+
128
+ context 'given a repeat with zero-or-more bounds' do
129
+
130
+ context 'when nested' do
131
+ it 'generates nested zero-or-more matching code with a direct action' do
132
+ nested_code {|g| g.gen_direct_action repeat, code }.
133
+ should == (<<-CODE).strip
134
+ begin
135
+ a = []
136
+ while r = @scanner.scan(/w+/)
137
+ a << r
138
+ end
139
+ (select_captures(a).size)
140
+ end
141
+ CODE
142
+ end
143
+ end
144
+
145
+ context 'when top-level' do
146
+ it 'generates top level zero-or-more matching code with a direct action' do
147
+ top_level_code {|g| g.gen_direct_action repeat, code }.
148
+ should == (<<-CODE).strip
149
+ a = []
150
+ while r = @scanner.scan(/w+/)
151
+ a << r
152
+ end
153
+ (select_captures(a).size)
154
+ CODE
155
+ end
156
+ end
157
+ end
158
+ end
159
+
160
+ describe '#gen_token' do
161
+
162
+ let(:nested) { Match[/w+/] }
163
+
164
+ context 'given a repeat with zero-or-more bounds' do
165
+
166
+ context 'when nested' do
167
+ it 'generates nested zero-or-more matching code' do
168
+ nested_code {|g| g.gen_token repeat }.
169
+ should == (<<-CODE).strip
170
+ begin
171
+ a = []
172
+ while r = @scanner.scan(/w+/)
173
+ a << r
174
+ end
175
+ a.join
176
+ end
177
+ CODE
178
+ end
179
+ end
180
+
181
+ context 'when top-level' do
182
+ it 'generates top level zero-or-more matching code' do
183
+ top_level_code {|g| g.gen_token repeat }.
184
+ should == (<<-CODE).strip
185
+ a = []
186
+ while r = @scanner.scan(/w+/)
187
+ a << r
188
+ end
189
+ a.join
190
+ CODE
191
+ end
192
+ end
193
+ end
194
+ end
195
+
196
+ describe '#gen_skip' do
197
+
198
+ let(:nested) { Match[/w+/] }
199
+
200
+ context 'given a repeat with zero-or-more bounds' do
201
+
202
+ context 'when nested' do
203
+ it 'generates nested zero-or-more skipping code' do
204
+ nested_code {|g| g.gen_skip repeat }.should == (<<-CODE).strip
205
+ begin
206
+ while @scanner.skip(/w+/); end
207
+ true
208
+ end
209
+ CODE
210
+ end
211
+ end
212
+
213
+ context 'when top-level' do
214
+ it 'generates top level zero-or-more skipping code' do
215
+ top_level_code {|g| g.gen_skip repeat }.should == (<<-CODE).strip
216
+ while @scanner.skip(/w+/); end
217
+ true
218
+ CODE
219
+ end
220
+ end
221
+ end
222
+ end
223
+
224
+ describe '#gen_intermediate' do
225
+
226
+ let(:nested) { Match[/w+/] }
227
+
228
+ context 'given a repeat with zero-or-more bounds' do
229
+ it 'generates nested zero-or-more matching code' do
230
+ nested_code {|g| g.gen_intermediate repeat }.
231
+ should == (<<-CODE).strip
232
+ begin
233
+ a = []
234
+ while r = @scanner.scan(/w+/)
235
+ a << r
236
+ end
237
+ a
238
+ end
239
+ CODE
240
+ end
241
+ end
242
+ end
243
+
244
+ describe '#gen_intermediate_assert' do
245
+ context 'given a repeat with zero-or-more bounds' do
246
+ it 'generates "true"' do
247
+ nested_code {|g| g.gen_intermediate_assert repeat }.should == 'true'
248
+ end
249
+ end
250
+ end
251
+
252
+ describe '#gen_intermediate_disallow' do
253
+ context 'given a repeat with zero-or-more bounds' do
254
+ it 'generates "false"' do
255
+ nested_code {|g| g.gen_intermediate_disallow repeat }.should == 'false'
256
+ end
257
+ end
258
+ end
259
+
260
+ describe '#gen_intermediate_skip' do
261
+
262
+ let(:nested) { Match[/w+/] }
263
+
264
+ context 'given a repeat with zero-or-more bounds' do
265
+ it 'generates nested zero-or-more skipping code' do
266
+ nested_code {|g| g.gen_intermediate_skip repeat }.
267
+ should == (<<-CODE).strip
268
+ begin
269
+ while @scanner.skip(/w+/); end
270
+ true
271
+ end
272
+ CODE
273
+ end
274
+ end
275
+ end
276
+
277
+ end