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.
- data/README.rdoc +9 -3
- data/features/command_line/dest_option.feature +1 -1
- data/features/command_line/lib_option.feature +2 -2
- data/features/command_line/output_option.feature +2 -2
- data/features/command_line/parser_generator.feature +3 -3
- data/features/grammar/any_character.feature +0 -4
- data/features/grammar/back_reference.feature +0 -4
- data/features/grammar/character_class.feature +0 -4
- data/features/grammar/comments.feature +0 -4
- data/features/grammar/e_symbol.feature +18 -0
- data/features/grammar/eof.feature +0 -4
- data/features/grammar/fail.feature +0 -4
- data/features/grammar/list_matching.feature +52 -3
- data/features/grammar/literal.feature +0 -4
- data/features/grammar/negative_lookahead.feature +0 -4
- data/features/grammar/negative_semantic_predicate.feature +99 -0
- data/features/grammar/node_action.feature +17 -4
- data/features/grammar/nonterminal.feature +3 -7
- data/features/grammar/one_or_more.feature +0 -4
- data/features/grammar/optional.feature +0 -4
- data/features/grammar/ordered_choice.feature +0 -4
- data/features/grammar/positive_lookahead.feature +0 -4
- data/features/grammar/positive_semantic_predicate.feature +99 -0
- data/features/grammar/posix_class.feature +3 -6
- data/features/grammar/repeat.feature +50 -0
- data/features/grammar/sequence.feature +0 -4
- data/features/grammar/side_effect.feature +81 -0
- data/features/grammar/skip_operator.feature +2 -5
- data/features/grammar/start_rule.feature +1 -5
- data/features/grammar/symantic_action.feature +9 -4
- data/features/grammar/token.feature +0 -4
- data/features/grammar/whitespace.feature +0 -4
- data/features/grammar/word_literal.feature +0 -4
- data/features/grammar/zero_or_more.feature +0 -4
- data/features/step_definitions/grammar_steps.rb +5 -1
- data/lib/rattler/back_end/optimizer.rb +1 -0
- data/lib/rattler/back_end/optimizer/reduce_repeat_match.rb +20 -8
- data/lib/rattler/back_end/optimizer/simplify_redundant_repeat.rb +10 -7
- data/lib/rattler/back_end/optimizer/specialize_repeat.rb +40 -0
- data/lib/rattler/back_end/parser_generator.rb +11 -6
- data/lib/rattler/back_end/parser_generator/delegating_generator.rb +20 -0
- data/lib/rattler/back_end/parser_generator/e_symbol_generator.rb +52 -0
- data/lib/rattler/back_end/parser_generator/eof_generator.rb +58 -0
- data/lib/rattler/back_end/parser_generator/expr_generator.rb +6 -2
- data/lib/rattler/back_end/parser_generator/gen_method_names.rb +15 -5
- data/lib/rattler/back_end/parser_generator/general_list_generator.rb +194 -0
- data/lib/rattler/back_end/parser_generator/general_repeat_generator.rb +177 -0
- data/lib/rattler/back_end/parser_generator/label_generator.rb +4 -1
- data/lib/rattler/back_end/parser_generator/list0_generating.rb +36 -0
- data/lib/rattler/back_end/parser_generator/list1_generating.rb +30 -0
- data/lib/rattler/back_end/parser_generator/list_generator.rb +16 -20
- data/lib/rattler/back_end/parser_generator/one_or_more_generating.rb +25 -0
- data/lib/rattler/back_end/parser_generator/{optional_generator.rb → optional_generating.rb} +66 -81
- data/lib/rattler/back_end/parser_generator/predicate_propogating.rb +4 -4
- data/lib/rattler/back_end/parser_generator/repeat_generator.rb +53 -0
- data/lib/rattler/back_end/parser_generator/skip_propogating.rb +2 -2
- data/lib/rattler/back_end/parser_generator/sub_generating.rb +16 -18
- data/lib/rattler/back_end/parser_generator/token_propogating.rb +1 -1
- data/lib/rattler/back_end/parser_generator/zero_or_more_generating.rb +31 -0
- data/lib/rattler/grammar/grammar_parser.rb +20 -0
- data/lib/rattler/grammar/metagrammar.rb +131 -13
- data/lib/rattler/grammar/rattler.rtlr +25 -12
- data/lib/rattler/parsers.rb +9 -5
- data/lib/rattler/parsers/assert_code.rb +31 -0
- data/lib/rattler/parsers/atomic.rb +19 -0
- data/lib/rattler/parsers/direct_action.rb +12 -4
- data/lib/rattler/parsers/disallow_code.rb +31 -0
- data/lib/rattler/parsers/dispatch_action.rb +3 -2
- data/lib/rattler/parsers/e_symbol.rb +47 -0
- data/lib/rattler/parsers/effect_code.rb +31 -0
- data/lib/rattler/parsers/eof.rb +6 -13
- data/lib/rattler/parsers/list_parser.rb +33 -14
- data/lib/rattler/parsers/match.rb +1 -6
- data/lib/rattler/parsers/parser_dsl.rb +78 -35
- data/lib/rattler/parsers/predicate.rb +1 -4
- data/lib/rattler/parsers/repeat.rb +76 -0
- data/lib/rattler/parsers/semantic_assert.rb +19 -0
- data/lib/rattler/parsers/semantic_disallow.rb +19 -0
- data/lib/rattler/parsers/side_effect.rb +19 -0
- data/lib/rattler/parsers/skip.rb +1 -9
- data/lib/rattler/parsers/token.rb +1 -6
- data/lib/rattler/util/graphviz/node_builder.rb +6 -3
- data/spec/rattler/back_end/assert_compiler_examples.rb +187 -0
- data/spec/rattler/back_end/direct_action_compiler_examples.rb +227 -0
- data/spec/rattler/back_end/disallow_compiler_examples.rb +187 -0
- data/spec/rattler/back_end/dispatch_action_compiler_examples.rb +225 -0
- data/spec/rattler/back_end/optimizer/reduce_repeat_match_spec.rb +45 -33
- data/spec/rattler/back_end/optimizer/simplify_redundant_repeat_spec.rb +32 -172
- data/spec/rattler/back_end/parser_generator/e_symbol_generator_spec.rb +149 -0
- data/spec/rattler/back_end/parser_generator/eof_generator_spec.rb +152 -0
- data/spec/rattler/back_end/parser_generator/label_generator_spec.rb +4 -4
- data/spec/rattler/back_end/parser_generator/list0_generator_examples.rb +322 -0
- data/spec/rattler/back_end/parser_generator/list1_generator_examples.rb +343 -0
- data/spec/rattler/back_end/parser_generator/list_generator_spec.rb +597 -140
- data/spec/rattler/back_end/parser_generator/one_or_more_generator_examples.rb +292 -0
- data/spec/rattler/back_end/parser_generator/optional_generator_examples.rb +233 -0
- data/spec/rattler/back_end/parser_generator/repeat_generator_spec.rb +281 -0
- data/spec/rattler/back_end/parser_generator/zero_or_more_generator_examples.rb +277 -0
- data/spec/rattler/back_end/semantic_assert_compiler_examples.rb +152 -0
- data/spec/rattler/back_end/semantic_disallow_compiler_examples.rb +152 -0
- data/spec/rattler/back_end/shared_compiler_examples.rb +106 -651
- data/spec/rattler/back_end/side_effect_compiler_examples.rb +227 -0
- data/spec/rattler/back_end/skip_compiler_examples.rb +161 -0
- data/spec/rattler/back_end/token_compiler_examples.rb +262 -0
- data/spec/rattler/grammar/grammar_parser_spec.rb +302 -23
- data/spec/rattler/parsers/apply_spec.rb +6 -0
- data/spec/rattler/parsers/assert_spec.rb +18 -7
- data/spec/rattler/parsers/back_reference_spec.rb +9 -0
- data/spec/rattler/parsers/choice_spec.rb +36 -21
- data/spec/rattler/parsers/direct_action_spec.rb +76 -36
- data/spec/rattler/parsers/disallow_spec.rb +18 -7
- data/spec/rattler/parsers/dispatch_action_spec.rb +128 -22
- data/spec/rattler/parsers/e_symbol_spec.rb +30 -0
- data/spec/rattler/parsers/eof_spec.rb +15 -6
- data/spec/rattler/parsers/label_spec.rb +15 -2
- data/spec/rattler/parsers/list_parser_spec.rb +187 -0
- data/spec/rattler/parsers/match_spec.rb +16 -7
- data/spec/rattler/parsers/parser_dsl_spec.rb +82 -23
- data/spec/rattler/parsers/repeat_spec.rb +233 -0
- data/spec/rattler/parsers/semantic_assert_spec.rb +83 -0
- data/spec/rattler/parsers/semantic_disallow_spec.rb +83 -0
- data/spec/rattler/parsers/sequence_spec.rb +34 -20
- data/spec/rattler/parsers/side_effect_spec.rb +214 -0
- data/spec/rattler/parsers/skip_spec.rb +17 -6
- data/spec/rattler_spec.rb +2 -0
- data/spec/support/compiler_spec_helper.rb +8 -0
- metadata +156 -447
- data/bin/rtlr.compiled.rbc +0 -201
- data/features/step_definitions/cli_steps.rbc +0 -149
- data/features/step_definitions/grammar_steps.rbc +0 -1211
- data/features/support/env.rbc +0 -389
- data/lib/rattler.rbc +0 -1231
- data/lib/rattler/back_end.rbc +0 -286
- data/lib/rattler/back_end/compiler.rbc +0 -1394
- data/lib/rattler/back_end/optimizer.rbc +0 -2000
- data/lib/rattler/back_end/optimizer/composite_reducing.rbc +0 -337
- data/lib/rattler/back_end/optimizer/flatten_choice.rbc +0 -443
- data/lib/rattler/back_end/optimizer/flatten_sequence.rbc +0 -827
- data/lib/rattler/back_end/optimizer/flattening.rbc +0 -570
- data/lib/rattler/back_end/optimizer/inline_regular_rules.rbc +0 -691
- data/lib/rattler/back_end/optimizer/join_match_capturing_sequence.rbc +0 -1299
- data/lib/rattler/back_end/optimizer/join_match_choice.rbc +0 -523
- data/lib/rattler/back_end/optimizer/join_match_matching_sequence.rbc +0 -619
- data/lib/rattler/back_end/optimizer/join_match_sequence.rbc +0 -174
- data/lib/rattler/back_end/optimizer/join_predicate_bare_match.rbc +0 -1505
- data/lib/rattler/back_end/optimizer/join_predicate_match.rbc +0 -174
- data/lib/rattler/back_end/optimizer/join_predicate_nested_match.rbc +0 -620
- data/lib/rattler/back_end/optimizer/join_predicate_or_bare_match.rbc +0 -1502
- data/lib/rattler/back_end/optimizer/join_predicate_or_match.rbc +0 -174
- data/lib/rattler/back_end/optimizer/join_predicate_or_nested_match.rbc +0 -616
- data/lib/rattler/back_end/optimizer/match_joining.rbc +0 -1454
- data/lib/rattler/back_end/optimizer/optimization.rbc +0 -1366
- data/lib/rattler/back_end/optimizer/optimization_context.rbc +0 -1386
- data/lib/rattler/back_end/optimizer/optimization_sequence.rbc +0 -520
- data/lib/rattler/back_end/optimizer/optimize_children.rbc +0 -793
- data/lib/rattler/back_end/optimizer/reduce_repeat_match.rbc +0 -788
- data/lib/rattler/back_end/optimizer/remove_meaningless_wrapper.rbc +0 -508
- data/lib/rattler/back_end/optimizer/simplify_redundant_repeat.rbc +0 -807
- data/lib/rattler/back_end/optimizer/simplify_token_match.rbc +0 -561
- data/lib/rattler/back_end/parser_generator.rbc +0 -1326
- data/lib/rattler/back_end/parser_generator/apply_generator.rbc +0 -2148
- data/lib/rattler/back_end/parser_generator/assert_generator.rbc +0 -1967
- data/lib/rattler/back_end/parser_generator/back_reference_generator.rbc +0 -1665
- data/lib/rattler/back_end/parser_generator/choice_generator.rbc +0 -2793
- data/lib/rattler/back_end/parser_generator/direct_action_generator.rbc +0 -1071
- data/lib/rattler/back_end/parser_generator/disallow_generator.rbc +0 -1967
- data/lib/rattler/back_end/parser_generator/dispatch_action_generator.rbc +0 -1071
- data/lib/rattler/back_end/parser_generator/expr_generator.rbc +0 -2295
- data/lib/rattler/back_end/parser_generator/fail_generator.rbc +0 -1216
- data/lib/rattler/back_end/parser_generator/gen_method_names.rbc +0 -296
- data/lib/rattler/back_end/parser_generator/group_match.rbc +0 -612
- data/lib/rattler/back_end/parser_generator/group_match_generator.rbc +0 -1647
- data/lib/rattler/back_end/parser_generator/label_generator.rbc +0 -1401
- data/lib/rattler/back_end/parser_generator/list1_generator.rb +0 -54
- data/lib/rattler/back_end/parser_generator/list1_generator.rbc +0 -1237
- data/lib/rattler/back_end/parser_generator/list_generating.rb +0 -71
- data/lib/rattler/back_end/parser_generator/list_generating.rbc +0 -1900
- data/lib/rattler/back_end/parser_generator/list_generator.rbc +0 -1068
- data/lib/rattler/back_end/parser_generator/match_generator.rbc +0 -1743
- data/lib/rattler/back_end/parser_generator/nested.rbc +0 -496
- data/lib/rattler/back_end/parser_generator/one_or_more_generator.rb +0 -56
- data/lib/rattler/back_end/parser_generator/one_or_more_generator.rbc +0 -1277
- data/lib/rattler/back_end/parser_generator/optional_generator.rbc +0 -2025
- data/lib/rattler/back_end/parser_generator/predicate_propogating.rbc +0 -648
- data/lib/rattler/back_end/parser_generator/repeat_generating.rb +0 -57
- data/lib/rattler/back_end/parser_generator/repeat_generating.rbc +0 -1549
- data/lib/rattler/back_end/parser_generator/rule_generator.rbc +0 -1239
- data/lib/rattler/back_end/parser_generator/rule_set_generator.rbc +0 -2641
- data/lib/rattler/back_end/parser_generator/sequence_generator.rbc +0 -4867
- data/lib/rattler/back_end/parser_generator/skip_generator.rbc +0 -1278
- data/lib/rattler/back_end/parser_generator/skip_propogating.rbc +0 -432
- data/lib/rattler/back_end/parser_generator/sub_generating.rbc +0 -2785
- data/lib/rattler/back_end/parser_generator/token_generator.rbc +0 -755
- data/lib/rattler/back_end/parser_generator/token_propogating.rbc +0 -324
- data/lib/rattler/back_end/parser_generator/top_level.rbc +0 -352
- data/lib/rattler/back_end/parser_generator/zero_or_more_generator.rb +0 -53
- data/lib/rattler/back_end/parser_generator/zero_or_more_generator.rbc +0 -1111
- data/lib/rattler/back_end/ruby_generator.rbc +0 -1841
- data/lib/rattler/grammar.rbc +0 -557
- data/lib/rattler/grammar/analysis.rbc +0 -1944
- data/lib/rattler/grammar/grammar.rbc +0 -1090
- data/lib/rattler/grammar/grammar_dsl.rbc +0 -1401
- data/lib/rattler/grammar/grammar_parser.rbc +0 -2096
- data/lib/rattler/grammar/metagrammar.rbc +0 -11014
- data/lib/rattler/parsers.rbc +0 -1006
- data/lib/rattler/parsers/action_code.rbc +0 -1577
- data/lib/rattler/parsers/apply.rbc +0 -562
- data/lib/rattler/parsers/assert.rbc +0 -378
- data/lib/rattler/parsers/back_reference.rbc +0 -871
- data/lib/rattler/parsers/choice.rbc +0 -607
- data/lib/rattler/parsers/combinator_parser.rbc +0 -612
- data/lib/rattler/parsers/combining.rbc +0 -570
- data/lib/rattler/parsers/direct_action.rbc +0 -1472
- data/lib/rattler/parsers/disallow.rbc +0 -379
- data/lib/rattler/parsers/dispatch_action.rbc +0 -2078
- data/lib/rattler/parsers/eof.rbc +0 -567
- data/lib/rattler/parsers/fail.rbc +0 -745
- data/lib/rattler/parsers/label.rbc +0 -749
- data/lib/rattler/parsers/list.rbc +0 -292
- data/lib/rattler/parsers/list0.rb +0 -26
- data/lib/rattler/parsers/list0.rbc +0 -292
- data/lib/rattler/parsers/list1.rb +0 -26
- data/lib/rattler/parsers/list1.rbc +0 -305
- data/lib/rattler/parsers/list_parser.rbc +0 -886
- data/lib/rattler/parsers/match.rbc +0 -621
- data/lib/rattler/parsers/node_code.rbc +0 -1064
- data/lib/rattler/parsers/one_or_more.rb +0 -47
- data/lib/rattler/parsers/one_or_more.rbc +0 -475
- data/lib/rattler/parsers/optional.rb +0 -42
- data/lib/rattler/parsers/optional.rbc +0 -450
- data/lib/rattler/parsers/parser.rbc +0 -994
- data/lib/rattler/parsers/parser_dsl.rbc +0 -4765
- data/lib/rattler/parsers/predicate.rbc +0 -490
- data/lib/rattler/parsers/rule.rbc +0 -777
- data/lib/rattler/parsers/rule_set.rbc +0 -1438
- data/lib/rattler/parsers/sequence.rbc +0 -1040
- data/lib/rattler/parsers/skip.rbc +0 -613
- data/lib/rattler/parsers/token.rbc +0 -457
- data/lib/rattler/parsers/zero_or_more.rb +0 -40
- data/lib/rattler/parsers/zero_or_more.rbc +0 -462
- data/lib/rattler/runner.rbc +0 -3813
- data/lib/rattler/runtime.rbc +0 -370
- data/lib/rattler/runtime/extended_packrat_parser.rbc +0 -2351
- data/lib/rattler/runtime/packrat_parser.rbc +0 -1390
- data/lib/rattler/runtime/parse_failure.rbc +0 -909
- data/lib/rattler/runtime/parse_node.rbc +0 -1007
- data/lib/rattler/runtime/parser.rbc +0 -2267
- data/lib/rattler/runtime/parser_helper.rbc +0 -337
- data/lib/rattler/runtime/recursive_descent_parser.rbc +0 -942
- data/lib/rattler/util.rbc +0 -286
- data/lib/rattler/util/graphviz.rbc +0 -327
- data/lib/rattler/util/graphviz/node_builder.rbc +0 -2207
- data/lib/rattler/util/line_counter.rbc +0 -988
- data/lib/rattler/util/node.rbc +0 -2393
- data/lib/rattler/util/parser_spec_helper.rbc +0 -2533
- data/spec/rattler/back_end/compiler_spec.rbc +0 -1187
- data/spec/rattler/back_end/optimizer/flatten_choice_spec.rbc +0 -2093
- data/spec/rattler/back_end/optimizer/flatten_sequence_spec.rbc +0 -4055
- data/spec/rattler/back_end/optimizer/inline_regular_rules_spec.rbc +0 -2345
- data/spec/rattler/back_end/optimizer/join_match_capturing_sequence_spec.rbc +0 -7006
- data/spec/rattler/back_end/optimizer/join_match_choice_spec.rbc +0 -3252
- data/spec/rattler/back_end/optimizer/join_match_matching_sequence_spec.rbc +0 -3681
- data/spec/rattler/back_end/optimizer/join_predicate_bare_match_spec.rbc +0 -5603
- data/spec/rattler/back_end/optimizer/join_predicate_nested_match_spec.rbc +0 -5232
- data/spec/rattler/back_end/optimizer/join_predicate_or_bare_match_spec.rbc +0 -4272
- data/spec/rattler/back_end/optimizer/join_predicate_or_nested_match_spec.rbc +0 -4342
- data/spec/rattler/back_end/optimizer/reduce_repeat_match_spec.rbc +0 -2960
- data/spec/rattler/back_end/optimizer/simplify_redundant_repeat_spec.rbc +0 -6929
- data/spec/rattler/back_end/optimizer/simplify_token_match_spec.rbc +0 -2327
- data/spec/rattler/back_end/optimizer_spec.rbc +0 -372
- data/spec/rattler/back_end/parser_generator/apply_generator_spec.rbc +0 -4710
- data/spec/rattler/back_end/parser_generator/assert_generator_spec.rbc +0 -4697
- data/spec/rattler/back_end/parser_generator/back_reference_generator_spec.rbc +0 -4855
- data/spec/rattler/back_end/parser_generator/choice_generator_spec.rbc +0 -5350
- data/spec/rattler/back_end/parser_generator/direct_action_generator_spec.rbc +0 -4737
- data/spec/rattler/back_end/parser_generator/disallow_generator_spec.rbc +0 -4697
- data/spec/rattler/back_end/parser_generator/dispatch_action_generator_spec.rbc +0 -4731
- data/spec/rattler/back_end/parser_generator/fail_generator_spec.rbc +0 -2115
- data/spec/rattler/back_end/parser_generator/group_match_generator_spec.rbc +0 -4195
- data/spec/rattler/back_end/parser_generator/group_match_spec.rbc +0 -1414
- data/spec/rattler/back_end/parser_generator/label_generator_spec.rbc +0 -4696
- data/spec/rattler/back_end/parser_generator/list1_generator_spec.rb +0 -309
- data/spec/rattler/back_end/parser_generator/list1_generator_spec.rbc +0 -5213
- data/spec/rattler/back_end/parser_generator/list_generator_spec.rbc +0 -5179
- data/spec/rattler/back_end/parser_generator/match_generator_spec.rbc +0 -4681
- data/spec/rattler/back_end/parser_generator/one_or_more_generator_spec.rb +0 -259
- data/spec/rattler/back_end/parser_generator/one_or_more_generator_spec.rbc +0 -4957
- data/spec/rattler/back_end/parser_generator/optional_generator_spec.rb +0 -190
- data/spec/rattler/back_end/parser_generator/optional_generator_spec.rbc +0 -4704
- data/spec/rattler/back_end/parser_generator/rule_generator_spec.rbc +0 -545
- data/spec/rattler/back_end/parser_generator/rule_set_generator_spec.rbc +0 -1110
- data/spec/rattler/back_end/parser_generator/sequence_generator_spec.rbc +0 -5453
- data/spec/rattler/back_end/parser_generator/skip_generator_spec.rbc +0 -4691
- data/spec/rattler/back_end/parser_generator/token_generator_spec.rbc +0 -4691
- data/spec/rattler/back_end/parser_generator/zero_or_more_generator_spec.rb +0 -244
- data/spec/rattler/back_end/parser_generator/zero_or_more_generator_spec.rbc +0 -4924
- data/spec/rattler/back_end/ruby_generator_spec.rbc +0 -2460
- data/spec/rattler/back_end/shared_compiler_examples.rbc +0 -41886
- data/spec/rattler/grammar/analysis_spec.rbc +0 -4365
- data/spec/rattler/grammar/grammar_parser_spec.rbc +0 -10344
- data/spec/rattler/grammar/grammar_spec.rbc +0 -1701
- data/spec/rattler/parsers/action_code_spec.rbc +0 -4674
- data/spec/rattler/parsers/apply_spec.rbc +0 -851
- data/spec/rattler/parsers/assert_spec.rbc +0 -752
- data/spec/rattler/parsers/back_reference_spec.rbc +0 -1002
- data/spec/rattler/parsers/choice_spec.rbc +0 -1696
- data/spec/rattler/parsers/combinator_parser_spec.rbc +0 -361
- data/spec/rattler/parsers/direct_action_spec.rbc +0 -5222
- data/spec/rattler/parsers/disallow_spec.rbc +0 -752
- data/spec/rattler/parsers/dispatch_action_spec.rbc +0 -3033
- data/spec/rattler/parsers/eof_spec.rbc +0 -728
- data/spec/rattler/parsers/fail_spec.rbc +0 -548
- data/spec/rattler/parsers/label_spec.rbc +0 -1091
- data/spec/rattler/parsers/list0_spec.rb +0 -82
- data/spec/rattler/parsers/list0_spec.rbc +0 -2308
- data/spec/rattler/parsers/list1_spec.rb +0 -82
- data/spec/rattler/parsers/list1_spec.rbc +0 -2287
- data/spec/rattler/parsers/list_spec.rbc +0 -2308
- data/spec/rattler/parsers/match_spec.rbc +0 -780
- data/spec/rattler/parsers/node_code_spec.rbc +0 -1754
- data/spec/rattler/parsers/one_or_more_spec.rb +0 -64
- data/spec/rattler/parsers/one_or_more_spec.rbc +0 -1698
- data/spec/rattler/parsers/optional_spec.rb +0 -64
- data/spec/rattler/parsers/optional_spec.rbc +0 -1717
- data/spec/rattler/parsers/parser_dsl_spec.rbc +0 -10150
- data/spec/rattler/parsers/rule_set_spec.rbc +0 -1060
- data/spec/rattler/parsers/sequence_spec.rbc +0 -2899
- data/spec/rattler/parsers/skip_spec.rbc +0 -753
- data/spec/rattler/parsers/token_spec.rbc +0 -1511
- data/spec/rattler/parsers/zero_or_more_spec.rb +0 -64
- data/spec/rattler/parsers/zero_or_more_spec.rbc +0 -1719
- data/spec/rattler/runtime/extended_packrat_parser_spec.rbc +0 -1341
- data/spec/rattler/runtime/packrat_parser_spec.rbc +0 -210
- data/spec/rattler/runtime/parse_failure_spec.rbc +0 -2244
- data/spec/rattler/runtime/parse_node_spec.rbc +0 -2008
- data/spec/rattler/runtime/parser_spec.rbc +0 -2757
- data/spec/rattler/runtime/recursive_descent_parser_spec.rbc +0 -210
- data/spec/rattler/runtime/shared_parser_examples.rbc +0 -2567
- data/spec/rattler/util/graphviz/node_builder_spec.rbc +0 -3439
- data/spec/rattler/util/line_counter_spec.rbc +0 -2272
- data/spec/rattler/util/node_spec.rbc +0 -15023
- data/spec/rattler_spec.rbc +0 -1591
- data/spec/spec_helper.rbc +0 -336
- data/spec/support/combinator_parser_spec_helper.rbc +0 -1284
- data/spec/support/compiler_spec_helper.rbc +0 -1941
- data/spec/support/parser_generator_spec_helper.rbc +0 -718
- data/spec/support/runtime_parser_spec_helper.rbc +0 -313
@@ -150,6 +150,12 @@ describe Rattler::Grammar::GrammarParser do
|
|
150
150
|
end
|
151
151
|
end
|
152
152
|
|
153
|
+
context 'given the E symbol' do
|
154
|
+
it 'parses as ESymbol[]' do
|
155
|
+
matching(' E ').as(:expression).should result_in(ESymbol[]).at(2)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
153
159
|
context 'given an upper-case POSIX class name' do
|
154
160
|
it 'parses as a Match of a POSIX character class' do
|
155
161
|
for name in posix_names
|
@@ -167,6 +173,87 @@ describe Rattler::Grammar::GrammarParser do
|
|
167
173
|
end
|
168
174
|
end
|
169
175
|
|
176
|
+
context 'given an optional expression' do
|
177
|
+
it 'parses as a Repeat with optional bounds' do
|
178
|
+
matching(' expr? ').as(:expression).
|
179
|
+
should result_in(Repeat[Apply[:expr], 0, 1]).at(6)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
context 'given a zero-or-more expression' do
|
184
|
+
it 'parses as a Repeat with zero-or-more bounds' do
|
185
|
+
matching(' expr* ').as(:expression).
|
186
|
+
should result_in(Repeat[Apply[:expr], 0, nil]).at(6)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
context 'given a one-or-more expression' do
|
191
|
+
it 'parses as a Repeat with one-or-more bounds' do
|
192
|
+
matching(' expr+ ').as(:expression).
|
193
|
+
should result_in(Repeat[Apply[:expr], 1, nil]).at(6)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
context 'given a generalized repeat expression' do
|
198
|
+
context 'with a single count' do
|
199
|
+
it 'parses as a Repeat with the count as both lower and upper bounds' do
|
200
|
+
matching(' expr 2 ').as(:expression).
|
201
|
+
should result_in(Repeat[Apply[:expr], 2, 2]).at(7)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
context 'with a range' do
|
206
|
+
it 'parses as a Repeat with lower and upper bounds' do
|
207
|
+
matching(' expr 2..4 ').as(:expression).
|
208
|
+
should result_in(Repeat[Apply[:expr], 2, 4]).at(10)
|
209
|
+
end
|
210
|
+
|
211
|
+
context 'with no upper bound' do
|
212
|
+
it 'parses as a Repeat with no upper bound' do
|
213
|
+
matching(' expr 2.. ').as(:expression).
|
214
|
+
should result_in(Repeat[Apply[:expr], 2, nil]).at(9)
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
context 'given a zero-or-more list expression' do
|
221
|
+
it 'parses as a ListParser with zero-or-more bounds' do
|
222
|
+
matching(' expr *, ";" ').as(:expression).
|
223
|
+
should result_in(ListParser[Apply[:expr], Match[/;/], 0, nil]).at(12)
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
context 'given a one-or-more list expression' do
|
228
|
+
it 'parses as a ListParser with one-or-more bounds' do
|
229
|
+
matching(' expr +, ";" ').as(:expression).
|
230
|
+
should result_in(ListParser[Apply[:expr], Match[/;/], 1, nil]).at(12)
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
context 'given a generalized list expression' do
|
235
|
+
context 'with a single count' do
|
236
|
+
it 'parses as a ListParser with the count as both lower and upper bounds' do
|
237
|
+
matching(' expr 2, ";" ').as(:expression).
|
238
|
+
should result_in(ListParser[Apply[:expr], Match[/;/], 2, 2]).at(12)
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
context 'with a range' do
|
243
|
+
it 'parses as a ListParser with lower and upper bounds' do
|
244
|
+
matching(' expr 2..4, ";" ').as(:expression).
|
245
|
+
should result_in(ListParser[Apply[:expr], Match[/;/], 2, 4]).at(15)
|
246
|
+
end
|
247
|
+
|
248
|
+
context 'with no upper bound' do
|
249
|
+
it 'parses as a Repeat with no upper bound' do
|
250
|
+
matching(' expr 2.., ";" ').as(:expression).
|
251
|
+
should result_in(ListParser[Apply[:expr], Match[/;/], 2, nil]).at(14)
|
252
|
+
end
|
253
|
+
end
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
170
257
|
context 'given a dispatch-action-attributed expression' do
|
171
258
|
|
172
259
|
context 'given an action with a class name' do
|
@@ -216,7 +303,7 @@ describe Rattler::Grammar::GrammarParser do
|
|
216
303
|
end
|
217
304
|
end
|
218
305
|
|
219
|
-
context 'given just a literal' do
|
306
|
+
context 'given an action with just a literal' do
|
220
307
|
it 'parses as a default node with the literal as the name' do
|
221
308
|
matching(' expr <"expression"> ').as(:expression).
|
222
309
|
should result_in(DispatchAction[Apply[:expr],
|
@@ -228,13 +315,71 @@ describe Rattler::Grammar::GrammarParser do
|
|
228
315
|
end
|
229
316
|
end
|
230
317
|
|
231
|
-
context 'given
|
318
|
+
context 'given a lone dispatch action' do
|
319
|
+
it 'parses as a DispatchAction on ESymbol[]' do
|
320
|
+
matching(' <Foo> ').as(:expression).
|
321
|
+
should result_in(DispatchAction[ESymbol[],
|
322
|
+
{:target => 'Foo', :method => 'parsed'}]).
|
323
|
+
at(6)
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
context 'given a direct-action-attributed expression' do
|
232
328
|
it 'parses as a DirectAction' do
|
233
329
|
matching(' digits {|_| _.to_i} ').as(:expression).
|
234
330
|
should result_in(DirectAction[Apply[:digits], '|_| _.to_i']).at(20)
|
235
331
|
end
|
236
332
|
end
|
237
333
|
|
334
|
+
context 'given a lone direct action' do
|
335
|
+
it 'parses as a DirectAction on ESymbol[]' do
|
336
|
+
matching(' { :foo } ').as(:expression).
|
337
|
+
should result_in(DirectAction[ESymbol[], ':foo']).at(9)
|
338
|
+
end
|
339
|
+
end
|
340
|
+
|
341
|
+
context 'given a side-effect-attributed expression' do
|
342
|
+
it 'parses as a SideEffect' do
|
343
|
+
matching(' digits ~{|_| @i = _.to_i} ').as(:expression).
|
344
|
+
should result_in(SideEffect[Apply[:digits], '|_| @i = _.to_i']).at(26)
|
345
|
+
end
|
346
|
+
end
|
347
|
+
|
348
|
+
context 'given a lone side effect' do
|
349
|
+
it 'parses as a SideEffect on ESymbol[]' do
|
350
|
+
matching(' ~{ @i = :foo } ').as(:expression).
|
351
|
+
should result_in(SideEffect[ESymbol[], '@i = :foo']).at(15)
|
352
|
+
end
|
353
|
+
end
|
354
|
+
|
355
|
+
context 'given a positive semantic-predicate-attributed expression' do
|
356
|
+
it 'parses as a SemanticAssert' do
|
357
|
+
matching(' digits &{|_| _.to_i} ').as(:expression).
|
358
|
+
should result_in(SemanticAssert[Apply[:digits], '|_| _.to_i']).at(21)
|
359
|
+
end
|
360
|
+
end
|
361
|
+
|
362
|
+
context 'given a lone positive semantic predicate' do
|
363
|
+
it 'parses as a SemanticAssert on ESymbol[]' do
|
364
|
+
matching(' &{ @foo } ').as(:expression).
|
365
|
+
should result_in(SemanticAssert[ESymbol[], '@foo']).at(10)
|
366
|
+
end
|
367
|
+
end
|
368
|
+
|
369
|
+
context 'given a negative semantic-predicate-attributed expression' do
|
370
|
+
it 'parses as a SemanticDisallow' do
|
371
|
+
matching(' digits !{|_| _.to_i} ').as(:expression).
|
372
|
+
should result_in(SemanticDisallow[Apply[:digits], '|_| _.to_i']).at(21)
|
373
|
+
end
|
374
|
+
end
|
375
|
+
|
376
|
+
context 'given a lone negative semantic predicate' do
|
377
|
+
it 'parses as a SemanticDisallow on ESymbol[]' do
|
378
|
+
matching(' !{ @foo } ').as(:expression).
|
379
|
+
should result_in(SemanticDisallow[ESymbol[], '@foo']).at(10)
|
380
|
+
end
|
381
|
+
end
|
382
|
+
|
238
383
|
context 'given a sequence expression' do
|
239
384
|
it 'parses as a Sequence' do
|
240
385
|
matching(' name "=" value ').as(:expression).
|
@@ -253,17 +398,163 @@ describe Rattler::Grammar::GrammarParser do
|
|
253
398
|
end
|
254
399
|
end
|
255
400
|
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
401
|
+
context 'given a dispatch-attributed sequence expression' do
|
402
|
+
it 'parses as a DispatchAction with a nested Sequence' do
|
403
|
+
matching(' name "=" value <Assign>').as(:expression).
|
404
|
+
should result_in(DispatchAction[
|
405
|
+
Sequence[Apply[:name], Match[%r{=}], Apply[:value]],
|
406
|
+
{:target => 'Assign', :method => 'parsed'}
|
407
|
+
]).at(24)
|
408
|
+
end
|
409
|
+
end
|
410
|
+
|
411
|
+
context 'given a multiple-dispatch-attributed expression' do
|
412
|
+
it 'parses as nested DispatchActions' do
|
413
|
+
matching(' digits <Int> <Foo> ').as(:expression).
|
414
|
+
should result_in(DispatchAction[
|
415
|
+
DispatchAction[Apply[:digits], {:target => 'Int', :method => 'parsed'}],
|
416
|
+
{:target => 'Foo', :method => 'parsed'}
|
417
|
+
]).at(19)
|
418
|
+
end
|
419
|
+
end
|
420
|
+
|
421
|
+
context 'given consecutive dispatch-attributed expressions' do
|
422
|
+
it 'parses as nested DispatchActions' do
|
423
|
+
matching(' digits <Int> foo <Foo> ').as(:expression).
|
424
|
+
should result_in(DispatchAction[
|
425
|
+
Sequence[
|
426
|
+
DispatchAction[Apply[:digits], {:target => 'Int', :method => 'parsed'}],
|
427
|
+
Apply[:foo]
|
428
|
+
],
|
429
|
+
{:target => 'Foo', :method => 'parsed'}
|
430
|
+
]).at(23)
|
431
|
+
end
|
432
|
+
end
|
433
|
+
|
434
|
+
context 'given a direct-attributed sequence expression' do
|
435
|
+
it 'parses as a DirectAction with a nested Sequence' do
|
436
|
+
matching(' name "=" value {|_| _.size }').as(:expression).
|
437
|
+
should result_in(DirectAction[
|
438
|
+
Sequence[Apply[:name], Match[%r{=}], Apply[:value]],
|
439
|
+
'|_| _.size'
|
440
|
+
]).at(29)
|
441
|
+
end
|
442
|
+
end
|
443
|
+
|
444
|
+
context 'given a multiple-direct-attirbuted expression' do
|
445
|
+
it 'parses as nested DirectActions' do
|
446
|
+
matching(' digits {|_| _.to_i } {|_| _ * 2 } ').as(:expression).
|
447
|
+
should result_in(DirectAction[
|
448
|
+
DirectAction[Apply[:digits], '|_| _.to_i'],
|
449
|
+
'|_| _ * 2'
|
450
|
+
]).at(34)
|
451
|
+
end
|
452
|
+
end
|
453
|
+
|
454
|
+
context 'given consecutive direct-attributed expressions' do
|
455
|
+
it 'parses as nested DirectActions' do
|
456
|
+
matching(' digits {|_| _.to_i } foo {|_| _ * 2 } ').as(:expression).
|
457
|
+
should result_in(DirectAction[
|
458
|
+
Sequence[
|
459
|
+
DirectAction[Apply[:digits], '|_| _.to_i'],
|
460
|
+
Apply[:foo]
|
461
|
+
],
|
462
|
+
'|_| _ * 2'
|
463
|
+
]).at(38)
|
464
|
+
end
|
465
|
+
end
|
466
|
+
|
467
|
+
context 'given a side-effect-attributed sequence expression' do
|
468
|
+
it 'parses as a SideEffect with a nested Sequence' do
|
469
|
+
matching(' name "=" value ~{|_| @n = _.size }').as(:expression).
|
470
|
+
should result_in(SideEffect[
|
471
|
+
Sequence[Apply[:name], Match[%r{=}], Apply[:value]],
|
472
|
+
'|_| @n = _.size'
|
473
|
+
]).at(35)
|
474
|
+
end
|
475
|
+
end
|
476
|
+
|
477
|
+
context 'given a multiple-effect-attirbuted expression' do
|
478
|
+
it 'parses as nested SideEffects' do
|
479
|
+
matching(' digits ~{|_| @i = _.to_i } ~{|_| @j = _ * 2 } ').as(:expression).
|
480
|
+
should result_in(SideEffect[
|
481
|
+
SideEffect[Apply[:digits], '|_| @i = _.to_i'],
|
482
|
+
'|_| @j = _ * 2'
|
483
|
+
]).at(46)
|
484
|
+
end
|
485
|
+
end
|
486
|
+
|
487
|
+
context 'given consecutive side-effect-attributed expressions' do
|
488
|
+
it 'parses as nested SideEffects' do
|
489
|
+
matching(' digits ~{|_| @i = _.to_i } foo ~{|_| @j = _ * 2 } ').as(:expression).
|
490
|
+
should result_in(SideEffect[
|
491
|
+
Sequence[
|
492
|
+
SideEffect[Apply[:digits], '|_| @i = _.to_i'],
|
493
|
+
Apply[:foo]
|
494
|
+
],
|
495
|
+
'|_| @j = _ * 2'
|
496
|
+
]).at(50)
|
497
|
+
end
|
498
|
+
end
|
499
|
+
|
500
|
+
context 'given a positive predicate-attributed sequence expression' do
|
501
|
+
it 'parses as a SemanticAssert with a nested Sequence' do
|
502
|
+
matching(' digits digits &{|a, b| a.to_i > b.to_i } ').as(:expression).
|
503
|
+
should result_in(SemanticAssert[
|
504
|
+
Sequence[Apply[:digits], Apply[:digits]],
|
505
|
+
'|a, b| a.to_i > b.to_i'
|
506
|
+
]).at(41)
|
507
|
+
end
|
262
508
|
end
|
263
509
|
|
264
|
-
|
265
|
-
|
266
|
-
|
510
|
+
context 'given a multiple-predicate-attirbuted expression' do
|
511
|
+
it 'parses as nested SemanticAsserts' do
|
512
|
+
matching(' digits &{|_| _.to_i > 1 } &{|_| _.to_i < 7 } ').as(:expression).
|
513
|
+
should result_in(SemanticAssert[
|
514
|
+
SemanticAssert[Apply[:digits], '|_| _.to_i > 1'],
|
515
|
+
'|_| _.to_i < 7'
|
516
|
+
]).at(45)
|
517
|
+
end
|
518
|
+
end
|
519
|
+
|
520
|
+
context 'given consecutive predicate-attributed expressions' do
|
521
|
+
it 'parses as nested SemanticAsserts' do
|
522
|
+
matching(' digits &{|_| _.to_i > 1 } foo &{|_| _.empty? } ').as(:expression).
|
523
|
+
should result_in(SemanticAssert[
|
524
|
+
Sequence[
|
525
|
+
SemanticAssert[Apply[:digits], '|_| _.to_i > 1'],
|
526
|
+
Apply[:foo]
|
527
|
+
],
|
528
|
+
'|_| _.empty?'
|
529
|
+
]).at(47)
|
530
|
+
end
|
531
|
+
end
|
532
|
+
|
533
|
+
context 'given a negative predicate-attributed sequence expression' do
|
534
|
+
it 'parses as a SemanticAssert with a nested Sequence' do
|
535
|
+
matching(' digits digits !{|a, b| a.to_i > b.to_i } ').as(:expression).
|
536
|
+
should result_in(SemanticDisallow[
|
537
|
+
Sequence[Apply[:digits], Apply[:digits]],
|
538
|
+
'|a, b| a.to_i > b.to_i'
|
539
|
+
]).at(41)
|
540
|
+
end
|
541
|
+
end
|
542
|
+
|
543
|
+
context 'given an ordered choice expression' do
|
544
|
+
it 'parses as a Choice' do
|
545
|
+
matching(' string / number ').as(:expression).
|
546
|
+
should result_in(Choice[Apply[:string], Apply[:number]]).at(16)
|
547
|
+
end
|
548
|
+
end
|
549
|
+
|
550
|
+
context 'given an ordered choice with sequences' do
|
551
|
+
it 'parses as a Choice of Sequences' do
|
552
|
+
matching(' foo bar / boo far ').as(:expression).
|
553
|
+
should result_in(Choice[
|
554
|
+
Sequence[Apply[:foo], Apply[:bar]],
|
555
|
+
Sequence[Apply[:boo], Apply[:far]]
|
556
|
+
]).at(18)
|
557
|
+
end
|
267
558
|
end
|
268
559
|
|
269
560
|
it 'skips normal whitespace' do
|
@@ -290,18 +581,6 @@ describe Rattler::Grammar::GrammarParser do
|
|
290
581
|
end
|
291
582
|
|
292
583
|
describe '#match(:term)' do
|
293
|
-
it 'recognizes optional terms' do
|
294
|
-
matching(' expr? ').as(:term).should result_in(Optional[Apply[:expr]]).at(6)
|
295
|
-
end
|
296
|
-
|
297
|
-
it 'recognizes zero-or-more terms' do
|
298
|
-
matching(' expr* ').as(:term).should result_in(ZeroOrMore[Apply[:expr]]).at(6)
|
299
|
-
end
|
300
|
-
|
301
|
-
it 'recognizes one-or-more terms' do
|
302
|
-
matching(' expr+ ').as(:term).should result_in(OneOrMore[Apply[:expr]]).at(6)
|
303
|
-
end
|
304
|
-
|
305
584
|
it 'recognizes assert terms' do
|
306
585
|
matching(' &expr ').as(:term).should result_in(Assert[Apply[:expr]]).at(6)
|
307
586
|
end
|
@@ -3,28 +3,39 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
|
3
3
|
describe Assert do
|
4
4
|
include CombinatorParserSpecHelper
|
5
5
|
|
6
|
-
subject { Assert[
|
7
|
-
|
6
|
+
subject { Assert[nested] }
|
7
|
+
|
8
|
+
let(:nested) { Match[/\w+/] }
|
9
|
+
|
8
10
|
describe '#parse' do
|
9
|
-
|
11
|
+
|
10
12
|
context 'when the parser matches' do
|
11
13
|
it 'returns true without advancing' do
|
12
14
|
parsing('abc123 ').should result_in(true).at(0)
|
13
15
|
end
|
14
16
|
end
|
15
|
-
|
17
|
+
|
16
18
|
context 'when the parser fails' do
|
17
19
|
it 'fails' do
|
18
20
|
parsing(' ').should fail
|
19
21
|
end
|
20
22
|
end
|
21
|
-
|
23
|
+
|
22
24
|
end
|
23
|
-
|
25
|
+
|
24
26
|
describe '#capturing?' do
|
25
27
|
it 'is false' do
|
26
28
|
subject.should_not be_capturing
|
27
29
|
end
|
28
30
|
end
|
29
|
-
|
31
|
+
|
32
|
+
describe '#with_ws' do
|
33
|
+
|
34
|
+
let(:ws) { Match[/\s*/] }
|
35
|
+
|
36
|
+
it 'applies #with_ws to the nested parser' do
|
37
|
+
subject.with_ws(ws).should == Assert[Sequence[Skip[ws], nested]]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
30
41
|
end
|
@@ -35,4 +35,13 @@ describe Rattler::Parsers::BackReference do
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
+
describe '#with_ws' do
|
39
|
+
|
40
|
+
let(:ws) { Match[/\s*/] }
|
41
|
+
|
42
|
+
it 'returns a parser that skips whitespace before matching' do
|
43
|
+
subject.with_ws(ws).should == Sequence[Skip[ws], subject]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
38
47
|
end
|
@@ -2,29 +2,31 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
|
2
2
|
|
3
3
|
describe Choice do
|
4
4
|
include CombinatorParserSpecHelper
|
5
|
-
|
5
|
+
|
6
|
+
subject { Choice[*nested] }
|
7
|
+
|
6
8
|
describe '#parse' do
|
7
|
-
|
8
|
-
|
9
|
-
|
9
|
+
|
10
|
+
let(:nested) { [Match[/[[:alpha:]]+/], Match[/[[:digit:]]+/]] }
|
11
|
+
|
10
12
|
context 'when any of the parsers match' do
|
11
13
|
it 'matches the same as the first parser that matches' do
|
12
14
|
parsing('abc123').should result_in('abc').at(3)
|
13
15
|
parsing('123abc').should result_in('123').at(3)
|
14
16
|
end
|
15
17
|
end
|
16
|
-
|
18
|
+
|
17
19
|
context 'when none of the parsers match' do
|
18
20
|
it 'fails' do
|
19
21
|
parsing('==').should fail
|
20
22
|
end
|
21
23
|
end
|
22
|
-
|
24
|
+
|
23
25
|
context 'with no capturing parsers' do
|
24
|
-
|
25
|
-
|
26
|
+
let :nested do
|
27
|
+
[Skip[Match[/[[:alpha:]]+/]], Skip[Match[/[[:digit:]]+/]]]
|
26
28
|
end
|
27
|
-
|
29
|
+
|
28
30
|
context 'when any of the parsers match' do
|
29
31
|
it 'returns true' do
|
30
32
|
parsing('abc123').should result_in(true).at(3)
|
@@ -32,29 +34,42 @@ describe Choice do
|
|
32
34
|
end
|
33
35
|
end
|
34
36
|
end
|
35
|
-
|
37
|
+
|
36
38
|
end
|
37
|
-
|
39
|
+
|
38
40
|
describe '#capturing?' do
|
39
|
-
|
41
|
+
|
40
42
|
context 'with any capturing parsers' do
|
41
|
-
|
42
|
-
|
43
|
-
|
43
|
+
|
44
|
+
let(:nested) { [Skip[Match[/[[:space:]]*/]], Match[/[[:alpha:]]+/]] }
|
45
|
+
|
44
46
|
it 'is true' do
|
45
47
|
subject.should be_capturing
|
46
48
|
end
|
47
49
|
end
|
48
|
-
|
50
|
+
|
49
51
|
context 'with no capturing parsers' do
|
50
|
-
|
51
|
-
|
52
|
-
|
52
|
+
|
53
|
+
let(:nested) { [Skip[Match[/[[:alpha:]]+/]], Skip[Match[/[[:digit:]]+/]]] }
|
54
|
+
|
53
55
|
it 'is false' do
|
54
56
|
subject.should_not be_capturing
|
55
57
|
end
|
56
58
|
end
|
57
|
-
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '#with_ws' do
|
63
|
+
|
64
|
+
let(:ws) { Match[/\s*/] }
|
65
|
+
let(:nested) { [Match[/[[:alpha:]]+/], Match[/[[:digit:]]+/]] }
|
66
|
+
|
67
|
+
it 'applies #with_ws to the nested parsers' do
|
68
|
+
subject.with_ws(ws).should == Choice[
|
69
|
+
Sequence[Skip[ws], nested[0]],
|
70
|
+
Sequence[Skip[ws], nested[1]]
|
71
|
+
]
|
72
|
+
end
|
58
73
|
end
|
59
|
-
|
74
|
+
|
60
75
|
end
|