Sha256: 454bf3f4dca25b48dac296e6decff428825c5d19e3db4ce8a1c877d07643e745

Contents?: true

Size: 1.25 KB

Versions: 7

Compression:

Stored size: 1.25 KB

Contents

class Code
  class Parser
    class Dictionnary < Parslet::Parser
      rule(:list) { ::Code::Parser::List.new }
      rule(:code) { ::Code::Parser::Code.new }
      rule(:string) { ::Code::Parser::String.new }

      rule(:opening_curly_bracket) { str("{") }
      rule(:closing_curly_bracket) { str("}") }
      rule(:colon) { str(":") }
      rule(:equal) { str("=") }
      rule(:right_caret) { str(">") }
      rule(:comma) { str(",") }

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

      rule(:key_value) do
        (string.as(:key) >> colon >> whitespace? >> code.as(:value)) |
          (
            code.as(:key) >> whitespace? >> equal >> right_caret >>
              whitespace? >> code.as(:value)
          )
      end

      rule(:dictionnary) do
        (
          opening_curly_bracket.ignore >> whitespace?.ignore >>
            key_value.repeat(0, 1) >>
            (whitespace? >> comma >> whitespace? >> key_value).repeat >>
            whitespace?.ignore >> comma.maybe.ignore >> whitespace?.ignore >>
            closing_curly_bracket.ignore
        ).as(:dictionnary) | list
      end

      root(:dictionnary)
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

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