Class: Language::Atom::And

Inherits:
Language::Atom show all
Defined in:
lib/language/atom/and.rb

Instance Method Summary collapse

Methods inherited from Language::Atom

#<<, #>>, #absent, #aka, #any, #ignore, #inspect, #maybe, #repeat, #str, #then, #|

Constructor Details

#initialize(left:, right:) ⇒ And

Returns a new instance of And.



6
7
8
9
# File 'lib/language/atom/and.rb', line 6

def initialize(left:, right:)
  @left = left
  @right = right
end

Instance Method Details

#parse(parser) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/language/atom/and.rb', line 11

def parse(parser)
  @left.parse(parser)
  right_clone =
    Parser.new(
      root: self,
      input: parser.input,
      cursor: parser.cursor,
      buffer: parser.buffer
    )
  @right.parse(right_clone)
  parser.cursor = right_clone.cursor
  parser.buffer = right_clone.buffer

  parser.output.merge(right_clone.output)
end

#to_sObject



27
28
29
# File 'lib/language/atom/and.rb', line 27

def to_s
  "#{@left} >> #{@right}".to_s
end