bolt/spec/ast.txt

366 lines
6.7 KiB
Text
Raw Normal View History

2020-05-10 11:58:31 +02:00
2020-05-10 15:56:34 +02:00
@language Bolt;
@language JS;
2020-05-10 11:58:31 +02:00
// Bolt language AST definitions
type BoltValue = Integer | bool | String;
node FunctionBody;
node BoltToken;
node BoltStringLiteral > BoltToken {
value: String,
}
node BoltIntegerLiteral > BoltToken {
2020-05-10 15:56:34 +02:00
value: Int,
2020-05-10 11:58:31 +02:00
}
node BoltSymbol > BoltToken {
}
node BoltIdentifier > BoltSymbol {
text: String,
}
node BoltOperator > BoltSymbol {
text: String,
}
node BoltEOS > BoltToken;
node BoltComma > BoltToken;
node BoltSemi > BoltToken;
2020-05-10 15:56:34 +02:00
node BoltColon > BoltToken;
2020-05-10 11:58:31 +02:00
node BoltDot > BoltToken;
node BoltDotDot > BoltToken;
node BoltRArrow > BoltToken;
node BoltLArrow > BoltToken;
node BoltEqSign > BoltToken;
node BoltKeyword;
node BoltFnKeyword > BoltToken, BoltKeyword;
node BoltForeignKeyword > BoltToken, BoltKeyword;
node BoltLetKeyword > BoltToken, BoltKeyword;
node BoltImportKeyword > BoltToken, BoltKeyword;
node BoltPubKeyword > BoltToken, BoltKeyword;
node BoltModKeyword > BoltToken, BoltKeyword;
node BoltEnumKeyword > BoltToken, BoltKeyword;
node BoltStructKeyword > BoltToken, BoltKeyword;
node BoltNewTypeKeyword > BoltToken, BoltKeyword;
node BoltPunctuated > BoltToken {
text: String,
}
node BoltParenthesized > BoltPunctuated;
node BoltBraced > BoltPunctuated;
node BoltBracketed > BoltPunctuated;
node BoltSourceFile {
elements: Vec<BoltSourceElement>,
}
node BoltQualName {
modulePath: Vec<BoltIdentifier>,
name: BoltSymbol,
}
2020-05-10 15:56:34 +02:00
node BoltSentence > BoltSourceElement {
tokens: Vec<BoltToken>,
}
2020-05-10 11:58:31 +02:00
node BoltTypeNode;
node BoltReferenceTypeNode > BoltTypeNode {
name: BoltQualName,
arguments: Option<Vec<BoltTypeNode>>,
}
node BoltPattern;
node BoltBindPattern > BoltPattern {
name: String,
}
node BoltTypePattern > BoltPattern {
2020-05-10 15:56:34 +02:00
type: BoltTypeNode,
2020-05-10 11:58:31 +02:00
nestedPattern: BoltPattern,
}
node BoltExpressionPattern > BoltPattern {
expression: BoltExpression,
}
node BoltTuplePatternElement {
index: usize,
pattern: BoltPattern,
}
node BoltTuplePattern > BoltPattern {
elements: Vec<BoltTuplePatternElement>,
}
node BoltRecordPatternField {
name: BoltIdentifier,
pattern: BoltPattern,
}
node BoltRecordPattern > BoltPattern {
2020-05-10 15:56:34 +02:00
name: BoltTypeNode,
2020-05-10 11:58:31 +02:00
fields: Vec<BoltRecordPatternField>,
}
node BoltExpression;
2020-05-10 15:56:34 +02:00
node BoltReferenceExpression > BoltExpression {
name: BoltQualName,
}
2020-05-10 11:58:31 +02:00
node BoltCallExpression > BoltExpression {
operator: BoltExpression,
operands: Vec<BoltExpression>,
}
node BoltYieldExpression > BoltExpression {
value: BoltExpression,
}
node BoltMatchArm {
pattern: BoltPattern,
body: BoltExpression,
}
node BoltMatchExpression > BoltExpression {
value: BoltExpression,
arms: Vec<BoltMatchArm>,
}
node BoltCase {
test: BoltExpression,
result: BoltExpression,
}
node BoltCaseExpression > BoltExpression {
cases: Vec<BoltCase>,
}
node BoltBlockExpression > BoltExpression {
statements: Vec<BoltStatement>,
}
node BoltConstantExpression > BoltExpression {
value: BoltValue,
}
2020-05-10 15:56:34 +02:00
node BoltStatement > BoltSourceElement;
2020-05-10 11:58:31 +02:00
node BoltReturnStatement > BoltStatement {
value: Option<BoltExpression>,
}
node BoltResumeStatement > BoltStatement {
value: BoltExpression,
}
node BoltExpressionStatement > BoltStatement {
expression: BoltExpression,
}
node BoltParameter {
index: usize,
bindings: BoltPattern,
2020-05-10 15:56:34 +02:00
type: Option<BoltTypeNode>,
2020-05-10 11:58:31 +02:00
defaultValue: Option<BoltExpression>,
}
2020-05-10 15:56:34 +02:00
node BoltDeclaration > BoltSourceElement;
enum BoltDeclarationModifiers {
Mutable = 0x1,
Public = 0x2,
IsType = 0x4,
}
node BoltNewTypeDeclaration > BoltDeclaration {
modifiers: BoltDeclarationModifiers,
name: BoltIdentifier,
}
node BoltModule > BoltDeclaration {
modifiers: BoltDeclarationModifiers,
name: BoltQualName,
elements: Vec<BoltSourceElement>,
}
2020-05-10 11:58:31 +02:00
node BoltFunctionDeclaration > BoltDeclaration {
modifiers: BoltDeclarationModifiers,
name: BoltSymbol,
params: Vec<BoltParameter>,
2020-05-10 15:56:34 +02:00
returnType: Option<BoltTypeNode>,
2020-05-10 11:58:31 +02:00
body: BoltExpression,
}
node BoltForeignFunctionDeclaration > BoltDeclaration {
modifiers: BoltDeclarationModifiers,
2020-05-10 15:56:34 +02:00
target: String,
2020-05-10 11:58:31 +02:00
name: BoltSymbol,
params: Vec<BoltParameter>,
2020-05-10 15:56:34 +02:00
returnType: Option<BoltTypeNode>,
2020-05-10 11:58:31 +02:00
body: FunctionBody,
}
node BoltVariableDeclaration > BoltDeclaration {
modifiers: BoltDeclarationModifiers,
2020-05-10 15:56:34 +02:00
bindings: BoltPattern,
2020-05-10 11:58:31 +02:00
type: Option<BoltTypeNode>,
value: Option<BoltExpression>,
}
node BoltImportSymbol;
node BoltPlainImportSymbol > BoltImportSymbol {
name: BoltQualName,
}
node BoltImportDeclaration > BoltDeclaration {
file: String,
symbols: Vec<BoltImportSymbol>,
}
node BoltRecordDeclarationField {
name: BoltIdentifier,
type: BoltTypeNode,
}
2020-05-10 15:56:34 +02:00
node BoltSourceElement;
2020-05-10 11:58:31 +02:00
node BoltRecordDeclaration > BoltDeclaration {
name: BoltQualName,
fields: Vec<BoltRecordDeclarationField>,
}
// JavaScript AST definitions
type JSValue = Int | String | Bool | Void;
node JSToken;
node JSOperator > JSToken {
text: String,
}
node JSIdentifier > JSToken {
text: String,
}
node JSPattern;
2020-05-10 15:56:34 +02:00
node JSBindPattern > JSPattern {
name: String,
2020-05-10 11:58:31 +02:00
}
node JSExpression;
node JSConstantExpression > JSExpression {
value: BoltValue,
}
enum JSMemberExpressionModifiers {
Computed = 0x1,
}
node JSMemberExpression > JSExpression {
value: JSExpression,
property: JSExpression,
modifiers: JSMemberExpressionModifiers,
}
node JSCallExpression > JSExpression {
operator: JSExpression,
operands: Vec<JSExpression>,
}
node JSBinaryExpression > JSExpression {
left: JSExpression,
operator: JSOperator,
right: JSExpression,
}
node JSUnaryExpression > JSExpression {
operator: JSOperator,
operand: JSExpression
}
node JSNewExpression > JSExpression {
target: JSExpression,
arguments: Vec<JSExpression>,
}
node JSSequenceExpression > JSExpression {
expressions: Vec<JSExpression>,
}
node JSConditionalExpression > JSExpression {
test: JSExpression,
consequent: JSExpression,
alternate: JSExpression,
}
node JSReferenceExpression > JSExpression {
name: String,
}
node JSStatement;
2020-05-10 15:56:34 +02:00
node JSExpressionStatement > JSStatement {
expression: JSExpression,
}
2020-05-10 11:58:31 +02:00
node JSConditionalStatement > JSStatement {
test: JSExpression,
consequent: Vec<JSStatement>,
alternate: Vec<JSStatement>,
}
2020-05-10 15:56:34 +02:00
node JSParameter {
index: usize,
bindings: JSPattern,
defaultValue: Option<JSExpression>,
}
2020-05-10 11:58:31 +02:00
node JSDeclaration;
2020-05-10 15:56:34 +02:00
enum JSDeclarationModifiers {
IsExported = 0x1,
}
node JSFunctionDeclaration > JSDeclaration {
modifiers: JSDeclarationModifiers,
name: JSIdentifier,
params: Vec<JSParameter>,
body: Vec<JSStatement>,
}
node JSArrowFunctionDeclaration > JSDeclaration {
name: JSIdentifier,
params: Vec<JSParameter>,
body: JSExpression,
}
node JSLetDeclaration > JSDeclaration {
bindings: JSPattern,
value: Option<JSExpression>,
}
2020-05-10 11:58:31 +02:00
node JSSourceFile {
elements: Vec<JSSourceElement>,
}
node JSSourceElement > JSDeclaration, JSStatement;