Parse the composite source model without instantiating the sources and
    prints information about its composition and the full logic tree
961420
def print_csm_info(fname):
    
    oqparam = readinput.get_oqparam(fname)
    csm = readinput.get_composite_source_model(oqparam, in_memory=False)
    print(csm.info)
    print('See http://docs.openquake.org/oq-engine/stable/'
          'effective-realizations.html for an explanation')
    rlzs_assoc = csm.info.get_rlzs_assoc()
    print(rlzs_assoc)
    dupl = [(srcs[0]['id'], len(srcs)) for srcs in csm.check_dupl_sources()]
    if dupl:
        print(rst_table(dupl, ['source_id', 'multiplicity']))
    tot, pairs = get_pickled_sizes(rlzs_assoc)
    print(rst_table(pairs, ['attribute', 'nbytes']))
355232
function parseInterp(source) {
    var walker = new Walker(source);

    var interp = {
        type: ExprType.INTERP,
        expr: readTertiaryExpr(walker),
        filters: [],
        raw: source
    };

    while (walker.goUntil(124)) { // |
        var callExpr = readCall(walker, []);
        switch (callExpr.name.paths[0].value) {
            case 'html':
                break;
            case 'raw':
                interp.original = 1;
                break;
            default:
                interp.filters.push(callExpr);
        }
    }

    return interp;
}
604472
def parse(self):
        
        if self.parse_string is not None and self._parse is None:
            self._parse = Tree.parse(self._parse_string)
        return self._parse
34461
def _printSourceCode(self, hrlinetop=True):
        
        if not self.currentEntity:  # ==> ontology level
            return
        x = self.currentEntity['object']
        if hrlinetop:
            self._print("----------------")

        self._print("Source:", "IMPORTANT")
        self.do_serialize("turtle")
        self._print("----------------")

        return
368599
private Document parseInputSource(InputSource s) throws JspException {
        try {
            DocumentBuilder db = XmlUtil.newDocumentBuilder();
            db.setEntityResolver(entityResolver);
            return db.parse(s);
        } catch (SAXException e) {
            throw new JspException(e);
        } catch (IOException e) {
            throw new JspException(e);
        }
    }
400311
private Resource parseResourceNode(Xpp3Dom rn) {
    Resource r = new Resource();
    if (rn.getChild("directory") != null) {
      r.setDirectory(getValue(getProject(), rn.getChild("directory")));
    }
    if (rn.getChild("filtering") != null) {
      r.setFiltering((Boolean.valueOf(getValue(getProject(), rn.getChild("filtering")))));
    }
    if (rn.getChild("targetPath") != null) {
      r.setTargetPath(rn.getChild("targetPath").getValue());
    }

    if (rn.getChild("excludes") != null) {
      List<String> excludes = new ArrayList<String>();
      Xpp3Dom[] excludeNodes = rn.getChild("excludes").getChildren("exclude");
      for (Xpp3Dom excludeNode : excludeNodes) {
        if (excludeNode != null && excludeNode.getValue() != null) {
          excludes.add(getValue(getProject(), excludeNode));
        }
      }
      r.setExcludes(excludes);
    }
    if (rn.getChild("includes") != null) {
      List<String> includes = new ArrayList<String>();
      Xpp3Dom[] includeNodes = rn.getChild("includes").getChildren("include");
      for (Xpp3Dom includeNode : includeNodes) {
        if (includeNode != null && includeNode.getValue() != null) {
          includes.add(getValue(getProject(), includeNode));
        }
      }
      r.setIncludes(includes);
    }

    return r;
  }
488606
function parse(source) {

	var moduleDefinitions = {},
		moduleReferences = [];

    estraverse.traverse(esprima.parse(source), {
        leave: function (node, parent) {
			
			if(!isAngular(node)) {
				return;
			}
			
            //console.log('node:', JSON.stringify(node, null, 3));
            //console.log('parent:', JSON.stringify(parent, null, 3));
			
			var moduleName = parent.arguments[0].value;
			
			// if a second argument exists
			// this is a module definition
			if(parent.arguments[1]) {
				if(parent.arguments[1].type === 'ArrayExpression') {
					moduleDefinitions[moduleName] = parent.arguments[1].elements.map(function(item){
						return item['value'];
					});
				} else {
					throw 'Argument must be an ArrayExpression, not a variable';
				}
			} else {
				// is a module reference
				pushDistinct(moduleReferences, moduleName);
			}
					          
        }
    });
		
	return {
		modules: moduleDefinitions,
		references: moduleReferences
	}	
}
380426
def _get_deps(self, tree, include_punct, representation, universal):
        """"""
        if universal:
            converter = self.universal_converter

            if self.universal_converter == self.converter:
                import warnings
                warnings.warn("This jar doesn't support universal "
                              "dependencies, falling back to Stanford "
                              "Dependencies. To suppress this message, "
                              "call with universal=False")
        else:
            converter = self.converter

        if include_punct:
            egs = converter(tree, self.acceptFilter)
        else:
            egs = converter(tree)

        if representation == 'basic':
            deps = egs.typedDependencies()
        elif representation == 'collapsed':
            deps = egs.typedDependenciesCollapsed(True)
        elif representation == 'CCprocessed':
            deps = egs.typedDependenciesCCprocessed(True)
        else:
            # _raise_on_bad_representation should ensure that this
            # assertion doesn't fail
            assert representation == 'collapsedTree'
            deps = egs.typedDependenciesCollapsedTree()
        return self._listify(deps)
798767
def parse_tree_to_objgraph(parser, parse_tree, file_name=None,
                           pre_ref_resolution_callback=None,
                           is_main_model=True, encoding='utf-8'):
    

    metamodel = parser.metamodel

    if metamodel.textx_tools_support:
        pos_rule_dict = {}
    pos_crossref_list = []

    def process_match(nt):
        """
        Process subtree for match rules.
        """
        if isinstance(nt, Terminal):
            return metamodel.convert(nt.value, nt.rule_name)
        else:
            # If RHS of assignment is NonTerminal it is a product of
            # complex match rule. Convert nodes to text and do the join.
            if len(nt) > 1:
                result = "".join([text(process_match(n)) for n in nt])
            else:
                result = process_match(nt[0])
            obj_processor = metamodel.obj_processors.get(nt.rule_name, None)
            if obj_processor:
                return obj_processor(result)
            else:
                return result

    def process_node(node):
        if isinstance(node, Terminal):
            from arpeggio import RegExMatch
            if metamodel.use_regexp_group and \
                    isinstance(node.rule, RegExMatch):
                if node.rule.regex.groups == 1:
                    value = node.extra_info.group(1)
                    return metamodel.convert(value, node.rule_name)
                else:
                    return metamodel.convert(node.value, node.rule_name)
            else:
                return metamodel.convert(node.value, node.rule_name)

        assert node.rule.root, \
            "Not a root node: {}".format(node.rule.rule_name)
        # If this node is created by some root rule
        # create metaclass instance.
        inst = None
        if not node.rule_name.startswith('__asgn'):
            # If not assignment
            # Get class
            mclass = node.rule._tx_class

            if mclass._tx_type == RULE_ABSTRACT:
                # If this meta-class is product of abstract rule replace it
                # with matched concrete meta-class down the inheritance tree.
                # Abstract meta-class should never be instantiated.
                if len(node) > 1:
                    try:
                        return process_node(
                            next(n for n in node
                                 if type(n) is not Terminal
                                 and n.rule._tx_class is not RULE_MATCH))
                    except StopIteration:
                        # All nodes are match rules, do concatenation
                        return ''.join(text(n) for n in node)
                else:
                    return process_node(node[0])
            elif mclass._tx_type == RULE_MATCH:
                # If this is a product of match rule handle it as a RHS
                # of assignment and return converted python type.
                return process_match(node)

            if parser.debug:
                parser.dprint("CREATING INSTANCE {}".format(node.rule_name))

            # If user class is given
            # use it instead of generic one
            if node.rule_name in metamodel.user_classes:
                user_class = metamodel.user_classes[node.rule_name]

                # Object initialization will be done afterwards
                # At this point we need object to be allocated
                # So that nested object get correct reference
                inst = user_class.__new__(user_class)

                # Initialize object attributes for user class
                parser.metamodel._init_obj_attrs(inst, user=True)
            else:
                # Generic class will call attributes init
                # from the constructor
                inst = mclass.__new__(mclass)

                # Initialize object attributes
                parser.metamodel._init_obj_attrs(inst)

            # Collect attributes directly on meta-class instance
            obj_attrs = inst

            inst._tx_position = node.position
            inst._tx_position_end = node.position_end

            # Push real obj. and dummy attr obj on the instance stack
            parser._inst_stack.append((inst, obj_attrs))

            for n in node:
                if parser.debug:
                    parser.dprint("Recursing into {} = '{}'"
                                  .format(type(n).__name__, text(n)))
                process_node(n)

            parser._inst_stack.pop()

            # If this object is nested add 'parent' reference
            if parser._inst_stack:
                if node.rule_name in metamodel.user_classes:
                    obj_attrs._txa_parent = parser._inst_stack[-1][0]
                else:
                    obj_attrs.parent = parser._inst_stack[-1][0]

            # If the class is user supplied we need to do
            # a proper initialization at this point.
            if node.rule_name in metamodel.user_classes:
                try:
                    # Get only attributes defined by the grammar as well
                    # as `parent` if exists
                    attrs = {}
                    if hasattr(obj_attrs, '_txa_parent'):
                        attrs['parent'] = obj_attrs._txa_parent
                        del obj_attrs._txa_parent
                    for a in obj_attrs.__class__._tx_attrs:
                        attrs[a] = getattr(obj_attrs, "_txa_%s" % a)
                        delattr(obj_attrs, "_txa_%s" % a)
                    inst.__init__(**attrs)
                except TypeError as e:
                    # Add class name information in case of
                    # wrong constructor parameters
                    e.args += ("for class %s" %
                               inst.__class__.__name__,)
                    parser.dprint(traceback.print_exc())
                    raise e

            # Special case for 'name' attrib. It is used for cross-referencing
            if hasattr(inst, 'name') and inst.name:
                # Objects of each class are in its own namespace
                if not id(inst.__class__) in parser._instances:
                    parser._instances[id(inst.__class__)] = {}
                parser._instances[id(inst.__class__)][inst.name] = inst

            if parser.debug:
                parser.dprint("LEAVING INSTANCE {}".format(node.rule_name))

        else:
            # Handle assignments
            attr_name = node.rule._attr_name
            op = node.rule_name.split('_')[-1]
            model_obj, obj_attr = parser._inst_stack[-1]
            cls = type(model_obj)
            metaattr = cls._tx_attrs[attr_name]

            # Mangle attribute name to prevent name clashing with property
            # setters on user classes
            if cls.__name__ in metamodel.user_classes:
                txa_attr_name = "_txa_%s" % attr_name
            else:
                txa_attr_name = attr_name

            if parser.debug:
                parser.dprint('Handling assignment: {} {}...'
                              .format(op, txa_attr_name))

            if op == 'optional':
                setattr(obj_attr, txa_attr_name, True)

            elif op == 'plain':
                attr_value = getattr(obj_attr, txa_attr_name)
                if attr_value and type(attr_value) is not list:
                    fmt = "Multiple assignments to attribute {} at {}"
                    raise TextXSemanticError(
                        message=fmt.format(
                            attr_name, parser.pos_to_linecol(node.position)),
                        err_type=MULT_ASSIGN_ERROR)

                # Convert tree bellow assignment to proper value
                value = process_node(node[0])

                if metaattr.ref and not metaattr.cont:
                    # If this is non-containing reference create ObjCrossRef
                    value = ObjCrossRef(obj_name=value, cls=metaattr.cls,
                                        position=node[0].position)
                    parser._crossrefs.append((model_obj, metaattr, value))
                    return model_obj

                if type(attr_value) is list:
                    attr_value.append(value)
                else:
                    setattr(obj_attr, txa_attr_name, value)

            elif op in ['list', 'oneormore', 'zeroormore']:
                for n in node:
                    # If the node is separator skip
                    if n.rule_name != 'sep':
                        # Convert node to proper type
                        # Rule links will be resolved later
                        value = process_node(n)

                        if metaattr.ref and not metaattr.cont:
                            # If this is non-containing reference
                            # create ObjCrossRef

                            value = ObjCrossRef(obj_name=value,
                                                cls=metaattr.cls,
                                                position=n.position)

                            parser._crossrefs.append((obj_attr, metaattr,
                                                      value))
                            continue

                        if not hasattr(obj_attr, txa_attr_name) or \
                                getattr(obj_attr, txa_attr_name) is None:
                            setattr(obj_attr, txa_attr_name, [])
                        getattr(obj_attr, txa_attr_name).append(value)
            else:
                # This shouldn't happen
                assert False

        # Collect rules for textx-tools
        if inst and metamodel.textx_tools_support:
            pos = (inst._tx_position, inst._tx_position_end)
            pos_rule_dict[pos] = inst

        return inst

    def call_obj_processors(metamodel, model_obj,
                            metaclass_of_grammar_rule=None):
        """
        Depth-first model object processing.
        """
        try:
            if metaclass_of_grammar_rule is None:
                metaclass_of_grammar_rule = \
                    metamodel[model_obj.__class__.__name__]
        except KeyError:
            raise TextXSemanticError(
                'Unknown meta-class "{}".'
                .format(model.obj.__class__.__name__))

        if metaclass_of_grammar_rule._tx_type is RULE_MATCH:
            # Object processors for match rules are already called
            # in `process_match`
            return

        many = [MULT_ONEORMORE, MULT_ZEROORMORE]

        # return value of obj_processor
        return_value_grammar = None
        return_value_current = None

        # enter recursive visit of attributes only, if the class of the
        # object being processed is a meta class of the current meta model
        if model_obj.__class__.__name__ in metamodel:
            current_metaclass_of_obj = metamodel[model_obj.__class__.__name__]

            for metaattr in current_metaclass_of_obj._tx_attrs.values():
                # If attribute is base type or containment reference go down
                if metaattr.cont:
                    attr = getattr(model_obj, metaattr.name)
                    if attr:
                        if metaattr.mult in many:
                            for idx, obj in enumerate(attr):
                                if obj:
                                    result = call_obj_processors(metamodel,
                                                                 obj,
                                                                 metaattr.cls)
                                    if result is not None:
                                        attr[idx] = result
                        else:
                            result = call_obj_processors(metamodel,
                                                         attr, metaattr.cls)
                            if result is not None:
                                setattr(model_obj, metaattr.name, result)

            # call obj_proc of the current meta_class if type == RULE_ABSTRACT
            if current_metaclass_of_obj._tx_fqn !=\
                    metaclass_of_grammar_rule._tx_fqn:
                assert RULE_ABSTRACT == metaclass_of_grammar_rule._tx_type
                obj_processor_current = metamodel.obj_processors.get(
                    current_metaclass_of_obj.__name__, None)
                if obj_processor_current:
                    return_value_current = obj_processor_current(model_obj)

        # call obj_proc of rule found in grammar
        obj_processor_grammar = metamodel.obj_processors.get(
            metaclass_of_grammar_rule.__name__, None)
        if obj_processor_grammar:
            return_value_grammar = obj_processor_grammar(model_obj)

        # both obj_processors are called, if two different processors
        # are defined for the object metaclass and the grammar metaclass
        # (can happen with type==RULE_ABSTRACT):
        # e.g.
        #   Base: Special1|Special2;
        #   RuleCurrentlyChecked: att_to_be_checked=[Base]
        # with object processors defined for Base, Special1, and Special2.
        #
        # Both processors are called, but for the return value the
        # obj_processor corresponding to the object (e.g. of type Special1)
        # dominates over the obj_processor of the grammar rule (Base).
        #
        # The order they are called is: first object (e.g., Special1), then
        # the grammar based metaclass object processor (e.g., Base).
        if return_value_current is not None:
            return return_value_current
        else:
            return return_value_grammar  # may be None

    model = process_node(parse_tree)
    # Register filename of the model for later use (e.g. imports/scoping).
    is_primitive_type = False
    try:
        model._tx_filename = file_name
    except AttributeError:
        # model is some primitive python type (e.g. str)
        is_primitive_type = True
        pass

    if pre_ref_resolution_callback:
        pre_ref_resolution_callback(model)

    for scope_provider in metamodel.scope_providers.values():
        from textx.scoping import ModelLoader
        if isinstance(scope_provider, ModelLoader):
            scope_provider.load_models(model, encoding=encoding)

    if not is_primitive_type:
        model._tx_reference_resolver = ReferenceResolver(
            parser, model, pos_crossref_list)
        model._tx_parser = parser

    if is_main_model:
        from textx.scoping import get_all_models_including_attached_models
        models = get_all_models_including_attached_models(model)
        # filter out all models w/o resolver:
        models = list(filter(
            lambda x: hasattr(x, "_tx_reference_resolver"), models))

        resolved_count = 1
        unresolved_count = 1
        while unresolved_count > 0 and resolved_count > 0:
            resolved_count = 0
            unresolved_count = 0
            # print("***RESOLVING {} models".format(len(models)))
            for m in models:
                resolved_count_for_this_model, delayed_crossrefs = \
                    m._tx_reference_resolver.resolve_one_step()
                resolved_count += resolved_count_for_this_model
                unresolved_count += len(delayed_crossrefs)
            # print("DEBUG: delayed #:{} unresolved #:{}".
            #      format(unresolved_count,unresolved_count))
        if (unresolved_count > 0):
            error_text = "Unresolvable cross references:"

            for m in models:
                for _, _, delayed \
                        in m._tx_reference_resolver.delayed_crossrefs:
                    line, col = parser.pos_to_linecol(delayed.position)
                    error_text += ' "{}" of class "{}" at {}'.format(
                        delayed.obj_name, delayed.cls.__name__, (line, col))
            raise TextXSemanticError(error_text, line=line, col=col)

        for m in models:
            # TODO: what does this check?
            assert not m._tx_reference_resolver.parser._inst_stack

        # cleanup
        for m in models:
            del m._tx_reference_resolver

        # final check that everything went ok
        for m in models:
            assert 0 == len(get_children_of_type(Postponed.__class__, m))

            # We have model loaded and all link resolved
            # So we shall do a depth-first call of object
            # processors if any processor is defined.
            if m._tx_metamodel.obj_processors:
                if parser.debug:
                    parser.dprint("CALLING OBJECT PROCESSORS")
                call_obj_processors(m._tx_metamodel, m)

    if metamodel.textx_tools_support \
            and type(model) not in PRIMITIVE_PYTHON_TYPES:
        # Cross-references for go-to definition language server support
        # Already sorted based on ref_pos_start attr
        # (required for binary search)
        model._pos_crossref_list = pos_crossref_list

        # Dict for storing rules where key is position of rule instance in text
        # Sorted based on nested rules
        model._pos_rule_dict = OrderedDict(sorted(pos_rule_dict.items(),
                                                  key=lambda x: x[0],
                                                  reverse=True))
    return model
986367
def assignment_source(num_pre, num_post, LISTNAME, ITERNAME):
    
    """
    children = []
    pre = unicode(num_pre)
    post = unicode(num_post)
    # This code builds the assignment source from lib2to3 tree primitives.
    # It's not very readable, but it seems like the most correct way to do it.
    if num_pre > 0:
        pre_part = Node(syms.power, [Name(LISTNAME), Node(syms.trailer, [Leaf(token.LSQB, u"["), Node(syms.subscript, [Leaf(token.COLON, u":"), Number(pre)]), Leaf(token.RSQB, u"]")])])
        children.append(pre_part)
        children.append(Leaf(token.PLUS, u"+", prefix=u" "))
    main_part = Node(syms.power, [Leaf(token.LSQB, u"[", prefix=u" "), Name(LISTNAME), Node(syms.trailer, [Leaf(token.LSQB, u"["), Node(syms.subscript, [Number(pre) if num_pre > 0 else Leaf(1, u""), Leaf(token.COLON, u":"), Node(syms.factor, [Leaf(token.MINUS, u"-"), Number(post)]) if num_post > 0 else Leaf(1, u"")]), Leaf(token.RSQB, u"]"), Leaf(token.RSQB, u"]")])])
    children.append(main_part)
    if num_post > 0:
        children.append(Leaf(token.PLUS, u"+", prefix=u" "))
        post_part = Node(syms.power, [Name(LISTNAME, prefix=u" "), Node(syms.trailer, [Leaf(token.LSQB, u"["), Node(syms.subscript, [Node(syms.factor, [Leaf(token.MINUS, u"-"), Number(post)]), Leaf(token.COLON, u":")]), Leaf(token.RSQB, u"]")])])
        children.append(post_part)
    source = Node(syms.arith_expr, children)
    return source
450962
def model_to_tree(model, title=None, lucent_id=TRANSLUCENT_BINDER_ID):
    
    id = model.ident_hash
    if id is None and isinstance(model, TranslucentBinder):
        id = lucent_id
    md = model.metadata
    shortid = md.get('shortId', md.get('cnx-archive-shortid'))
    title = title is not None and title or md.get('title')
    tree = {'id': id, 'title': title, 'shortId': shortid}
    if hasattr(model, '__iter__'):
        contents = tree['contents'] = []
        for node in model:
            item = model_to_tree(node, model.get_title_for_node(node),
                                 lucent_id=lucent_id)
            contents.append(item)
    return tree
1076868
def parse_dis_tree(self, dis_tree, indent=0):
        """"""
        tree_type = get_tree_type(dis_tree)
        assert tree_type in SUBTREE_TYPES
        if tree_type == 'Root':
            # replace generic root node with tree root
            old_root_id = self.root
            root_id = get_node_id(dis_tree, self.ns)
            self.root = root_id
            self.add_node(root_id)
            self.remove_node(old_root_id)

            children = dis_tree[1:]
            for child in children:
                child_id = get_node_id(child, self.ns)
                self.add_edge(
                    root_id, child_id,
                    #~ attr_dict={self.ns+':rel_type': relation_type},
                    edge_type=EdgeTypes.dominance_relation)

                self.parse_dis_tree(child, indent=indent+1)

        else: # tree_type in ('Nucleus', 'Satellite')
            node_id = get_node_id(dis_tree, self.ns)
            node_type = get_node_type(dis_tree)
            relation_type = get_relation_type(dis_tree)
            if node_type == 'leaf':
                edu_text = get_edu_text(dis_tree[-1])
                self.add_node(node_id, attr_dict={
                    self.ns+':text': edu_text,
                    'label': u'{0}: {1}'.format(node_id, edu_text[:20])})
                if self.tokenized:
                    edu_tokens = edu_text.split()
                    for i, token in enumerate(edu_tokens):
                        token_node_id = '{0}_{1}'.format(node_id, i)
                        self.tokens.append(token_node_id)
                        self.add_node(token_node_id, attr_dict={self.ns+':token': token,
                                                                'label': token})
                        self.add_edge(node_id, '{0}_{1}'.format(node_id, i))

            else: # node_type == 'span'
                self.add_node(node_id, attr_dict={self.ns+':rel_type': relation_type,
                                                  self.ns+':node_type': node_type})
                children = dis_tree[3:]
                child_types = get_child_types(children)

                expected_child_types = set(['Nucleus', 'Satellite'])
                unexpected_child_types = set(child_types).difference(expected_child_types)
                assert not unexpected_child_types, \
                    "Node '{0}' contains unexpected child types: {1}\n".format(
                        node_id, unexpected_child_types)

                if 'Satellite' not in child_types:
                    # span only contains nucleii -> multinuc
                    for child in children:
                        child_node_id = get_node_id(child, self.ns)
                        self.add_edge(node_id, child_node_id, attr_dict={
                            self.ns+':rel_type': relation_type})

                elif len(child_types['Satellite']) == 1 and len(children) == 1:
                    if tree_type == 'Nucleus':
                        child = children[0]
                        child_node_id = get_node_id(child, self.ns)
                        self.add_edge(
                            node_id, child_node_id,
                            attr_dict={self.ns+':rel_type': relation_type},
                            edge_type=EdgeTypes.dominance_relation)
                    else:
                        assert tree_type == 'Satellite'
                        raise NotImplementedError("I don't know how to combine two satellites")

                elif len(child_types['Satellite']) == 1 and len(child_types['Nucleus']) == 1:
                    # standard RST relation, where one satellite is dominated by one nucleus
                    nucleus_index = child_types['Nucleus'][0]
                    satellite_index = child_types['Satellite'][0]

                    nucleus_node_id = get_node_id(children[nucleus_index], self.ns)
                    satellite_node_id = get_node_id(children[satellite_index], self.ns)
                    self.add_edge(node_id, nucleus_node_id, attr_dict={self.ns+':rel_type': 'span'},
                                  edge_type=EdgeTypes.spanning_relation)
                    self.add_edge(nucleus_node_id, satellite_node_id,
                                  attr_dict={self.ns+':rel_type': relation_type},
                                  edge_type=EdgeTypes.dominance_relation)
                else:
                    raise ValueError("Unexpected child combinations: {}\n".format(child_types))

                for child in children:
                    self.parse_dis_tree(child, indent=indent+1)
1147172
def parse_tl(file_path, layer, methods=None, ignored_ids=CORE_TYPES):
    
    method_info = {m.name: m for m in (methods or [])}
    obj_all = []
    obj_by_name = {}
    obj_by_type = collections.defaultdict(list)
    with file_path.open() as file:
        is_function = False
        for line in file:
            comment_index = line.find('//')
            if comment_index != -1:
                line = line[:comment_index]

            line = line.strip()
            if not line:
                continue

            match = re.match('---(\w+)---', line)
            if match:
                following_types = match.group(1)
                is_function = following_types == 'functions'
                continue

            try:
                result = _from_line(
                    line, is_function, method_info, layer=layer)

                if result.id in ignored_ids:
                    continue

                obj_all.append(result)
                if not result.is_function:
                    obj_by_name[result.fullname] = result
                    obj_by_type[result.result].append(result)
            except ValueError as e:
                if 'vector#1cb5c415' not in str(e):
                    raise

    # Once all objects have been parsed, replace the
    # string type from the arguments with references
    for obj in obj_all:
        if obj.id in AUTH_KEY_TYPES:
            for arg in obj.args:
                if arg.type == 'string':
                    arg.type = 'bytes'

        for arg in obj.args:
            arg.cls = obj_by_type.get(arg.type) or (
                [obj_by_name[arg.type]] if arg.type in obj_by_name else []
            )

    yield from obj_all
447000
def _iter_rawterms(cls, tree):
        
        for elem in tree.iterfind(OWL_CLASS):
            if RDF_ABOUT not in elem.keys():   # This avoids parsing a class
                continue                       # created by restriction
            rawterm = cls._extract_resources(elem)
            rawterm['id'] = cls._get_id_from_url(elem.get(RDF_ABOUT))
            yield rawterm
545249
def read_source_models(fnames, converter, monitor):
    
    for fname in fnames:
        if fname.endswith(('.xml', '.nrml')):
            sm = to_python(fname, converter)
        elif fname.endswith('.hdf5'):
            sm = sourceconverter.to_python(fname, converter)
        else:
            raise ValueError('Unrecognized extension in %s' % fname)
        sm.fname = fname
        yield sm
1309431
def parse_dependencies(dependencies: List[List[str]],
                       patton_config: PattonRunningConfig) -> Dict:
    """"""

    result = {}

    for source_type, source_content in dependencies:

        # Select parser
        parser = DEPENDENCIES_PARSERS[patton_config.source_type]

        if not source_content:
            continue

        if source_type == "cli_input":
            fixed_source = "\n".join(source_content)
        else:
            fixed_source = source_content

        result.update(parser(fixed_source, patton_config))

    return result
781222
def from_file(cls, source):
        """"""
        if hasattr(source, 'read'):
            relations = cls.from_string(source.read())
        else:
            with open(source) as f:
                relations = cls.from_string(f.read())
        return relations