MCPcopy Index your code
hub / github.com/numpy/numpy / parse_expr

Function parse_expr

numpy/_build_utils/tempita/_tempita.py:767–811  ·  view source on GitHub ↗
(tokens, name, context=())

Source from the content-addressed store, hash-verified

765
766
767def parse_expr(tokens, name, context=()):
768 if isinstance(tokens[0], basestring_):
769 return tokens[0], tokens[1:]
770 expr, pos = tokens[0]
771 expr = expr.strip()
772 if expr.startswith("py:"):
773 expr = expr[3:].lstrip(" \t")
774 if expr.startswith(("\n", "\r")):
775 expr = expr.lstrip("\r\n")
776 if "\r" in expr:
777 expr = expr.replace("\r\n", "\n")
778 expr = expr.replace("\r", "")
779 expr += "\n"
780 elif "\n" in expr:
781 raise TemplateError(
782 "Multi-line py blocks must start with a newline",
783 position=pos,
784 name=name,
785 )
786 return ("py", pos, expr), tokens[1:]
787 elif expr in ("continue", "break"):
788 if "for" not in context:
789 raise TemplateError("continue outside of for loop", position=pos, name=name)
790 return (expr, pos), tokens[1:]
791 elif expr.startswith("if "):
792 return parse_cond(tokens, name, context)
793 elif expr.startswith("elif ") or expr == "else":
794 raise TemplateError(
795 f"{expr.split()[0]} outside of an if block", position=pos, name=name
796 )
797 elif expr in ("if", "elif", "for"):
798 raise TemplateError(f"{expr} with no expression", position=pos, name=name)
799 elif expr in ("endif", "endfor", "enddef"):
800 raise TemplateError(f"Unexpected {expr}", position=pos, name=name)
801 elif expr.startswith("for "):
802 return parse_for(tokens, name, context)
803 elif expr.startswith("default "):
804 return parse_default(tokens, name, context)
805 elif expr.startswith("inherit "):
806 return parse_inherit(tokens, name, context)
807 elif expr.startswith("def "):
808 return parse_def(tokens, name, context)
809 elif expr.startswith("#"):
810 return ("comment", pos, tokens[0][0]), tokens[1:]
811 return ("expr", pos, tokens[0][0]), tokens[1:]
812
813
814def parse_cond(tokens, name, context):

Callers 4

parseFunction · 0.85
parse_one_condFunction · 0.85
parse_forFunction · 0.85
parse_defFunction · 0.85

Calls 11

TemplateErrorClass · 0.85
parse_condFunction · 0.85
parse_forFunction · 0.85
parse_defaultFunction · 0.85
parse_inheritFunction · 0.85
parse_defFunction · 0.85
stripMethod · 0.80
startswithMethod · 0.80
lstripMethod · 0.80
replaceMethod · 0.80
splitMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…