pub enum Expr {
Show 20 variants
Unit,
Literal(Literal),
FunctionOrValue {
module_name: ModuleName,
name: Ident,
},
PrefixOperator(Ident),
OperatorApplication {
operator: Ident,
direction: InfixDirection,
left: Box<Spanned<Expr>>,
right: Box<Spanned<Expr>>,
},
BinOps {
operands_and_operators: Vec<(Spanned<Expr>, Spanned<Ident>)>,
final_operand: Box<Spanned<Expr>>,
},
Application(Vec<Spanned<Expr>>),
IfElse {
branches: Vec<IfBranch>,
else_branch: Box<Spanned<Expr>>,
},
Negation(Box<Spanned<Expr>>),
Tuple(Vec<Spanned<Expr>>),
Parenthesized {
expr: Box<Spanned<Expr>>,
trailing_comments: Vec<Spanned<Comment>>,
},
LetIn {
declarations: Vec<Spanned<LetDeclaration>>,
body: Box<Spanned<Expr>>,
trailing_comments: Vec<Spanned<Comment>>,
},
CaseOf {
expr: Box<Spanned<Expr>>,
branches: Vec<CaseBranch>,
},
Lambda {
args: Vec<Spanned<Pattern>>,
body: Box<Spanned<Expr>>,
},
Record(Vec<Spanned<RecordSetter>>),
RecordUpdate {
base: Spanned<Ident>,
updates: Vec<Spanned<RecordSetter>>,
},
RecordAccess {
record: Box<Spanned<Expr>>,
field: Spanned<Ident>,
},
RecordAccessFunction(Ident),
List {
elements: Vec<Spanned<Expr>>,
element_inline_comments: Vec<Option<Spanned<Comment>>>,
trailing_comments: Vec<Spanned<Comment>>,
},
GLSLExpression(String),
}Expand description
An expression in Elm source code.
This covers every expression form in Elm 0.19.1.
Variants§
Unit
Unit expression: ()
Literal(Literal)
A literal value: 42, "hello", 'c', 3.14
FunctionOrValue
A reference to a value or constructor, possibly qualified.
Examples:
foo→FunctionOrValue { module_name: [], name: "foo" }Just→FunctionOrValue { module_name: [], name: "Just" }Maybe.Just→FunctionOrValue { module_name: ["Maybe"], name: "Just" }
PrefixOperator(Ident)
An operator used as a prefix (in parentheses): (+), (::)
OperatorApplication
Operator application with resolved precedence and associativity:
a + b → OperatorApplication { operator: "+", direction: Left, left, right }
Note: in the source AST from elm/compiler this is Binops, a flat list.
We use the resolved form from elm-syntax for ergonomics, but also provide
BinOps below for representing the raw unresolved form.
BinOps
Raw unresolved binary operator chain, as in the source AST.
a + b * c → BinOps { operands_and_operators: [(a, +), (b, *)], final_operand: c }
This is the form directly from parsing, before operator precedence
resolution. Corresponds to Binops in AST/Source.hs.
Fields
Application(Vec<Spanned<Expr>>)
Function application: f x y → Application [f, x, y]
IfElse
If-then-else expression: if a then b else c
Chained if-else: if a then b else if c then d else e
is represented as IfElse { branches: [IfBranch(a, b), IfBranch(c, d)], else_branch: e }
Negation(Box<Spanned<Expr>>)
Negation: -expr
Tuple(Vec<Spanned<Expr>>)
Tuple expression: ( a, b ) or ( a, b, c )
Parenthesized
Parenthesized expression: ( expr ).
trailing_comments captures comments that appear between the inner
expression and the closing ), e.g.
( expr
-- trailing
)LetIn
Let-in expression:
let
x = 1
y = 2
in
x + ytrailing_comments captures any comments that appear between the
last declaration and the in keyword. elm-format preserves them
as a dangling block at the end of the let body.
Fields
declarations: Vec<Spanned<LetDeclaration>>CaseOf
Case-of expression:
case msg of
Increment -> model + 1
Decrement -> model - 1Lambda
Lambda expression: \x y -> x + y
Record(Vec<Spanned<RecordSetter>>)
Record expression: { name = "Alice", age = 30 }
RecordUpdate
Record update expression: { model | count = model.count + 1 }
RecordAccess
Record field access: model.count
RecordAccessFunction(Ident)
Record access function: .name
List
List expression: [ 1, 2, 3 ].
trailing_comments captures any comments that appear between the
last element and the closing ], e.g.
[ a
, b
-- dangling
]Fields
GLSLExpression(String)
GLSL shader block: [glsl| ... |]