Skip to content

Commit

Permalink
Removed explicit-type-choice
Browse files Browse the repository at this point in the history
  • Loading branch information
Pete Cordell committed Jan 31, 2018
1 parent 5511a1a commit 2294e66
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 33 deletions.
6 changes: 2 additions & 4 deletions abnf/jcr-abnf.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ member-name-spec = regex / q-string
type-rule = value-rule / type-choice / target-rule-name
type-choice = annotations "(" type-choice-items
*( choice-combiner type-choice-items ) ")"
explicit-type-choice = type-designator type-choice
type-choice-items = *sp-cmt ( type-choice / type-rule ) *sp-cmt

annotations = *( "@{" *sp-cmt annotation-set *sp-cmt "}"
Expand Down Expand Up @@ -145,15 +144,14 @@ array-rule = annotations "[" *sp-cmt [ array-items *sp-cmt ] "]"
array-items = array-item [ 1*( sequence-combiner array-item ) /
1*( choice-combiner array-item ) ]
array-item = array-item-types *sp-cmt [ repetition *sp-cmt ]
array-item-types = array-group / type-rule / explicit-type-choice
array-item-types = array-group / type-rule
array-group = annotations "(" *sp-cmt [ array-items *sp-cmt ] ")"

group-rule = annotations "(" *sp-cmt [ group-items *sp-cmt ] ")"
group-items = group-item [ 1*( sequence-combiner group-item ) /
1*( choice-combiner group-item ) ]
group-item = group-item-types *sp-cmt [ repetition *sp-cmt ]
group-item-types = group-group / member-rule /
type-rule / explicit-type-choice
group-item-types = group-group / member-rule / type-rule
group-group = group-rule

sequence-combiner = "," *sp-cmt
Expand Down
11 changes: 4 additions & 7 deletions lib/jcr/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,6 @@ class Parser < Parslet::Parser
rule(:type_choice) { ( annotations >> str('(') >> type_choice_items >> ( choice_combiner >> type_choice_items ).repeat >> str(')') ).as(:group_rule) }
#! type_choice = annotations "(" type_choice_items
#! *( choice_combiner type_choice_items ) ")"
rule(:explicit_type_choice) { type_designator >> type_choice }
#! explicit_type_choice = type_designator type_choice
rule(:type_choice_items) { spcCmnt? >> (type_choice | type_rule) >> spcCmnt? }
#! type_choice_items = spcCmnt? ( type_choice / type_rule ) spcCmnt?
#!
Expand Down Expand Up @@ -332,8 +330,8 @@ class Parser < Parslet::Parser
#! 1*( choice_combiner array_item ) ]
rule(:array_item) { array_item_types >> spcCmnt? >> ( repetition >> spcCmnt? ).maybe }
#! array_item = array_item_types spcCmnt? [ repetition spcCmnt? ]
rule(:array_item_types) { array_group | type_rule | explicit_type_choice }
#! array_item_types = array_group / type_rule / explicit_type_choice
rule(:array_item_types) { array_group | type_rule }
#! array_item_types = array_group / type_rule
rule(:array_group) { ( annotations >> str('(') >> spcCmnt? >> array_items.maybe >> spcCmnt? >> str(')') ).as(:group_rule) }
#! array_group = annotations "(" spcCmnt? [ array_items spcCmnt? ] ")"
#!
Expand All @@ -346,9 +344,8 @@ class Parser < Parslet::Parser
#! 1*( choice_combiner group_item ) ]
rule(:group_item) { group_item_types >> spcCmnt? >> ( repetition >> spcCmnt? ).maybe }
#! group_item = group_item_types spcCmnt? [ repetition spcCmnt? ]
rule(:group_item_types) { group_group | member_rule | type_rule | explicit_type_choice }
#! group_item_types = group_group / member_rule /
#! type_rule / explicit_type_choice
rule(:group_item_types) { group_group | member_rule | type_rule }
#! group_item_types = group_group / member_rule / type_rule
rule(:group_group) { group_rule }
#! group_group = group_rule
#!
Expand Down
22 changes: 0 additions & 22 deletions spec/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -893,28 +893,6 @@
expect(tree[0][:rule][:array_rule][:group_rule][1][:target_rule_name][:rule_name]).to eq("my_rule2")
end

it 'should parse an array rule with an explicit type choice' do
tree = JCR.parse( '$trule = :[ :($my_rule1| $my_rule2 )+]' )
expect(tree[0][:rule][:rule_name]).to eq("trule")
expect(tree[0][:rule][:array_rule][:group_rule][0][:target_rule_name][:rule_name]).to eq("my_rule1")
expect(tree[0][:rule][:array_rule][:group_rule][1][:target_rule_name][:rule_name]).to eq("my_rule2")
end

it 'should parse an array rule with an explicit type choice' do
tree = JCR.parse( '$trule = :[ type ($my_rule1| $my_rule2 )+]' )
expect(tree[0][:rule][:rule_name]).to eq("trule")
expect(tree[0][:rule][:array_rule][:group_rule][0][:target_rule_name][:rule_name]).to eq("my_rule1")
expect(tree[0][:rule][:array_rule][:group_rule][1][:target_rule_name][:rule_name]).to eq("my_rule2")
end

it 'should NOT parse an array rule with an invalid explicit type choice' do
expect{ tree = JCR.parse( '$trule = :[ :($my_rule1, $my_rule2 )+]' ) }.to raise_error Parslet::ParseFailed
end

it 'should NOT parse an array rule with an invalid explicit type choice' do
expect{ tree = JCR.parse( '$trule = :[ type ($my_rule1, $my_rule2 )+]' ) }.to raise_error Parslet::ParseFailed
end

it 'should parse an array rule with a rulename and a group rule' do
tree = JCR.parse( '$trule = :[ $my_rule1 | ( integer | { $my_rule2 } ) ]' )
expect(tree[0][:rule][:rule_name]).to eq("trule")
Expand Down

0 comments on commit 2294e66

Please sign in to comment.