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

Method parse_tuple

tools/inspector_protocol/jinja2/parser.py:586–639  ·  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=False, with_condexpr=True,
                    extra_end_rules=None, explicit_parentheses=False)

Source from the content-addressed store, hash-verified

584 return node
585
586 def parse_tuple(self, simplified=False, with_condexpr=True,
587 extra_end_rules=None, explicit_parentheses=False):
588 """Works like `parse_expression` but if multiple expressions are
589 delimited by a comma a :class:`~jinja2.nodes.Tuple` node is created.
590 This method could also return a regular expression instead of a tuple
591 if no commas where found.
592
593 The default parsing mode is a full tuple. If `simplified` is `True`
594 only names and literals are parsed. The `no_condexpr` parameter is
595 forwarded to :meth:`parse_expression`.
596
597 Because tuples do not require delimiters and may end in a bogus comma
598 an extra hint is needed that marks the end of a tuple. For example
599 for loops support tuples between `for` and `in`. In that case the
600 `extra_end_rules` is set to ``['name:in']``.
601
602 `explicit_parentheses` is true if the parsing was triggered by an
603 expression in parentheses. This is used to figure out if an empty
604 tuple is a valid expression or not.
605 """
606 lineno = self.stream.current.lineno
607 if simplified:
608 parse = self.parse_primary
609 elif with_condexpr:
610 parse = self.parse_expression
611 else:
612 parse = lambda: self.parse_expression(with_condexpr=False)
613 args = []
614 is_tuple = False
615 while 1:
616 if args:
617 self.stream.expect('comma')
618 if self.is_tuple_end(extra_end_rules):
619 break
620 args.append(parse())
621 if self.stream.current.type == 'comma':
622 is_tuple = True
623 else:
624 break
625 lineno = self.stream.current.lineno
626
627 if not is_tuple:
628 if args:
629 return args[0]
630
631 # if we don't have explicit parentheses, an empty tuple is
632 # not a valid expression. This would mean nothing (literally
633 # nothing) in the spot of an expression would be an empty
634 # tuple.
635 if not explicit_parentheses:
636 self.fail('Expected an expression, got \'%s\'' %
637 describe_token(self.stream.current))
638
639 return nodes.Tuple(args, 'load', lineno=lineno)
640
641 def parse_list(self):
642 token = self.stream.expect('lbracket')

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 7

parse_expressionMethod · 0.95
is_tuple_endMethod · 0.95
failMethod · 0.95
describe_tokenFunction · 0.90
parseFunction · 0.50
expectMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected