lib/citrus/file.rb in citrus-1.6.0 vs lib/citrus/file.rb in citrus-1.7.0

- old
+ new

@@ -73,59 +73,59 @@ end } end rule :sequence do - zero_or_more(:prefix) { + zero_or_more(:appendix) { def values matches.map {|m| m.value } end def value matches.length > 1 ? Sequence.new(values) : values[0] end } end - rule :prefix do - all(zero_or_one(:qualifier), :appendix) { + rule :appendix do + all(:prefix, zero_or_one(:extension)) { def value - rule = appendix.value - qualifier = matches[0].first - rule = qualifier.wrap(rule) if qualifier + rule = prefix.value + extension = matches[1].first + rule.extension = extension.value if extension rule end } end - rule :appendix do - all(:suffix, zero_or_one(:extension)) { + rule :prefix do + all(zero_or_one(:predicate), :suffix) { def value rule = suffix.value - extension = matches[1].first - extension.apply(rule) if extension + predicate = matches[0].first + rule = predicate.wrap(rule) if predicate rule end } end rule :suffix do - all(:primary, zero_or_one(:quantifier)) { + all(:primary, zero_or_one(:repeat)) { def value rule = primary.value - quantifier = matches[1].first - rule = quantifier.wrap(rule) if quantifier + repeat = matches[1].first + rule = repeat.wrap(rule) if repeat rule end } end rule :primary do - any(:super, :alias, :rule_body_paren, :terminal) + any(:super, :alias, :grouping, :terminal) end - rule :rule_body_paren do + rule :grouping do all(:lparen, :rule_body, :rparen) { def value rule_body.value end } @@ -155,12 +155,14 @@ rule_name.value end } end + # Rule names may contain letters, numbers, underscores, and dashes. They + # MUST start with a letter. rule :rule_name do - all(/[a-zA-Z_-]+/, :space) { + all(/[a-zA-Z][a-zA-Z0-9_-]*/, :space) { def value first.text end } end @@ -182,11 +184,11 @@ end rule :terminal do any(:quoted_string, :character_class, :anything_symbol, :regular_expression) { def value - Rule.create(super) + Rule.new(super) end } end rule :quoted_string do @@ -219,11 +221,11 @@ eval(first.text) end } end - rule :qualifier do + rule :predicate do any(:and, :not, :label) end rule :and do all('&', :space) { @@ -252,15 +254,11 @@ end } end rule :extension do - any(:tag, :block) { - def apply(rule) - rule.extension = value - end - } + any(:tag, :block) end rule :tag do all(:lt, :module_name, :gt) { def value @@ -275,12 +273,12 @@ eval('Proc.new ' + text) end } end - rule :quantifier do - any(:question, :plus, :repeat) { + rule :repeat do + any(:question, :plus, :star_quantity) { def wrap(rule) Repeat.new(min, max, rule) end } end @@ -297,10 +295,10 @@ def min; 1 end def max; Infinity end } end - rule :repeat do + rule :star_quantity do all(/[0-9]*/, '*', /[0-9]*/, :space) { def min matches[0] == '' ? 0 : matches[0].text.to_i end