Sha256: 44d6789a8cbb74bbf7de42e08443e8e14101a0f6122fab53f4aaaa4ed6935490

Contents?: true

Size: 1.42 KB

Versions: 2

Compression:

Stored size: 1.42 KB

Contents

class Code
  class Parser
    class Equal < ::Code::Parser
      def parse
        previous_cursor = cursor

        left = parse_left

        comments_before = parse_comments

        if left && operator = match(EQUALS)
          comments_after = parse_comments

          right = parse_subclass(::Code::Parser::Equal)

          if right
            {
              equal: {
                left: left,
                right: right,
                comments_before: comments_before,
                comments_after: comments_after
              }.compact
            }
          else
            @cursor = previous_cursor
            buffer!
            parse_next
          end
        else
          @cursor = previous_cursor
          buffer!
          parse_next
        end
      end

      private

      def parse_next
        parse_subclass(::Code::Parser::Rescue)
      end

      def parse_left
        left = parse_subclass(::Code::Parser::Name)
        return unless left

        previous_cursor = cursor
        comments_before = parse_comments

        if match(DOT) || match(COLON + COLON)
          right = parse_subclass(::Code::Parser::Name)
          if right
            { left: left, right: right }
          else
            @cursor = previous_cursor
            buffer!
            return
          end
        else
          @cursor = previous_cursor
          buffer!
          left
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
template-ruby-parser-0.1.5 lib/code/parser/equal.rb
code-ruby-parser-0.1.5 lib/code/parser/equal.rb