Class: Packcr::Node::ExpandNode

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Packcr::Node

#alt, #nodes, #seq, #setup_rule

Constructor Details

#initialize(index = nil) ⇒ ExpandNode

Returns a new instance of ExpandNode.



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

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

Instance Attribute Details

#colObject

Returns the value of attribute col.



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

def col
  @col
end

#indexObject

Returns the value of attribute index.



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

def index
  @index
end

#lineObject

Returns the value of attribute line.



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

def line
  @line
end

Instance Method Details

#debug_dump(indent = 0) ⇒ Object



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

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

#generate_code(gen, onfail, indent, bare) ⇒ Object



16
17
18
19
# File 'lib/packcr/node/expand_node.rb', line 16

def generate_code(gen, onfail, indent, bare)
  gen.write Packcr.template("node/expand.#{gen.lang}.erb", binding, indent: indent, unwrap: bare)
  return Packcr::CODE_REACH__BOTH
end


36
37
# File 'lib/packcr/node/expand_node.rb', line 36

def link_references(ctx)
end

#verify_captures(ctx, capts) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/packcr/node/expand_node.rb', line 24

def verify_captures(ctx, capts)
  found = capts.any? do |capt|
    unless capt.is_a?(Packcr::Node::CaptureNode)
      raise "unexpected capture: #{capt.class}"
    end
    index == capt.index
  end
  if !found && index != nil
    ctx.error line + 1, col + 1, "Capture #{index + 1} not available at this position"
  end
end

#verify_variables(vars) ⇒ Object



21
22
# File 'lib/packcr/node/expand_node.rb', line 21

def verify_variables(vars)
end