# Generate the Nit source code of the lexer
# `filepath` is the name of the ouptit file
# `parser` is the name of the parser module (used to import the token classes)
- fun gen_to_nit(filepath: String, parser: nullable String)
+ fun gen_to_nit(filepath: String, name: String, parser: nullable String)
do
- var gen = new DFAGenerator(filepath, self, parser)
+ var gen = new DFAGenerator(filepath, name, self, parser)
gen.gen_to_nit
end
end
# Generate the Nit source code of the lexer
private class DFAGenerator
var filepath: String
+ var name: String
var automaton: Automaton
var parser: nullable String
var out: OStream
- init(filepath: String, automaton: Automaton, parser: nullable String) do
+ init(filepath: String, name: String, automaton: Automaton, parser: nullable String) do
self.filepath = filepath
+ self.name = name
self.automaton = automaton
self.parser = parser
self.out = new OFStream.open(filepath)
i += 1
end
- add "# Lexer generated by nitcc"
+ add "# Lexer generated by nitcc for the grammar {name}"
add("import nitcc_runtime\n")
var p = parser
if p != null then add("import {p}\n")
- add("class MyLexer\n")
+ add("class Lexer_{name}\n")
add("\tsuper Lexer\n")
add("\tredef fun start_state do return dfastate_{names[automaton.start]}\n")
add("end\n")