Class: Packcr::Node::QuantityNode
- Inherits:
-
Packcr::Node
- Object
- Packcr::Node
- Packcr::Node::QuantityNode
- Defined in:
- lib/packcr/node/quantity_node.rb
Instance Attribute Summary collapse
-
#expr ⇒ Object
Returns the value of attribute expr.
-
#max ⇒ Object
Returns the value of attribute max.
-
#min ⇒ Object
Returns the value of attribute min.
Instance Method Summary collapse
- #debug_dump(indent = 0) ⇒ Object
- #generate_code(gen, onfail, indent, bare) ⇒ Object
-
#initialize ⇒ QuantityNode
constructor
A new instance of QuantityNode.
- #link_references(ctx) ⇒ Object
- #verify_captures(ctx, capts) ⇒ Object
- #verify_variables(vars) ⇒ Object
Constructor Details
#initialize ⇒ QuantityNode
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
#expr ⇒ Object
Returns the value of attribute expr.
4 5 6 |
# File 'lib/packcr/node/quantity_node.rb', line 4 def expr @expr end |
#max ⇒ Object
Returns the value of attribute max.
4 5 6 |
# File 'lib/packcr/node/quantity_node.rb', line 4 def max @max end |
#min ⇒ Object
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, ) if max > 1 || max < 0 r = nil gen.write Packcr.template("node/quantify_many.#{gen.lang}.erb", binding, indent: indent, unwrap: ) 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, ) else gen.write Packcr.template("node/quantify_one.#{gen.lang}.erb", binding, indent: indent, unwrap: ) return Packcr::CODE_REACH__ALWAYS_SUCCEED end else # no code to generate return Packcr::CODE_REACH__ALWAYS_SUCCEED end end |
#link_references(ctx) ⇒ Object
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 |