Class: Packcr::Node::QuantityNode

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeQuantityNode

Returns a new instance of QuantityNode.



6
7
8
9
10
# File 'lib/packcr/node/quantity_node.rb', line 6

def initialize
  super
  self.min = 0
  self.max = 0
end

Instance Attribute Details

#exprObject

Returns the value of attribute expr.



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

def expr
  @expr
end

#maxObject

Returns the value of attribute max.



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

def max
  @max
end

#minObject

Returns the value of attribute min.



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

def min
  @min
end

Instance Method Details

#debug_dump(indent = 0) ⇒ Object



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

def debug_dump(indent = 0)
  $stdout.print "#{" " * indent}Quantity(min:#{min}, max:#{max}) {\n"
  expr.debug_dump(indent + 2)
  $stdout.print "#{" " * indent}}\n"
end

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



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/packcr/node/quantity_node.rb', line 18

def generate_code(gen, onfail, indent, bare)
  if max > 1 || max < 0
    r = nil
    gen.write Packcr.template("node/quantify_many.#{gen.lang}.erb", binding, indent: indent, unwrap: bare)
    if min <= 0
      return Packcr::CODE_REACH__ALWAYS_SUCCEED
    end
    if r == Packcr::CODE_REACH__ALWAYS_FAIL
      return Packcr::CODE_REACH__ALWAYS_FAIL
    end
    return Packcr::CODE_REACH__BOTH
  elsif max == 1
    if min > 0
      return gen.generate_code(expr, onfail, indent, bare)
    else
      gen.write Packcr.template("node/quantify_one.#{gen.lang}.erb", binding, indent: indent, unwrap: bare)
      return Packcr::CODE_REACH__ALWAYS_SUCCEED
    end
  else
    # no code to generate
    return Packcr::CODE_REACH__ALWAYS_SUCCEED
  end
end


50
51
52
# File 'lib/packcr/node/quantity_node.rb', line 50

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

#verify_captures(ctx, capts) ⇒ Object



46
47
48
# File 'lib/packcr/node/quantity_node.rb', line 46

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

#verify_variables(vars) ⇒ Object



42
43
44
# File 'lib/packcr/node/quantity_node.rb', line 42

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