parser: specialize error tokens
authorJean Privat <jean@pryen.org>
Thu, 18 Jul 2013 08:47:42 +0000 (04:47 -0400)
committerJean Privat <jean@pryen.org>
Thu, 18 Jul 2013 08:47:42 +0000 (04:47 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/parser/lexer.nit
src/parser/parser.nit
src/parser/parser_abs.nit
src/parser/parser_nodes.nit
src/parser/xss/lexer.xss
src/parser/xss/parser.xss
src/parser/xss/tokens.xss

index 3c975a6..4867685 100644 (file)
@@ -1148,6 +1148,25 @@ redef class AError
     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
@@ -1583,7 +1602,7 @@ class Lexer
                                        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)
index f709698..30087de 100644 (file)
@@ -141,7 +141,7 @@ class Parser
                                (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
index 9e9e7a2..8c41b98 100644 (file)
@@ -307,6 +307,14 @@ class AError
        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
index 775c120..17f8558 100644 (file)
@@ -386,6 +386,14 @@ class AError
        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
index e4342ae..577c592 100644 (file)
@@ -191,7 +191,7 @@ $ end foreach
                                        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)
index 45d4590..a461563 100644 (file)
@@ -153,7 +153,7 @@ class Parser
                                (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
index 7a883f7..e1a4e33 100644 (file)
@@ -31,6 +31,14 @@ class PError
        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()
@@ -90,4 +98,23 @@ redef class PError
     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