def __init__(self, children): objs = [] builtin = None extranodes = [] for filenode in children: if filenode.GetProperty('NAME') == 'pp_stdint.idl': builtin = filenode break IDLNode.__init__(self, 'AST', 'BuiltIn', 1, 0, extranodes + children) self.Resolve()
def main(argv): nodes = [] parser = IDLParser(IDLLexer()) errors = 0 for filename in argv: filenode = ParseFile(parser, filename) errors += filenode.GetProperty('ERRORS') nodes.append(filenode) ast = IDLNode('AST', '__AST__', 0, 0, nodes) print '\n'.join(ast.Tree(accept_props=['PROD'])) if errors: print '\nFound %d errors.\n' % errors return errors
def p_top_short(self, p): """top : COMMENT ext_attr_block top_list""" Copyright = self.BuildComment('Copyright', p, 1) Filedoc = IDLNode('Comment', self.lexobj.filename, p.lineno(2)-1, p.lexpos(2)-1, [self.BuildAttribute('NAME', ''), self.BuildAttribute('FORM', 'cc')]) p[0] = ListFromConcat(Copyright, Filedoc, p[2], p[3]) if self.parse_debug: DumpReduction('top', p)
def BuildProduction(self, cls, p, index, childlist=None): if not childlist: childlist = [] filename = self.lexobj.filename lineno = p.lineno(index) pos = p.lexpos(index) out = IDLNode(cls, filename, lineno, pos, childlist) if self.build_debug: InfoOut.Log("Building %s" % out) return out
def ParseText(self, filename, data): self._parse_errors = 0 self._parse_warnings = 0 self._last_error_msg = None self._last_error_lineno = 0 self._last_error_pos = 0 try: self.lexer.Tokenize(data, filename) nodes = self.yaccobj.parse(lexer=self.lexer) or [] name = self.BuildAttribute('NAME', filename) return IDLNode('File', filename, 0, 0, nodes + [name]) except lex.LexError as lexError: sys.stderr.write('Error in token: %s\n' % str(lexError)) return None
def BuildProduction(self, cls, p, index, childlist=None): try: if not childlist: childlist = [] filename = self.lexer.Lexer().filename lineno = p.lineno(index) pos = p.lexpos(index) out = IDLNode(cls, filename, lineno, pos, childlist) return out except: print 'Exception while parsing:' for num, item in enumerate(p): print ' [%d] %s' % (num, ExpandProduction(item)) if self.LastToken(): print 'Last token: %s' % str(self.LastToken()) raise
def __init__(self, children): IDLNode.__init__(self, 'AST', 'BuiltIn', 1, 0, children) self.Resolve()