like parse, but only consumes a single top level node, e.g. parsing
    'a\nb' will only return a node for 'a', leaving b unparsed
544201
def parsesingle(s, strictmode=True, expansionlimit=None, convertpos=False):
    ''''''
    p = _parser(s, strictmode=strictmode, expansionlimit=expansionlimit)
    tree = p.parse()
    if convertpos:
        ast.posconverter(s).visit(tree)
    return tree
1002325
def visit_slice(self, node):
        """"""
        lower = node.lower.accept(self) if node.lower else ""
        upper = node.upper.accept(self) if node.upper else ""
        step = node.step.accept(self) if node.step else ""
        if step:
            return "%s:%s:%s" % (lower, upper, step)
        return "%s:%s" % (lower, upper)
1186926
def _parse_tree(self, node):
        
        self.kind = node.tag
        if 'compare' in node.attrib:
            self.compare = node.attrib['compare']
        if 'version' in node.attrib:
            self.version = node.attrib['version']
        self.value = node.text
936565
def parse_with(self, node):
        

        if 'instance' in node.lattrib:
            instance = node.lattrib['instance']
            list = None
            index = None
        elif 'list' in node.lattrib and 'index' in node.lattrib:
            instance = None
            list = node.lattrib['list']
            index = node.lattrib['index']
        else:
            self.raise_error('<With> must specify EITHER instance OR list & index')

        if 'as' in node.lattrib:
            as_ = node.lattrib['as']
        else:
            self.raise_error('<With> must specify a name for the '
                             'target instance')

        self.current_structure.add_with(With(instance, as_, list, index))
192785
def _parse_token(word, chunk="O", pnp="O", relation="O", anchor="O", 
                 format=[WORD, POS, CHUNK, PNP, REL, ANCHOR, LEMMA]):
    
    tags = []
    for tag in format:
        if   tag == WORD   : tags.append(xml_decode(word.value))
        elif tag == POS    : tags.append(xml_decode(word.get(XML_TYPE, "O")))
        elif tag == CHUNK  : tags.append(chunk)
        elif tag == PNP    : tags.append(pnp)
        elif tag == REL    : tags.append(relation)
        elif tag == ANCHOR : tags.append(anchor)
        elif tag == LEMMA  : tags.append(xml_decode(word.get(XML_LEMMA, "")))
        else:
            # Custom tags when the parser has been extended, see also Word.custom_tags{}.
            tags.append(xml_decode(word.get(tag, "O")))
    return tags
886682
def get_node(self, key):
    """"""
    if key in self.names:
      return self.values.get_member_node(key) if hasattr(self.values, 'get_member_node') else None
    return self.parent.get_node(key)
219155
def parse(node)
      node.xpath('*').each do |node_child|
        case node_child.name
        when 'blip'
          @blip = Blip.new(parent: self).parse(node_child)
        when 'stretch'
          @stretch = Stretch.new(parent: self).parse(node_child)
        end
      end
      self
    end
631752
def _parse_node(graph, text, condition_node_params, leaf_node_params):
    """"""
    match = _NODEPAT.match(text)
    if match is not None:
        node = match.group(1)
        graph.node(node, label=match.group(2), **condition_node_params)
        return node
    match = _LEAFPAT.match(text)
    if match is not None:
        node = match.group(1)
        graph.node(node, label=match.group(2), **leaf_node_params)
        return node
    raise ValueError('Unable to parse node: {0}'.format(text))
845794
def parse_for_each(self, node):
        
        
        if self.current_structure == None:
            self.raise_error('<ForEach> can only be made within ' +
                             'a structure definition')

        if 'instances' in node.lattrib:
            instances = node.lattrib['instances']
        else:
            self.raise_error('<ForEach> must specify a reference to target'
                             'instances')

        if 'as' in node.lattrib:
            as_ = node.lattrib['as']
        else:
            self.raise_error('<ForEach> must specify a name for the '
                             'enumerated target instances')

        old_structure = self.current_structure
        fe = ForEach(instances, as_)
        self.current_structure.add_for_each(fe)
        self.current_structure = fe
        
        self.process_nested_tags(node)

        self.current_structure = old_structure
173490
def _parse(self, root, line, idx):
        
        # Base (or degenerate..) case.
        if len(line) == 0:
            return [], idx

        parse = []
        curr = 0
        node = root
        cidx = idx
        while curr < len(line):
            node = node.children.get(line[curr])
            curr += 1
            if not node:
                break
            if node.sentinel:
                subparse, cidx = self._parse(root, line[curr:], idx + curr)
                # Always keep the latest valid parse, which will be
                # the longest-matched (greedy match) graphemes.
                parse = [line[:curr]]
                parse.extend(subparse)
        if parse:
            idx = cidx
        return parse, idx
851985
def parse(node)
      node.xpath('*').each do |node_child|
        case node_child.name
        when 'lnL', 'left'
          @left = TableCellLine.new(parent: self).parse(node_child)
        when 'lnR', 'right'
          @right = TableCellLine.new(parent: self).parse(node_child)
        when 'lnT', 'top'
          @top = TableCellLine.new(parent: self).parse(node_child)
        when 'lnB', 'bottom'
          @bottom = TableCellLine.new(parent: self).parse(node_child)
        when 'lnTlToBr', 'tl2br'
          @top_left_to_bottom_right = TableCellLine.new(parent: self).parse(node_child)
        when 'lnBlToTr', 'tr2bl'
          @top_right_to_bottom_left = TableCellLine.new(parent: self).parse(node_child)
        when 'insideV'
          @inner_vertical = TableCellLine.new(parent: self).parse(node_child)
        when 'insideH'
          @inner_horizontal = TableCellLine.new(parent: self).parse(node_child)
        end
      end
      self
    end
348033
def withdict(parser, token):
    
    bits = token.split_contents()
    if len(bits) != 2:
        raise TemplateSyntaxError("{% withdict %} expects one argument")

    nodelist = parser.parse(('endwithdict',))
    parser.delete_first_token()

    return WithDictNode(
        nodelist=nodelist,
        context_expr=parser.compile_filter(bits[1])
    )
1343820
def _get_node(self, treelist, pos):
        
        node = None
        if pos is not None:
            subtree = self._get_substructure(treelist, pos)
            if subtree is not None:
                node = subtree[0]
        return node
143726
function readFullTree() {
                        // Return null if the contextTree is not correctly closed
                        if (root !== currentContext) {
                            return null;
                        }

                        function recusiveRead(node) {
                            if (node.children.length === 0) {
                                delete node.children;
                            } else {
                                for (var i=0, max=node.children.length ; i<max ; i++) {
                                    recusiveRead(node.children[i]);
                                }
                            }
                            delete node.parent;
                        }
                        recusiveRead(root);

                        return root;
                    }
889705
function topLevelNodeAt(node, top) {
    while (node && node.parentNode != top)
      node = node.parentNode;
    return node;
  }
979993
def surround_parse(self, node, pre_char, post_char):
        """"""
        self.add_text(pre_char)
        self.subnode_parse(node)
        self.add_text(post_char)
666435
private Node parseSubExp(TokenType term) {
        Node node = parseBranch(term);

        if (token.type == term) {
            return node;
        } else if (token.type == TokenType.ALT) {
            ListNode top = ListNode.newAlt(node, null);
            ListNode t = top;
            while (token.type == TokenType.ALT) {
                fetchToken();
                node = parseBranch(term);

                t.setTail(ListNode.newAlt(node, null));
                t = t.tail;
            }

            if (token.type != term) parseSubExpError(term);
            return top;
        } else {
            parseSubExpError(term);
            return null; //not reached
        }
    }