Class: ShellOpts::Line
- Inherits:
-
Object
- Object
- ShellOpts::Line
- Defined in:
- lib/shellopts/lexer.rb
Instance Attribute Summary collapse
-
#charno ⇒ Object
readonly
Returns the value of attribute charno.
-
#lineno ⇒ Object
readonly
Returns the value of attribute lineno.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
- #blank? ⇒ Boolean
- #dump ⇒ Object
-
#initialize(lineno, charno, source) ⇒ Line
constructor
A new instance of Line.
- #to_s ⇒ Object
-
#words ⇒ Object
Split on whitespace while keeping track of character position.
Constructor Details
#initialize(lineno, charno, source) ⇒ Line
Returns a new instance of Line.
9 10 11 12 13 |
# File 'lib/shellopts/lexer.rb', line 9 def initialize(lineno, charno, source) @lineno, @source = lineno, source @charno = charno + ((@source =~ /(\S.*?)\s*$/) || 0) @text = $1 || "" end |
Instance Attribute Details
#charno ⇒ Object (readonly)
Returns the value of attribute charno.
6 7 8 |
# File 'lib/shellopts/lexer.rb', line 6 def charno @charno end |
#lineno ⇒ Object (readonly)
Returns the value of attribute lineno.
5 6 7 |
# File 'lib/shellopts/lexer.rb', line 5 def lineno @lineno end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
4 5 6 |
# File 'lib/shellopts/lexer.rb', line 4 def source @source end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
7 8 9 |
# File 'lib/shellopts/lexer.rb', line 7 def text @text end |
Instance Method Details
#blank? ⇒ Boolean
15 |
# File 'lib/shellopts/lexer.rb', line 15 def blank?() @text == "" end |
#dump ⇒ Object
34 |
# File 'lib/shellopts/lexer.rb', line 34 def dump() puts "#{lineno}:#{charno} #{text.inspect}" end |
#to_s ⇒ Object
33 |
# File 'lib/shellopts/lexer.rb', line 33 def to_s() text end |
#words ⇒ Object
Split on whitespace while keeping track of character position. Returns array of char, word tuples
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/shellopts/lexer.rb', line 21 def words return @words if @words @words = [] charno = self.charno text.scan(/(\s*)(\S*)/)[0..-2].each { |spaces, word| charno += spaces.size @words << [charno, word] if word != "" charno += word.size } @words end |