Module: BuildTool::Cfg::LexerBase
- Included in:
- Lexer
- Defined in:
- lib/build-tool/cfg/lexer_base.rb
Overview
Base class for all lexer.
Defined Under Namespace
Modules: ClassMethods
Classes: ScanError
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.included(klass) ⇒ Object
14
15
16
17
18
19
20
|
# File 'lib/build-tool/cfg/lexer_base.rb', line 14
def self.included( klass )
klass.extend( ClassMethods )
klass.module_eval do
alias_method( :rex_next_token, :next_token )
remove_method( :next_token )
end
end
|
Instance Method Details
#error(str) ⇒ Object
70
71
72
73
74
75
|
# File 'lib/build-tool/cfg/lexer_base.rb', line 70
def error( str )
if !instance_variable_defined?( "@filename" )
@filename = "<unknown>"
end
raise ParseError, "#{filename}[#{lineno}] #{str}"
end
|
#next_token ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/build-tool/cfg/lexer_base.rb', line 39
def next_token
begin
token = rex_next_token
case token[0]
when :IGNORE; redo
when :COMMENT; redo
when :GARBAGE; raise StandardError.new("can not match: '#{token[1]}' near '#{pre_match()}'")
else break
end if !token.nil?
break
end while true
return token
rescue StandardError => e
error = ScanError.new(e.to_s)
error.lineno = lineno
error.filename = filename
raise error
end
|
#on_error(error_token_id, error_value, value_stack) ⇒ Object
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/build-tool/cfg/lexer_base.rb', line 59
def on_error( error_token_id, error_value, value_stack )
token_name = token_to_str( error_token_id )
token_name.downcase!
token = error_value.to_s.inspect
str = 'parse error on value '
str << '"' << token_name << '" ' unless token_name == token
str << token
error(str)
end
|
#parse_string(str, filename = "<string>") ⇒ Object
77
78
79
80
|
# File 'lib/build-tool/cfg/lexer_base.rb', line 77
def parse_string( str, filename = "<string>" )
@filename = filename
scan_str( str )
end
|
#peek(len) ⇒ Object
30
31
32
|
# File 'lib/build-tool/cfg/lexer_base.rb', line 30
def peek( len )
@ss.peek( len )
end
|
#pre_match ⇒ Object
34
35
36
37
|
# File 'lib/build-tool/cfg/lexer_base.rb', line 34
def pre_match
@ss.pre_match()[-20,20]
end
|