Esempio n. 1
0
 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
Esempio n. 2
0
    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)
    
except Exception as e:
    print("Unable to create lexical analyzer: %s" % str(e))
    sys.exit(1)