def _parse_type_node(xml): ret = [] for child in xml.children(): if child.name == '#text': ret.extend(list(cpplex.tokenize(child.node.nodeValue))) elif child.name == 'ref': xref = create_item_ref(child['@refid']) ret.append(xref) return ret
def is_enum_class(xml): # FIXME: Make 'enum class' detection more robust filename = xml['@file'] line = int(xml['@line']) if not filename in _file_cache.keys(): with open(filename) as f: _file_cache[filename] = f.read().split('\n') tokens = [x for x in list(cpplex.tokenize(_file_cache[filename][line - 2])) if not isinstance(x, cpplex.WhiteSpace)] if tokens[0].value != 'enum': raise Exception('Expected an enum declaration.') return tokens[1].value == 'class'
def run(text, result): global passed global failed try: got = repr(list(cpplex.tokenize(text))) except Exception as e: got = repr(e) expected = repr(result) if expected == got: passed = passed + 1 else: print("%s test %s failed -- expected %s, got %s" % (parser.__name__, repr(text), expected, got)) failed = failed + 1
def signature(item, scope): ret = [] if isinstance(item, Variable) or isinstance(item, Function): if item.kind == 'typedef': ret.append(cpplex.Keyword(item.kind)) ret.append(cpplex.WhiteSpace(' ')) ret.extend(item.vartype) ret.append(cpplex.WhiteSpace(' ')) elif item.kind == 'enumclass': ret.append(cpplex.Keyword('enum')) ret.append(cpplex.WhiteSpace(' ')) ret.append(cpplex.Keyword('class')) ret.append(cpplex.WhiteSpace(' ')) elif item.kind != 'enumvalue': ret.append(cpplex.Keyword(item.kind)) ret.append(cpplex.WhiteSpace(' ')) if isinstance(item, FunctionPointer): ret.append(cpplex.Operator('(')) ret.append(cpplex.Operator('*')) names = list(get_scoped_name(item, scope)) for i, (name, qname) in enumerate(names): if i < len(names) - 1: sref = _items[qname] if len(sref) > 1: raise Exception('{0} is ambiguous'.format(qname)) ret.append(sref[0]) ret.append(cpplex.Operator('::')) else: ret.extend(cpplex.tokenize(name)) if isinstance(item, FunctionPointer): ret.append(cpplex.Operator(')')) if isinstance(item, Function): ret.append(cpplex.Operator('(')) for i, arg in enumerate(item.args): ret.extend(arg.vartype) ret.append(cpplex.WhiteSpace(' ')) ret.append(cpplex.Identifier(arg.name)) if i != len(item.args) - 1: ret.append(cpplex.Operator(',')) ret.append(cpplex.WhiteSpace(' ')) ret.append(cpplex.Operator(')')) return ret