lib/code/parser/list.rb in code-ruby-0.4.0 vs lib/code/parser/list.rb in code-ruby-0.5.0

- old
+ new

@@ -1,29 +1,42 @@ class Code class Parser - class List < Parslet::Parser - rule(:string) { ::Code::Parser::String.new } - rule(:code) { ::Code::Parser::Code.new.present } + class List < Language + def code + ::Code::Parser::Code.new.present + end - rule(:opening_square_bracket) { str("[") } - rule(:closing_square_bracket) { str("]") } - rule(:comma) { str(",") } + def whitespace + ::Code::Parser::Whitespace + end - rule(:space) { str(" ") } - rule(:newline) { str("\n") } - rule(:whitespace) { (space | newline).repeat(1) } - rule(:whitespace?) { whitespace.maybe } + def whitespace? + whitespace.maybe + end - rule(:list) do - ( - opening_square_bracket.ignore >> whitespace?.ignore >> - code.as(:code).repeat(0, 1) >> - (whitespace? >> comma >> whitespace? >> code.as(:code)).repeat >> - whitespace?.ignore >> comma.maybe.ignore >> whitespace?.ignore >> - closing_square_bracket.ignore - ).as(:list) | string + def opening_square_bracket + str("[") end - root(:list) + def closing_square_bracket + str("]") + end + + def comma + str(",") + end + + def element + code + end + + def root + ( + opening_square_bracket.ignore << whitespace? << + element.repeat(0, 1) << + (whitespace? << comma << whitespace? << element).repeat << + (whitespace? << closing_square_bracket.ignore).maybe + ).aka(:list) | ::Code::Parser::String + end end end end