Sha256: a50a03387c2f03583ac0cff014538e8edeff4946af438052934b040e70067dee

Contents?: true

Size: 1.08 KB

Versions: 6

Compression:

Stored size: 1.08 KB

Contents

class Code
  class Parser
    class Dictionnary < ::Code::Parser
      def parse
        if match(OPENING_CURLY_BRACKET)
          dictionnary = []

          comments = parse_comments

          dictionnary << parse_key_value

          dictionnary << parse_key_value while match(COMMA) && !end_of_input?

          match(CLOSING_CURLY_BRACKET)

          { dictionnary: dictionnary.compact, comments: comments }
        else
          parse_subclass(::Code::Parser::List)
        end
      end

      def parse_key_value
        comments_before = parse_comments

        key = parse_subclass(::Code::Parser::Statement)

        comments_after = parse_comments

        return unless key

        if match(COLON) || match(EQUAL + GREATER)
          {
            key: key,
            value: parse_code,
            comments_before: comments_before,
            comments_after: comments_after
          }.compact
        else
          {
            key: key,
            comments_before: comments_before,
            comments_after: comments_after
          }.compact
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
template-ruby-parser-0.1.2 lib/code/parser/dictionnary.rb
code-ruby-parser-0.1.2 lib/code/parser/dictionnary.rb
template-ruby-parser-0.1.1 lib/code/parser/dictionnary.rb
code-ruby-parser-0.1.1 lib/code/parser/dictionnary.rb
template-ruby-parser-0.1.0 lib/code/parser/dictionnary.rb
code-ruby-parser-0.1.0 lib/code/parser/dictionnary.rb