Sha256: 96ff4a1292fc6fe9895036b6c31f8025b2670fbe38a3cf5992ee121be99c6077

Contents?: true

Size: 658 Bytes

Versions: 6

Compression:

Stored size: 658 Bytes

Contents

class Code
  class Parser
    class Ternary < Parslet::Parser
      rule(:range) { ::Code::Parser::Range.new }

      rule(:question_mark) { str("?") }
      rule(:colon) { str(":") }

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

      rule(:ternary) do
        (
          range.as(:left) >> whitespace >> question_mark >> whitespace? >>
            ternary.as(:middle) >>
            (whitespace? >> colon >> whitespace? >> ternary.as(:right)).maybe
        ).as(:ternary) | range
      end

      root(:ternary)
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
code-ruby-0.2.4 lib/code/parser/ternary.rb
template-ruby-0.2.4 lib/code/parser/ternary.rb
template-ruby-0.2.3 lib/code/parser/ternary.rb
template-ruby-0.2.2 lib/code/parser/ternary.rb
template-ruby-0.2.1 lib/code/parser/ternary.rb
template-ruby-0.2.0 lib/code/parser/ternary.rb