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



87
88
89
# File 'lib/shellopts/grammar.rb', line 87

def attr
  @attr
end

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



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

def command
  @command
end

#identObject

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



75
76
77
# File 'lib/shellopts/grammar.rb', line 75

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



83
84
85
# File 'lib/shellopts/grammar.rb', line 83

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



63
64
65
# File 'lib/shellopts/grammar.rb', line 63

def path
  @path
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



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



89
90
91
92
93
94
# File 'lib/shellopts/grammar.rb', line 89

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

#uidObject

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



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

def uid()
  @uid ||= command && [command.uid, ident].compact.join(".").sub(/!\./, ".")
end