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, #seq

Constructor Details

#initialize(expr = nil) ⇒ 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) ⇒ Object



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

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


33
34
35
# File 'lib/packcr/node/capture_node.rb', line 33

def link_references(ctx)
  expr.link_references(ctx)
end

#nodesObject



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

def nodes
  [expr]
end

#setup_rule(rule) ⇒ Object



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

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

#verify_captures(ctx, capts) ⇒ Object



28
29
30
31
# File 'lib/packcr/node/capture_node.rb', line 28

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

#verify_variables(vars) ⇒ Object



24
25
26
# File 'lib/packcr/node/capture_node.rb', line 24

def verify_variables(vars)
  expr.verify_variables(vars)
end