$ foreach {//token}
$ if {@parser_index}
class @ename
-special Token
+ super Token
end
$ end
$ end
class EOF
-special Token
-private init noinit do end
+ super Token
end
class PError
-special EOF
-private init noinit do end
+ super EOF
+end
+class PLexerError
+ super PError
+end
+class PParserError
+ super PError
end
$ end template
$ template make_tokens()
-
-redef class Token
- readable var _text: String
-
- fun parser_index: Int is abstract
-
- redef fun to_s: String do
- return "'{_text}'"
- end
-end
-
$ foreach {//token}
$ if {@parser_index}
redef class @ename
return @parser_index
end
-$ if {not(@text)}
- init init_tk(text: String, loc: Location)
- do
- _text = text
-$ else
init init_tk(loc: Location)
do
- _text = once "${sablecc:string2escaped_unicode(@text)}"
-$ end
_location = loc
end
end
do
return ${tokens/eof/@parser_index}
end
-
- init(loc: Location)
- do
- _text = ""
- _location = loc
- end
-end
-
-redef class PError
- readable var _message: String
-
- init init_error(message: String, loc: Location)
- do
- init(loc)
- _message = message
- end
end
$ end template