lerzegov/elm-syntax-fork/1.0.0

NOTE: the latest version is 1.1.0

Elm.Syntax.Expression

This syntax represents all that you can express in Elm. Although it is a easy and simple language, you can express a lot! See the Expression type for all the things you can express.

Types

= UnitExpr
| Application (List (Node Expression))
| OperatorApplication
String
| FunctionOrValue ModuleName String
| PrefixOperator String
| Operator String
| Integer Int
| Hex Int
| Floatable Float
| Negation (Node Expression)
| Literal String
| CharLiteral Char
| TupledExpression (List (Node Expression))
| ParenthesizedExpression (Node Expression)
| LetExpression LetBlock
| CaseExpression CaseBlock
| LambdaExpression Lambda
| RecordExpr (List (Node RecordSetter))
| ListExpr (List (Node Expression))
| RecordAccess (Node Expression) (Node String)
| RecordAccessFunction String
| RecordUpdateExpression (Node String) (List (Node RecordSetter))
| GLSLExpression String

Custom type for all expressions such as:

  • Unit: ()
  • Application: add a b
  • OperatorApplication: a + b
  • FunctionOrValue: add or True
  • IfBlock: if a then b else c
  • PrefixOperator: (+)
  • Operator: + (not possible to get in practice)
  • Integer: 42
  • Hex: 0x1F
  • Floatable: 42.0
  • Negation: -a
  • Literal: "text"
  • CharLiteral: 'a'
  • TupledExpression: (a, b) or (a, b, c)
  • ParenthesizedExpression: (a)
  • LetExpression: let a = 4 in a
  • CaseExpression: case a of followed by pattern matches
  • LambdaExpression: (\a -> a)
  • RecordExpr: { name = "text" }
  • ListExpr: [ x, y ]
  • RecordAccess: a.name
  • RecordAccessFunction: .name
  • RecordUpdateExpression: { a | name = "text" }
  • GLSLExpression: [glsl| ... |]
type alias Lambda =
{ args : List (Node Pattern)
, expression : Node Expression
}

Expression for a lambda

type alias LetBlock =
{ declarations : List (Node LetDeclaration)
, expression : Node Expression
}

Expression for a let block

= LetFunction Function
| LetDestructuring (Node Pattern) (Node Expression)

Union type for all possible declarations in a let block

type alias RecordSetter =
( Node String, Node Expression )

Expression for setting a record field

type alias CaseBlock =
{ expression : Node Expression
, cases : Cases
}

Expression for a case block

type alias Cases =
List Case

Type alias for a list of cases

type alias Case =

A case in a case block

type alias Function =
{ documentation : Maybe (Node Documentation)
, signature : Maybe (Node Signature)
, declaration : Node FunctionImplementation
}

Type alias for a full function

{ name : Node String
, arguments : List (Node Pattern)
, expression : Node Expression
}

Type alias for a function's implementation

Functions

functionRange : Function -> Range

Get the full range of a function

Check whether an expression is a lambda-expression

isLet : Expression -> Bool

Check whether an expression is a let-expression

Check whether an expression is an if-else-expression

isCase : Expression -> Bool

Check whether an expression is a case-expression

Check whether an expression is an operator application expression

Serialization

encode : Expression -> Value

Encode an Expression syntax element to JSON.

encodeFunction : Function -> Value

Encode a Function syntax element to JSON.

JSON decoder for an Expression syntax element.

functionDecoder : Decoder Function

JSON decoder for an Function syntax element.