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

- old
+ new

@@ -1,18 +1,25 @@ class Code class Parser - class Code < Parslet::Parser - rule(:statement) { ::Code::Parser::Statement.new } + class Code < Language + 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?(&block) + whitespace.maybe(&block) + end - rule(:present) do - (whitespace?.ignore >> statement >> whitespace?.ignore).repeat(1) + def statement + ::Code::Parser::Statement end - rule(:code) { present | whitespace?.ignore } - root(:code) + + def present + (whitespace? << statement << whitespace?).repeat(1) + end + + def root + present | whitespace?.then { [] } + end end end end