TaglessFinal.Expression
This module provides a type that represents a Python expression.
type ('arguments, 'bin_op, 'bool_op, 'compare, 'comprehension, 'constant, 'expr_context, 'identifier, 'keyword, 'location, 'unary_op, 'expr)
t =
private {
bool_op : location:'location -> op:'bool_op -> values:'expr list -> 'expr;
Represents a boolean expression.
a and b
a or b or c
named_expr : location:'location -> target:'expr -> value:'expr -> 'expr;
Represents an assignment expression, a.k.a. the "walrus" operator. target
is guaranteed by the CPython parser to always be a simple identifier. See PEP 572.
(a := b)
bin_op : location:'location ->
left:'expr ->
op:'bin_op ->
right:'expr ->
'expr;
Represents a numerical binary expression.
a + b
unary_op : location:'location -> op:'unary_op -> operand:'expr -> 'expr;
Represents an unary expression.
not a
lambda : location:'location -> args:'arguments -> body:'expr -> 'expr;
if_exp : location:'location ->
test:'expr ->
body:'expr ->
orelse:'expr ->
'expr;
dict : location:'location ->
keys:'expr option list ->
values:'expr list ->
'expr;
Represents a Python dictionary display.
{}
{ "a": 1, "b": 2 }
{ "a": 1, **b }
. The element **b
here will be represented with a None
key and a value of b
.set : location:'location -> elts:'expr list -> 'expr;
Represents a Python set display.
{ "a", "b" }
list_comp : location:'location ->
elt:'expr ->
generators:'comprehension list ->
'expr;
Represents a list comprehension. See PEP 202.
[y for x in l if len(x) > 1 for y in x if y < 4]
set_comp : location:'location ->
elt:'expr ->
generators:'comprehension list ->
'expr;
Represents a set comprehension.
{x for x in l}
dict_comp : location:'location ->
key:'expr ->
value:'expr ->
generators:'comprehension list ->
'expr;
generator_exp : location:'location ->
elt:'expr ->
generators:'comprehension list ->
'expr;
await : location:'location -> value:'expr -> 'expr;
yield : location:'location -> value:'expr option -> 'expr;
yield_from : location:'location -> value:'expr -> 'expr;
compare : location:'location ->
left:'expr ->
ops:'compare list ->
comparators:'expr list ->
'expr;
Represents a comparison expression.
x is y
x > y > z
call : location:'location ->
func:'expr ->
args:'expr list ->
keywords:'keyword list ->
'expr;
Represents a call expression, where args
is the list of positionally-specified arguments, and keywords
is the list of keyword-specified arguments.
foo(x, y=1)
foo(x, *y, **z)
formatted_value : location:'location ->
value:'expr ->
conversion:int ->
format_spec:'expr option ->
'expr;
Represents the expression component of an f-string. See PEP 498. conversion
is an integer representing the type conversion operator:
-1
means no formatting.115
means !s
string formatting.114
means !r
repr formatting97
means !a
ascii formattingformat_spec
represents the format specifier. This is always going to be a joined_str
expression.
f"derp={a+b:{foo}}"
. The entire expression will be a joined_str
but the a+b
part will be represented as a formatted_value
with the foo
part as its format specifier.joined_str : location:'location -> values:'expr list -> 'expr;
constant : location:'location ->
value:'constant ->
kind:string option ->
'expr;
Represents a constant expression.
42
attribute : location:'location ->
value:'expr ->
attr:'identifier ->
ctx:'expr_context ->
'expr;
Represents an attribute access expression.
a.b
subscript : location:'location ->
value:'expr ->
slice:'expr ->
ctx:'expr_context ->
'expr;
Represents a subscript access expression.
a[b]
starred : location:'location -> value:'expr -> ctx:'expr_context -> 'expr;
Represents an starred expression, which is used to represent iterable unpacking (inside call
, list
, or comprehension expressions, for example). See PEP 448.
name : location:'location -> id:'identifier -> ctx:'expr_context -> 'expr;
Represents a simple identifier.
a
list : location:'location -> elts:'expr list -> ctx:'expr_context -> 'expr;
Represents a Python list display.
[]
[a, b]
[a, *b]
tuple : location:'location -> elts:'expr list -> ctx:'expr_context -> 'expr;
Represents a Python tuple display.
()
(a, b)
(a, *b)
slice : location:'location ->
lower:'expr option ->
upper:'expr option ->
step:'expr option ->
'expr;
Represents a slice expression. This kind of expression can only appear within the slice
field of the subscript
expression, either directly or as an element of a tuple
expression.
a[:]
a[1:2, 3:4]
}
val make :
bool_op:(location:'a -> op:'b -> values:'c list -> 'c) ->
named_expr:(location:'a -> target:'c -> value:'c -> 'c) ->
bin_op:(location:'a -> left:'c -> op:'d -> right:'c -> 'c) ->
unary_op:(location:'a -> op:'e -> operand:'c -> 'c) ->
lambda:(location:'a -> args:'f -> body:'c -> 'c) ->
if_exp:(location:'a -> test:'c -> body:'c -> orelse:'c -> 'c) ->
dict:(location:'a -> keys:'c option list -> values:'c list -> 'c) ->
set:(location:'a -> elts:'c list -> 'c) ->
list_comp:(location:'a -> elt:'c -> generators:'g list -> 'c) ->
set_comp:(location:'a -> elt:'c -> generators:'g list -> 'c) ->
dict_comp:(location:'a -> key:'c -> value:'c -> generators:'g list -> 'c) ->
generator_exp:(location:'a -> elt:'c -> generators:'g list -> 'c) ->
await:(location:'a -> value:'c -> 'c) ->
yield:(location:'a -> value:'c option -> 'c) ->
yield_from:(location:'a -> value:'c -> 'c) ->
compare:(location:'a -> left:'c -> ops:'h list -> comparators:'c list -> 'c) ->
call:(location:'a -> func:'c -> args:'c list -> keywords:'i list -> 'c) ->
formatted_value:
(location:'a -> value:'c -> conversion:int -> format_spec:'c option -> 'c) ->
joined_str:(location:'a -> values:'c list -> 'c) ->
constant:(location:'a -> value:'j -> kind:string option -> 'c) ->
attribute:(location:'a -> value:'c -> attr:'k -> ctx:'l -> 'c) ->
subscript:(location:'a -> value:'c -> slice:'c -> ctx:'l -> 'c) ->
starred:(location:'a -> value:'c -> ctx:'l -> 'c) ->
name:(location:'a -> id:'k -> ctx:'l -> 'c) ->
list:(location:'a -> elts:'c list -> ctx:'l -> 'c) ->
tuple:(location:'a -> elts:'c list -> ctx:'l -> 'c) ->
slice:
(location:'a -> lower:'c option -> upper:'c option -> step:'c option -> 'c) ->
unit ->
('f, 'd, 'b, 'h, 'g, 'j, 'l, 'k, 'i, 'a, 'e, 'c) t
Constructor of t
.