Class: ShellOpts::Ast::Node
- Inherits:
-
Object
- Object
- ShellOpts::Ast::Node
- Defined in:
- lib/shellopts/ast/node.rb
Instance Attribute Summary collapse
-
#grammar ⇒ Object
readonly
The associated Grammar::Node object.
-
#name ⇒ Object
readonly
Name of node (either program, command, or option name).
Instance Method Summary collapse
-
#dump(&block) ⇒ Object
:nocov:.
-
#initialize(grammar, name) ⇒ Node
constructor
Initialize an
Ast::Nodeobject. -
#key ⇒ Object
Key of node.
-
#to_tuple ⇒ Object
Return a name/value pair.
-
#values ⇒ Object
Return either a value (option value), an array of values (command), or nil (option without a value).
Constructor Details
#initialize(grammar, name) ⇒ Node
Initialize an Ast::Node object. grammar is the corresponding grammar object (Grammar::Node) and name is the name of the option or sub-command
16 17 18 |
# File 'lib/shellopts/ast/node.rb', line 16 def initialize(grammar, name) @grammar, @name = grammar, name end |
Instance Attribute Details
#grammar ⇒ Object (readonly)
The associated Grammar::Node object
5 6 7 |
# File 'lib/shellopts/ast/node.rb', line 5 def grammar @grammar end |
#name ⇒ Object (readonly)
Name of node (either program, command, or option name)
11 12 13 |
# File 'lib/shellopts/ast/node.rb', line 11 def name @name end |
Instance Method Details
#dump(&block) ⇒ Object
:nocov:
30 31 32 33 |
# File 'lib/shellopts/ast/node.rb', line 30 def dump(&block) puts key.inspect indent { yield } if block_given? end |
#key ⇒ Object
Key of node. Shorthand for grammar.key
8 |
# File 'lib/shellopts/ast/node.rb', line 8 def key() @grammar.key end |
#to_tuple ⇒ Object
Return a name/value pair
21 22 23 |
# File 'lib/shellopts/ast/node.rb', line 21 def to_tuple [name, values] end |
#values ⇒ Object
Return either a value (option value), an array of values (command), or nil (option without a value). Should be defined in sub-classes
27 |
# File 'lib/shellopts/ast/node.rb', line 27 def values() raise end |