Class: ShellOpts::Token
- Inherits:
-
Object
- Object
- ShellOpts::Token
- Defined in:
- lib/shellopts/token.rb
Constant Summary collapse
- KINDS =
Each kind should have a corresponding Grammar class with the same name
[ :program, :section, :option, :command, :spec, :argument, :usage, :usage_string, :brief, :text, :blank ]
Instance Attribute Summary collapse
-
#charno ⇒ Object
Char number (one-based).
-
#kind ⇒ Object
readonly
Kind of token.
-
#lineno ⇒ Object
readonly
Line number (one-based).
-
#source ⇒ Object
readonly
Source of the token.
Instance Method Summary collapse
- #dump ⇒ Object
-
#initialize(kind, lineno, charno, source) ⇒ Token
constructor
A new instance of Token.
- #inspect ⇒ Object
- #pos(start_lineno = 1, start_charno = 1) ⇒ Object
- #to_s ⇒ Object
Constructor Details
Instance Attribute Details
#charno ⇒ Object
Char number (one-based). The lexer may adjust the char number (eg. for blank lines)
18 19 20 |
# File 'lib/shellopts/token.rb', line 18 def charno @charno end |
#kind ⇒ Object (readonly)
Kind of token
11 12 13 |
# File 'lib/shellopts/token.rb', line 11 def kind @kind end |
#lineno ⇒ Object (readonly)
Line number (one-based)
14 15 16 |
# File 'lib/shellopts/token.rb', line 14 def lineno @lineno end |
#source ⇒ Object (readonly)
Source of the token
21 22 23 |
# File 'lib/shellopts/token.rb', line 21 def source @source end |
Instance Method Details
#dump ⇒ Object
40 41 42 |
# File 'lib/shellopts/token.rb', line 40 def dump puts "#{kind}@#{lineno}:#{charno} #{source.inspect}" end |
#inspect ⇒ Object
36 37 38 |
# File 'lib/shellopts/token.rb', line 36 def inspect() "<#{self.class.to_s.sub(/.*::/, "")} #{pos} #{kind.inspect} #{source.inspect}>" end |
#pos(start_lineno = 1, start_charno = 1) ⇒ Object
30 31 32 |
# File 'lib/shellopts/token.rb', line 30 def pos(start_lineno = 1, start_charno = 1) "#{start_lineno + lineno - 1}:#{start_charno + charno - 1}" end |
#to_s ⇒ Object
34 |
# File 'lib/shellopts/token.rb', line 34 def to_s() source end |