Class: ShellOpts::Grammar::IdrNode
- Defined in:
- lib/shellopts/dump.rb,
lib/shellopts/parser.rb,
lib/shellopts/grammar.rb
Constant Summary
Constants inherited from Node
Instance Attribute Summary collapse
-
#attr ⇒ Object
readonly
The associated attribute (Symbol) in the parent command object.
-
#command ⇒ Object
readonly
Command of this object (nil for the top-level Program object).
-
#ident ⇒ Object
Canonical identifier (Symbol) of the object.
-
#name ⇒ Object
readonly
Canonical name (String) of the object.
-
#path ⇒ Object
readonly
Path from Program object and down to this node.
Attributes inherited from Node
Instance Method Summary collapse
- #dump_doc ⇒ Object
-
#parse ⇒ Object
Assumes that @name and @path has been defined.
- #set_name(name, path) ⇒ Object
-
#uid ⇒ Object
Unique identifier of node (String) within the context of a program.
Methods inherited from Node
#analyzer_error, #ancestors, #dump_ast, #dump_attrs, #dump_idr, #initialize, #inspect, #parents, parse, #parser_error, #puts_help, #puts_usage, #remove_arg_descr_nodes, #remove_arg_spec_nodes, #remove_brief_nodes, #traverse
Constructor Details
This class inherits a constructor from ShellOpts::Grammar::Node
Instance Attribute Details
#attr ⇒ Object (readonly)
The associated attribute (Symbol) in the parent command object. nil if #ident is a reserved word. Initialized by the parser
84 85 86 |
# File 'lib/shellopts/grammar.rb', line 84 def attr @attr end |
#command ⇒ Object (readonly)
Command of this object (nil for the top-level Program object). This is different from #parent when a subcommand is nested textually on a higher level than its supercommand. Initialized by the analyzer
48 49 50 |
# File 'lib/shellopts/grammar.rb', line 48 def command @command end |
#ident ⇒ Object
Canonical identifier (Symbol) of the object
For options, this is the canonical name of the objekt without the initial '-' or '--'. For commands it is the command name including the suffixed exclamation mark. Both options and commands have internal dashes replaced with underscores. Initialized by the parser
Note that the analyzer fails with an an error if both --with-separator and --with_separator are used because they would both map to :with_separator
72 73 74 |
# File 'lib/shellopts/grammar.rb', line 72 def ident @ident end |
#name ⇒ Object (readonly)
Canonical name (String) of the object
This is the name of the object as the user sees it. For options it is the name of the first long option or the name of the first short option if there is no long option name. For commands it is the name without the exclamation mark. Initialized by the parser
80 81 82 |
# File 'lib/shellopts/grammar.rb', line 80 def name @name end |
#path ⇒ Object (readonly)
Path from Program object and down to this node. Array of identifiers. Empty for the Program object. Initialized by the parser
60 61 62 |
# File 'lib/shellopts/grammar.rb', line 60 def path @path end |
Instance Method Details
#dump_doc ⇒ Object
4 5 6 7 8 9 |
# File 'lib/shellopts/dump.rb', line 4 def dump_doc puts "#{self.class} #{ident}" indent { children.each(&:dump_doc) } end |
#parse ⇒ Object
Assumes that @name and @path has been defined
19 20 21 22 23 |
# File 'lib/shellopts/parser.rb', line 19 def parse # @ident = @path.last || :! # @attr = ::ShellOpts::Command::RESERVED_OPTION_NAMES.include?(ident.to_s) ? nil : ident # @uid = parent && @path.join(".").sub(/!\./, ".") # uid is nil for the Program object end |
#set_name(name, path) ⇒ Object
86 87 88 89 90 91 |
# File 'lib/shellopts/grammar.rb', line 86 def set_name(name, path) @name = name.to_s @path = path @ident = @path.last || :! @attr = ::ShellOpts::Command::RESERVED_OPTION_NAMES.include?(@ident.to_s) ? nil : @ident end |
#uid ⇒ Object
Unique identifier of node (String) within the context of a program. nil for the Program object. It is the dot-joined elements of path with internal exclamation marks removed (eg. "cmd.opt" or "cmd.cmd!"). Initialize by the analyzer
54 55 56 |
# File 'lib/shellopts/grammar.rb', line 54 def uid() @uid ||= command && [command.uid, ident].compact.join(".").sub(/!\./, ".") end |