Ejemplo n.º 1
0
    def parse(self):
        """ Parse the document layout.

        To get the results, use the following properties:
            - root_node
            - variables
            - paragraphs
        """
        # preview in preferences dialog have no file path
        if not self.editor.filePath:
            return
        root_node = None
        variables = []
        paragraphs = []
        try:
            root_node, variables, paragraphs = parse_ast(self.editor.filePath, encoding=self.editor.fileEncoding)
        except (TypeError, IOError):
            # file does not exists
            pass
        except AttributeError:
            # this should never happen but we must exit gracefully
            logging.exception("Failed to parse document, probably due to " "a malformed syntax.")
        changed = False
        if self.__root_node is None or cmp_doc_node(root_node, self.__root_node):
            changed = True
        self.__root_node = root_node
        self.__vars = variables
        self.__paragraphs = paragraphs
        if changed:
            self.documentLayoutChanged.emit(self.root_node)
Ejemplo n.º 2
0
def test_free_parser():
    """
    HelloWorld.cbl and HelloWorldFree.cbl must have the same ast.
    """
    non_free_ast, non_free_vars, non_free_procs = parser.parse_ast(
        "test/testfiles/HelloWorld.cbl")
    free_ast, free_vars, free_procs = parser.parse_ast("test/testfiles/HelloWorldFree.cbl",
                                                       free=True)
    result = parser.cmp_doc_node(non_free_ast, free_ast)
    assert result == 0  # 0 means same statement.