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.
def test_paragraphes(): """ Test printer must have 2 procedures """ ast, vars, procs = parser.parse_ast("test/testfiles/TEST-PRINTER.cbl") # 1 procedure assert len(procs) == 2
def test_variables(): """ Virtual printer must have 8 vars """ ast, vars, procs = parser.parse_ast("test/testfiles/VIRTUAL-PRINTER.cbl") # 8 variables assert len(vars) == 8
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)
def test_parse_pco(): """ Parses a pco file, which contains characters in column 1-6 (see bug #23) """ ast, vars, procs = parser.parse_ast("test/testfiles/HelloWorld.pco") # 4 divs assert len(ast.children) == 4 # 2 sections in env div assert len(ast.children[1].children) == 2 # 2 sections in data div assert len(ast.children[2].children) == 2 assert len(vars) == 0 assert len(procs) == 1
def test_malformed(): """ Parses the hello world example """ ast, vars, procs = parser.parse_ast("test/testfiles/MALFORMED.cbl") # 4 divs assert len(ast.children) == 4 # 2 sections in env div assert len(ast.children[0].children) == 2 # 2 sections in data div assert len(ast.children[1].children) == 2 assert len(vars) == 0 assert len(procs) == 1
def test_parse_ast(): """ Parses the hello world example """ ast, vars, procs = parser.parse_ast("test/testfiles/HelloWorld.cbl") # 4 divs assert len(ast.children) == 4 # 2 sections in env div assert len(ast.children[1].children) == 2 # 2 sections in data div assert len(ast.children[2].children) == 2 assert len(vars) == 0 assert len(procs) == 1
def complete(self, code, line, column, completionPrefix, filePath, fileEncoding): completions = [] try: root, vars, functions = parse_ast( filePath, code=code, encoding=fileEncoding) except AttributeError: vars = [] functions = [] for var in vars: completions.append(pyqode.core.Completion( var.name, icon=constants.ICON_VAR, tooltip=var.description)) for func in functions: completions.append(pyqode.core.Completion( func.name, icon=constants.ICON_PARAGRAPH)) completions += self.__keywordsCompletions return completions