1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Ad-hoc hand-writen lexer for nitcc
16 # This avoid to commit (and relyon ) a generated lexer
20 # Required for the tokens definitions
23 # Hand-writen lexer of nitcc
24 # Used only for the boostrap of the tool.
28 var iter
: Iterator[Char] = "".iterator
31 var tokens
= new Array[NToken]
33 fun lex
: Array[NToken]
38 if not iter
.is_ok
then break
49 if iter
.item
== '>' then
73 else if c
== '\'' then
75 else if c >= 'a
' and c <= 'z
' then
77 else if c >= 'A
' and c <= 'Z
' then
79 else if c == '/' and iter.is_ok and iter.item == '/' then
80 while iter.is_ok and iter.item != '\n
' do iter.next
91 print "pos {pos}: Lexer error on '{c}'."
103 if not iter
.is_ok
then
109 else if c
== '\'' then
128 if c != '_
' and (c<'a
' or c >'z
') and (c<'0' or c>'9') then
145 if c != '_
' and (c<'a
' or c >'z
') and (c<'0' or c>'9') then
158 while iter.is_ok and iter.item <= ' ' do