niti: disable interpretor_type_test
[nit.git] / src / parser / lexer.nit
index e66dc87..d226006 100644 (file)
@@ -6,13 +6,18 @@ intrude import parser_nodes
 private import tables
 
 redef class Token
-    readable var _text: String
+    var _text: nullable String
 
-    fun parser_index: Int is abstract
-
-    redef fun to_s: String do
-        return "'{_text}'"
+    redef fun text
+    do
+        var res = _text
+        if res != null then return res
+        res = location.text
+       _text = res
+       return res
     end
+
+    fun parser_index: Int is abstract
 end
 
 redef class TEol
@@ -21,9 +26,8 @@ redef class TEol
        return 0
     end
 
-    init init_tk(text: String, loc: Location)
+    init init_tk(loc: Location)
     do
-        _text = text
                _location = loc
     end
 end
@@ -34,9 +38,8 @@ redef class TComment
        return 1
     end
 
-    init init_tk(text: String, loc: Location)
+    init init_tk(loc: Location)
     do
-        _text = text
                _location = loc
     end
 end
@@ -47,9 +50,8 @@ redef class TKwmodule
        return 2
     end
 
-    init init_tk(text: String, loc: Location)
+    init init_tk(loc: Location)
     do
-        _text = text
                _location = loc
     end
 end
@@ -62,7 +64,6 @@ redef class TKwimport
 
     init init_tk(loc: Location)
     do
-        _text = once "import"
                _location = loc
     end
 end
@@ -75,7 +76,6 @@ redef class TKwclass
 
     init init_tk(loc: Location)
     do
-        _text = once "class"
                _location = loc
     end
 end
@@ -88,7 +88,6 @@ redef class TKwabstract
 
     init init_tk(loc: Location)
     do
-        _text = once "abstract"
                _location = loc
     end
 end
@@ -101,7 +100,6 @@ redef class TKwinterface
 
     init init_tk(loc: Location)
     do
-        _text = once "interface"
                _location = loc
     end
 end
@@ -112,9 +110,8 @@ redef class TKwenum
        return 7
     end
 
-    init init_tk(text: String, loc: Location)
+    init init_tk(loc: Location)
     do
-        _text = text
                _location = loc
     end
 end
@@ -127,7 +124,6 @@ redef class TKwspecial
 
     init init_tk(loc: Location)
     do
-        _text = once "special"
                _location = loc
     end
 end
@@ -140,7 +136,6 @@ redef class TKwend
 
     init init_tk(loc: Location)
     do
-        _text = once "end"
                _location = loc
     end
 end
@@ -153,7 +148,6 @@ redef class TKwmeth
 
     init init_tk(loc: Location)
     do
-        _text = once "fun"
                _location = loc
     end
 end
@@ -166,7 +160,6 @@ redef class TKwtype
 
     init init_tk(loc: Location)
     do
-        _text = once "type"
                _location = loc
     end
 end
@@ -179,7 +172,6 @@ redef class TKwinit
 
     init init_tk(loc: Location)
     do
-        _text = once "init"
                _location = loc
     end
 end
@@ -192,7 +184,6 @@ redef class TKwredef
 
     init init_tk(loc: Location)
     do
-        _text = once "redef"
                _location = loc
     end
 end
@@ -205,7 +196,6 @@ redef class TKwis
 
     init init_tk(loc: Location)
     do
-        _text = once "is"
                _location = loc
     end
 end
@@ -218,7 +208,6 @@ redef class TKwdo
 
     init init_tk(loc: Location)
     do
-        _text = once "do"
                _location = loc
     end
 end
@@ -231,7 +220,6 @@ redef class TKwreadable
 
     init init_tk(loc: Location)
     do
-        _text = once "readable"
                _location = loc
     end
 end
@@ -244,7 +232,6 @@ redef class TKwwritable
 
     init init_tk(loc: Location)
     do
-        _text = once "writable"
                _location = loc
     end
 end
@@ -257,7 +244,6 @@ redef class TKwvar
 
     init init_tk(loc: Location)
     do
-        _text = once "var"
                _location = loc
     end
 end
@@ -270,7 +256,6 @@ redef class TKwintern
 
     init init_tk(loc: Location)
     do
-        _text = once "intern"
                _location = loc
     end
 end
@@ -283,7 +268,6 @@ redef class TKwextern
 
     init init_tk(loc: Location)
     do
-        _text = once "extern"
                _location = loc
     end
 end
@@ -296,7 +280,6 @@ redef class TKwprotected
 
     init init_tk(loc: Location)
     do
-        _text = once "protected"
                _location = loc
     end
 end
@@ -309,7 +292,6 @@ redef class TKwprivate
 
     init init_tk(loc: Location)
     do
-        _text = once "private"
                _location = loc
     end
 end
@@ -322,7 +304,6 @@ redef class TKwintrude
 
     init init_tk(loc: Location)
     do
-        _text = once "intrude"
                _location = loc
     end
 end
@@ -335,7 +316,6 @@ redef class TKwif
 
     init init_tk(loc: Location)
     do
-        _text = once "if"
                _location = loc
     end
 end
@@ -348,7 +328,6 @@ redef class TKwthen
 
     init init_tk(loc: Location)
     do
-        _text = once "then"
                _location = loc
     end
 end
@@ -361,7 +340,6 @@ redef class TKwelse
 
     init init_tk(loc: Location)
     do
-        _text = once "else"
                _location = loc
     end
 end
@@ -374,7 +352,6 @@ redef class TKwwhile
 
     init init_tk(loc: Location)
     do
-        _text = once "while"
                _location = loc
     end
 end
@@ -387,7 +364,6 @@ redef class TKwloop
 
     init init_tk(loc: Location)
     do
-        _text = once "loop"
                _location = loc
     end
 end
@@ -400,7 +376,6 @@ redef class TKwfor
 
     init init_tk(loc: Location)
     do
-        _text = once "for"
                _location = loc
     end
 end
@@ -413,7 +388,6 @@ redef class TKwin
 
     init init_tk(loc: Location)
     do
-        _text = once "in"
                _location = loc
     end
 end
@@ -426,7 +400,6 @@ redef class TKwand
 
     init init_tk(loc: Location)
     do
-        _text = once "and"
                _location = loc
     end
 end
@@ -439,7 +412,6 @@ redef class TKwor
 
     init init_tk(loc: Location)
     do
-        _text = once "or"
                _location = loc
     end
 end
@@ -452,7 +424,6 @@ redef class TKwnot
 
     init init_tk(loc: Location)
     do
-        _text = once "not"
                _location = loc
     end
 end
@@ -465,7 +436,6 @@ redef class TKwreturn
 
     init init_tk(loc: Location)
     do
-        _text = once "return"
                _location = loc
     end
 end
@@ -478,7 +448,6 @@ redef class TKwcontinue
 
     init init_tk(loc: Location)
     do
-        _text = once "continue"
                _location = loc
     end
 end
@@ -491,7 +460,6 @@ redef class TKwbreak
 
     init init_tk(loc: Location)
     do
-        _text = once "break"
                _location = loc
     end
 end
@@ -504,7 +472,6 @@ redef class TKwabort
 
     init init_tk(loc: Location)
     do
-        _text = once "abort"
                _location = loc
     end
 end
@@ -517,7 +484,6 @@ redef class TKwassert
 
     init init_tk(loc: Location)
     do
-        _text = once "assert"
                _location = loc
     end
 end
@@ -530,7 +496,6 @@ redef class TKwnew
 
     init init_tk(loc: Location)
     do
-        _text = once "new"
                _location = loc
     end
 end
@@ -543,7 +508,6 @@ redef class TKwisa
 
     init init_tk(loc: Location)
     do
-        _text = once "isa"
                _location = loc
     end
 end
@@ -556,7 +520,6 @@ redef class TKwonce
 
     init init_tk(loc: Location)
     do
-        _text = once "once"
                _location = loc
     end
 end
@@ -569,7 +532,6 @@ redef class TKwsuper
 
     init init_tk(loc: Location)
     do
-        _text = once "super"
                _location = loc
     end
 end
@@ -582,7 +544,6 @@ redef class TKwself
 
     init init_tk(loc: Location)
     do
-        _text = once "self"
                _location = loc
     end
 end
@@ -595,7 +556,6 @@ redef class TKwtrue
 
     init init_tk(loc: Location)
     do
-        _text = once "true"
                _location = loc
     end
 end
@@ -608,7 +568,6 @@ redef class TKwfalse
 
     init init_tk(loc: Location)
     do
-        _text = once "false"
                _location = loc
     end
 end
@@ -621,7 +580,6 @@ redef class TKwnull
 
     init init_tk(loc: Location)
     do
-        _text = once "null"
                _location = loc
     end
 end
@@ -634,7 +592,6 @@ redef class TKwas
 
     init init_tk(loc: Location)
     do
-        _text = once "as"
                _location = loc
     end
 end
@@ -647,7 +604,6 @@ redef class TKwnullable
 
     init init_tk(loc: Location)
     do
-        _text = once "nullable"
                _location = loc
     end
 end
@@ -660,7 +616,6 @@ redef class TKwisset
 
     init init_tk(loc: Location)
     do
-        _text = once "isset"
                _location = loc
     end
 end
@@ -673,12 +628,11 @@ redef class TKwlabel
 
     init init_tk(loc: Location)
     do
-        _text = once "label"
                _location = loc
     end
 end
 
-redef class TOpar
+redef class TKwdebug
     redef fun parser_index: Int
     do
        return 51
@@ -686,12 +640,11 @@ redef class TOpar
 
     init init_tk(loc: Location)
     do
-        _text = once "("
                _location = loc
     end
 end
 
-redef class TCpar
+redef class TOpar
     redef fun parser_index: Int
     do
        return 52
@@ -699,12 +652,11 @@ redef class TCpar
 
     init init_tk(loc: Location)
     do
-        _text = once ")"
                _location = loc
     end
 end
 
-redef class TObra
+redef class TCpar
     redef fun parser_index: Int
     do
        return 53
@@ -712,12 +664,11 @@ redef class TObra
 
     init init_tk(loc: Location)
     do
-        _text = once "["
                _location = loc
     end
 end
 
-redef class TCbra
+redef class TObra
     redef fun parser_index: Int
     do
        return 54
@@ -725,12 +676,11 @@ redef class TCbra
 
     init init_tk(loc: Location)
     do
-        _text = once "]"
                _location = loc
     end
 end
 
-redef class TComma
+redef class TCbra
     redef fun parser_index: Int
     do
        return 55
@@ -738,12 +688,11 @@ redef class TComma
 
     init init_tk(loc: Location)
     do
-        _text = once ","
                _location = loc
     end
 end
 
-redef class TColumn
+redef class TComma
     redef fun parser_index: Int
     do
        return 56
@@ -751,12 +700,11 @@ redef class TColumn
 
     init init_tk(loc: Location)
     do
-        _text = once ":"
                _location = loc
     end
 end
 
-redef class TQuad
+redef class TColumn
     redef fun parser_index: Int
     do
        return 57
@@ -764,12 +712,11 @@ redef class TQuad
 
     init init_tk(loc: Location)
     do
-        _text = once "::"
                _location = loc
     end
 end
 
-redef class TAssign
+redef class TQuad
     redef fun parser_index: Int
     do
        return 58
@@ -777,12 +724,11 @@ redef class TAssign
 
     init init_tk(loc: Location)
     do
-        _text = once "="
                _location = loc
     end
 end
 
-redef class TPluseq
+redef class TAssign
     redef fun parser_index: Int
     do
        return 59
@@ -790,12 +736,11 @@ redef class TPluseq
 
     init init_tk(loc: Location)
     do
-        _text = once "+="
                _location = loc
     end
 end
 
-redef class TMinuseq
+redef class TPluseq
     redef fun parser_index: Int
     do
        return 60
@@ -803,12 +748,11 @@ redef class TMinuseq
 
     init init_tk(loc: Location)
     do
-        _text = once "-="
                _location = loc
     end
 end
 
-redef class TDotdotdot
+redef class TMinuseq
     redef fun parser_index: Int
     do
        return 61
@@ -816,12 +760,11 @@ redef class TDotdotdot
 
     init init_tk(loc: Location)
     do
-        _text = once "..."
                _location = loc
     end
 end
 
-redef class TDotdot
+redef class TDotdotdot
     redef fun parser_index: Int
     do
        return 62
@@ -829,12 +772,11 @@ redef class TDotdot
 
     init init_tk(loc: Location)
     do
-        _text = once ".."
                _location = loc
     end
 end
 
-redef class TDot
+redef class TDotdot
     redef fun parser_index: Int
     do
        return 63
@@ -842,12 +784,11 @@ redef class TDot
 
     init init_tk(loc: Location)
     do
-        _text = once "."
                _location = loc
     end
 end
 
-redef class TPlus
+redef class TDot
     redef fun parser_index: Int
     do
        return 64
@@ -855,12 +796,11 @@ redef class TPlus
 
     init init_tk(loc: Location)
     do
-        _text = once "+"
                _location = loc
     end
 end
 
-redef class TMinus
+redef class TPlus
     redef fun parser_index: Int
     do
        return 65
@@ -868,12 +808,11 @@ redef class TMinus
 
     init init_tk(loc: Location)
     do
-        _text = once "-"
                _location = loc
     end
 end
 
-redef class TStar
+redef class TMinus
     redef fun parser_index: Int
     do
        return 66
@@ -881,12 +820,11 @@ redef class TStar
 
     init init_tk(loc: Location)
     do
-        _text = once "*"
                _location = loc
     end
 end
 
-redef class TSlash
+redef class TStar
     redef fun parser_index: Int
     do
        return 67
@@ -894,12 +832,11 @@ redef class TSlash
 
     init init_tk(loc: Location)
     do
-        _text = once "/"
                _location = loc
     end
 end
 
-redef class TPercent
+redef class TSlash
     redef fun parser_index: Int
     do
        return 68
@@ -907,12 +844,11 @@ redef class TPercent
 
     init init_tk(loc: Location)
     do
-        _text = once "%"
                _location = loc
     end
 end
 
-redef class TEq
+redef class TPercent
     redef fun parser_index: Int
     do
        return 69
@@ -920,12 +856,11 @@ redef class TEq
 
     init init_tk(loc: Location)
     do
-        _text = once "=="
                _location = loc
     end
 end
 
-redef class TNe
+redef class TEq
     redef fun parser_index: Int
     do
        return 70
@@ -933,12 +868,11 @@ redef class TNe
 
     init init_tk(loc: Location)
     do
-        _text = once "!="
                _location = loc
     end
 end
 
-redef class TLt
+redef class TNe
     redef fun parser_index: Int
     do
        return 71
@@ -946,12 +880,11 @@ redef class TLt
 
     init init_tk(loc: Location)
     do
-        _text = once "<"
                _location = loc
     end
 end
 
-redef class TLe
+redef class TLt
     redef fun parser_index: Int
     do
        return 72
@@ -959,12 +892,11 @@ redef class TLe
 
     init init_tk(loc: Location)
     do
-        _text = once "<="
                _location = loc
     end
 end
 
-redef class TLl
+redef class TLe
     redef fun parser_index: Int
     do
        return 73
@@ -972,12 +904,11 @@ redef class TLl
 
     init init_tk(loc: Location)
     do
-        _text = once "<<"
                _location = loc
     end
 end
 
-redef class TGt
+redef class TLl
     redef fun parser_index: Int
     do
        return 74
@@ -985,12 +916,11 @@ redef class TGt
 
     init init_tk(loc: Location)
     do
-        _text = once ">"
                _location = loc
     end
 end
 
-redef class TGe
+redef class TGt
     redef fun parser_index: Int
     do
        return 75
@@ -998,12 +928,11 @@ redef class TGe
 
     init init_tk(loc: Location)
     do
-        _text = once ">="
                _location = loc
     end
 end
 
-redef class TGg
+redef class TGe
     redef fun parser_index: Int
     do
        return 76
@@ -1011,12 +940,11 @@ redef class TGg
 
     init init_tk(loc: Location)
     do
-        _text = once ">>"
                _location = loc
     end
 end
 
-redef class TStarship
+redef class TGg
     redef fun parser_index: Int
     do
        return 77
@@ -1024,12 +952,11 @@ redef class TStarship
 
     init init_tk(loc: Location)
     do
-        _text = once "<=>"
                _location = loc
     end
 end
 
-redef class TBang
+redef class TStarship
     redef fun parser_index: Int
     do
        return 78
@@ -1037,137 +964,162 @@ redef class TBang
 
     init init_tk(loc: Location)
     do
-        _text = once "!"
                _location = loc
     end
 end
 
-redef class TClassid
+redef class TBang
     redef fun parser_index: Int
     do
        return 79
     end
 
-    init init_tk(text: String, loc: Location)
+    init init_tk(loc: Location)
     do
-        _text = text
                _location = loc
     end
 end
 
-redef class TId
+redef class TClassid
     redef fun parser_index: Int
     do
        return 80
     end
 
-    init init_tk(text: String, loc: Location)
+    init init_tk(loc: Location)
     do
-        _text = text
                _location = loc
     end
 end
 
-redef class TAttrid
+redef class TId
     redef fun parser_index: Int
     do
        return 81
     end
 
-    init init_tk(text: String, loc: Location)
+    init init_tk(loc: Location)
     do
-        _text = text
                _location = loc
     end
 end
 
-redef class TNumber
+redef class TAttrid
     redef fun parser_index: Int
     do
        return 82
     end
 
-    init init_tk(text: String, loc: Location)
+    init init_tk(loc: Location)
     do
-        _text = text
                _location = loc
     end
 end
 
-redef class TFloat
+redef class TNumber
     redef fun parser_index: Int
     do
        return 83
     end
 
-    init init_tk(text: String, loc: Location)
+    init init_tk(loc: Location)
     do
-        _text = text
                _location = loc
     end
 end
 
-redef class TChar
+redef class TFloat
     redef fun parser_index: Int
     do
        return 84
     end
 
-    init init_tk(text: String, loc: Location)
+    init init_tk(loc: Location)
     do
-        _text = text
                _location = loc
     end
 end
 
-redef class TString
+redef class TChar
     redef fun parser_index: Int
     do
        return 85
     end
 
-    init init_tk(text: String, loc: Location)
+    init init_tk(loc: Location)
     do
-        _text = text
                _location = loc
     end
 end
 
-redef class TStartString
+redef class TString
     redef fun parser_index: Int
     do
        return 86
     end
 
-    init init_tk(text: String, loc: Location)
+    init init_tk(loc: Location)
     do
-        _text = text
                _location = loc
     end
 end
 
-redef class TMidString
+redef class TStartString
     redef fun parser_index: Int
     do
        return 87
     end
 
-    init init_tk(text: String, loc: Location)
+    init init_tk(loc: Location)
     do
-        _text = text
                _location = loc
     end
 end
 
-redef class TEndString
+redef class TMidString
     redef fun parser_index: Int
     do
        return 88
     end
 
-    init init_tk(text: String, loc: Location)
+    init init_tk(loc: Location)
+    do
+               _location = loc
+    end
+end
+
+redef class TEndString
+    redef fun parser_index: Int
+    do
+       return 89
+    end
+
+    init init_tk(loc: Location)
+    do
+               _location = loc
+    end
+end
+
+redef class TBadChar
+    redef fun parser_index: Int
+    do
+       return 90
+    end
+
+    init init_tk(loc: Location)
+    do
+               _location = loc
+    end
+end
+
+redef class TBadString
+    redef fun parser_index: Int
+    do
+       return 91
+    end
+
+    init init_tk(loc: Location)
     do
-        _text = text
                _location = loc
     end
 end
@@ -1176,7 +1128,7 @@ end
 redef class EOF
     redef fun parser_index: Int
     do
-       return 89
+       return 92
     end
 
     init(loc: Location)
@@ -1207,17 +1159,11 @@ class Lexer
        # Lexer current state
        var _state: Int = 0
 
-       # Name of the stream (as given to tokens)
-       readable var _filename: String
-
-       # Input stream where character are read
-       var _stream: IStream
+       # The source file
+       readable var _file: SourceFile
 
-       # Pushback buffer to store unread character
-       var _stream_buf: Buffer
-
-       # Number of character stored in the pushback buffer
-       var _stream_pos: Int
+       # Current character in the stream
+       var _stream_pos: Int = 0
 
        # Current line number in the input stream
        var _line: Int = 0
@@ -1228,23 +1174,13 @@ class Lexer
        # Was the last character a cariage-return?
        var _cr: Bool = false
 
-       # If the end of stream?
-       var _eof: Bool = false
-
-       # Current working text read from the input stream
-       var _text: Buffer
-
        # Constante state values
        private fun state_initial: Int do return 0 end
 
        # Create a new lexer for a stream (and a name)
-       init(stream: IStream, fname: String)
+       init(file: SourceFile)
        do
-               _filename = fname
-               _text = new Buffer
-               _stream = stream
-               _stream_pos = -1
-               _stream_buf = new Buffer
+               _file = file
        end
 
        # Give the next token (but do not consume it)
@@ -1272,8 +1208,12 @@ class Lexer
        do
                var dfa_state = 0
 
+               var sp = _stream_pos
+               var start_stream_pos = sp
                var start_pos = _pos
                var start_line = _line
+               var string = _file.string
+               var string_len = string.length
 
                var accept_state = -1
                var accept_token = -1
@@ -1281,34 +1221,35 @@ class Lexer
                var accept_pos = -1
                var accept_line = -1
 
-               var text = _text
-               text.clear
-
                loop
-                       var c = get_char
+                       if sp >= string_len then
+                               dfa_state = -1
+                       else
+                               var c = string[sp].ascii
+                               sp += 1
 
-                       if c != -1 then
                                var cr = _cr
                                var line = _line
                                var pos = _pos
                                if c == 10 then
                                        if cr then
                                                cr = false
+                                               _file.line_starts[line] = sp
                                        else
                                                line = line + 1
                                                pos = 0
+                                               _file.line_starts[line] = sp
                                        end
                                else if c == 13 then
                                        line = line + 1
                                        pos = 0
                                        cr = true
+                                       _file.line_starts[line] = sp
                                else
                                        pos = pos + 1
                                        cr = false
                                end
 
-                               text.add(c.ascii)
-
                                loop
                                        var old_state = dfa_state
                                        if dfa_state < -1 then
@@ -1341,8 +1282,6 @@ class Lexer
                                _cr = cr
                                _line = line
                                _pos = pos
-                       else
-                               dfa_state = -1
                        end
 
                        if dfa_state >= 0 then
@@ -1350,30 +1289,27 @@ class Lexer
                                if tok != -1 then
                                        accept_state = dfa_state
                                        accept_token = tok
-                                       accept_length = text.length
+                                       accept_length = sp - start_stream_pos
                                        accept_pos = _pos
                                        accept_line = _line
                                end
                        else
                                if accept_state != -1 then
-                                       var location = new Location(_filename, 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
-                                       push_back(accept_length)
+                                       _stream_pos = start_stream_pos + accept_length
                                        if accept_token == 0 then
                                                return null
                                        end
                                        if accept_token == 1 then
-                                               var token_text = text.substring(0, accept_length)
-                                               return new TEol.init_tk(token_text, location)
+                                               return new TEol.init_tk(location)
                                        end
                                        if accept_token == 2 then
-                                               var token_text = text.substring(0, accept_length)
-                                               return new TComment.init_tk(token_text, location)
+                                               return new TComment.init_tk(location)
                                        end
                                        if accept_token == 3 then
-                                               var token_text = text.substring(0, accept_length)
-                                               return new TKwmodule.init_tk(token_text, location)
+                                               return new TKwmodule.init_tk(location)
                                        end
                                        if accept_token == 4 then
                                                return new TKwimport.init_tk(location)
@@ -1388,8 +1324,7 @@ class Lexer
                                                return new TKwinterface.init_tk(location)
                                        end
                                        if accept_token == 8 then
-                                               var token_text = text.substring(0, accept_length)
-                                               return new TKwenum.init_tk(token_text, location)
+                                               return new TKwenum.init_tk(location)
                                        end
                                        if accept_token == 9 then
                                                return new TKwspecial.init_tk(location)
@@ -1521,132 +1456,133 @@ class Lexer
                                                return new TKwlabel.init_tk(location)
                                        end
                                        if accept_token == 52 then
-                                               return new TOpar.init_tk(location)
+                                               return new TKwdebug.init_tk(location)
                                        end
                                        if accept_token == 53 then
-                                               return new TCpar.init_tk(location)
+                                               return new TOpar.init_tk(location)
                                        end
                                        if accept_token == 54 then
-                                               return new TObra.init_tk(location)
+                                               return new TCpar.init_tk(location)
                                        end
                                        if accept_token == 55 then
-                                               return new TCbra.init_tk(location)
+                                               return new TObra.init_tk(location)
                                        end
                                        if accept_token == 56 then
-                                               return new TComma.init_tk(location)
+                                               return new TCbra.init_tk(location)
                                        end
                                        if accept_token == 57 then
-                                               return new TColumn.init_tk(location)
+                                               return new TComma.init_tk(location)
                                        end
                                        if accept_token == 58 then
-                                               return new TQuad.init_tk(location)
+                                               return new TColumn.init_tk(location)
                                        end
                                        if accept_token == 59 then
-                                               return new TAssign.init_tk(location)
+                                               return new TQuad.init_tk(location)
                                        end
                                        if accept_token == 60 then
-                                               return new TPluseq.init_tk(location)
+                                               return new TAssign.init_tk(location)
                                        end
                                        if accept_token == 61 then
-                                               return new TMinuseq.init_tk(location)
+                                               return new TPluseq.init_tk(location)
                                        end
                                        if accept_token == 62 then
-                                               return new TDotdotdot.init_tk(location)
+                                               return new TMinuseq.init_tk(location)
                                        end
                                        if accept_token == 63 then
-                                               return new TDotdot.init_tk(location)
+                                               return new TDotdotdot.init_tk(location)
                                        end
                                        if accept_token == 64 then
-                                               return new TDot.init_tk(location)
+                                               return new TDotdot.init_tk(location)
                                        end
                                        if accept_token == 65 then
-                                               return new TPlus.init_tk(location)
+                                               return new TDot.init_tk(location)
                                        end
                                        if accept_token == 66 then
-                                               return new TMinus.init_tk(location)
+                                               return new TPlus.init_tk(location)
                                        end
                                        if accept_token == 67 then
-                                               return new TStar.init_tk(location)
+                                               return new TMinus.init_tk(location)
                                        end
                                        if accept_token == 68 then
-                                               return new TSlash.init_tk(location)
+                                               return new TStar.init_tk(location)
                                        end
                                        if accept_token == 69 then
-                                               return new TPercent.init_tk(location)
+                                               return new TSlash.init_tk(location)
                                        end
                                        if accept_token == 70 then
-                                               return new TEq.init_tk(location)
+                                               return new TPercent.init_tk(location)
                                        end
                                        if accept_token == 71 then
-                                               return new TNe.init_tk(location)
+                                               return new TEq.init_tk(location)
                                        end
                                        if accept_token == 72 then
-                                               return new TLt.init_tk(location)
+                                               return new TNe.init_tk(location)
                                        end
                                        if accept_token == 73 then
-                                               return new TLe.init_tk(location)
+                                               return new TLt.init_tk(location)
                                        end
                                        if accept_token == 74 then
-                                               return new TLl.init_tk(location)
+                                               return new TLe.init_tk(location)
                                        end
                                        if accept_token == 75 then
-                                               return new TGt.init_tk(location)
+                                               return new TLl.init_tk(location)
                                        end
                                        if accept_token == 76 then
-                                               return new TGe.init_tk(location)
+                                               return new TGt.init_tk(location)
                                        end
                                        if accept_token == 77 then
-                                               return new TGg.init_tk(location)
+                                               return new TGe.init_tk(location)
                                        end
                                        if accept_token == 78 then
-                                               return new TStarship.init_tk(location)
+                                               return new TGg.init_tk(location)
                                        end
                                        if accept_token == 79 then
-                                               return new TBang.init_tk(location)
+                                               return new TStarship.init_tk(location)
                                        end
                                        if accept_token == 80 then
-                                               var token_text = text.substring(0, accept_length)
-                                               return new TClassid.init_tk(token_text, location)
+                                               return new TBang.init_tk(location)
                                        end
                                        if accept_token == 81 then
-                                               var token_text = text.substring(0, accept_length)
-                                               return new TId.init_tk(token_text, location)
+                                               return new TClassid.init_tk(location)
                                        end
                                        if accept_token == 82 then
-                                               var token_text = text.substring(0, accept_length)
-                                               return new TAttrid.init_tk(token_text, location)
+                                               return new TId.init_tk(location)
                                        end
                                        if accept_token == 83 then
-                                               var token_text = text.substring(0, accept_length)
-                                               return new TNumber.init_tk(token_text, location)
+                                               return new TAttrid.init_tk(location)
                                        end
                                        if accept_token == 84 then
-                                               var token_text = text.substring(0, accept_length)
-                                               return new TFloat.init_tk(token_text, location)
+                                               return new TNumber.init_tk(location)
                                        end
                                        if accept_token == 85 then
-                                               var token_text = text.substring(0, accept_length)
-                                               return new TChar.init_tk(token_text, location)
+                                               return new TFloat.init_tk(location)
                                        end
                                        if accept_token == 86 then
-                                               var token_text = text.substring(0, accept_length)
-                                               return new TString.init_tk(token_text, location)
+                                               return new TChar.init_tk(location)
                                        end
                                        if accept_token == 87 then
-                                               var token_text = text.substring(0, accept_length)
-                                               return new TStartString.init_tk(token_text, location)
+                                               return new TString.init_tk(location)
                                        end
                                        if accept_token == 88 then
-                                               var token_text = text.substring(0, accept_length)
-                                               return new TMidString.init_tk(token_text, location)
+                                               return new TStartString.init_tk(location)
                                        end
                                        if accept_token == 89 then
-                                               var token_text = text.substring(0, accept_length)
-                                               return new TEndString.init_tk(token_text, location)
+                                               return new TMidString.init_tk(location)
+                                       end
+                                       if accept_token == 90 then
+                                               return new TEndString.init_tk(location)
+                                       end
+                                       if accept_token == 91 then
+                                               return new TBadChar.init_tk(location)
+                                       end
+                                       if accept_token == 92 then
+                                               return new TBadString.init_tk(location)
                                        end
                                else
-                                       var location = new Location(_filename, start_line + 1, start_line + 1, start_pos + 1, start_pos + 1)
-                                       if text.length > 0 then
+                                       _stream_pos = sp
+                                       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)
                                                return token
                                        else
@@ -1657,45 +1593,5 @@ class Lexer
                        end
                end
        end
-
-       # Read the next character.
-       # The character is read from the stream of from the pushback buffer.
-       private fun get_char: Int
-       do
-               if _eof then
-                       return -1
-               end
-
-               var result: Int
-
-               var sp = _stream_pos
-               if sp >= 0 then
-                       var res = _stream_buf[_stream_pos]
-                       _stream_pos = sp - 1
-                       result = res.ascii
-               else
-                       result = _stream.read_char
-               end
-
-               if result == -1 then
-                       _eof = true
-               end
-
-               return result
-       end
-
-       # Unread some characters.
-       # Unread characters are stored in the pushback buffer.
-       private fun push_back(accept_length: Int)
-       do
-               var length = _text.length
-               var i = length - 1
-               while i >= accept_length do
-                       _eof = false
-                       _stream_pos = _stream_pos + 1
-                       _stream_buf[_stream_pos] = _text[i]
-                       i = i - 1
-               end
-       end
 end