Roughly Python/ast.c:fstring_find_expr
540317
def _find_expr(s, start, level, parts, exprs):
    """"""
    i = start
    nested_depth = 0
    quote_char = None
    triple_quoted = None

    def _check_end():
        if i == len(s):
            raise SyntaxError("f-string: expecting '}'")

    if level >= 2:
        raise SyntaxError("f-string: expressions nested too deeply")

    parts.append(s[i])
    i += 1

    while i < len(s):
        ch = s[i]

        if ch == '\\':
            raise SyntaxError(
                'f-string expression part cannot include a backslash',
            )
        if quote_char is not None:
            if ch == quote_char:
                if triple_quoted:
                    if i + 2 < len(s) and s[i + 1] == ch and s[i + 2] == ch:
                        i += 2
                        quote_char = None
                        triple_quoted = None
                else:
                    quote_char = None
                    triple_quoted = None
        elif ch in ('"', "'"):
            quote_char = ch
            if i + 2 < len(s) and s[i + 1] == ch and s[i + 2] == ch:
                triple_quoted = True
                i += 2
            else:
                triple_quoted = False
        elif ch in ('[', '{', '('):
            nested_depth += 1
        elif nested_depth and ch in (']', '}', ')'):
            nested_depth -= 1
        elif ch == '#':
            raise SyntaxError("f-string expression cannot include '#'")
        elif nested_depth == 0 and ch in ('!', ':', '}'):
            if ch == '!' and i + 1 < len(s) and s[i + 1] == '=':
                # Allow != at top level as `=` isn't a valid conversion
                pass
            else:
                break
        i += 1

    if quote_char is not None:
        raise SyntaxError('f-string: unterminated string')
    elif nested_depth:
        raise SyntaxError("f-string: mismatched '(', '{', or '['")
    _check_end()

    exprs.append(s[start + 1:i])

    if s[i] == '!':
        parts.append(s[i])
        i += 1
        _check_end()
        parts.append(s[i])
        i += 1

    _check_end()

    if s[i] == ':':
        parts.append(s[i])
        i += 1
        _check_end()
        i = _fstring_parse(s, i, level + 1, parts, exprs)

    _check_end()
    if s[i] != '}':
        raise SyntaxError("f-string: expecting '}'")

    parts.append(s[i])
    i += 1
    return i
552729
def p_expr_ternary_op(p):
    ''
    p[0] = ast.TernaryOp(p[1], p[3], p[5], lineno=p.lineno(2))
707803
def expressionToAST(ex):
    
    return ASTNode(ex.astType, ex.astKind, ex.value,
                   [expressionToAST(c) for c in ex.children])
1043199
def rex(expr):
    
    r = re.compile(expr)
    return lambda key: isinstance(key, six.string_types) and r.match(key)
379318
def AsIter(arg):
  """"""
  if isinstance(arg, string_types):
    rslt = [arg]
  elif isinstance(arg, collections.Iterable):
    rslt = arg
  elif not arg:
    rslt = []
  else:
    rslt = [arg]
  return tuple(rslt)
323575
def p_expr_include_once(p):
    ''
    p[0] = ast.Include(p[2], True, lineno=p.lineno(1))
916292
def p_funcall_expr(p):
    
    if (len(p) == 5 and len(p[3]) == 1 and p[3][0].__class__ is node.expr and
            p[3][0].op == ":" and not p[3][0].args):
        # foo(:) => ravel(foo)
        p[0] = node.funcall(
            func_expr=node.ident("ravel"), args=node.expr_list([p[1]]))
    else:
        args = node.expr_list() if len(p) == 4 else p[3]
        assert isinstance(args, node.expr_list)
        p[0] = node.funcall(func_expr=p[1], args=args)
186586
def find_generator_as_statement(node):
    """"""
    return (
        isinstance(node, ast.Expr)
        and isinstance(node.value, ast.GeneratorExp)
    )
952286
def visit_Expr(self, node: ast.Expr) -> Any:
        """"""
        result = self.visit(node=node.value)

        self.recomputed_values[node] = result
        return result
93792
def _regexp(expr, item):
    ''' 
    '''
    reg = re.compile(expr)
    return reg.search(item) is not None
438555
def p_expr(self, p):
        
        if len(p) == 2:
            p[0] = p[1]
        else:
            p[0] = self.asttypes.Comma(left=p[1], right=p[3])
            p[0].setpos(p, 2)
129327
def expr_match(line, expr):
    '''
    
    '''
    if line == expr:
        return True
    if fnmatch.fnmatch(line, expr):
        return True
    try:
        if re.match(r'\A{0}\Z'.format(expr), line):
            return True
    except re.error:
        pass
    return False
758101
def _check_expr_filename(expr):
    
    expr_lst = expr.split()
    f = [x for x in expr_lst if x not in DATA_FRAMES and x.endswith(".lpd")]
    return f
1213232
def p_postfix_expr(self, p):
        
        if len(p) == 2:
            p[0] = p[1]
        else:
            p[0] = ast.UnaryOp(op=p[2], value=p[1], postfix=True)
561699
def _GetPredicate(self, pred_str, test_attr=False):
        
        predicate, args, func_type = self.predicates.LookupWithType(pred_str)
        if predicate:
            pred = predicate, args, func_type
        else:
            # Nicer syntax, {.debug?} is shorthand for {.if test debug}.
            # Currently there is not if/elif chain; just use
            # {.if test debug} {.or test release} {.or} {.end}
            if test_attr:
                assert pred_str.endswith('?')
                # func, args, func_type
                pred = (_TestAttribute, (pred_str[:-1],), ENHANCED_FUNC)
            else:
                raise BadPredicate('%r is not a valid predicate' % pred_str)
        return pred
1246039
def inspect
      expr = @expr || @unit.expr
      expr = (expr) ? ","+expr.inspect : ""
      sufx = (@@verbose_inspect) ? " "+@unit.inspect : ""
      self.class.to_s+"["+Unit::Utils.num_inspect(@value)+expr+"]"+sufx
    end
446310
def describe_token_expr(expr):
    """"""
    if ':' in expr:
        type, value = expr.split(':', 1)
        if type == 'name':
            return value
    else:
        type = expr
    return _describe_token_type(type)