Sha256: c60fb79991fe9a9b223ba335f86770129bbf60c29a0705c35ee2f8782e63dbe8

Contents?: true

Size: 1.03 KB

Versions: 15

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

class Language
  class Atom
    class Or < Atom
      def initialize(left:, right:)
        @left = left
        @right = right
      end

      def parse(parser)
        left_clone =
          Parser.new(
            root: self,
            input: parser.input,
            cursor: parser.cursor,
            buffer: parser.buffer
          )

        right_clone =
          Parser.new(
            root: self,
            input: parser.input,
            cursor: parser.cursor,
            buffer: parser.buffer
          )

        begin
          @left.parse(left_clone)
          parser.cursor = left_clone.cursor
          parser.buffer = left_clone.buffer
          parser.output.merge(left_clone.output)
        rescue Parser::Interuption
          @right.parse(right_clone)
          parser.cursor = right_clone.cursor
          parser.buffer = right_clone.buffer
          parser.output.merge(right_clone.output)
        end
      end

      def to_s
        "((#{@left}) | (#{@right}))"
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
language-ruby-1.1.2 lib/language/atom/or.rb
language-ruby-1.1.0 lib/language/atom/or.rb
language-ruby-1.0.1 lib/language/atom/or.rb
language-ruby-1.0.0 lib/language/atom/or.rb
language-ruby-0.9.3 lib/language/atom/or.rb
language-ruby-0.9.2 lib/language/atom/or.rb
language-ruby-0.9.0 lib/language/atom/or.rb
language-ruby-0.8.4 lib/language/atom/or.rb
language-ruby-0.8.3 lib/language/atom/or.rb
language-ruby-0.8.2 lib/language/atom/or.rb
language-ruby-0.8.1 lib/language/atom/or.rb
language-ruby-0.8.0 lib/language/atom/or.rb
language-ruby-0.7.0 lib/language/atom/or.rb
language-ruby-0.6.2 lib/language/atom/or.rb
language-ruby-0.6.1 lib/language/atom/or.rb