示例#1
0
    def loadFromJson(self, filename):
        manager = JsonManager()
        language_boxes = manager.load(filename)

        self.tm = TreeManager()

        self.tm.load_file(language_boxes)
        self.reset()
示例#2
0
    def loadFromJson(self, filename):
        manager = JsonManager()
        language_boxes = manager.load(filename)

        self.tm = TreeManager()

        self.tm.load_file(language_boxes)
        self.reset()
示例#3
0
 def saveToJson(self, filename, swap=False):
     whitespaces = self.tm.get_mainparser().whitespaces
     root = self.tm.parsers[0][0].previous_version.parent
     language = self.tm.parsers[0][2]
     manager = JsonManager()
     manager.save(root, language, whitespaces, filename)
     if not swap:
         self.tm.changed = False
         self.emit(SIGNAL("painted()"))
示例#4
0
 def saveToJson(self, filename, swap=False):
     whitespaces = self.tm.get_mainparser().whitespaces
     root = self.tm.parsers[0][0].previous_version.parent
     language = self.tm.parsers[0][2]
     manager = JsonManager()
     manager.save(root, language, whitespaces, filename)
     if not swap:
         self.tm.changed = False
         self.emit(SIGNAL("painted()"))
示例#5
0
文件: grammars.py 项目: snim2/eco
    def load(self):
        from grammar_parser.bootstrap import BootstrapParser
        from jsonmanager import JsonManager

        if _cache.has_key(self.name + "::parser"):

            root, language, whitespaces = _cache[self.name + "::json"]

            # parse rules as they are needed by the incremental parser to
            # detect comments

            manager = JsonManager(unescape=True)
            root, language, whitespaces = manager.load(self.filename)[0]

            pickle_id = hash(self)
            bootstrap = BootstrapParser(lr_type=1, whitespaces=whitespaces)
            bootstrap.ast = root
            bootstrap.parse_rules(root.children[1].children[1].children[0])

            pickle_id, whitespace = _cache[self.name + "::parser"]
            from incparser.incparser import IncParser
            incparser = IncParser()
            incparser.from_dict(bootstrap.rules, None, None, whitespace, pickle_id, None)
            incparser.init_ast()

            inclexer = _cache[self.name + "::lexer"]
            incparser.lexer = inclexer # give parser a reference to its lexer (needed for multiline comments)

            return (incparser, inclexer)
        else:
            manager = JsonManager(unescape=True)
            root, language, whitespaces = manager.load(self.filename)[0]

            pickle_id = hash(self)
            bootstrap = BootstrapParser(lr_type=1, whitespaces=whitespaces)
            bootstrap.ast = root
            bootstrap.extra_alternatives = self.alts
            bootstrap.change_startrule = self.extract
            bootstrap.read_options()

            bootstrap.create_parser(pickle_id)
            whitespace = bootstrap.implicit_ws()

            bootstrap.create_lexer()

            _cache[self.name + "::lexer"] = bootstrap.inclexer
            _cache[self.name + "::json"] = (root, language, whitespaces)
            _cache[self.name + "::parser"] = (pickle_id, whitespace)

            bootstrap.incparser.lexer = bootstrap.inclexer
            return (bootstrap.incparser, bootstrap.inclexer)
示例#6
0
    def load_nb_file(self, filename):
        from jsonmanager import JsonManager
        from grammars.grammars import lang_dict

        manager = JsonManager(unescape=True)

        # load nb file
        root, language, whitespaces = manager.load(filename)[0]

        # load scoping grammar
        grammar = lang_dict[language]
        parser, lexer = grammar.load()
        parser.previous_version.parent = root
        parser.reparse()
        return parser.previous_version.parent
示例#7
0
    def load_nb_file(self, filename):
        from jsonmanager import JsonManager
        from grammar_parser.bootstrap import BootstrapParser
        from grammars.grammars import lang_dict

        manager = JsonManager(unescape=True)

        # load nb file
        root, language, whitespaces = manager.load(filename)[0]

        # load scoping grammar
        grammar = lang_dict[language]
        parser, lexer = grammar.load()
        parser.previous_version.parent = root
        parser.reparse()
        return parser.previous_version.parent
示例#8
0
    def load(self, buildlexer=True):
        from grammar_parser.bootstrap import BootstrapParser
        from jsonmanager import JsonManager
        from incparser.incparser import IncParser

        if self.name + "::parser" in _cache:

            syntaxtable, whitespaces = _cache[self.name + "::parser"]
            incparser = IncParser()
            incparser.syntaxtable = syntaxtable
            incparser.whitespaces = whitespaces
            incparser.init_ast()
            incparser.lang = self.name

            inclexer = _cache[self.name + "::lexer"]
            incparser.lexer = inclexer  # give parser a reference to its lexer (needed for multiline comments)
            incparser.previous_version.parent.name = self.name

            return (incparser, inclexer)
        else:
            manager = JsonManager(unescape=True)
            root, language, whitespaces = manager.load(self.filename)[0]

            bootstrap = BootstrapParser(lr_type=1, whitespaces=whitespaces)
            bootstrap.ast = root
            bootstrap.extra_alternatives = self.alts
            bootstrap.change_startrule = self.extract
            bootstrap.read_options()
            whitespace = bootstrap.implicit_ws()

            pickle_id = self.pickleid(whitespace)

            bootstrap.parse_both()
            bootstrap.create_parser(pickle_id)
            bootstrap.create_lexer(buildlexer)

            _cache[self.name + "::lexer"] = bootstrap.inclexer
            _cache[self.name + "::json"] = (root, language, whitespaces)
            _cache[self.name + "::parser"] = (bootstrap.incparser.syntaxtable,
                                              whitespace)

            bootstrap.incparser.lang = self.name
            bootstrap.incparser.previous_version.parent.name = self.name
            bootstrap.incparser.lexer = bootstrap.inclexer
            return (bootstrap.incparser, bootstrap.inclexer)
示例#9
0
文件: eco.py 项目: willemneal/eco
    def cli_export(self, source, dest, fast):
        print("Exporting...")
        print("    Source: %s" % source)
        print("    Destination: %s" % dest)

        from jsonmanager import JsonManager
        manager = JsonManager()
        language_boxes = manager.load(source)

        from treemanager import TreeManager
        self.tm = TreeManager()

        if fast:
            self.tm.fast_export(language_boxes, dest)
        else:
            self.tm.load_file(language_boxes)
            self.tm.export(dest)
        QApplication.quit()
        sys.exit(1)
示例#10
0
    def load(self):
        from grammar_parser.bootstrap import BootstrapParser
        from jsonmanager import JsonManager

        if _cache.has_key(self.name + "::parser"):

            root, language, whitespaces = _cache[self.name + "::json"]

            pickle_id, whitespace = _cache[self.name + "::parser"]
            from incparser.incparser import IncParser
            incparser = IncParser()
            incparser.from_dict(None, None, None, whitespace, pickle_id, None)
            incparser.init_ast()

            inclexer = _cache[self.name + "::lexer"]

            return (incparser, inclexer)
        else:
            manager = JsonManager(unescape=True)
            root, language, whitespaces = manager.load(self.filename)[0]

            pickle_id = hash(self)
            bootstrap = BootstrapParser(lr_type=1, whitespaces=whitespaces)
            bootstrap.ast = root
            bootstrap.extra_alternatives = self.alts
            bootstrap.change_startrule = self.extract
            bootstrap.read_options()

            bootstrap.create_parser(pickle_id)
            whitespace = bootstrap.implicit_ws()

            bootstrap.create_lexer()

            _cache[self.name + "::lexer"] = bootstrap.inclexer
            _cache[self.name + "::json"] = (root, language, whitespaces)
            _cache[self.name + "::parser"] = (pickle_id, whitespace)
            return (bootstrap.incparser, bootstrap.inclexer)
示例#11
0
    def load(self):
        from grammar_parser.bootstrap import BootstrapParser
        from jsonmanager import JsonManager

        if _cache.has_key(self.name + "::parser"):

            root, language, whitespaces = _cache[self.name + "::json"]

            # parse rules as they are needed by the incremental parser to
            # detect comments

            manager = JsonManager(unescape=True)
            root, language, whitespaces = manager.load(self.filename)[0]

            pickle_id = hash(self)
            bootstrap = BootstrapParser(lr_type=1, whitespaces=whitespaces)
            bootstrap.ast = root
            bootstrap.parse_rules(root.children[1].children[1].children[0])

            pickle_id, whitespace = _cache[self.name + "::parser"]
            from incparser.incparser import IncParser
            incparser = IncParser()
            incparser.from_dict(bootstrap.rules, None, None, whitespace,
                                pickle_id, None)
            incparser.init_ast()

            inclexer = _cache[self.name + "::lexer"]
            incparser.lexer = inclexer  # give parser a reference to its lexer (needed for multiline comments)

            return (incparser, inclexer)
        else:
            manager = JsonManager(unescape=True)
            root, language, whitespaces = manager.load(self.filename)[0]

            pickle_id = hash(self)
            bootstrap = BootstrapParser(lr_type=1, whitespaces=whitespaces)
            bootstrap.ast = root
            bootstrap.extra_alternatives = self.alts
            bootstrap.change_startrule = self.extract
            bootstrap.read_options()

            bootstrap.parse_both()
            bootstrap.create_parser(pickle_id)
            bootstrap.create_lexer()
            whitespace = bootstrap.implicit_ws()

            _cache[self.name + "::lexer"] = bootstrap.inclexer
            _cache[self.name + "::json"] = (root, language, whitespaces)
            _cache[self.name + "::parser"] = (pickle_id, whitespace)

            bootstrap.incparser.lexer = bootstrap.inclexer
            return (bootstrap.incparser, bootstrap.inclexer)
示例#12
0
    printClient(printer, ticket)
    printCompany(printer, ticket)
    print("Gerou senha " + str(ticket) + " em " +
          now.strftime("%d/%m/%Y as %H:%M:%S"))

    # salva ticket gerado e hora
    _json.set("ticket", ticket)
    _json.set("data", str(now))
    ticket += 1

    tcflush(sys.stdin, TCIFLUSH)


if __name__ == "__main__":
    time.sleep(5)  # espera o sistema terminar de acordar
    _json = JsonManager("contador")
    ticket = _json.get("ticket") + 1
    printerpath = _json.get("printer")
    print("O programa se conectara com a impressora no caminho \"" +
          printerpath + "\".")

    printer = Printer(printerpath)

    print("Pressione enter para gerar proximas senhas (proxima: %d)" % ticket)

    hello_world(printer)

    lastenter = time.time()
    keyboard.on_press(kbevent)

    while True: