ExpressionSyntax Base Class
All expression nodes inherit fromExpressionSyntax, which itself inherits from LuaSyntaxNode.
Expressions can appear in many contexts:
- Assignment values
- Function arguments
- Conditions
- Return values
- Table fields
- And more
Literal Expressions
LiteralExpressionSyntax
Represents literal values. Kinds:NumericalLiteralExpression- Numbers:123,0xFF,3.14StringLiteralExpression- Strings:"hello",'world',[[long string]]TrueLiteralExpression- BooleantrueFalseLiteralExpression- BooleanfalseNilLiteralExpression-nil
Token- The literal token
Identifier Expressions
IdentifierNameSyntax
Represents a variable or function name. Key properties:Identifier- The identifier tokenName- The identifier text as a string
Binary Expressions
BinaryExpressionSyntax
Represents binary operations with two operands. Key properties:Left- Left operand expressionOperatorToken- The operator tokenRight- Right operand expression
AddExpression-a + bSubtractExpression-a - bMultiplyExpression-a * bDivideExpression-a / bFloorDivideExpression-a // b(Lua 5.3+)ModuloExpression-a % bExponentiateExpression-a ^ b
EqualsExpression-a == bNotEqualsExpression-a ~= bora != bLessThanExpression-a < bLessThanOrEqualExpression-a <= bGreaterThanExpression-a > bGreaterThanOrEqualExpression-a >= b
LogicalAndExpression-a and bLogicalOrExpression-a or b
BitwiseAndExpression-a & bBitwiseOrExpression-a | bExclusiveOrExpression-a ~ bora ^^ bLeftShiftExpression-a << bRightShiftExpression-a >> b
ConcatExpression-a .. b
Unary Expressions
UnaryExpressionSyntax
Represents unary operations with one operand. Key properties:OperatorToken- The operator tokenOperand- The operand expression
UnaryMinusExpression--x(negation)LogicalNotExpression-not xLengthExpression-#x(length operator)BitwiseNotExpression-~x(bitwise not, if enabled)
Table Constructor
TableConstructorExpressionSyntax
Represents table literal construction. Syntax:{ field1, field2, key = value }
Key properties:
OpenBraceToken- The{tokenFields- List of table fields (SeparatedSyntaxList<TableFieldSyntax>)CloseBraceToken- The}token
UnkeyedTableFieldSyntax- Array-style:valueIdentifierKeyedTableFieldSyntax- Named field:key = valueExpressionKeyedTableFieldSyntax- Computed key:[expr] = value
Function Expressions
AnonymousFunctionExpressionSyntax
Represents anonymous function (lambda) expressions. Syntax:function(param1, param2) body end
Key properties:
FunctionKeyword- ThefunctionkeywordTypeParameterList- Optional generic type parameters (Luau)Parameters- Parameter listTypeBinding- Optional return type annotationBody- Function body statementsEndKeyword- Theendkeyword
Function Call Expression
FunctionCallExpressionSyntax
Represents a function call. Syntax:func(arg1, arg2) or func "string" or func { table }
Key properties:
Expression- The function being called (aPrefixExpressionSyntax)Argument- The function argument (one ofExpressionListFunctionArgumentSyntax,StringFunctionArgumentSyntax, orTableConstructorFunctionArgumentSyntax)
MethodCallExpressionSyntax
Represents a method call using colon syntax. Syntax:obj:method(arg1, arg2)
Key properties:
Expression- The object expressionColonToken- The:tokenIdentifier- The method nameArgument- The function argument
Member Access Expressions
MemberAccessExpressionSyntax
Represents member access using dot notation. Syntax:table.field
Key properties:
Expression- The table expressionDotSeparator- The.tokenMemberName- The member identifier token
ElementAccessExpressionSyntax
Represents element access using bracket notation. Syntax:table[key]
Key properties:
Expression- The table expressionOpenBracketToken- The[tokenKeyExpression- The key expressionCloseBracketToken- The]token
Other Expressions
ParenthesizedExpressionSyntax
Represents an expression wrapped in parentheses. Syntax:(expression)
Key properties:
OpenParenthesisToken- The(tokenExpression- The inner expressionCloseParenthesisToken- The)token
VarArgExpressionSyntax
Represents the vararg expression....
Key properties:
VarArgToken- The...token
TypeCastExpressionSyntax
Represents a type cast (Luau). Syntax:expression :: Type
Key properties:
Expression- The expression being castColonColonToken- The::tokenType- The target type
IfExpressionSyntax
Represents an if-expression (Luau). Syntax:if condition then trueValue elseif condition2 then value2 else falseValue
Key properties:
IfKeyword- TheifkeywordCondition- The condition expressionThenKeyword- ThethenkeywordTrueValue- Expression for true caseElseIfClauses- List of elseif clausesElseKeyword- TheelsekeywordFalseValue- Expression for false case
InterpolatedStringExpressionSyntax
Represents an interpolated string (if enabled). Syntax:`Hello {name}!`
Key properties:
StringStartToken- The opening backtickContents- List of string text and interpolationsStringEndToken- The closing backtick
PrefixExpressionSyntax
PrefixExpressionSyntax is an abstract base class for expressions that can appear as prefixes in certain contexts (like the left side of assignments or before method calls). It includes:
IdentifierNameSyntaxParenthesizedExpressionSyntaxMemberAccessExpressionSyntaxElementAccessExpressionSyntaxFunctionCallExpressionSyntaxMethodCallExpressionSyntax
VariableExpressionSyntax
VariableExpressionSyntax is an abstract base class for expressions that can be assigned to:
IdentifierNameSyntaxMemberAccessExpressionSyntaxElementAccessExpressionSyntax
See Also
- Overview - Syntax node hierarchy
- Statements - Statement node types
- Types - Type annotation nodes
- SyntaxFactory - Creating syntax nodes