rattler 0.5.0 → 0.6.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 (329) hide show
  1. data/README.rdoc +3 -175
  2. data/features/README.markdown +27 -0
  3. data/features/Tutorial.md +224 -0
  4. data/features/command_line/output_option.feature +2 -1
  5. data/features/command_line/{parser_generator.feature → rtlr.feature} +43 -15
  6. data/features/error_reporting/automatic_error_messages.feature +40 -0
  7. data/features/error_reporting/custom_error_messages.feature +28 -0
  8. data/features/examples/json_parser.markdown +88 -0
  9. data/features/{grammar → extended_matching_syntax}/back_reference.feature +5 -3
  10. data/features/{grammar → extended_matching_syntax}/e_symbol.feature +2 -2
  11. data/features/{grammar → extended_matching_syntax}/eof.feature +4 -3
  12. data/features/{grammar → extended_matching_syntax}/fail.feature +8 -6
  13. data/features/extended_matching_syntax/fragments.feature +29 -0
  14. data/features/extended_matching_syntax/include.feature +42 -0
  15. data/features/{grammar → extended_matching_syntax}/list_matching.feature +7 -6
  16. data/features/extended_matching_syntax/posix_class.feature +127 -0
  17. data/features/{grammar → extended_matching_syntax}/repeat.feature +29 -3
  18. data/features/{grammar → extended_matching_syntax}/skip_operator.feature +2 -1
  19. data/features/extended_matching_syntax/super.feature +24 -0
  20. data/features/{grammar → extended_matching_syntax}/token.feature +6 -5
  21. data/features/{grammar → extended_matching_syntax}/whitespace.feature +7 -6
  22. data/features/{grammar → extended_matching_syntax}/word_literal.feature +10 -6
  23. data/features/grammar_heading/explicit_start_rule.feature +20 -0
  24. data/features/grammar_heading/grammar_declaration.feature +60 -0
  25. data/features/grammar_heading/include.feature +19 -0
  26. data/features/grammar_heading/require.feature +27 -0
  27. data/features/{grammar → peg_syntax}/any_character.feature +1 -1
  28. data/features/peg_syntax/character_class.feature +25 -0
  29. data/features/{grammar → peg_syntax}/comments.feature +1 -1
  30. data/features/{grammar → peg_syntax}/literal.feature +5 -3
  31. data/features/{grammar → peg_syntax}/negative_lookahead.feature +5 -3
  32. data/features/peg_syntax/nonterminal.feature +46 -0
  33. data/features/peg_syntax/one_or_more.feature +59 -0
  34. data/features/{grammar → peg_syntax}/optional.feature +2 -2
  35. data/features/peg_syntax/ordered_choice.feature +24 -0
  36. data/features/{grammar → peg_syntax}/positive_lookahead.feature +6 -4
  37. data/features/peg_syntax/sequence.feature +23 -0
  38. data/features/{grammar → peg_syntax}/start_rule.feature +1 -1
  39. data/features/peg_syntax/zero_or_more.feature +59 -0
  40. data/features/{grammar → semantics}/labels.feature +0 -0
  41. data/features/{grammar → semantics}/negative_semantic_predicate.feature +30 -9
  42. data/features/{grammar → semantics}/node_action.feature +0 -0
  43. data/features/{grammar → semantics}/positive_semantic_predicate.feature +29 -8
  44. data/features/{grammar/symantic_action.feature → semantics/semantic_action.feature} +2 -2
  45. data/features/semantics/semantic_result.feature +86 -0
  46. data/features/{grammar → semantics}/side_effect.feature +33 -21
  47. data/features/step_definitions/cli_steps.rb +1 -1
  48. data/features/step_definitions/grammar_steps.rb +19 -5
  49. data/features/support/env.rb +5 -0
  50. data/lib/rattler.rb +21 -44
  51. data/lib/rattler/compiler.rb +69 -0
  52. data/lib/rattler/{grammar → compiler}/grammar_parser.rb +58 -24
  53. data/lib/rattler/compiler/metagrammar.rb +1570 -0
  54. data/lib/rattler/compiler/optimizer.rb +77 -0
  55. data/lib/rattler/{back_end → compiler}/optimizer/composite_reducing.rb +2 -2
  56. data/lib/rattler/{back_end → compiler}/optimizer/flatten_choice.rb +3 -12
  57. data/lib/rattler/{back_end → compiler}/optimizer/flatten_sequence.rb +4 -16
  58. data/lib/rattler/{back_end → compiler}/optimizer/flattening.rb +2 -2
  59. data/lib/rattler/compiler/optimizer/inline_regular_rules.rb +24 -0
  60. data/lib/rattler/{back_end → compiler}/optimizer/join_match_capturing_sequence.rb +16 -14
  61. data/lib/rattler/{back_end → compiler}/optimizer/join_match_choice.rb +4 -13
  62. data/lib/rattler/{back_end → compiler}/optimizer/join_match_matching_sequence.rb +4 -13
  63. data/lib/rattler/compiler/optimizer/join_match_sequence.rb +7 -0
  64. data/lib/rattler/{back_end → compiler}/optimizer/join_predicate_bare_match.rb +3 -12
  65. data/lib/rattler/compiler/optimizer/join_predicate_match.rb +7 -0
  66. data/lib/rattler/{back_end → compiler}/optimizer/join_predicate_nested_match.rb +4 -13
  67. data/lib/rattler/{back_end → compiler}/optimizer/join_predicate_or_bare_match.rb +3 -12
  68. data/lib/rattler/compiler/optimizer/join_predicate_or_match.rb +7 -0
  69. data/lib/rattler/{back_end → compiler}/optimizer/join_predicate_or_nested_match.rb +4 -13
  70. data/lib/rattler/{back_end → compiler}/optimizer/match_joining.rb +2 -2
  71. data/lib/rattler/{back_end → compiler}/optimizer/optimization.rb +12 -34
  72. data/lib/rattler/compiler/optimizer/optimization_context.rb +83 -0
  73. data/lib/rattler/{back_end → compiler}/optimizer/optimization_sequence.rb +3 -11
  74. data/lib/rattler/compiler/optimizer/optimizations.rb +27 -0
  75. data/lib/rattler/{back_end → compiler}/optimizer/optimize_children.rb +6 -14
  76. data/lib/rattler/{back_end → compiler}/optimizer/reduce_repeat_match.rb +4 -13
  77. data/lib/rattler/compiler/optimizer/remove_meaningless_wrapper.rb +22 -0
  78. data/lib/rattler/{back_end → compiler}/optimizer/simplify_redundant_repeat.rb +4 -13
  79. data/lib/rattler/{back_end → compiler}/optimizer/simplify_token_match.rb +4 -13
  80. data/lib/rattler/compiler/parser_generator.rb +108 -0
  81. data/lib/rattler/{back_end → compiler}/parser_generator/apply_generator.rb +7 -21
  82. data/lib/rattler/{back_end → compiler}/parser_generator/assert_generator.rb +11 -19
  83. data/lib/rattler/compiler/parser_generator/attributed_sequence_generator.rb +37 -0
  84. data/lib/rattler/{back_end → compiler}/parser_generator/back_reference_generator.rb +10 -10
  85. data/lib/rattler/{back_end → compiler}/parser_generator/choice_generator.rb +10 -22
  86. data/lib/rattler/{back_end → compiler}/parser_generator/delegating_generator.rb +2 -2
  87. data/lib/rattler/{back_end → compiler}/parser_generator/disallow_generator.rb +11 -19
  88. data/lib/rattler/{back_end → compiler}/parser_generator/e_symbol_generator.rb +2 -10
  89. data/lib/rattler/{back_end → compiler}/parser_generator/eof_generator.rb +2 -10
  90. data/lib/rattler/{back_end → compiler}/parser_generator/expr_generator.rb +9 -35
  91. data/lib/rattler/{back_end → compiler}/parser_generator/fail_generator.rb +7 -3
  92. data/lib/rattler/{back_end → compiler}/parser_generator/gen_method_names.rb +3 -5
  93. data/lib/rattler/{back_end → compiler}/parser_generator/general_list_generator.rb +6 -18
  94. data/lib/rattler/{back_end → compiler}/parser_generator/general_repeat_generator.rb +16 -22
  95. data/lib/rattler/{back_end/parser_generator/rule_set_generator.rb → compiler/parser_generator/grammar_generator.rb} +24 -33
  96. data/lib/rattler/compiler/parser_generator/group_match.rb +33 -0
  97. data/lib/rattler/{back_end → compiler}/parser_generator/group_match_generator.rb +4 -17
  98. data/lib/rattler/compiler/parser_generator/label_generator.rb +37 -0
  99. data/lib/rattler/{back_end → compiler}/parser_generator/list0_generating.rb +5 -5
  100. data/lib/rattler/{back_end → compiler}/parser_generator/list1_generating.rb +3 -3
  101. data/lib/rattler/{back_end → compiler}/parser_generator/list_generator.rb +2 -2
  102. data/lib/rattler/{back_end → compiler}/parser_generator/match_generator.rb +10 -10
  103. data/lib/rattler/{back_end → compiler}/parser_generator/nested.rb +2 -2
  104. data/lib/rattler/compiler/parser_generator/node_action_generator.rb +49 -0
  105. data/lib/rattler/{back_end → compiler}/parser_generator/one_or_more_generating.rb +3 -3
  106. data/lib/rattler/{back_end → compiler}/parser_generator/optional_generating.rb +6 -22
  107. data/lib/rattler/compiler/parser_generator/predicate_propogating.rb +24 -0
  108. data/lib/rattler/{back_end → compiler}/parser_generator/repeat_generator.rb +2 -2
  109. data/lib/rattler/compiler/parser_generator/rule_generator.rb +66 -0
  110. data/lib/rattler/compiler/parser_generator/rule_set_generator.rb +33 -0
  111. data/lib/rattler/compiler/parser_generator/semantic_action_generator.rb +58 -0
  112. data/lib/rattler/compiler/parser_generator/sequence_generating.rb +138 -0
  113. data/lib/rattler/compiler/parser_generator/sequence_generator.rb +57 -0
  114. data/lib/rattler/{back_end → compiler}/parser_generator/skip_generator.rb +4 -18
  115. data/lib/rattler/compiler/parser_generator/skip_propogating.rb +16 -0
  116. data/lib/rattler/{back_end → compiler}/parser_generator/sub_generating.rb +19 -11
  117. data/lib/rattler/compiler/parser_generator/super_generator.rb +54 -0
  118. data/lib/rattler/{back_end → compiler}/parser_generator/token_generator.rb +3 -3
  119. data/lib/rattler/compiler/parser_generator/token_propogating.rb +10 -0
  120. data/lib/rattler/{back_end → compiler}/parser_generator/top_level.rb +2 -2
  121. data/lib/rattler/{back_end → compiler}/parser_generator/zero_or_more_generating.rb +5 -5
  122. data/lib/rattler/compiler/rattler.rtlr +201 -0
  123. data/lib/rattler/{back_end → compiler}/ruby_generator.rb +16 -25
  124. data/lib/rattler/parsers.rb +12 -33
  125. data/lib/rattler/parsers/action_code.rb +25 -16
  126. data/lib/rattler/{grammar → parsers}/analysis.rb +32 -11
  127. data/lib/rattler/parsers/apply.rb +10 -19
  128. data/lib/rattler/parsers/assert.rb +4 -14
  129. data/lib/rattler/parsers/atomic.rb +3 -10
  130. data/lib/rattler/parsers/attributed_sequence.rb +50 -0
  131. data/lib/rattler/parsers/back_reference.rb +19 -14
  132. data/lib/rattler/parsers/choice.rb +11 -12
  133. data/lib/rattler/parsers/combinator_parser.rb +15 -7
  134. data/lib/rattler/parsers/combining.rb +15 -9
  135. data/lib/rattler/parsers/disallow.rb +5 -12
  136. data/lib/rattler/parsers/e_symbol.rb +5 -14
  137. data/lib/rattler/parsers/eof.rb +10 -15
  138. data/lib/rattler/parsers/fail.rb +16 -26
  139. data/lib/rattler/{grammar → parsers}/grammar.rb +15 -20
  140. data/lib/rattler/parsers/label.rb +10 -16
  141. data/lib/rattler/parsers/list_parser.rb +14 -14
  142. data/lib/rattler/parsers/match.rb +5 -17
  143. data/lib/rattler/parsers/node_action.rb +72 -0
  144. data/lib/rattler/parsers/node_code.rb +47 -30
  145. data/lib/rattler/parsers/parser.rb +63 -32
  146. data/lib/rattler/parsers/parser_scope.rb +88 -0
  147. data/lib/rattler/parsers/predicate.rb +12 -10
  148. data/lib/rattler/parsers/repeat.rb +15 -8
  149. data/lib/rattler/parsers/rule.rb +8 -23
  150. data/lib/rattler/parsers/rule_set.rb +67 -12
  151. data/lib/rattler/parsers/semantic.rb +36 -0
  152. data/lib/rattler/parsers/semantic_action.rb +39 -0
  153. data/lib/rattler/parsers/sequence.rb +25 -40
  154. data/lib/rattler/parsers/sequencing.rb +40 -0
  155. data/lib/rattler/parsers/skip.rb +11 -12
  156. data/lib/rattler/parsers/super.rb +33 -0
  157. data/lib/rattler/parsers/token.rb +3 -13
  158. data/lib/rattler/rake_task.rb +50 -0
  159. data/lib/rattler/runner.rb +19 -22
  160. data/lib/rattler/runtime.rb +0 -10
  161. data/lib/rattler/runtime/extended_packrat_parser.rb +40 -45
  162. data/lib/rattler/runtime/packrat_parser.rb +17 -31
  163. data/lib/rattler/runtime/parse_failure.rb +16 -26
  164. data/lib/rattler/runtime/parse_node.rb +8 -18
  165. data/lib/rattler/runtime/parser.rb +6 -18
  166. data/lib/rattler/runtime/parser_helper.rb +3 -10
  167. data/lib/rattler/runtime/recursive_descent_parser.rb +26 -23
  168. data/lib/rattler/runtime/syntax_error.rb +0 -10
  169. data/lib/rattler/util.rb +2 -6
  170. data/lib/rattler/util/grammar_cli.rb +19 -0
  171. data/lib/rattler/util/graphviz.rb +6 -17
  172. data/lib/rattler/util/graphviz/digraph_builder.rb +10 -17
  173. data/lib/rattler/util/graphviz/node_builder.rb +45 -31
  174. data/lib/rattler/util/line_counter.rb +11 -20
  175. data/lib/rattler/util/node.rb +52 -30
  176. data/lib/rattler/util/parser_cli.rb +84 -0
  177. data/lib/rattler/util/parser_spec_helper.rb +8 -12
  178. data/spec/rattler/compiler/assert_compiler_examples.rb +284 -0
  179. data/spec/rattler/compiler/attributed_sequence_compiler_examples.rb +154 -0
  180. data/spec/rattler/compiler/disallow_compiler_examples.rb +293 -0
  181. data/spec/rattler/compiler/grammar_parser_spec.rb +700 -0
  182. data/spec/rattler/{back_end → compiler}/optimizer/flatten_choice_spec.rb +1 -1
  183. data/spec/rattler/{back_end → compiler}/optimizer/flatten_sequence_spec.rb +1 -1
  184. data/spec/rattler/compiler/optimizer/inline_regular_rules_spec.rb +50 -0
  185. data/spec/rattler/{back_end → compiler}/optimizer/join_match_capturing_sequence_spec.rb +106 -22
  186. data/spec/rattler/{back_end → compiler}/optimizer/join_match_choice_spec.rb +1 -1
  187. data/spec/rattler/{back_end → compiler}/optimizer/join_match_matching_sequence_spec.rb +1 -1
  188. data/spec/rattler/{back_end → compiler}/optimizer/join_predicate_bare_match_spec.rb +1 -1
  189. data/spec/rattler/{back_end → compiler}/optimizer/join_predicate_nested_match_spec.rb +1 -1
  190. data/spec/rattler/{back_end → compiler}/optimizer/join_predicate_or_bare_match_spec.rb +1 -1
  191. data/spec/rattler/{back_end → compiler}/optimizer/join_predicate_or_nested_match_spec.rb +1 -1
  192. data/spec/rattler/{back_end → compiler}/optimizer/reduce_repeat_match_spec.rb +1 -1
  193. data/spec/rattler/compiler/optimizer/remove_meaningless_wrapper_spec.rb +82 -0
  194. data/spec/rattler/{back_end → compiler}/optimizer/simplify_redundant_repeat_spec.rb +1 -1
  195. data/spec/rattler/{back_end → compiler}/optimizer/simplify_token_match_spec.rb +1 -1
  196. data/spec/rattler/{back_end → compiler}/optimizer_spec.rb +1 -1
  197. data/spec/rattler/{back_end → compiler}/parser_generator/apply_generator_spec.rb +1 -39
  198. data/spec/rattler/{back_end → compiler}/parser_generator/assert_generator_spec.rb +1 -55
  199. data/spec/rattler/compiler/parser_generator/attributed_sequence_generator_spec.rb +699 -0
  200. data/spec/rattler/{back_end → compiler}/parser_generator/back_reference_generator_spec.rb +3 -56
  201. data/spec/rattler/{back_end → compiler}/parser_generator/choice_generator_spec.rb +1 -63
  202. data/spec/rattler/{back_end → compiler}/parser_generator/disallow_generator_spec.rb +1 -55
  203. data/spec/rattler/{back_end → compiler}/parser_generator/e_symbol_generator_spec.rb +1 -39
  204. data/spec/rattler/{back_end → compiler}/parser_generator/eof_generator_spec.rb +1 -39
  205. data/spec/rattler/{back_end → compiler}/parser_generator/fail_generator_spec.rb +94 -23
  206. data/spec/rattler/compiler/parser_generator/grammar_generator_spec.rb +98 -0
  207. data/spec/rattler/compiler/parser_generator/group_match_generator_spec.rb +67 -0
  208. data/spec/rattler/{back_end → compiler}/parser_generator/group_match_spec.rb +1 -1
  209. data/spec/rattler/{back_end → compiler}/parser_generator/label_generator_spec.rb +1 -55
  210. data/spec/rattler/{back_end → compiler}/parser_generator/list0_generator_examples.rb +0 -88
  211. data/spec/rattler/{back_end → compiler}/parser_generator/list1_generator_examples.rb +0 -88
  212. data/spec/rattler/{back_end → compiler}/parser_generator/list_generator_spec.rb +1 -227
  213. data/spec/rattler/{back_end → compiler}/parser_generator/match_generator_spec.rb +1 -55
  214. data/spec/rattler/compiler/parser_generator/node_action_generator_spec.rb +135 -0
  215. data/spec/rattler/{back_end → compiler}/parser_generator/one_or_more_generator_examples.rb +0 -74
  216. data/spec/rattler/{back_end → compiler}/parser_generator/optional_generator_examples.rb +0 -62
  217. data/spec/rattler/{back_end → compiler}/parser_generator/repeat_generator_spec.rb +66 -1
  218. data/spec/rattler/{back_end → compiler}/parser_generator/rule_generator_spec.rb +3 -2
  219. data/spec/rattler/{back_end → compiler}/parser_generator/rule_set_generator_spec.rb +9 -27
  220. data/spec/rattler/compiler/parser_generator/semantic_action_generator_spec.rb +437 -0
  221. data/spec/rattler/{back_end → compiler}/parser_generator/sequence_generator_spec.rb +234 -68
  222. data/spec/rattler/{back_end → compiler}/parser_generator/skip_generator_spec.rb +1 -55
  223. data/spec/rattler/compiler/parser_generator/super_generator_spec.rb +93 -0
  224. data/spec/rattler/{back_end → compiler}/parser_generator/token_generator_spec.rb +1 -55
  225. data/spec/rattler/{back_end → compiler}/parser_generator/zero_or_more_generator_examples.rb +0 -74
  226. data/spec/rattler/{back_end → compiler}/ruby_generator_spec.rb +13 -13
  227. data/spec/rattler/compiler/semantic_action_compiler_examples.rb +57 -0
  228. data/spec/rattler/{back_end → compiler}/shared_compiler_examples.rb +111 -140
  229. data/spec/rattler/{back_end → compiler}/skip_compiler_examples.rb +60 -57
  230. data/spec/rattler/{back_end → compiler}/token_compiler_examples.rb +99 -104
  231. data/spec/rattler/compiler_spec.rb +67 -0
  232. data/spec/rattler/parsers/action_code_spec.rb +34 -18
  233. data/spec/rattler/{grammar → parsers}/analysis_spec.rb +13 -67
  234. data/spec/rattler/parsers/apply_spec.rb +6 -0
  235. data/spec/rattler/parsers/assert_spec.rb +38 -2
  236. data/spec/rattler/parsers/attributed_sequence_spec.rb +204 -0
  237. data/spec/rattler/parsers/back_reference_spec.rb +6 -0
  238. data/spec/rattler/parsers/choice_spec.rb +38 -1
  239. data/spec/rattler/parsers/combinator_parser_spec.rb +2 -1
  240. data/spec/rattler/parsers/disallow_spec.rb +38 -2
  241. data/spec/rattler/parsers/e_symbol_spec.rb +6 -0
  242. data/spec/rattler/parsers/eof_spec.rb +6 -0
  243. data/spec/rattler/parsers/fail_spec.rb +6 -0
  244. data/spec/rattler/{grammar → parsers}/grammar_spec.rb +10 -15
  245. data/spec/rattler/parsers/label_spec.rb +30 -0
  246. data/spec/rattler/parsers/list_parser_spec.rb +31 -2
  247. data/spec/rattler/parsers/match_spec.rb +6 -0
  248. data/spec/rattler/parsers/node_action_spec.rb +121 -0
  249. data/spec/rattler/parsers/parser_scope_spec.rb +105 -0
  250. data/spec/rattler/parsers/repeat_spec.rb +56 -0
  251. data/spec/rattler/parsers/rule_set_spec.rb +42 -0
  252. data/spec/rattler/parsers/semantic_action_spec.rb +89 -0
  253. data/spec/rattler/parsers/sequence_spec.rb +156 -12
  254. data/spec/rattler/parsers/skip_spec.rb +21 -0
  255. data/spec/rattler/parsers/super_spec.rb +45 -0
  256. data/spec/rattler/parsers/token_spec.rb +33 -14
  257. data/spec/rattler/runtime/extended_packrat_parser_spec.rb +10 -8
  258. data/spec/rattler/runtime/recursive_descent_parser_spec.rb +26 -0
  259. data/spec/rattler/runtime/shared_parser_examples.rb +22 -16
  260. data/spec/rattler/util/graphviz/node_builder_spec.rb +33 -17
  261. data/spec/rattler/util/line_counter_spec.rb +21 -21
  262. data/spec/rattler/util/node_spec.rb +62 -0
  263. data/spec/rattler_spec.rb +7 -41
  264. data/spec/spec_helper.rb +1 -2
  265. data/spec/support/combinator_parser_spec_helper.rb +1 -1
  266. data/spec/support/compiler_spec_helper.rb +0 -4
  267. data/spec/support/parser_generator_spec_helper.rb +7 -7
  268. data/spec/support/runtime_parser_spec_helper.rb +57 -3
  269. metadata +447 -303
  270. data/features/grammar/character_class.feature +0 -20
  271. data/features/grammar/nonterminal.feature +0 -24
  272. data/features/grammar/one_or_more.feature +0 -34
  273. data/features/grammar/ordered_choice.feature +0 -21
  274. data/features/grammar/posix_class.feature +0 -70
  275. data/features/grammar/sequence.feature +0 -20
  276. data/features/grammar/zero_or_more.feature +0 -34
  277. data/lib/rattler/back_end.rb +0 -22
  278. data/lib/rattler/back_end/compiler.rb +0 -128
  279. data/lib/rattler/back_end/optimizer.rb +0 -101
  280. data/lib/rattler/back_end/optimizer/inline_regular_rules.rb +0 -46
  281. data/lib/rattler/back_end/optimizer/join_match_sequence.rb +0 -17
  282. data/lib/rattler/back_end/optimizer/join_predicate_match.rb +0 -17
  283. data/lib/rattler/back_end/optimizer/join_predicate_or_match.rb +0 -17
  284. data/lib/rattler/back_end/optimizer/optimization_context.rb +0 -72
  285. data/lib/rattler/back_end/optimizer/remove_meaningless_wrapper.rb +0 -32
  286. data/lib/rattler/back_end/optimizer/specialize_repeat.rb +0 -40
  287. data/lib/rattler/back_end/parser_generator.rb +0 -113
  288. data/lib/rattler/back_end/parser_generator/direct_action_generator.rb +0 -45
  289. data/lib/rattler/back_end/parser_generator/dispatch_action_generator.rb +0 -45
  290. data/lib/rattler/back_end/parser_generator/group_match.rb +0 -26
  291. data/lib/rattler/back_end/parser_generator/label_generator.rb +0 -64
  292. data/lib/rattler/back_end/parser_generator/predicate_propogating.rb +0 -24
  293. data/lib/rattler/back_end/parser_generator/rule_generator.rb +0 -53
  294. data/lib/rattler/back_end/parser_generator/sequence_generator.rb +0 -190
  295. data/lib/rattler/back_end/parser_generator/skip_propogating.rb +0 -16
  296. data/lib/rattler/back_end/parser_generator/token_propogating.rb +0 -10
  297. data/lib/rattler/grammar.rb +0 -43
  298. data/lib/rattler/grammar/grammar_dsl.rb +0 -51
  299. data/lib/rattler/grammar/metagrammar.rb +0 -990
  300. data/lib/rattler/grammar/rattler.rtlr +0 -183
  301. data/lib/rattler/parsers/assert_code.rb +0 -31
  302. data/lib/rattler/parsers/direct_action.rb +0 -85
  303. data/lib/rattler/parsers/disallow_code.rb +0 -31
  304. data/lib/rattler/parsers/dispatch_action.rb +0 -121
  305. data/lib/rattler/parsers/effect_code.rb +0 -31
  306. data/lib/rattler/parsers/parser_dsl.rb +0 -414
  307. data/lib/rattler/parsers/semantic_assert.rb +0 -19
  308. data/lib/rattler/parsers/semantic_disallow.rb +0 -19
  309. data/lib/rattler/parsers/side_effect.rb +0 -19
  310. data/spec/rattler/back_end/assert_compiler_examples.rb +0 -187
  311. data/spec/rattler/back_end/compiler_spec.rb +0 -43
  312. data/spec/rattler/back_end/direct_action_compiler_examples.rb +0 -227
  313. data/spec/rattler/back_end/disallow_compiler_examples.rb +0 -187
  314. data/spec/rattler/back_end/dispatch_action_compiler_examples.rb +0 -225
  315. data/spec/rattler/back_end/optimizer/inline_regular_rules_spec.rb +0 -80
  316. data/spec/rattler/back_end/parser_generator/direct_action_generator_spec.rb +0 -204
  317. data/spec/rattler/back_end/parser_generator/dispatch_action_generator_spec.rb +0 -204
  318. data/spec/rattler/back_end/parser_generator/group_match_generator_spec.rb +0 -185
  319. data/spec/rattler/back_end/semantic_assert_compiler_examples.rb +0 -152
  320. data/spec/rattler/back_end/semantic_disallow_compiler_examples.rb +0 -152
  321. data/spec/rattler/back_end/side_effect_compiler_examples.rb +0 -227
  322. data/spec/rattler/grammar/grammar_parser_spec.rb +0 -626
  323. data/spec/rattler/parsers/direct_action_spec.rb +0 -224
  324. data/spec/rattler/parsers/dispatch_action_spec.rb +0 -209
  325. data/spec/rattler/parsers/node_code_spec.rb +0 -59
  326. data/spec/rattler/parsers/parser_dsl_spec.rb +0 -334
  327. data/spec/rattler/parsers/semantic_assert_spec.rb +0 -83
  328. data/spec/rattler/parsers/semantic_disallow_spec.rb +0 -83
  329. data/spec/rattler/parsers/side_effect_spec.rb +0 -214
@@ -0,0 +1,50 @@
1
+ require 'rattler/parsers'
2
+
3
+ module Rattler::Parsers
4
+
5
+ # +AttributedSequence+ combines one or more parsers with a semantic action
6
+ # and matches the parser in sequence and applies the action to the captured
7
+ # results.
8
+ class AttributedSequence < Parser
9
+ include Sequencing
10
+
11
+ # @private
12
+ def self.parsed(results, *_) #:nodoc:
13
+ op, action = results
14
+ (op + [action]).reduce(:>>)
15
+ end
16
+
17
+ # Parse each parser in sequence, and if they all succeed return the result
18
+ # of applying the semantic action to the captured results.
19
+ #
20
+ # @param (see Match#parse)
21
+ #
22
+ # @return the result of applying the semantic action to the captured
23
+ # results of each parser, or +false
24
+ def parse(scanner, rules, scope = ParserScope.empty)
25
+ result = false
26
+ backtracking(scanner) do
27
+ if scope = parse_children(scanner, rules, scope.nest) {|r| result = r }
28
+ yield scope if block_given?
29
+ result
30
+ end
31
+ end
32
+ end
33
+
34
+ # (see Parser#capturing?)
35
+ def capturing?
36
+ children.last.capturing?
37
+ end
38
+
39
+ # (see Parser#capturing_decidable?)
40
+ def capturing_decidable?
41
+ false
42
+ end
43
+
44
+ # (see Sequence#capture_count)
45
+ def capture_count
46
+ @capture_count ||= children[0...-1].count {|_| _.capturing? }
47
+ end
48
+
49
+ end
50
+ end
@@ -1,42 +1,47 @@
1
- #
2
- # = rattler/parsers/back_reference.rb
3
- #
4
- # Author:: Jason Arhart
5
- # Documentation:: Author
6
- #
7
-
8
1
  require 'rattler/parsers'
9
2
 
10
3
  module Rattler::Parsers
11
- #
4
+
12
5
  # +BackReference+ matches the labeled result of an earlier match.
13
- #
14
- # @author Jason Arhart
15
- #
16
6
  class BackReference < Parser
17
7
 
8
+ # @param [Symbol,String] ref_label the label referencing the earlier match
9
+ # @return [BackReference] a new parser that matches the value an earlier
10
+ # match whose result is labeled by +ref_label+
18
11
  def self.[](ref_label)
19
12
  self.new(:ref_label => ref_label.to_sym)
20
13
  end
21
14
 
15
+ # @private
22
16
  def self.parsed(results, *_)
23
17
  self[results.first[1..-1]]
24
18
  end
25
19
 
26
- def parse(scanner, rules, scope={})
20
+ # If the earlier referenced match result appears again at the parse
21
+ # position, match that string, otherwise return a false value.
22
+ #
23
+ # @param (see Match#parse)
24
+ #
25
+ # @return the matched string, or +nil+
26
+ def parse(scanner, rules, scope = ParserScope.empty)
27
27
  scanner.scan Regexp.compile(Regexp.escape scope[ref_label])
28
28
  end
29
29
 
30
+ # @param [ParserScope] scope the scope of captured results
31
+ # return [String] ruby code for a +Regexp+ that matches the earlier
32
+ # referenced match result
30
33
  def re_expr(scope)
31
34
  "/#{re_source scope}/"
32
35
  end
33
36
 
37
+ # @param [ParserScope] scope the scope of captured results
38
+ # return [String] the source of a +Regexp+ that matches the earlier
39
+ # referenced match result
34
40
  def re_source(scope)
35
41
  '#{' + Regexp.escape(scope[ref_label].to_s) + '}'
36
42
  end
37
43
 
38
- # @param (see Parser#with_ws)
39
- # @return (see Parser#with_ws)
44
+ # (see Parser#with_ws)
40
45
  def with_ws(ws)
41
46
  ws.skip & self
42
47
  end
@@ -1,19 +1,10 @@
1
- #
2
- # = rattler/parsers/choice.rb
3
- #
4
- # Author:: Jason Arhart
5
- # Documentation:: Author
6
- #
7
1
 
8
2
  require 'rattler/parsers'
9
3
 
10
4
  module Rattler::Parsers
11
- #
5
+
12
6
  # +Choice+ combines two or more parsers and matches by trying each one in
13
7
  # order until one succeeds and returning that result.
14
- #
15
- # @author Jason Arhart
16
- #
17
8
  class Choice < Parser
18
9
  include Combining
19
10
 
@@ -24,10 +15,10 @@ module Rattler::Parsers
24
15
 
25
16
  # Try each parser in order until one succeeds and return that result.
26
17
  #
27
- # @param (see Parser#parse_labeled)
18
+ # @param (see Match#parse)
28
19
  #
29
20
  # @return the result of the first parser that matches, or +false+
30
- def parse(scanner, rules, scope = {})
21
+ def parse(scanner, rules, scope = ParserScope.empty)
31
22
  for child in children
32
23
  if r = child.parse(scanner, rules, scope)
33
24
  return r
@@ -36,6 +27,14 @@ module Rattler::Parsers
36
27
  false
37
28
  end
38
29
 
30
+ # (see Parser#capturing_decidable?)
31
+ def capturing_decidable?
32
+ @capturing_decidable ||=
33
+ children.all? {|_| _.capturing_decidable? } and
34
+ ( children.all? {|_| _.capturing? } or
35
+ children.none? {|_| _.capturing? } )
36
+ end
37
+
39
38
  # Return a new parser that tries this parser first and if it fails tries
40
39
  # +other+.
41
40
  #
@@ -1,15 +1,16 @@
1
- #
2
- # = rattler/parsers/rule_set.rb
3
- #
4
- # Author:: Jason Arhart
5
- # Documentation:: Author
6
- #
7
-
8
1
  require 'rattler/parsers'
9
2
 
10
3
  module Rattler::Parsers
4
+
5
+ # +CombinatorParser+ is a runtime parser that parses using the parse rules
6
+ # directly instead of using match methods generated from the parse rules
11
7
  class CombinatorParser < Rattler::Runtime::Parser
12
8
 
9
+ # @param [Symbol] start_rule the initial rule to use for parsing
10
+ # @param [RuleSet] rule_set the set of rules to use for parsing
11
+ #
12
+ # @return [Class] a subclass of +CombinatorParser+ that uses the given
13
+ # start rule and rule set and can be instantiated with only a source
13
14
  def self.as_class(start_rule, rule_set)
14
15
  new_class = Class.new(self)
15
16
  new_class.send :define_method, :initialize do |source|
@@ -18,12 +19,19 @@ module Rattler::Parsers
18
19
  new_class
19
20
  end
20
21
 
22
+ # Create a new +CombinatorParser+ to parse +source+ using +rule_set+ and
23
+ # starting with +start_rule+
24
+ #
25
+ # @param [String] source the source to parse
26
+ # @param [Symbol] start_rule the initial rule to use for parsing
27
+ # @param [RuleSet] rule_set the set of rules to use for parsing
21
28
  def initialize(source, start_rule, rule_set)
22
29
  super source
23
30
  @start_rule = start_rule
24
31
  @rule_set = rule_set
25
32
  end
26
33
 
34
+ # (see Rattler::Runtime::RecursiveDescentParser#__parse__)
27
35
  def __parse__
28
36
  @start_rule.parse(@scanner, @rule_set)
29
37
  end
@@ -1,18 +1,24 @@
1
- #
2
- # = rattler/parsers/combining.rb
3
- #
4
- # Author:: Jason Arhart
5
- # Documentation:: Author
6
- #
7
-
8
1
  module Rattler::Parsers
9
- # @private
10
- module Combining #:nodoc:
11
2
 
3
+ # +Combining+ describes a parser that is a combination of other parsers.
4
+ module Combining
5
+
6
+ # (see Parser#capturing?)
12
7
  def capturing?
13
8
  @capturing ||= any? {|child| child.capturing? }
14
9
  end
15
10
 
11
+ # (see Parser#capturing_decidable?)
12
+ def capturing_decidable?
13
+ @capturing_decidable ||= all? {|child| child.capturing_decidable? }
14
+ end
15
+
16
+ # (see Parser#semantic?)
17
+ def semantic?
18
+ @semantic = any? {|child| child.semantic? }
19
+ end
20
+
21
+ # (see Parser#with_ws)
16
22
  def with_ws(ws)
17
23
  self.class.new(children.map {|_| _.with_ws(ws) }, attrs)
18
24
  end
@@ -1,26 +1,19 @@
1
- #
2
- # = rattler/parsers/disallow.rb
3
- #
4
- # Author:: Jason Arhart
5
- # Documentation:: Author
6
- #
7
-
8
1
  require 'rattler/parsers'
9
2
 
10
3
  module Rattler::Parsers
11
- #
4
+
12
5
  # +Disallow+ decorates a parser and succeeds if the decorated parser fails
13
- # and vice versa.
14
- #
6
+ # and fails if the parser succeeds and never consumes any input (zero-width
7
+ # negative lookahead).
15
8
  class Disallow < Predicate
16
9
 
17
- # Succeed and return +true+ if and only if decorated parser fails. Never
10
+ # Succeed and return +true+ if and only if decorated parser fails. Never
18
11
  # consumes any input.
19
12
  #
20
13
  # @param (see Parser#parse_labeled)
21
14
  #
22
15
  # @return [Boolean] +true+ if the decorated parser fails
23
- def parse(scanner, rules, scope = {})
16
+ def parse(scanner, rules, scope = ParserScope.empty)
24
17
  pos = scanner.pos
25
18
  result = !child.parse(scanner, rules, scope)
26
19
  scanner.pos = pos
@@ -1,19 +1,9 @@
1
- #
2
- # = rattler/parsers/e_symbol.rb
3
- #
4
- # Author:: Jason Arhart
5
- # Documentation:: Author
6
- #
7
-
8
1
  require 'rattler/parsers'
9
2
  require 'singleton'
10
3
 
11
4
  module Rattler::Parsers
12
- #
5
+
13
6
  # +ESymbol+ always succeeds without advancing.
14
- #
15
- # @author Jason Arhart
16
- #
17
7
  class ESymbol < Parser
18
8
  include Atomic
19
9
  include Singleton
@@ -32,13 +22,14 @@ module Rattler::Parsers
32
22
 
33
23
  # Return +true+ without advancing
34
24
  #
35
- # @param (see Parser#parse)
25
+ # @param (see Match#parse)
36
26
  #
37
- # @return true
38
- def parse(scanner, rules, scope = {})
27
+ # @return [Boolean] +true+
28
+ def parse(*_)
39
29
  true
40
30
  end
41
31
 
32
+ # (see Parser#capturing?)
42
33
  def capturing?
43
34
  false
44
35
  end
@@ -1,20 +1,10 @@
1
- #
2
- # = rattler/parsers/eof.rb
3
- #
4
- # Author:: Jason Arhart
5
- # Documentation:: Author
6
- #
7
-
8
1
  require 'rattler/parsers'
9
2
  require 'singleton'
10
3
 
11
4
  module Rattler::Parsers
12
- #
5
+
13
6
  # +Eof+ succeeds if there is no more input to parse.
14
- #
15
- # @author Jason Arhart
16
- #
17
- class Eof < Predicate
7
+ class Eof < Parser
18
8
  include Atomic
19
9
  include Singleton
20
10
 
@@ -32,12 +22,17 @@ module Rattler::Parsers
32
22
 
33
23
  # Return +true+ if there is no more input to parse
34
24
  #
35
- # @param (see Parser#parse_labeled)
25
+ # @param (see Match#parse)
36
26
  #
37
- # @return true if there is no more input to parse
38
- def parse(scanner, rules, scope = {})
27
+ # @return [Boolean] +true+ if there is no more input to parse
28
+ def parse(scanner, *_)
39
29
  scanner.eos?
40
30
  end
41
31
 
32
+ # (see Parser#capturing?)
33
+ def capturing?
34
+ false
35
+ end
36
+
42
37
  end
43
38
  end
@@ -1,32 +1,23 @@
1
- #
2
- # = rattler/parsers/fail.rb
3
- #
4
- # Author:: Jason Arhart
5
- # Documentation:: Author
6
- #
7
-
8
1
  require 'rattler/parsers'
9
2
 
10
3
  module Rattler::Parsers
11
- #
4
+
12
5
  # +Fail+ is a parser that always fails. It can be used to define more useful
13
6
  # error messages.
14
- #
15
- # @author Jason Arhart
16
- #
17
7
  class Fail < Parser
18
-
8
+
19
9
  # @private
20
10
  def self.parsed(results, *_) #:nodoc:
21
- keyword, message_expr = results
22
- message = eval(message_expr)
11
+ keyword, arg_expr = results
12
+ arg = eval(arg_expr)
23
13
  case keyword
24
- when 'fail' then self[:expr, message]
25
- when 'fail_rule' then self[:rule, message]
26
- when 'fail_parse' then self[:parse, message]
14
+ when 'fail' then self[:expr, arg]
15
+ when 'fail_rule' then self[:rule, arg]
16
+ when 'fail_parse' then self[:parse, arg]
17
+ when 'expected' then self[:expr, arg.to_sym]
27
18
  end
28
19
  end
29
-
20
+
30
21
  # Create a new parser that always fails with +message+. The +type+ should
31
22
  # be one of <tt>:expr</tt>, <tt>:rule</tt> or <tt>:parse</tt>, indicating
32
23
  # to simply fail, to cause its parse rule to fail, or to cause the entire
@@ -38,24 +29,23 @@ module Rattler::Parsers
38
29
  def self.[](type, message)
39
30
  self.new(:type => type, :message => message)
40
31
  end
41
-
32
+
42
33
  # Always return +false+. The parser code generated for this parser should
43
34
  # use +message+ as the failure message, and should cause its parse rule
44
35
  # to fail if +type+ is <tt>:rule</tt> or cause the entire parse to fail
45
- # +type+ is <tt>:parse</tt>
36
+ # if +type+ is <tt>:parse</tt>
46
37
  #
47
- # @param (see Parser#parse_labeled)
38
+ # @param (see Match#parse)
48
39
  #
49
40
  # @return false
50
- def parse(scanner, rules, labeled = {})
41
+ def parse(*_)
51
42
  false
52
43
  end
53
-
54
- # Always +false+
55
- # @return false
44
+
45
+ # @return +false+
56
46
  def capturing?
57
47
  false
58
48
  end
59
-
49
+
60
50
  end
61
51
  end
@@ -1,16 +1,8 @@
1
- #
2
- # = rattler/grammar/grammar.rb
3
- #
4
- # Author:: Jason Arhart
5
- # Documentation:: Author
6
- #
7
- require 'rattler/grammar'
1
+ require 'rattler/parsers'
2
+
3
+ module Rattler::Parsers
8
4
 
9
- module Rattler::Grammar
10
- #
11
5
  # +Grammar+ represents a parsed grammar
12
- #
13
- # @author Jason Arhart
14
6
  class Grammar < Rattler::Util::Node
15
7
 
16
8
  # The name of the default parser base class
@@ -32,35 +24,38 @@ module Rattler::Grammar
32
24
 
33
25
  # @param rules [RuleSet] the parse rules that define the parser
34
26
  #
35
- # @option opts [String] start_rule (rules.first)
27
+ # @option opts [String] start_rule (rules.first.name)
36
28
  # @option opts [String] grammar_name (nil)
37
29
  # @option opts [String] parser_name (nil)
38
30
  # @option opts [String] base_name (Rattler::Runtime::RecursiveDescentParser)
39
31
  # @option opts [Array<String>] requires ([])
40
32
  # @option opts [Array<String>] includes ([])
41
33
  def initialize(rules, opts={})
42
- super @@default_opts.merge(opts)
43
-
44
- case attrs[:start_rule]
45
- when Symbol then attrs[:start_rule] = rules[start_rule]
46
- when nil then attrs[:start_rule] = rules.first
47
- end
34
+ start_rule =
35
+ opts[:start_rule] || rules.start_rule || (rules.first && rules.first.name)
48
36
 
49
- @rules = rules.with_attrs(:start_rule => start_rule.name)
37
+ super rules.with_attrs(:start_rule => start_rule),
38
+ @@default_opts.merge(:start_rule => start_rule).merge(opts)
50
39
 
51
40
  attrs[:name] ||= grammar_name || parser_name
52
41
  end
53
42
 
54
- attr_reader :rules
43
+ alias_method :rules, :child
55
44
 
45
+ # @param [Symbol] name the name of a parse rule in the grammar
46
+ # @return [Rule] the parse rule referenced by +name+
56
47
  def rule(name)
57
48
  rules[name]
58
49
  end
59
50
 
51
+ # @return [Analysis] a static analysis of the grammar rules
60
52
  def analysis
61
53
  rules.analysis
62
54
  end
63
55
 
56
+ # @param [RuleSet] new_rules
57
+ # @return [Grammar] a new grammar with the parse rules replaced by
58
+ # +new_rules+
64
59
  def with_rules(new_rules)
65
60
  self.class.new new_rules, attrs
66
61
  end