end
end
+redef class ALexerError
+ readable var _string: String
+
+ init init_lexer_error(message: String, loc: Location, string: String)
+ do
+ init_error(message, loc)
+ _string = string
+ end
+end
+
+redef class AParserError
+ readable var _token: Token
+
+ init init_parser_error(message: String, loc: Location, token: Token)
+ do
+ init_error(message, loc)
+ _token = token
+ end
+end
# The lexer extract NIT tokens from an input stream.
# It is better user with the Parser
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 AError.init_error("Syntax error: unknown token {text}.", location)
+ var token = new ALexerError.init_lexer_error("Syntax error: unknown token {text}.", location, text)
return token
else
var token = new EOF(location)
(new ComputeProdLocationVisitor).enter_visit(node)
return node
else if action_type == 3 then # ERROR
- var node2 = new AError.init_error("Syntax error: unexpected {token}.", token.location)
+ var node2 = new AParserError.init_parser_error("Syntax error: unexpected {token}.", token.location, token)
var node = new Start(null, node2)
return node
end
super EOF
private init noinit do end
end
+class ALexerError
+ super AError
+private init noinit do end
+end
+class AParserError
+ super AError
+private init noinit do end
+end
class AModule super Prod end
class AModuledecl super Prod end
super EOF
private init noinit do end
end
+class ALexerError
+ super AError
+private init noinit do end
+end
+class AParserError
+ super AError
+private init noinit do end
+end
class AModule
super Prod
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 PError.init_error("Syntax error: unknown token {text}.", location)
+ var token = new PLexerError.init_lexer_error("Syntax error: unknown token {text}.", location, text)
return token
else
var token = new EOF(location)
(new ComputeProdLocationVisitor).enter_visit(node)
return node
else if action_type == 3 then # ERROR
- var node2 = new PError.init_error("Syntax error: unexpected {token}.", token.location)
+ var node2 = new PParserError.init_parser_error("Syntax error: unexpected {token}.", token.location, token)
var node = new Start(null, node2)
return node
end
super EOF
private init noinit do end
end
+class PLexerError
+ super PError
+private init noinit do end
+end
+class PParserError
+ super PError
+private init noinit do end
+end
$ end template
$ template make_tokens()
end
end
+redef class PLexerError
+ readable var _string: String
+
+ init init_lexer_error(message: String, loc: Location, string: String)
+ do
+ init_error(message, loc)
+ _string = string
+ end
+end
+
+redef class PParserError
+ readable var _token: Token
+
+ init init_parser_error(message: String, loc: Location, token: Token)
+ do
+ init_error(message, loc)
+ _token = token
+ end
+end
$ end template