def run_poodle_lex(self, language): output_dir = tempfile.mkdtemp() rules_file_path = os.path.join(base_directory, "Example", "CLexer", "CLexer.rules") rules_file = RulesFile.Parser.parse(rules_file_path, "utf-8") rules_file.accept(RulesFile.Traverser(RulesFile.Validator())) nfa_ir = RulesFile.NonDeterministicIR(rules_file) dfa_ir = RulesFile.DeterministicIR(nfa_ir) plugin_file_path = os.path.join(base_directory, "Plugins/Plugins.json") language_plugins, default_language = LanguagePlugins.load(plugin_file_path, 'utf-8') language_plugins[language].load() language_plugin = language_plugins[language] representation = dfa_ir if language_plugin.default_form == LanguagePlugins.PluginOptions.NFA_IR: representation = nfa_ir plugin_options = LanguagePlugins.PluginOptions() emitter = language_plugin.create(representation, plugin_options) executor = LanguagePlugins.Executor(emitter, language_plugin.plugin_files_directory, output_dir) executor.execute() return output_dir
form = LanguagePlugins.PluginOptions.NFA_IR elif arguments.form == "dfa": form = LanguagePlugins.PluginOptions.DFA_IR if form not in language_plugin.forms: raise Exception("Specified state machine form '{0}' not supported by language plugin".format(arguments.form)) ir = RulesFile.NonDeterministicIR(rules_file) if form == LanguagePlugins.PluginOptions.DFA_IR: ir = RulesFile.DeterministicIR(ir, minimizer) except Exception as e: print("Error processing rules. %s" % str(e), file=sys.stderr) sys.exit(1) # Emit output try: plugin_options = LanguagePlugins.PluginOptions() plugin_options.class_name = arguments.class_name plugin_options.namespace = arguments.namespace plugin_options.file_name = arguments.file_name plugin_options.form = form emitter = language_plugin.create(ir, plugin_options) if os.path.normcase(os.path.realpath(arguments.OUTPUT_DIR)) == this_folder: print("Output directory cannot be same as executable directory", file=sys.stderr) sys.exit(1) executor = LanguagePlugins.Executor(emitter, language_plugin.plugin_files_directory, arguments.OUTPUT_DIR) executor.execute() except IOError as e: print("Unable to write to output directory because of an error", file=sys.stderr) sys.exit(1)