2020-05-10 11:58:31 +02:00
|
|
|
|
2020-05-10 15:56:34 +02:00
|
|
|
@language Bolt;
|
|
|
|
@language JS;
|
|
|
|
|
2020-05-22 19:50:47 +02:00
|
|
|
node EndOfFile > BoltToken, JSToken;
|
|
|
|
|
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,
|
|
|
|
}
|
|
|
|
|
2020-05-10 23:50:42 +02:00
|
|
|
node BoltAssignment > BoltToken {
|
|
|
|
operator: Option<String>,
|
|
|
|
}
|
|
|
|
|
2020-05-10 11:58:31 +02:00
|
|
|
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;
|
2020-05-10 18:21:44 +02:00
|
|
|
node BoltGtSign > BoltToken;
|
|
|
|
node BoltLtSign > BoltToken;
|
2020-05-10 11:58:31 +02:00
|
|
|
|
|
|
|
node BoltKeyword;
|
|
|
|
|
|
|
|
node BoltFnKeyword > BoltToken, BoltKeyword;
|
|
|
|
node BoltForeignKeyword > BoltToken, BoltKeyword;
|
|
|
|
node BoltLetKeyword > BoltToken, BoltKeyword;
|
2020-05-10 18:21:44 +02:00
|
|
|
node BoltReturnKeyword > BoltToken, BoltKeyword;
|
|
|
|
node BoltLoopKeyword > BoltToken, BoltKeyword;
|
|
|
|
node BoltYieldKeyword > BoltToken, BoltKeyword;
|
2020-05-10 18:54:57 +02:00
|
|
|
node BoltMatchKeyword > BoltToken, BoltKeyword;
|
2020-05-10 11:58:31 +02:00
|
|
|
node BoltImportKeyword > BoltToken, BoltKeyword;
|
|
|
|
node BoltPubKeyword > BoltToken, BoltKeyword;
|
|
|
|
node BoltModKeyword > BoltToken, BoltKeyword;
|
2020-05-10 18:21:44 +02:00
|
|
|
node BoltMutKeyword > BoltToken, BoltKeyword;
|
2020-05-10 11:58:31 +02:00
|
|
|
node BoltEnumKeyword > BoltToken, BoltKeyword;
|
|
|
|
node BoltStructKeyword > BoltToken, BoltKeyword;
|
2020-05-22 19:50:47 +02:00
|
|
|
node BoltTypeKeyword > BoltToken, BoltKeyword;
|
|
|
|
node BoltTraitKeyworkd > BoltToken, BoltKeyword;
|
2020-05-10 11:58:31 +02:00
|
|
|
|
|
|
|
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-22 19:50:47 +02:00
|
|
|
node BoltTypeExpression;
|
2020-05-10 11:58:31 +02:00
|
|
|
|
2020-05-22 19:50:47 +02:00
|
|
|
node BoltReferenceTypeExpression > BoltTypeExpression {
|
2020-05-10 11:58:31 +02:00
|
|
|
name: BoltQualName,
|
2020-05-22 19:50:47 +02:00
|
|
|
arguments: Option<Vec<BoltTypeExpression>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
node BoltTypeParameter {
|
|
|
|
index: usize,
|
|
|
|
name: BoltIdentifier,
|
|
|
|
defaultType: Option<BoltTypeExpression>,
|
2020-05-10 11:58:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
node BoltPattern;
|
|
|
|
|
|
|
|
node BoltBindPattern > BoltPattern {
|
2020-05-10 18:21:44 +02:00
|
|
|
name: BoltIdentifier,
|
2020-05-10 11:58:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
node BoltTypePattern > BoltPattern {
|
2020-05-22 19:50:47 +02:00
|
|
|
type: BoltTypeExpression,
|
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-22 19:50:47 +02:00
|
|
|
name: BoltTypeExpression,
|
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-22 19:50:47 +02:00
|
|
|
type: Option<BoltTypeExpression>,
|
2020-05-10 11:58:31 +02:00
|
|
|
defaultValue: Option<BoltExpression>,
|
|
|
|
}
|
|
|
|
|
2020-05-10 15:56:34 +02:00
|
|
|
node BoltDeclaration > BoltSourceElement;
|
|
|
|
|
2020-05-22 19:50:47 +02:00
|
|
|
node BoltTypeDeclaration > BoltDeclaration;
|
|
|
|
|
2020-05-10 15:56:34 +02:00
|
|
|
enum BoltDeclarationModifiers {
|
2020-05-10 18:21:44 +02:00
|
|
|
Mutable = 0x1,
|
|
|
|
Public = 0x2,
|
|
|
|
IsType = 0x4,
|
|
|
|
IsForeign = 0x8,
|
2020-05-10 15:56:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
node BoltModule > BoltDeclaration {
|
|
|
|
modifiers: BoltDeclarationModifiers,
|
|
|
|
name: BoltQualName,
|
|
|
|
elements: Vec<BoltSourceElement>,
|
|
|
|
}
|
2020-05-10 11:58:31 +02:00
|
|
|
|
|
|
|
node BoltFunctionDeclaration > 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-22 19:50:47 +02:00
|
|
|
returnType: Option<BoltTypeExpression>,
|
2020-05-10 18:54:57 +02:00
|
|
|
body: Vec<BoltStatement>,
|
2020-05-10 11:58:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
node BoltVariableDeclaration > BoltDeclaration {
|
|
|
|
modifiers: BoltDeclarationModifiers,
|
2020-05-10 15:56:34 +02:00
|
|
|
bindings: BoltPattern,
|
2020-05-22 19:50:47 +02:00
|
|
|
type: Option<BoltTypeExpression>,
|
2020-05-10 11:58:31 +02:00
|
|
|
value: Option<BoltExpression>,
|
|
|
|
}
|
|
|
|
|
|
|
|
node BoltImportSymbol;
|
|
|
|
|
|
|
|
node BoltPlainImportSymbol > BoltImportSymbol {
|
|
|
|
name: BoltQualName,
|
|
|
|
}
|
|
|
|
|
|
|
|
node BoltImportDeclaration > BoltDeclaration {
|
|
|
|
file: String,
|
|
|
|
symbols: Vec<BoltImportSymbol>,
|
|
|
|
}
|
|
|
|
|
|
|
|
node BoltRecordDeclarationField {
|
|
|
|
name: BoltIdentifier,
|
2020-05-22 19:50:47 +02:00
|
|
|
type: BoltTypeExpression,
|
|
|
|
}
|
|
|
|
|
|
|
|
node BoltTypeAliasDeclaration > BoltTypeDeclaration {
|
|
|
|
modifiers: BoltDeclarationModifiers,
|
|
|
|
name: BoltIdentifier,
|
|
|
|
typeParams: Option<Vec<BoltTypeParameter>>,
|
|
|
|
typeExpr: BoltTypeExpression,
|
2020-05-10 11:58:31 +02:00
|
|
|
}
|
|
|
|
|
2020-05-10 15:56:34 +02:00
|
|
|
node BoltSourceElement;
|
|
|
|
|
2020-05-22 19:50:47 +02:00
|
|
|
node BoltRecordDeclaration > BoltTypeDeclaration {
|
2020-05-10 19:05:37 +02:00
|
|
|
modifiers: BoltDeclarationModifiers,
|
2020-05-10 11:58:31 +02:00
|
|
|
name: BoltQualName,
|
2020-05-22 19:50:47 +02:00
|
|
|
typeParms: Option<Vec<BoltTypeParameter>>,
|
2020-05-10 11:58:31 +02:00
|
|
|
fields: Vec<BoltRecordDeclarationField>,
|
|
|
|
}
|
|
|
|
|
|
|
|
// JavaScript AST definitions
|
|
|
|
|
|
|
|
type JSValue = Int | String | Bool | Void;
|
|
|
|
|
|
|
|
node JSToken;
|
|
|
|
|
|
|
|
node JSOperator > JSToken {
|
|
|
|
text: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
node JSIdentifier > JSToken {
|
|
|
|
text: String,
|
|
|
|
}
|
|
|
|
|
2020-05-22 19:50:47 +02:00
|
|
|
node JSReturnKeyword > JSToken;
|
|
|
|
node JSTryKeyword > JSToken;
|
|
|
|
node JSCatchKeyword > JSToken;
|
|
|
|
|
2020-05-10 11:58:31 +02:00
|
|
|
node JSPattern;
|
|
|
|
|
2020-05-10 15:56:34 +02:00
|
|
|
node JSBindPattern > JSPattern {
|
2020-05-10 18:21:44 +02:00
|
|
|
name: JSIdentifier,
|
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,
|
|
|
|
}
|
|
|
|
|
2020-05-22 19:50:47 +02:00
|
|
|
node JSSourceElement;
|
|
|
|
|
|
|
|
node JSStatement > JSSourceElement;
|
2020-05-10 11:58:31 +02:00
|
|
|
|
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-22 19:50:47 +02:00
|
|
|
node JSDeclaration > JSSourceElement;
|
2020-05-10 11:58:31 +02:00
|
|
|
|
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>,
|
|
|
|
}
|
|
|
|
|