Class: ShellOpts::Grammar::IdrNode

Inherits:
Node
  • Object
show all
Defined in:
lib/shellopts/dump.rb,
lib/shellopts/parser.rb,
lib/shellopts/grammar.rb

Direct Known Subclasses

Command, Option

Constant Summary

Constants inherited from Node

Node::ALLOWED_PARENTS

Instance Attribute Summary collapse

Attributes inherited from Node

#children, #parent, #token

Instance Method Summary collapse

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

#attrObject (readonly)

The associated attribute (Symbol) in the parent command object. nil if #ident is a reserved word. Initialized by the parser



85
86
87
# File 'lib/shellopts/grammar.rb', line 85

def attr
  @attr
end

#commandObject (readonly)

Command of this object. This is different from #parent when a subcommand is nested on a higher level than its supercommand. Initialized by the analyzer



51
52
53
# File 'lib/shellopts/grammar.rb', line 51

def command
  @command
end

#identObject (readonly)

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



73
74
75
# File 'lib/shellopts/grammar.rb', line 73

def ident
  @ident
end

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



81
82
83
# File 'lib/shellopts/grammar.rb', line 81

def name
  @name
end

#pathObject (readonly)

Path from Program object and down to this node. Array of identifiers. Empty for the Program object. Initialized by the parser



61
62
63
# File 'lib/shellopts/grammar.rb', line 61

def path
  @path
end

#uidObject (readonly)

Unique identifier of node (String) within the context of a program. nil for the Program object. It is the list of path elements concatenated with ‘.’ and with internal ‘!’ removed (eg. “cmd.opt” or “cmd.cmd!”). Initialized by the parser



57
58
59
# File 'lib/shellopts/grammar.rb', line 57

def uid
  @uid
end

Instance Method Details

#dump_docObject



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

#parseObject

Assumes that @name and @path has been defined



18
19
20
21
22
# File 'lib/shellopts/parser.rb', line 18

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