MCPcopy Index your code
hub / github.com/nodejs/node / parse_tuple

Method parse_tuple

deps/v8/third_party/jinja2/parser.py:678–742  ·  view source on GitHub ↗

Works like `parse_expression` but if multiple expressions are delimited by a comma a :class:`~jinja2.nodes.Tuple` node is created. This method could also return a regular expression instead of a tuple if no commas where found. The default parsing mode is a full tuple

(
        self,
        simplified: bool = False,
        with_condexpr: bool = True,
        extra_end_rules: t.Optional[t.Tuple[str, ...]] = None,
        explicit_parentheses: bool = False,
    )

Source from the content-addressed store, hash-verified

676 return node
677
678 def parse_tuple(
679 self,
680 simplified: bool = False,
681 with_condexpr: bool = True,
682 extra_end_rules: t.Optional[t.Tuple[str, ...]] = None,
683 explicit_parentheses: bool = False,
684 ) -> t.Union[nodes.Tuple, nodes.Expr]:
685 """Works like `parse_expression` but if multiple expressions are
686 delimited by a comma a :class:`~jinja2.nodes.Tuple` node is created.
687 This method could also return a regular expression instead of a tuple
688 if no commas where found.
689
690 The default parsing mode is a full tuple. If `simplified` is `True`
691 only names and literals are parsed. The `no_condexpr` parameter is
692 forwarded to :meth:`parse_expression`.
693
694 Because tuples do not require delimiters and may end in a bogus comma
695 an extra hint is needed that marks the end of a tuple. For example
696 for loops support tuples between `for` and `in`. In that case the
697 `extra_end_rules` is set to ``['name:in']``.
698
699 `explicit_parentheses` is true if the parsing was triggered by an
700 expression in parentheses. This is used to figure out if an empty
701 tuple is a valid expression or not.
702 """
703 lineno = self.stream.current.lineno
704 if simplified:
705 parse = self.parse_primary
706 elif with_condexpr:
707 parse = self.parse_expression
708 else:
709
710 def parse() -> nodes.Expr:
711 return self.parse_expression(with_condexpr=False)
712
713 args: t.List[nodes.Expr] = []
714 is_tuple = False
715
716 while True:
717 if args:
718 self.stream.expect("comma")
719 if self.is_tuple_end(extra_end_rules):
720 break
721 args.append(parse())
722 if self.stream.current.type == "comma":
723 is_tuple = True
724 else:
725 break
726 lineno = self.stream.current.lineno
727
728 if not is_tuple:
729 if args:
730 return args[0]
731
732 # if we don't have explicit parentheses, an empty tuple is
733 # not a valid expression. This would mean nothing (literally
734 # nothing) in the spot of an expression would be an empty
735 # tuple.

Callers 7

parse_setMethod · 0.95
parse_forMethod · 0.95
parse_ifMethod · 0.95
parse_assign_targetMethod · 0.95
parse_primaryMethod · 0.95
subparseMethod · 0.95
parseMethod · 0.45

Calls 6

is_tuple_endMethod · 0.95
failMethod · 0.95
describe_tokenFunction · 0.70
parseFunction · 0.50
expectMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected