Sha256: de25d02291a0ca995b21f4935d52ebf4ca2c4245bf8bf52d9d90a073ec4a54b5

Contents?: true

Size: 983 Bytes

Versions: 4

Compression:

Stored size: 983 Bytes

Contents

class Code
  class Parser
    class Operation < ::Code::Parser
      def initialize(input, operators:, subclass:, **kargs)
        super(input, **kargs)

        @operators = operators
        @subclass = subclass
      end

      def parse
        previous_cursor = cursor
        left = parse_subclass(subclass)
        right = []
        previous_cursor = cursor
        comments = parse_comments

        while operator = match(operators)
          comments = parse_comments
          statement = parse_subclass(subclass)
          right << {
            comments: comments,
            statement: statement,
            operator: operator
          }.compact
        end

        if right.empty?
          @cursor = previous_cursor
          buffer!
          left
        else
          {
            operation: { left: left, comments: comments, right: right }.compact
          }
        end
      end

      private

      attr_reader :operators, :subclass
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

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