Class: Packcr::Node::CaptureNode

Inherits:
Packcr::Node show all
Defined in:
lib/packcr/node/capture_node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Packcr::Node

#alt, #link_references, #reversible?, #seq, #sequence?, #setup, #verify_variables

Constructor Details

#initialize(expr = nil) ⇒ CaptureNode

Returns a new instance of CaptureNode.



6
7
8
# File 'lib/packcr/node/capture_node.rb', line 6

def initialize(expr = nil)
  @expr = expr
end

Instance Attribute Details

#exprObject

Returns the value of attribute expr.



4
5
6
# File 'lib/packcr/node/capture_node.rb', line 4

def expr
  @expr
end

#indexObject

Returns the value of attribute index.



4
5
6
# File 'lib/packcr/node/capture_node.rb', line 4

def index
  @index
end

Instance Method Details

#debug_dump(indent = 0) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/packcr/node/capture_node.rb', line 10

def debug_dump(indent = 0)
  $stdout.print "#{" " * indent}Capture(index:"
  Packcr.dump_integer_value(index)
  $stdout.print ") {\n"
  expr.debug_dump(indent + 2)
  $stdout.print "#{" " * indent}}\n"
end

#generate_code(gen, onfail, indent, bare, oncut: nil) ⇒ Object



18
19
20
# File 'lib/packcr/node/capture_node.rb', line 18

def generate_code(gen, onfail, indent, bare, oncut: nil)
  gen.write Packcr.template("node/capture.#{gen.lang}.erb", binding, indent: indent)
end

#nodesObject



31
32
33
# File 'lib/packcr/node/capture_node.rb', line 31

def nodes
  [expr]
end

#reachabilityObject



22
23
24
# File 'lib/packcr/node/capture_node.rb', line 22

def reachability
  expr.reachability
end

#setup_rule(rule) ⇒ Object



35
36
37
38
# File 'lib/packcr/node/capture_node.rb', line 35

def setup_rule(rule)
  @index = rule.capts.length
  rule.capts << self
end

#to_hObject



40
41
42
43
44
45
# File 'lib/packcr/node/capture_node.rb', line 40

def to_h
  {
    type: :capture,
    expr: expr&.to_h,
  }
end

#verify_captures(ctx, capts) ⇒ Object



26
27
28
29
# File 'lib/packcr/node/capture_node.rb', line 26

def verify_captures(ctx, capts)
  super
  capts.push(self)
end