nitlanguage
/
nit.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge: Portable stack-traces
[nit.git]
/
contrib
/
nitcc
/
src
/
nitcc_lexer0.nit
diff --git
a/contrib/nitcc/src/nitcc_lexer0.nit
b/contrib/nitcc/src/nitcc_lexer0.nit
index
50d590e
..
f3ff58d
100644
(file)
--- a/
contrib/nitcc/src/nitcc_lexer0.nit
+++ b/
contrib/nitcc/src/nitcc_lexer0.nit
@@
-12,27
+12,32
@@
# See the License for the specific language governing permissions and
# limitations under the License.
# See the License for the specific language governing permissions and
# limitations under the License.
-# Ad-hoc hand-writen lexer for nitcc
-# This avoid to commit (and relyon ) a generated lexer
-#
+# Ad-hoc hand-written lexer for nitcc
+# This avoid to commit (and rely on) a generated lexer
module nitcc_lexer0
# Required for the tokens definitions
import nitcc_parser
module nitcc_lexer0
# Required for the tokens definitions
import nitcc_parser
-# Hand-writen lexer of nitcc
-# Used only for the boostrap of the tool.
-class MyLexer
+# Hand-written lexer of nitcc.
+# Used only for the bootstrap of the tool.
+class Lexer_nitcc
+ # The text to tokenize
var text: String
var text: String
- var iter: Iterator[Char] = "".iterator
+ # The iterator on text
+ private var iter: Iterator[Char] is noinit
+
+ # The current position
var pos = 0
var pos = 0
- var tokens = new Array[NToken]
+ # The tokens currently produced
+ private var tokens = new Array[NToken]
+ # Tokenize and returns the tokens
fun lex: Array[NToken]
do
fun lex: Array[NToken]
do
- iter = text.iterator
+ iter = text.chars.iterator
while iter.is_ok do
trim
if not iter.is_ok then break
while iter.is_ok do
trim
if not iter.is_ok then break
@@
-62,6
+67,8
@@
class MyLexer
tokens.add new Nccur
else if c == '|' then
tokens.add new Npipe
tokens.add new Nccur
else if c == '|' then
tokens.add new Npipe
+ else if c == ',' then
+ tokens.add new Ncomma
else if c == ':' then
tokens.add new Ncolo
else if c == ';' then
else if c == ':' then
tokens.add new Ncolo
else if c == ';' then
@@
-86,15
+93,15
@@
class MyLexer
return tokens
end
return tokens
end
- fun error(c: Char)
+ private fun error(c: Char)
do
print "pos {pos}: Lexer error on '{c}'."
abort
end
do
print "pos {pos}: Lexer error on '{c}'."
abort
end
- fun str
+ private fun str
do
do
- var b = new Buffer
+ var b = new FlatBuffer
b.add('\'')
while iter.is_ok do
var c = iter.item
b.add('\'')
while iter.is_ok do
var c = iter.item
@@
-119,9
+126,9
@@
class MyLexer
abort
end
abort
end
- fun id(c: Char)
+ private fun id(c: Char)
do
do
- var b = new Buffer
+ var b = new FlatBuffer
b.add c
while iter.is_ok do
c = iter.item
b.add c
while iter.is_ok do
c = iter.item
@@
-136,9
+143,9
@@
class MyLexer
tokens.add token
end
tokens.add token
end
- fun kw(c: Char)
+ private fun kw(c: Char)
do
do
- var b = new Buffer
+ var b = new FlatBuffer
b.add c
while iter.is_ok do
c = iter.item
b.add c
while iter.is_ok do
c = iter.item
@@
-153,7
+160,7
@@
class MyLexer
tokens.add token
end
tokens.add token
end
- fun trim
+ private fun trim
do
while iter.is_ok and iter.item <= ' ' do
iter.next
do
while iter.is_ok and iter.item <= ' ' do
iter.next