Class: ShellOpts::Ast::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/shellopts/ast/node.rb

Direct Known Subclasses

Command, Option

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#grammarObject (readonly)

The associated Grammar::Node object



5
6
7
# File 'lib/shellopts/ast/node.rb', line 5

def grammar
  @grammar
end

#nameObject (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

#keyObject

Key of node. Shorthand for grammar.key



8
# File 'lib/shellopts/ast/node.rb', line 8

def key() @grammar.key end

#to_tupleObject

Return a name/value pair



21
22
23
# File 'lib/shellopts/ast/node.rb', line 21

def to_tuple
  [name, values]
end

#valuesObject

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