Class: CTokenizer::Lexer
- Inherits:
-
Object
- Object
- CTokenizer::Lexer
- Includes:
- CTokenizer
- Defined in:
- lib/dbc/ctokenizer.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize(str, file = nil, line = 1) ⇒ Lexer
constructor
A new instance of Lexer.
- #peek_nonspace ⇒ Object
- #shift ⇒ Object
Methods included from CTokenizer
check_string, check_token, #collect, create_newlines, #each, error, #error, join, line_count, #parse_error, split, split_token, #to_a, #token_error, #warning, whitespace?
Constructor Details
#initialize(str, file = nil, line = 1) ⇒ Lexer
Returns a new instance of Lexer.
162 163 164 165 166 167 |
# File 'lib/dbc/ctokenizer.rb', line 162 def initialize(str, file=nil, line=1) CTokenizer.check_string(str) @rest = str @file = file @line = line end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
169 170 171 |
# File 'lib/dbc/ctokenizer.rb', line 169 def file @file end |
#line ⇒ Object (readonly)
Returns the value of attribute line.
169 170 171 |
# File 'lib/dbc/ctokenizer.rb', line 169 def line @line end |
Instance Method Details
#empty? ⇒ Boolean
181 182 183 |
# File 'lib/dbc/ctokenizer.rb', line 181 def empty? @rest.empty? end |
#peek_nonspace ⇒ Object
171 172 173 174 175 176 177 178 179 |
# File 'lib/dbc/ctokenizer.rb', line 171 def peek_nonspace t = nil tmp_rest = @rest # @rest is unchanged loop do t, tmp_rest = CTokenizer.split_token(tmp_rest) break unless CTokenizer.whitespace?(t) end t end |
#shift ⇒ Object
185 186 187 188 189 |
# File 'lib/dbc/ctokenizer.rb', line 185 def shift t, @rest = CTokenizer.split_token(@rest) @line += CTokenizer.line_count(t[1]) t end |