MCPcopy Index your code
hub / github.com/pyload/pyload / parse_tuple

Method parse_tuple

module/lib/jinja2/parser.py:578–631  ·  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

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

Calls 7

parse_expressionMethod · 0.95
is_tuple_endMethod · 0.95
failMethod · 0.95
describe_tokenFunction · 0.90
parseFunction · 0.85
expectMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected