nitcc: better name of generated classes to avoid name conflicts
[nit.git] / contrib / nitcc / src / autom.nit
index 2d1ca78..86befbb 100644 (file)
@@ -393,9 +393,9 @@ class Automaton
        # 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
@@ -403,12 +403,14 @@ 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)
@@ -425,13 +427,13 @@ private class DFAGenerator
                        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")