Sha256: 0dbb86cb21788f2043226f3875aeb561338257e8e443e5f754c0af6a4e5270e1

Contents?: true

Size: 735 Bytes

Versions: 12

Compression:

Stored size: 735 Bytes

Contents

class Code
  class Parser
    class Addition < Parslet::Parser
      rule(:multiplication) { ::Code::Parser::Multiplication.new }

      rule(:plus) { str("+") }
      rule(:minus) { str("-") }

      rule(:operator) { plus | minus }

      rule(:space) { str(" ") }
      rule(:newline) { str("\n") }
      rule(:whitespace) { (space | newline).repeat(1) }
      rule(:whitespace?) { whitespace.maybe }

      rule(:addition) do
        (
          multiplication.as(:first) >>
            (
              whitespace? >> operator.as(:operator) >> whitespace? >>
                multiplication.as(:statement)
            ).repeat(1).as(:rest)
        ).as(:addition) | multiplication
      end

      root(:addition)
    end
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
template-ruby-0.4.0 lib/code/parser/addition.rb
code-ruby-0.4.0 lib/code/parser/addition.rb
template-ruby-0.3.1 lib/code/parser/addition.rb
code-ruby-0.3.1 lib/code/parser/addition.rb
template-ruby-0.3.0 lib/code/parser/addition.rb
code-ruby-0.3.0 lib/code/parser/addition.rb
code-ruby-0.2.4 lib/code/parser/addition.rb
template-ruby-0.2.4 lib/code/parser/addition.rb
template-ruby-0.2.3 lib/code/parser/addition.rb
template-ruby-0.2.2 lib/code/parser/addition.rb
template-ruby-0.2.1 lib/code/parser/addition.rb
template-ruby-0.2.0 lib/code/parser/addition.rb