Merge branch 'annotations'
[nit.git] / src / parser / lexer.nit
index 3c975a6..7e07395 100644 (file)
@@ -17,6 +17,11 @@ redef class Token
        return res
     end
 
+    redef fun text=(text)
+    do
+        _text = text
+    end
+
     fun parser_index: Int is abstract
 end
 
@@ -968,7 +973,7 @@ redef class TBang
     end
 end
 
-redef class TClassid
+redef class TAt
     redef fun parser_index: Int
     do
        return 79
@@ -980,7 +985,7 @@ redef class TClassid
     end
 end
 
-redef class TId
+redef class TClassid
     redef fun parser_index: Int
     do
        return 80
@@ -992,7 +997,7 @@ redef class TId
     end
 end
 
-redef class TAttrid
+redef class TId
     redef fun parser_index: Int
     do
        return 81
@@ -1004,7 +1009,7 @@ redef class TAttrid
     end
 end
 
-redef class TNumber
+redef class TAttrid
     redef fun parser_index: Int
     do
        return 82
@@ -1016,7 +1021,7 @@ redef class TNumber
     end
 end
 
-redef class TFloat
+redef class TNumber
     redef fun parser_index: Int
     do
        return 83
@@ -1028,7 +1033,7 @@ redef class TFloat
     end
 end
 
-redef class TChar
+redef class TFloat
     redef fun parser_index: Int
     do
        return 84
@@ -1088,7 +1093,7 @@ redef class TEndString
     end
 end
 
-redef class TBadChar
+redef class TChar
     redef fun parser_index: Int
     do
        return 89
@@ -1112,7 +1117,7 @@ redef class TBadString
     end
 end
 
-redef class TExternCodeSegment
+redef class TBadChar
     redef fun parser_index: Int
     do
        return 91
@@ -1124,14 +1129,26 @@ redef class TExternCodeSegment
     end
 end
 
+redef class TExternCodeSegment
+    redef fun parser_index: Int
+    do
+       return 92
+    end
+
+    init init_tk(loc: Location)
+    do
+               _location = loc
+    end
+end
+
 
 redef class EOF
     redef fun parser_index: Int
     do
-       return 92
+       return 93
     end
 
-    init(loc: Location)
+    init init_tk(loc: Location)
     do
         _text = ""
                _location = loc
@@ -1143,11 +1160,30 @@ redef class AError
 
     init init_error(message: String, loc: Location)
     do
-               init(loc)
+               init_tk(loc)
                _message = message
     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
@@ -1540,22 +1576,22 @@ class Lexer
                                                return new TBang.init_tk(location)
                                        end
                                        if accept_token == 80 then
-                                               return new TClassid.init_tk(location)
+                                               return new TAt.init_tk(location)
                                        end
                                        if accept_token == 81 then
-                                               return new TId.init_tk(location)
+                                               return new TClassid.init_tk(location)
                                        end
                                        if accept_token == 82 then
-                                               return new TAttrid.init_tk(location)
+                                               return new TId.init_tk(location)
                                        end
                                        if accept_token == 83 then
-                                               return new TNumber.init_tk(location)
+                                               return new TAttrid.init_tk(location)
                                        end
                                        if accept_token == 84 then
-                                               return new TFloat.init_tk(location)
+                                               return new TNumber.init_tk(location)
                                        end
                                        if accept_token == 85 then
-                                               return new TChar.init_tk(location)
+                                               return new TFloat.init_tk(location)
                                        end
                                        if accept_token == 86 then
                                                return new TString.init_tk(location)
@@ -1570,12 +1606,15 @@ class Lexer
                                                return new TEndString.init_tk(location)
                                        end
                                        if accept_token == 90 then
-                                               return new TBadChar.init_tk(location)
+                                               return new TChar.init_tk(location)
                                        end
                                        if accept_token == 91 then
                                                return new TBadString.init_tk(location)
                                        end
                                        if accept_token == 92 then
+                                               return new TBadChar.init_tk(location)
+                                       end
+                                       if accept_token == 93 then
                                                return new TExternCodeSegment.init_tk(location)
                                        end
                                else
@@ -1583,10 +1622,10 @@ 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)
+                                               var token = new EOF.init_tk(location)
                                                return token
                                        end
                                end