Signed-off-by: Jean Privat <jean@pryen.org>
- readable var _message: String
init init_error(message: String, loc: Location)
do
init_tk(loc)
init init_error(message: String, loc: Location)
do
init_tk(loc)
end
end
redef class ALexerError
end
end
redef class ALexerError
- readable var _string: String
init init_lexer_error(message: String, loc: Location, string: String)
do
init_error(message, loc)
init init_lexer_error(message: String, loc: Location, string: String)
do
init_error(message, loc)
end
end
redef class AParserError
end
end
redef class AParserError
- readable var _token: Token
init init_parser_error(message: String, loc: Location, token: Token)
do
init_error(message, loc)
init init_parser_error(message: String, loc: Location, token: Token)
do
init_error(message, loc)
var _state: Int = 0
# The source file
var _state: Int = 0
# The source file
- readable var _file: SourceFile
# Current character in the stream
var _stream_pos: Int = 0
# Current character in the stream
var _stream_pos: Int = 0
# Create a new lexer for a stream (and a name)
init(file: SourceFile)
do
# Create a new lexer for a stream (and a name)
init(file: SourceFile)
do
end
# The last peeked token to chain them
end
# The last peeked token to chain them
l.next_token = t
t.prev_token = l
else
l.next_token = t
t.prev_token = l
else
var start_stream_pos = sp
var start_pos = _pos
var start_line = _line
var start_stream_pos = sp
var start_pos = _pos
var start_line = _line
- var string = _file.string
+ var file = self.file
+ var string = file.string
var string_len = string.length
var accept_state = -1
var string_len = string.length
var accept_state = -1
if c == 10 then
if cr then
cr = false
if c == 10 then
if cr then
cr = false
- _file.line_starts[line] = sp
+ file.line_starts[line] = sp
else
line = line + 1
pos = 0
else
line = line + 1
pos = 0
- _file.line_starts[line] = sp
+ file.line_starts[line] = sp
end
else if c == 13 then
line = line + 1
pos = 0
cr = true
end
else if c == 13 then
line = line + 1
pos = 0
cr = true
- _file.line_starts[line] = sp
+ file.line_starts[line] = sp
else
pos = pos + 1
cr = false
else
pos = pos + 1
cr = false
end
else
if accept_state != -1 then
end
else
if accept_state != -1 then
- var location = new Location(_file, start_line + 1, accept_line + 1, start_pos + 1, accept_pos)
+ var location = new Location(file, start_line + 1, accept_line + 1, start_pos + 1, accept_pos)
_pos = accept_pos
_line = accept_line
_stream_pos = start_stream_pos + accept_length
_pos = accept_pos
_line = accept_line
_stream_pos = start_stream_pos + accept_length
return make_token(accept_token, location)
else
_stream_pos = sp
return make_token(accept_token, location)
else
_stream_pos = sp
- var location = new Location(_file, start_line + 1, start_line + 1, start_pos + 1, start_pos + 1)
+ var location = new Location(file, start_line + 1, start_line + 1, start_pos + 1, start_pos + 1)
if sp > start_stream_pos then
var text = string.substring(start_stream_pos, sp-start_stream_pos)
var token = new ALexerError.init_lexer_error("Syntax error: unknown token {text}.", location, text)
if sp > start_stream_pos then
var text = string.substring(start_stream_pos, sp-start_stream_pos)
var token = new ALexerError.init_lexer_error("Syntax error: unknown token {text}.", location, text)
- _file.last_token = token
+ file.last_token = token
return token
else
var token = new EOF.init_tk(location)
return token
else
var token = new EOF.init_tk(location)
- _file.last_token = token
+ file.last_token = token
# State of the parser automata as stored in the parser stack.
private class State
# The internal state number
# State of the parser automata as stored in the parser stack.
private class State
# The internal state number
- readable writable var _state: Int
# The node stored with the state in the stack
# The node stored with the state in the stack
- readable writable var _nodes: nullable Object
+ var _nodes: nullable Object
init(state: Int, nodes: nullable Object)
do
init(state: Int, nodes: nullable Object)
do
_stack_pos = pos
if pos < _stack.length then
var state = _stack[pos]
_stack_pos = pos
if pos < _stack.length then
var state = _stack[pos]
- state.state = numstate
- state.nodes = list_node
+ state._state = numstate
+ state._nodes = list_node
else
_stack.push(new State(numstate, list_node))
end
else
_stack.push(new State(numstate, list_node))
end
# The current state
private fun state: Int
do
# The current state
private fun state: Int
do
- return _stack[_stack_pos].state
+ return _stack[_stack_pos]._state
end
# Pop something from the stack state
private fun pop: nullable Object
do
end
# Pop something from the stack state
private fun pop: nullable Object
do
- var res = _stack[_stack_pos].nodes
+ var res = _stack[_stack_pos]._nodes
_stack_pos = _stack_pos -1
return res
end
_stack_pos = _stack_pos -1
return res
end