Example #1
0
 def get_parent(self):
     with open(self.pth_langlet.joinpath("langlet_config.py")) as f:
         source = f.read()
         m = p_parent.search(source)
         parent_name = m.group("name") if m else ''
         if parent_name:
             parent_path, m = find_langlet(parent_name)
             return parent_name, m.__file__
     return '', ''
Example #2
0
 def get_parent(self):
     with open(self.pth_langlet.joinpath("langlet_config.py")) as f:
         source = f.read()
         m = p_parent.search(source)
         parent_name = m.group("name") if m else ''
         if parent_name:
             parent_path, m = find_langlet(parent_name)
             return parent_name, m.__file__
     return '', ''
Example #3
0
    def create_langlet_data(self, pth_langlet_py):
        from langscape.base.grammar_gen import ParserGrammar, LexerGrammar

        LexerGrammar(self.name, pth_langlet_py, {"build_langlet": True}).load_grammar()
        ParserGrammar(self.name, pth_langlet_py, {"build_langlet": True}).load_grammar()

        module_path, langlet = loader.find_langlet(self.name)
        langlet_obj = langlet.Langlet()
        langlet_obj.package = loader.get_package(module_path)
        loader.load_nfas(langlet.Langlet(), True, True)
Example #4
0
    def create_files(self):
        self.update_options()
        if self.options["location"]:
            loc = path(self.options["location"])
            if loc.basename() != self.name:
                pth_langlet = loc.joinpath(self.name)
            else:
                pth_langlet = loc
        else:
            pth_langlet = langlets_path.joinpath(self.name)

        self.new_langlet_pth = pth_langlet
        if pth_langlet.exists():
            raise IOError("Langlet directory already exists: '%s'"%pth_langlet)
        try:
            pth_langlet_module = pth_langlet.joinpath("langlet.py")

            count  = self.create_new_langlet_counter()
            lnlt_id = count*(10**4)

            pth_template = parent_path.joinpath("langlet_template")
            pth_conf = pth_template.joinpath("langlet_config.strtempl")

            pth_langlet_py = pth_template.joinpath("langlet.strtempl")
            langlet_py = ""

            pth_template.copytree(pth_langlet)

            if self.options["parent"]:
                parent_langlet   = path(loader.find_langlet(self.options["parent"])[1].__file__).dirname()
                grammar_gen_path = parent_langlet.joinpath("parsedef", "GrammarGen.g")
                grammar_gen_path.copy(pth_langlet.joinpath("parsedef", "GrammarBase.g"))
                token_gen_path = parent_langlet.joinpath("lexdef", "TokenGen.g")
                token_gen_path.copy(pth_langlet.joinpath("lexdef", "TokenBase.g"))

            # operate on destination folder...
            pth_conf = pth_langlet.joinpath("langlet_config.py")
            pth_conf_template = pth_langlet.joinpath("langlet_config.strtempl")
            with open(pth_conf,"w") as f_conf:
                f_conf.write(self.create_langlet_config_py(lnlt_id, pth_conf_template))
            pth_langlet.joinpath("run.py").rename(pth_langlet.joinpath("run_"+self.name+".py"))
            pth_langlet.joinpath("langlet_config.strtempl").remove()

            # update LANGLET_ID in lex_token.py
            pth_lex_token = pth_langlet.joinpath("lexdef","lex_token.py")
            pth_lex_token_template = path(pth_lex_token.replace(".py",".strtempl"))
            with open(pth_lex_token, "w") as f_lex:
                f_lex.write(self.update_lex_token(lnlt_id, pth_lex_token_template))

            self.create_langlet_data(pth_conf)
            pth_lex_token_template.remove()
        except Exception, e:
            print get_traceback()
            self.new_langlet_pth.rmtree()
            exit(2)
Example #5
0
 def update_options(self):
     '''
     Overrides empty options settings by parent options.
     '''
     if self.options["parent"]:
         pth, module = loader.find_langlet(self.options["parent"])
         if self.options["prompt"] == "> ":
             self.options["prompt"] = module.config.prompt
         if self.options["target"] == "":
             self.options["target"] = module.config.target_langlet
         if self.options["source_ext"] == "":
             self.options["source_ext"] = module.config.source_ext
         if self.options["compiled_ext"] == "":
             self.options["compiled_ext"] = module.config.compiled_ext
         if self.options["target_compiler"] == "":
             self.options["target_compiler"] = module.config.target_compiler
     if self.options["target"] == "":
         self.options["target"] = self.name