Fix most error in src/parser.ts
This commit is contained in:
parent
7aa86d2789
commit
824cf57c13
7 changed files with 590 additions and 385 deletions
11
spec/ast.txt
11
spec/ast.txt
|
@ -40,15 +40,21 @@ node BoltDotDot > BoltToken;
|
||||||
node BoltRArrow > BoltToken;
|
node BoltRArrow > BoltToken;
|
||||||
node BoltLArrow > BoltToken;
|
node BoltLArrow > BoltToken;
|
||||||
node BoltEqSign > BoltToken;
|
node BoltEqSign > BoltToken;
|
||||||
|
node BoltGtSign > BoltToken;
|
||||||
|
node BoltLtSign > BoltToken;
|
||||||
|
|
||||||
node BoltKeyword;
|
node BoltKeyword;
|
||||||
|
|
||||||
node BoltFnKeyword > BoltToken, BoltKeyword;
|
node BoltFnKeyword > BoltToken, BoltKeyword;
|
||||||
node BoltForeignKeyword > BoltToken, BoltKeyword;
|
node BoltForeignKeyword > BoltToken, BoltKeyword;
|
||||||
node BoltLetKeyword > BoltToken, BoltKeyword;
|
node BoltLetKeyword > BoltToken, BoltKeyword;
|
||||||
|
node BoltReturnKeyword > BoltToken, BoltKeyword;
|
||||||
|
node BoltLoopKeyword > BoltToken, BoltKeyword;
|
||||||
|
node BoltYieldKeyword > BoltToken, BoltKeyword;
|
||||||
node BoltImportKeyword > BoltToken, BoltKeyword;
|
node BoltImportKeyword > BoltToken, BoltKeyword;
|
||||||
node BoltPubKeyword > BoltToken, BoltKeyword;
|
node BoltPubKeyword > BoltToken, BoltKeyword;
|
||||||
node BoltModKeyword > BoltToken, BoltKeyword;
|
node BoltModKeyword > BoltToken, BoltKeyword;
|
||||||
|
node BoltMutKeyword > BoltToken, BoltKeyword;
|
||||||
node BoltEnumKeyword > BoltToken, BoltKeyword;
|
node BoltEnumKeyword > BoltToken, BoltKeyword;
|
||||||
node BoltStructKeyword > BoltToken, BoltKeyword;
|
node BoltStructKeyword > BoltToken, BoltKeyword;
|
||||||
node BoltNewTypeKeyword > BoltToken, BoltKeyword;
|
node BoltNewTypeKeyword > BoltToken, BoltKeyword;
|
||||||
|
@ -84,7 +90,7 @@ node BoltReferenceTypeNode > BoltTypeNode {
|
||||||
node BoltPattern;
|
node BoltPattern;
|
||||||
|
|
||||||
node BoltBindPattern > BoltPattern {
|
node BoltBindPattern > BoltPattern {
|
||||||
name: String,
|
name: BoltIdentifier,
|
||||||
}
|
}
|
||||||
|
|
||||||
node BoltTypePattern > BoltPattern {
|
node BoltTypePattern > BoltPattern {
|
||||||
|
@ -184,6 +190,7 @@ enum BoltDeclarationModifiers {
|
||||||
Mutable = 0x1,
|
Mutable = 0x1,
|
||||||
Public = 0x2,
|
Public = 0x2,
|
||||||
IsType = 0x4,
|
IsType = 0x4,
|
||||||
|
IsForeign = 0x8,
|
||||||
}
|
}
|
||||||
|
|
||||||
node BoltNewTypeDeclaration > BoltDeclaration {
|
node BoltNewTypeDeclaration > BoltDeclaration {
|
||||||
|
@ -261,7 +268,7 @@ node JSIdentifier > JSToken {
|
||||||
node JSPattern;
|
node JSPattern;
|
||||||
|
|
||||||
node JSBindPattern > JSPattern {
|
node JSBindPattern > JSPattern {
|
||||||
name: String,
|
name: JSIdentifier,
|
||||||
}
|
}
|
||||||
|
|
||||||
node JSExpression;
|
node JSExpression;
|
||||||
|
|
359
src/ast.d.ts
vendored
359
src/ast.d.ts
vendored
|
@ -14,71 +14,77 @@ export const enum SyntaxKind {
|
||||||
BoltRArrow = 16,
|
BoltRArrow = 16,
|
||||||
BoltLArrow = 17,
|
BoltLArrow = 17,
|
||||||
BoltEqSign = 18,
|
BoltEqSign = 18,
|
||||||
BoltFnKeyword = 20,
|
BoltGtSign = 19,
|
||||||
BoltForeignKeyword = 21,
|
BoltLtSign = 20,
|
||||||
BoltLetKeyword = 22,
|
BoltFnKeyword = 22,
|
||||||
BoltImportKeyword = 23,
|
BoltForeignKeyword = 23,
|
||||||
BoltPubKeyword = 24,
|
BoltLetKeyword = 24,
|
||||||
BoltModKeyword = 25,
|
BoltReturnKeyword = 25,
|
||||||
BoltEnumKeyword = 26,
|
BoltLoopKeyword = 26,
|
||||||
BoltStructKeyword = 27,
|
BoltYieldKeyword = 27,
|
||||||
BoltNewTypeKeyword = 28,
|
BoltImportKeyword = 28,
|
||||||
BoltParenthesized = 30,
|
BoltPubKeyword = 29,
|
||||||
BoltBraced = 31,
|
BoltModKeyword = 30,
|
||||||
BoltBracketed = 32,
|
BoltMutKeyword = 31,
|
||||||
BoltSourceFile = 33,
|
BoltEnumKeyword = 32,
|
||||||
BoltQualName = 34,
|
BoltStructKeyword = 33,
|
||||||
BoltSentence = 35,
|
BoltNewTypeKeyword = 34,
|
||||||
BoltReferenceTypeNode = 37,
|
BoltParenthesized = 36,
|
||||||
BoltBindPattern = 39,
|
BoltBraced = 37,
|
||||||
BoltTypePattern = 40,
|
BoltBracketed = 38,
|
||||||
BoltExpressionPattern = 41,
|
BoltSourceFile = 39,
|
||||||
BoltTuplePatternElement = 42,
|
BoltQualName = 40,
|
||||||
BoltTuplePattern = 43,
|
BoltSentence = 41,
|
||||||
BoltRecordPatternField = 44,
|
BoltReferenceTypeNode = 43,
|
||||||
BoltRecordPattern = 45,
|
BoltBindPattern = 45,
|
||||||
BoltReferenceExpression = 47,
|
BoltTypePattern = 46,
|
||||||
BoltCallExpression = 48,
|
BoltExpressionPattern = 47,
|
||||||
BoltYieldExpression = 49,
|
BoltTuplePatternElement = 48,
|
||||||
BoltMatchArm = 50,
|
BoltTuplePattern = 49,
|
||||||
BoltMatchExpression = 51,
|
BoltRecordPatternField = 50,
|
||||||
BoltCase = 52,
|
BoltRecordPattern = 51,
|
||||||
BoltCaseExpression = 53,
|
BoltReferenceExpression = 53,
|
||||||
BoltBlockExpression = 54,
|
BoltCallExpression = 54,
|
||||||
BoltConstantExpression = 55,
|
BoltYieldExpression = 55,
|
||||||
BoltReturnStatement = 57,
|
BoltMatchArm = 56,
|
||||||
BoltResumeStatement = 58,
|
BoltMatchExpression = 57,
|
||||||
BoltExpressionStatement = 59,
|
BoltCase = 58,
|
||||||
BoltParameter = 60,
|
BoltCaseExpression = 59,
|
||||||
BoltNewTypeDeclaration = 63,
|
BoltBlockExpression = 60,
|
||||||
BoltModule = 64,
|
BoltConstantExpression = 61,
|
||||||
BoltFunctionDeclaration = 65,
|
BoltReturnStatement = 63,
|
||||||
BoltForeignFunctionDeclaration = 66,
|
BoltResumeStatement = 64,
|
||||||
BoltVariableDeclaration = 67,
|
BoltExpressionStatement = 65,
|
||||||
BoltPlainImportSymbol = 69,
|
BoltParameter = 66,
|
||||||
BoltImportDeclaration = 70,
|
BoltNewTypeDeclaration = 69,
|
||||||
BoltRecordDeclarationField = 71,
|
BoltModule = 70,
|
||||||
BoltRecordDeclaration = 73,
|
BoltFunctionDeclaration = 71,
|
||||||
JSOperator = 76,
|
BoltForeignFunctionDeclaration = 72,
|
||||||
JSIdentifier = 77,
|
BoltVariableDeclaration = 73,
|
||||||
JSBindPattern = 79,
|
BoltPlainImportSymbol = 75,
|
||||||
JSConstantExpression = 81,
|
BoltImportDeclaration = 76,
|
||||||
JSMemberExpression = 83,
|
BoltRecordDeclarationField = 77,
|
||||||
JSCallExpression = 84,
|
BoltRecordDeclaration = 79,
|
||||||
JSBinaryExpression = 85,
|
JSOperator = 82,
|
||||||
JSUnaryExpression = 86,
|
JSIdentifier = 83,
|
||||||
JSNewExpression = 87,
|
JSBindPattern = 85,
|
||||||
JSSequenceExpression = 88,
|
JSConstantExpression = 87,
|
||||||
JSConditionalExpression = 89,
|
JSMemberExpression = 89,
|
||||||
JSReferenceExpression = 90,
|
JSCallExpression = 90,
|
||||||
JSExpressionStatement = 92,
|
JSBinaryExpression = 91,
|
||||||
JSConditionalStatement = 93,
|
JSUnaryExpression = 92,
|
||||||
JSParameter = 94,
|
JSNewExpression = 93,
|
||||||
JSFunctionDeclaration = 97,
|
JSSequenceExpression = 94,
|
||||||
JSArrowFunctionDeclaration = 98,
|
JSConditionalExpression = 95,
|
||||||
JSLetDeclaration = 99,
|
JSReferenceExpression = 96,
|
||||||
JSSourceFile = 100,
|
JSExpressionStatement = 98,
|
||||||
JSSourceElement = 101,
|
JSConditionalStatement = 99,
|
||||||
|
JSParameter = 100,
|
||||||
|
JSFunctionDeclaration = 103,
|
||||||
|
JSArrowFunctionDeclaration = 104,
|
||||||
|
JSLetDeclaration = 105,
|
||||||
|
JSSourceFile = 106,
|
||||||
|
JSSourceElement = 107,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -91,7 +97,6 @@ interface SyntaxBase {
|
||||||
kind: SyntaxKind;
|
kind: SyntaxKind;
|
||||||
parentNode: Syntax | null;
|
parentNode: Syntax | null;
|
||||||
span: TextSpan | null;
|
span: TextSpan | null;
|
||||||
origNodes: SyntaxRange | null;
|
|
||||||
}
|
}
|
||||||
export interface FunctionBody extends SyntaxBase {
|
export interface FunctionBody extends SyntaxBase {
|
||||||
kind: SyntaxKind.FunctionBody;
|
kind: SyntaxKind.FunctionBody;
|
||||||
|
@ -111,12 +116,18 @@ export type BoltToken
|
||||||
| BoltRArrow
|
| BoltRArrow
|
||||||
| BoltLArrow
|
| BoltLArrow
|
||||||
| BoltEqSign
|
| BoltEqSign
|
||||||
|
| BoltGtSign
|
||||||
|
| BoltLtSign
|
||||||
| BoltFnKeyword
|
| BoltFnKeyword
|
||||||
| BoltForeignKeyword
|
| BoltForeignKeyword
|
||||||
| BoltLetKeyword
|
| BoltLetKeyword
|
||||||
|
| BoltReturnKeyword
|
||||||
|
| BoltLoopKeyword
|
||||||
|
| BoltYieldKeyword
|
||||||
| BoltImportKeyword
|
| BoltImportKeyword
|
||||||
| BoltPubKeyword
|
| BoltPubKeyword
|
||||||
| BoltModKeyword
|
| BoltModKeyword
|
||||||
|
| BoltMutKeyword
|
||||||
| BoltEnumKeyword
|
| BoltEnumKeyword
|
||||||
| BoltStructKeyword
|
| BoltStructKeyword
|
||||||
| BoltNewTypeKeyword
|
| BoltNewTypeKeyword
|
||||||
|
@ -186,13 +197,25 @@ export interface BoltEqSign extends SyntaxBase {
|
||||||
kind: SyntaxKind.BoltEqSign;
|
kind: SyntaxKind.BoltEqSign;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface BoltGtSign extends SyntaxBase {
|
||||||
|
kind: SyntaxKind.BoltGtSign;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BoltLtSign extends SyntaxBase {
|
||||||
|
kind: SyntaxKind.BoltLtSign;
|
||||||
|
}
|
||||||
|
|
||||||
export type BoltKeyword
|
export type BoltKeyword
|
||||||
= BoltFnKeyword
|
= BoltFnKeyword
|
||||||
| BoltForeignKeyword
|
| BoltForeignKeyword
|
||||||
| BoltLetKeyword
|
| BoltLetKeyword
|
||||||
|
| BoltReturnKeyword
|
||||||
|
| BoltLoopKeyword
|
||||||
|
| BoltYieldKeyword
|
||||||
| BoltImportKeyword
|
| BoltImportKeyword
|
||||||
| BoltPubKeyword
|
| BoltPubKeyword
|
||||||
| BoltModKeyword
|
| BoltModKeyword
|
||||||
|
| BoltMutKeyword
|
||||||
| BoltEnumKeyword
|
| BoltEnumKeyword
|
||||||
| BoltStructKeyword
|
| BoltStructKeyword
|
||||||
| BoltNewTypeKeyword
|
| BoltNewTypeKeyword
|
||||||
|
@ -210,6 +233,18 @@ export interface BoltLetKeyword extends SyntaxBase {
|
||||||
kind: SyntaxKind.BoltLetKeyword;
|
kind: SyntaxKind.BoltLetKeyword;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface BoltReturnKeyword extends SyntaxBase {
|
||||||
|
kind: SyntaxKind.BoltReturnKeyword;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BoltLoopKeyword extends SyntaxBase {
|
||||||
|
kind: SyntaxKind.BoltLoopKeyword;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BoltYieldKeyword extends SyntaxBase {
|
||||||
|
kind: SyntaxKind.BoltYieldKeyword;
|
||||||
|
}
|
||||||
|
|
||||||
export interface BoltImportKeyword extends SyntaxBase {
|
export interface BoltImportKeyword extends SyntaxBase {
|
||||||
kind: SyntaxKind.BoltImportKeyword;
|
kind: SyntaxKind.BoltImportKeyword;
|
||||||
}
|
}
|
||||||
|
@ -222,6 +257,10 @@ export interface BoltModKeyword extends SyntaxBase {
|
||||||
kind: SyntaxKind.BoltModKeyword;
|
kind: SyntaxKind.BoltModKeyword;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface BoltMutKeyword extends SyntaxBase {
|
||||||
|
kind: SyntaxKind.BoltMutKeyword;
|
||||||
|
}
|
||||||
|
|
||||||
export interface BoltEnumKeyword extends SyntaxBase {
|
export interface BoltEnumKeyword extends SyntaxBase {
|
||||||
kind: SyntaxKind.BoltEnumKeyword;
|
kind: SyntaxKind.BoltEnumKeyword;
|
||||||
}
|
}
|
||||||
|
@ -291,7 +330,7 @@ export type BoltPattern
|
||||||
|
|
||||||
export interface BoltBindPattern extends SyntaxBase {
|
export interface BoltBindPattern extends SyntaxBase {
|
||||||
kind: SyntaxKind.BoltBindPattern;
|
kind: SyntaxKind.BoltBindPattern;
|
||||||
name: string;
|
name: BoltIdentifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface BoltTypePattern extends SyntaxBase {
|
export interface BoltTypePattern extends SyntaxBase {
|
||||||
|
@ -427,7 +466,7 @@ export type BoltDeclaration
|
||||||
|
|
||||||
|
|
||||||
export const enum BoltDeclarationModifiers {
|
export const enum BoltDeclarationModifiers {
|
||||||
Mutable = 1,Public = 2,IsType = 4,}
|
Mutable = 1,Public = 2,IsType = 4,IsForeign = 8,}
|
||||||
|
|
||||||
export interface BoltNewTypeDeclaration extends SyntaxBase {
|
export interface BoltNewTypeDeclaration extends SyntaxBase {
|
||||||
kind: SyntaxKind.BoltNewTypeDeclaration;
|
kind: SyntaxKind.BoltNewTypeDeclaration;
|
||||||
|
@ -531,7 +570,7 @@ export type JSPattern
|
||||||
|
|
||||||
export interface JSBindPattern extends SyntaxBase {
|
export interface JSBindPattern extends SyntaxBase {
|
||||||
kind: SyntaxKind.JSBindPattern;
|
kind: SyntaxKind.JSBindPattern;
|
||||||
name: string;
|
name: JSIdentifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type JSExpression
|
export type JSExpression
|
||||||
|
@ -682,12 +721,18 @@ export type BoltSyntax
|
||||||
| BoltRArrow
|
| BoltRArrow
|
||||||
| BoltLArrow
|
| BoltLArrow
|
||||||
| BoltEqSign
|
| BoltEqSign
|
||||||
|
| BoltGtSign
|
||||||
|
| BoltLtSign
|
||||||
| BoltFnKeyword
|
| BoltFnKeyword
|
||||||
| BoltForeignKeyword
|
| BoltForeignKeyword
|
||||||
| BoltLetKeyword
|
| BoltLetKeyword
|
||||||
|
| BoltReturnKeyword
|
||||||
|
| BoltLoopKeyword
|
||||||
|
| BoltYieldKeyword
|
||||||
| BoltImportKeyword
|
| BoltImportKeyword
|
||||||
| BoltPubKeyword
|
| BoltPubKeyword
|
||||||
| BoltModKeyword
|
| BoltModKeyword
|
||||||
|
| BoltMutKeyword
|
||||||
| BoltEnumKeyword
|
| BoltEnumKeyword
|
||||||
| BoltStructKeyword
|
| BoltStructKeyword
|
||||||
| BoltNewTypeKeyword
|
| BoltNewTypeKeyword
|
||||||
|
@ -767,12 +812,18 @@ export type Syntax
|
||||||
| BoltRArrow
|
| BoltRArrow
|
||||||
| BoltLArrow
|
| BoltLArrow
|
||||||
| BoltEqSign
|
| BoltEqSign
|
||||||
|
| BoltGtSign
|
||||||
|
| BoltLtSign
|
||||||
| BoltFnKeyword
|
| BoltFnKeyword
|
||||||
| BoltForeignKeyword
|
| BoltForeignKeyword
|
||||||
| BoltLetKeyword
|
| BoltLetKeyword
|
||||||
|
| BoltReturnKeyword
|
||||||
|
| BoltLoopKeyword
|
||||||
|
| BoltYieldKeyword
|
||||||
| BoltImportKeyword
|
| BoltImportKeyword
|
||||||
| BoltPubKeyword
|
| BoltPubKeyword
|
||||||
| BoltModKeyword
|
| BoltModKeyword
|
||||||
|
| BoltMutKeyword
|
||||||
| BoltEnumKeyword
|
| BoltEnumKeyword
|
||||||
| BoltStructKeyword
|
| BoltStructKeyword
|
||||||
| BoltNewTypeKeyword
|
| BoltNewTypeKeyword
|
||||||
|
@ -836,85 +887,91 @@ export type Syntax
|
||||||
|
|
||||||
export function kindToString(kind: SyntaxKind): string;
|
export function kindToString(kind: SyntaxKind): string;
|
||||||
|
|
||||||
export function createFunctionBody(span?: TextSpan | null, origNodes?: SyntaxRange | null): FunctionBody;
|
export function createFunctionBody(span?: TextSpan | null): FunctionBody;
|
||||||
export function createBoltStringLiteral(value: string, span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltStringLiteral;
|
export function createBoltStringLiteral(value: string, span?: TextSpan | null): BoltStringLiteral;
|
||||||
export function createBoltIntegerLiteral(value: bigint, span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltIntegerLiteral;
|
export function createBoltIntegerLiteral(value: bigint, span?: TextSpan | null): BoltIntegerLiteral;
|
||||||
export function createBoltIdentifier(text: string, span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltIdentifier;
|
export function createBoltIdentifier(text: string, span?: TextSpan | null): BoltIdentifier;
|
||||||
export function createBoltOperator(text: string, span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltOperator;
|
export function createBoltOperator(text: string, span?: TextSpan | null): BoltOperator;
|
||||||
export function createBoltEOS(span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltEOS;
|
export function createBoltEOS(span?: TextSpan | null): BoltEOS;
|
||||||
export function createBoltComma(span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltComma;
|
export function createBoltComma(span?: TextSpan | null): BoltComma;
|
||||||
export function createBoltSemi(span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltSemi;
|
export function createBoltSemi(span?: TextSpan | null): BoltSemi;
|
||||||
export function createBoltColon(span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltColon;
|
export function createBoltColon(span?: TextSpan | null): BoltColon;
|
||||||
export function createBoltDot(span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltDot;
|
export function createBoltDot(span?: TextSpan | null): BoltDot;
|
||||||
export function createBoltDotDot(span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltDotDot;
|
export function createBoltDotDot(span?: TextSpan | null): BoltDotDot;
|
||||||
export function createBoltRArrow(span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltRArrow;
|
export function createBoltRArrow(span?: TextSpan | null): BoltRArrow;
|
||||||
export function createBoltLArrow(span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltLArrow;
|
export function createBoltLArrow(span?: TextSpan | null): BoltLArrow;
|
||||||
export function createBoltEqSign(span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltEqSign;
|
export function createBoltEqSign(span?: TextSpan | null): BoltEqSign;
|
||||||
export function createBoltFnKeyword(span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltFnKeyword;
|
export function createBoltGtSign(span?: TextSpan | null): BoltGtSign;
|
||||||
export function createBoltForeignKeyword(span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltForeignKeyword;
|
export function createBoltLtSign(span?: TextSpan | null): BoltLtSign;
|
||||||
export function createBoltLetKeyword(span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltLetKeyword;
|
export function createBoltFnKeyword(span?: TextSpan | null): BoltFnKeyword;
|
||||||
export function createBoltImportKeyword(span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltImportKeyword;
|
export function createBoltForeignKeyword(span?: TextSpan | null): BoltForeignKeyword;
|
||||||
export function createBoltPubKeyword(span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltPubKeyword;
|
export function createBoltLetKeyword(span?: TextSpan | null): BoltLetKeyword;
|
||||||
export function createBoltModKeyword(span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltModKeyword;
|
export function createBoltReturnKeyword(span?: TextSpan | null): BoltReturnKeyword;
|
||||||
export function createBoltEnumKeyword(span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltEnumKeyword;
|
export function createBoltLoopKeyword(span?: TextSpan | null): BoltLoopKeyword;
|
||||||
export function createBoltStructKeyword(span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltStructKeyword;
|
export function createBoltYieldKeyword(span?: TextSpan | null): BoltYieldKeyword;
|
||||||
export function createBoltNewTypeKeyword(span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltNewTypeKeyword;
|
export function createBoltImportKeyword(span?: TextSpan | null): BoltImportKeyword;
|
||||||
export function createBoltParenthesized(text: string, span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltParenthesized;
|
export function createBoltPubKeyword(span?: TextSpan | null): BoltPubKeyword;
|
||||||
export function createBoltBraced(text: string, span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltBraced;
|
export function createBoltModKeyword(span?: TextSpan | null): BoltModKeyword;
|
||||||
export function createBoltBracketed(text: string, span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltBracketed;
|
export function createBoltMutKeyword(span?: TextSpan | null): BoltMutKeyword;
|
||||||
export function createBoltSourceFile(elements: BoltSourceElement[], span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltSourceFile;
|
export function createBoltEnumKeyword(span?: TextSpan | null): BoltEnumKeyword;
|
||||||
export function createBoltQualName(modulePath: BoltIdentifier[], name: BoltSymbol, span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltQualName;
|
export function createBoltStructKeyword(span?: TextSpan | null): BoltStructKeyword;
|
||||||
export function createBoltSentence(tokens: BoltToken[], span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltSentence;
|
export function createBoltNewTypeKeyword(span?: TextSpan | null): BoltNewTypeKeyword;
|
||||||
export function createBoltReferenceTypeNode(name: BoltQualName, arguments: BoltTypeNode[] | null, span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltReferenceTypeNode;
|
export function createBoltParenthesized(text: string, span?: TextSpan | null): BoltParenthesized;
|
||||||
export function createBoltBindPattern(name: string, span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltBindPattern;
|
export function createBoltBraced(text: string, span?: TextSpan | null): BoltBraced;
|
||||||
export function createBoltTypePattern(type: BoltTypeNode, nestedPattern: BoltPattern, span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltTypePattern;
|
export function createBoltBracketed(text: string, span?: TextSpan | null): BoltBracketed;
|
||||||
export function createBoltExpressionPattern(expression: BoltExpression, span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltExpressionPattern;
|
export function createBoltSourceFile(elements: BoltSourceElement[], span?: TextSpan | null): BoltSourceFile;
|
||||||
export function createBoltTuplePatternElement(index: number, pattern: BoltPattern, span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltTuplePatternElement;
|
export function createBoltQualName(modulePath: BoltIdentifier[], name: BoltSymbol, span?: TextSpan | null): BoltQualName;
|
||||||
export function createBoltTuplePattern(elements: BoltTuplePatternElement[], span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltTuplePattern;
|
export function createBoltSentence(tokens: BoltToken[], span?: TextSpan | null): BoltSentence;
|
||||||
export function createBoltRecordPatternField(name: BoltIdentifier, pattern: BoltPattern, span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltRecordPatternField;
|
export function createBoltReferenceTypeNode(name: BoltQualName, arguments: BoltTypeNode[] | null, span?: TextSpan | null): BoltReferenceTypeNode;
|
||||||
export function createBoltRecordPattern(name: BoltTypeNode, fields: BoltRecordPatternField[], span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltRecordPattern;
|
export function createBoltBindPattern(name: BoltIdentifier, span?: TextSpan | null): BoltBindPattern;
|
||||||
export function createBoltReferenceExpression(name: BoltQualName, span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltReferenceExpression;
|
export function createBoltTypePattern(type: BoltTypeNode, nestedPattern: BoltPattern, span?: TextSpan | null): BoltTypePattern;
|
||||||
export function createBoltCallExpression(operator: BoltExpression, operands: BoltExpression[], span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltCallExpression;
|
export function createBoltExpressionPattern(expression: BoltExpression, span?: TextSpan | null): BoltExpressionPattern;
|
||||||
export function createBoltYieldExpression(value: BoltExpression, span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltYieldExpression;
|
export function createBoltTuplePatternElement(index: number, pattern: BoltPattern, span?: TextSpan | null): BoltTuplePatternElement;
|
||||||
export function createBoltMatchArm(pattern: BoltPattern, body: BoltExpression, span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltMatchArm;
|
export function createBoltTuplePattern(elements: BoltTuplePatternElement[], span?: TextSpan | null): BoltTuplePattern;
|
||||||
export function createBoltMatchExpression(value: BoltExpression, arms: BoltMatchArm[], span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltMatchExpression;
|
export function createBoltRecordPatternField(name: BoltIdentifier, pattern: BoltPattern, span?: TextSpan | null): BoltRecordPatternField;
|
||||||
export function createBoltCase(test: BoltExpression, result: BoltExpression, span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltCase;
|
export function createBoltRecordPattern(name: BoltTypeNode, fields: BoltRecordPatternField[], span?: TextSpan | null): BoltRecordPattern;
|
||||||
export function createBoltCaseExpression(cases: BoltCase[], span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltCaseExpression;
|
export function createBoltReferenceExpression(name: BoltQualName, span?: TextSpan | null): BoltReferenceExpression;
|
||||||
export function createBoltBlockExpression(statements: BoltStatement[], span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltBlockExpression;
|
export function createBoltCallExpression(operator: BoltExpression, operands: BoltExpression[], span?: TextSpan | null): BoltCallExpression;
|
||||||
export function createBoltConstantExpression(value: BoltValue, span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltConstantExpression;
|
export function createBoltYieldExpression(value: BoltExpression, span?: TextSpan | null): BoltYieldExpression;
|
||||||
export function createBoltReturnStatement(value: BoltExpression | null, span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltReturnStatement;
|
export function createBoltMatchArm(pattern: BoltPattern, body: BoltExpression, span?: TextSpan | null): BoltMatchArm;
|
||||||
export function createBoltResumeStatement(value: BoltExpression, span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltResumeStatement;
|
export function createBoltMatchExpression(value: BoltExpression, arms: BoltMatchArm[], span?: TextSpan | null): BoltMatchExpression;
|
||||||
export function createBoltExpressionStatement(expression: BoltExpression, span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltExpressionStatement;
|
export function createBoltCase(test: BoltExpression, result: BoltExpression, span?: TextSpan | null): BoltCase;
|
||||||
export function createBoltParameter(index: number, bindings: BoltPattern, type: BoltTypeNode | null, defaultValue: BoltExpression | null, span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltParameter;
|
export function createBoltCaseExpression(cases: BoltCase[], span?: TextSpan | null): BoltCaseExpression;
|
||||||
export function createBoltNewTypeDeclaration(modifiers: BoltDeclarationModifiers, name: BoltIdentifier, span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltNewTypeDeclaration;
|
export function createBoltBlockExpression(statements: BoltStatement[], span?: TextSpan | null): BoltBlockExpression;
|
||||||
export function createBoltModule(modifiers: BoltDeclarationModifiers, name: BoltQualName, elements: BoltSourceElement[], span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltModule;
|
export function createBoltConstantExpression(value: BoltValue, span?: TextSpan | null): BoltConstantExpression;
|
||||||
export function createBoltFunctionDeclaration(modifiers: BoltDeclarationModifiers, name: BoltSymbol, params: BoltParameter[], returnType: BoltTypeNode | null, body: BoltExpression, span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltFunctionDeclaration;
|
export function createBoltReturnStatement(value: BoltExpression | null, span?: TextSpan | null): BoltReturnStatement;
|
||||||
export function createBoltForeignFunctionDeclaration(modifiers: BoltDeclarationModifiers, target: string, name: BoltSymbol, params: BoltParameter[], returnType: BoltTypeNode | null, body: FunctionBody, span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltForeignFunctionDeclaration;
|
export function createBoltResumeStatement(value: BoltExpression, span?: TextSpan | null): BoltResumeStatement;
|
||||||
export function createBoltVariableDeclaration(modifiers: BoltDeclarationModifiers, bindings: BoltPattern, type: BoltTypeNode | null, value: BoltExpression | null, span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltVariableDeclaration;
|
export function createBoltExpressionStatement(expression: BoltExpression, span?: TextSpan | null): BoltExpressionStatement;
|
||||||
export function createBoltPlainImportSymbol(name: BoltQualName, span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltPlainImportSymbol;
|
export function createBoltParameter(index: number, bindings: BoltPattern, type: BoltTypeNode | null, defaultValue: BoltExpression | null, span?: TextSpan | null): BoltParameter;
|
||||||
export function createBoltImportDeclaration(file: string, symbols: BoltImportSymbol[], span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltImportDeclaration;
|
export function createBoltNewTypeDeclaration(modifiers: BoltDeclarationModifiers, name: BoltIdentifier, span?: TextSpan | null): BoltNewTypeDeclaration;
|
||||||
export function createBoltRecordDeclarationField(name: BoltIdentifier, type: BoltTypeNode, span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltRecordDeclarationField;
|
export function createBoltModule(modifiers: BoltDeclarationModifiers, name: BoltQualName, elements: BoltSourceElement[], span?: TextSpan | null): BoltModule;
|
||||||
export function createBoltRecordDeclaration(name: BoltQualName, fields: BoltRecordDeclarationField[], span?: TextSpan | null, origNodes?: SyntaxRange | null): BoltRecordDeclaration;
|
export function createBoltFunctionDeclaration(modifiers: BoltDeclarationModifiers, name: BoltSymbol, params: BoltParameter[], returnType: BoltTypeNode | null, body: BoltExpression, span?: TextSpan | null): BoltFunctionDeclaration;
|
||||||
export function createJSOperator(text: string, span?: TextSpan | null, origNodes?: SyntaxRange | null): JSOperator;
|
export function createBoltForeignFunctionDeclaration(modifiers: BoltDeclarationModifiers, target: string, name: BoltSymbol, params: BoltParameter[], returnType: BoltTypeNode | null, body: FunctionBody, span?: TextSpan | null): BoltForeignFunctionDeclaration;
|
||||||
export function createJSIdentifier(text: string, span?: TextSpan | null, origNodes?: SyntaxRange | null): JSIdentifier;
|
export function createBoltVariableDeclaration(modifiers: BoltDeclarationModifiers, bindings: BoltPattern, type: BoltTypeNode | null, value: BoltExpression | null, span?: TextSpan | null): BoltVariableDeclaration;
|
||||||
export function createJSBindPattern(name: string, span?: TextSpan | null, origNodes?: SyntaxRange | null): JSBindPattern;
|
export function createBoltPlainImportSymbol(name: BoltQualName, span?: TextSpan | null): BoltPlainImportSymbol;
|
||||||
export function createJSConstantExpression(value: BoltValue, span?: TextSpan | null, origNodes?: SyntaxRange | null): JSConstantExpression;
|
export function createBoltImportDeclaration(file: string, symbols: BoltImportSymbol[], span?: TextSpan | null): BoltImportDeclaration;
|
||||||
export function createJSMemberExpression(value: JSExpression, property: JSExpression, modifiers: JSMemberExpressionModifiers, span?: TextSpan | null, origNodes?: SyntaxRange | null): JSMemberExpression;
|
export function createBoltRecordDeclarationField(name: BoltIdentifier, type: BoltTypeNode, span?: TextSpan | null): BoltRecordDeclarationField;
|
||||||
export function createJSCallExpression(operator: JSExpression, operands: JSExpression[], span?: TextSpan | null, origNodes?: SyntaxRange | null): JSCallExpression;
|
export function createBoltRecordDeclaration(name: BoltQualName, fields: BoltRecordDeclarationField[], span?: TextSpan | null): BoltRecordDeclaration;
|
||||||
export function createJSBinaryExpression(left: JSExpression, operator: JSOperator, right: JSExpression, span?: TextSpan | null, origNodes?: SyntaxRange | null): JSBinaryExpression;
|
export function createJSOperator(text: string, span?: TextSpan | null): JSOperator;
|
||||||
export function createJSUnaryExpression(operator: JSOperator, operand: JSExpression, span?: TextSpan | null, origNodes?: SyntaxRange | null): JSUnaryExpression;
|
export function createJSIdentifier(text: string, span?: TextSpan | null): JSIdentifier;
|
||||||
export function createJSNewExpression(target: JSExpression, arguments: JSExpression[], span?: TextSpan | null, origNodes?: SyntaxRange | null): JSNewExpression;
|
export function createJSBindPattern(name: JSIdentifier, span?: TextSpan | null): JSBindPattern;
|
||||||
export function createJSSequenceExpression(expressions: JSExpression[], span?: TextSpan | null, origNodes?: SyntaxRange | null): JSSequenceExpression;
|
export function createJSConstantExpression(value: BoltValue, span?: TextSpan | null): JSConstantExpression;
|
||||||
export function createJSConditionalExpression(test: JSExpression, consequent: JSExpression, alternate: JSExpression, span?: TextSpan | null, origNodes?: SyntaxRange | null): JSConditionalExpression;
|
export function createJSMemberExpression(value: JSExpression, property: JSExpression, modifiers: JSMemberExpressionModifiers, span?: TextSpan | null): JSMemberExpression;
|
||||||
export function createJSReferenceExpression(name: string, span?: TextSpan | null, origNodes?: SyntaxRange | null): JSReferenceExpression;
|
export function createJSCallExpression(operator: JSExpression, operands: JSExpression[], span?: TextSpan | null): JSCallExpression;
|
||||||
export function createJSExpressionStatement(expression: JSExpression, span?: TextSpan | null, origNodes?: SyntaxRange | null): JSExpressionStatement;
|
export function createJSBinaryExpression(left: JSExpression, operator: JSOperator, right: JSExpression, span?: TextSpan | null): JSBinaryExpression;
|
||||||
export function createJSConditionalStatement(test: JSExpression, consequent: JSStatement[], alternate: JSStatement[], span?: TextSpan | null, origNodes?: SyntaxRange | null): JSConditionalStatement;
|
export function createJSUnaryExpression(operator: JSOperator, operand: JSExpression, span?: TextSpan | null): JSUnaryExpression;
|
||||||
export function createJSParameter(index: number, bindings: JSPattern, defaultValue: JSExpression | null, span?: TextSpan | null, origNodes?: SyntaxRange | null): JSParameter;
|
export function createJSNewExpression(target: JSExpression, arguments: JSExpression[], span?: TextSpan | null): JSNewExpression;
|
||||||
export function createJSFunctionDeclaration(modifiers: JSDeclarationModifiers, name: JSIdentifier, params: JSParameter[], body: JSStatement[], span?: TextSpan | null, origNodes?: SyntaxRange | null): JSFunctionDeclaration;
|
export function createJSSequenceExpression(expressions: JSExpression[], span?: TextSpan | null): JSSequenceExpression;
|
||||||
export function createJSArrowFunctionDeclaration(name: JSIdentifier, params: JSParameter[], body: JSExpression, span?: TextSpan | null, origNodes?: SyntaxRange | null): JSArrowFunctionDeclaration;
|
export function createJSConditionalExpression(test: JSExpression, consequent: JSExpression, alternate: JSExpression, span?: TextSpan | null): JSConditionalExpression;
|
||||||
export function createJSLetDeclaration(bindings: JSPattern, value: JSExpression | null, span?: TextSpan | null, origNodes?: SyntaxRange | null): JSLetDeclaration;
|
export function createJSReferenceExpression(name: string, span?: TextSpan | null): JSReferenceExpression;
|
||||||
export function createJSSourceFile(elements: JSSourceElement[], span?: TextSpan | null, origNodes?: SyntaxRange | null): JSSourceFile;
|
export function createJSExpressionStatement(expression: JSExpression, span?: TextSpan | null): JSExpressionStatement;
|
||||||
export function createJSSourceElement(span?: TextSpan | null, origNodes?: SyntaxRange | null): JSSourceElement;
|
export function createJSConditionalStatement(test: JSExpression, consequent: JSStatement[], alternate: JSStatement[], span?: TextSpan | null): JSConditionalStatement;
|
||||||
|
export function createJSParameter(index: number, bindings: JSPattern, defaultValue: JSExpression | null, span?: TextSpan | null): JSParameter;
|
||||||
|
export function createJSFunctionDeclaration(modifiers: JSDeclarationModifiers, name: JSIdentifier, params: JSParameter[], body: JSStatement[], span?: TextSpan | null): JSFunctionDeclaration;
|
||||||
|
export function createJSArrowFunctionDeclaration(name: JSIdentifier, params: JSParameter[], body: JSExpression, span?: TextSpan | null): JSArrowFunctionDeclaration;
|
||||||
|
export function createJSLetDeclaration(bindings: JSPattern, value: JSExpression | null, span?: TextSpan | null): JSLetDeclaration;
|
||||||
|
export function createJSSourceFile(elements: JSSourceElement[], span?: TextSpan | null): JSSourceFile;
|
||||||
|
export function createJSSourceElement(span?: TextSpan | null): JSSourceElement;
|
||||||
|
|
||||||
export function isFunctionBody(value: any): value is FunctionBody;
|
export function isFunctionBody(value: any): value is FunctionBody;
|
||||||
export function isBoltToken(value: any): value is BoltToken;
|
export function isBoltToken(value: any): value is BoltToken;
|
||||||
|
@ -932,13 +989,19 @@ export function isBoltDotDot(value: any): value is BoltDotDot;
|
||||||
export function isBoltRArrow(value: any): value is BoltRArrow;
|
export function isBoltRArrow(value: any): value is BoltRArrow;
|
||||||
export function isBoltLArrow(value: any): value is BoltLArrow;
|
export function isBoltLArrow(value: any): value is BoltLArrow;
|
||||||
export function isBoltEqSign(value: any): value is BoltEqSign;
|
export function isBoltEqSign(value: any): value is BoltEqSign;
|
||||||
|
export function isBoltGtSign(value: any): value is BoltGtSign;
|
||||||
|
export function isBoltLtSign(value: any): value is BoltLtSign;
|
||||||
export function isBoltKeyword(value: any): value is BoltKeyword;
|
export function isBoltKeyword(value: any): value is BoltKeyword;
|
||||||
export function isBoltFnKeyword(value: any): value is BoltFnKeyword;
|
export function isBoltFnKeyword(value: any): value is BoltFnKeyword;
|
||||||
export function isBoltForeignKeyword(value: any): value is BoltForeignKeyword;
|
export function isBoltForeignKeyword(value: any): value is BoltForeignKeyword;
|
||||||
export function isBoltLetKeyword(value: any): value is BoltLetKeyword;
|
export function isBoltLetKeyword(value: any): value is BoltLetKeyword;
|
||||||
|
export function isBoltReturnKeyword(value: any): value is BoltReturnKeyword;
|
||||||
|
export function isBoltLoopKeyword(value: any): value is BoltLoopKeyword;
|
||||||
|
export function isBoltYieldKeyword(value: any): value is BoltYieldKeyword;
|
||||||
export function isBoltImportKeyword(value: any): value is BoltImportKeyword;
|
export function isBoltImportKeyword(value: any): value is BoltImportKeyword;
|
||||||
export function isBoltPubKeyword(value: any): value is BoltPubKeyword;
|
export function isBoltPubKeyword(value: any): value is BoltPubKeyword;
|
||||||
export function isBoltModKeyword(value: any): value is BoltModKeyword;
|
export function isBoltModKeyword(value: any): value is BoltModKeyword;
|
||||||
|
export function isBoltMutKeyword(value: any): value is BoltMutKeyword;
|
||||||
export function isBoltEnumKeyword(value: any): value is BoltEnumKeyword;
|
export function isBoltEnumKeyword(value: any): value is BoltEnumKeyword;
|
||||||
export function isBoltStructKeyword(value: any): value is BoltStructKeyword;
|
export function isBoltStructKeyword(value: any): value is BoltStructKeyword;
|
||||||
export function isBoltNewTypeKeyword(value: any): value is BoltNewTypeKeyword;
|
export function isBoltNewTypeKeyword(value: any): value is BoltNewTypeKeyword;
|
||||||
|
|
|
@ -60,7 +60,7 @@ export class Compiler {
|
||||||
for (const element of s.elements) {
|
for (const element of s.elements) {
|
||||||
this.compileDecl(element, body);
|
this.compileDecl(element, body);
|
||||||
}
|
}
|
||||||
return createJSSourceFile(body, s.span, [s, s]);
|
return createJSSourceFile(body, s.span);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,21 +75,18 @@ export class Compiler {
|
||||||
compiledOperator,
|
compiledOperator,
|
||||||
compiledArgs,
|
compiledArgs,
|
||||||
node.span,
|
node.span,
|
||||||
[node, node],
|
|
||||||
);
|
);
|
||||||
|
|
||||||
case SyntaxKind.BoltReferenceExpression:
|
case SyntaxKind.BoltReferenceExpression:
|
||||||
return createJSReferenceExpression(
|
return createJSReferenceExpression(
|
||||||
getFullTextOfQualName(node.name),
|
getFullTextOfQualName(node.name),
|
||||||
node.span,
|
node.span,
|
||||||
[node, node],
|
|
||||||
);
|
);
|
||||||
|
|
||||||
case SyntaxKind.BoltConstantExpression:
|
case SyntaxKind.BoltConstantExpression:
|
||||||
return createJSConstantExpression(
|
return createJSConstantExpression(
|
||||||
node.value,
|
node.value,
|
||||||
node.span,
|
node.span,
|
||||||
[node, node]
|
|
||||||
);
|
);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -128,10 +125,9 @@ export class Compiler {
|
||||||
const compiledValue = node.value !== null ? this.compileExpr(node.value, preamble) : null;
|
const compiledValue = node.value !== null ? this.compileExpr(node.value, preamble) : null;
|
||||||
preamble.push(
|
preamble.push(
|
||||||
createJSLetDeclaration(
|
createJSLetDeclaration(
|
||||||
createJSBindPattern((node.bindings as BoltBindPattern).name, node.bindings.span, [node.bindings, node.bindings]),
|
createJSBindPattern((node.bindings as BoltBindPattern).name, node.bindings.span),
|
||||||
compiledValue,
|
compiledValue,
|
||||||
node.span,
|
node.span,
|
||||||
[node, node],
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
@ -145,11 +141,10 @@ export class Compiler {
|
||||||
}
|
}
|
||||||
let result = createJSFunctionDeclaration(
|
let result = createJSFunctionDeclaration(
|
||||||
0,
|
0,
|
||||||
createJSIdentifier(node.name.text, node.name.span, [node.name, node.name]),
|
createJSIdentifier(node.name.text, node.name.span),
|
||||||
params,
|
params,
|
||||||
body,
|
body,
|
||||||
node.span,
|
node.span,
|
||||||
[node, node],
|
|
||||||
);
|
);
|
||||||
if (hasPublicModifier(node)) {
|
if (hasPublicModifier(node)) {
|
||||||
result.modifiers |= JSDeclarationModifiers.IsExported;;
|
result.modifiers |= JSDeclarationModifiers.IsExported;;
|
||||||
|
|
|
@ -5,8 +5,13 @@ export class Emitter {
|
||||||
|
|
||||||
emit(node: Syntax) {
|
emit(node: Syntax) {
|
||||||
|
|
||||||
|
debug(node);
|
||||||
|
|
||||||
switch (node.kind) {
|
switch (node.kind) {
|
||||||
|
|
||||||
|
case SyntaxKind.JSReferenceExpression:
|
||||||
|
return node.name;
|
||||||
|
|
||||||
case SyntaxKind.JSSourceFile:
|
case SyntaxKind.JSSourceFile:
|
||||||
let out = ''
|
let out = ''
|
||||||
for (const element of node.elements) {
|
for (const element of node.elements) {
|
||||||
|
|
586
src/parser.ts
586
src/parser.ts
|
@ -1,46 +1,34 @@
|
||||||
|
|
||||||
import * as acorn from "acorn"
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
SyntaxKind,
|
SyntaxKind,
|
||||||
|
kindToString,
|
||||||
BoltToken,
|
BoltToken,
|
||||||
BoltIdentifier,
|
BoltIdentifier,
|
||||||
createBoltFuncDecl,
|
BoltConstantExpression,
|
||||||
createBoltIdentifier,
|
BoltReferenceExpression,
|
||||||
createBoltSyntaxKind,
|
BoltExpression,
|
||||||
createBoltTokenStream,
|
BoltRecordDeclaration,
|
||||||
createBoltRetStmt,
|
BoltStatement,
|
||||||
createBoltVarDecl,
|
|
||||||
createBoltStmt,
|
|
||||||
createBoltPatt,
|
|
||||||
createBoltExpr,
|
|
||||||
createBoltBindPatt,
|
|
||||||
createBoltParam,
|
|
||||||
createBoltRefExpr,
|
|
||||||
createBoltTypeRef,
|
|
||||||
createBoltTypeDecl,
|
|
||||||
createBoltConstExpr,
|
|
||||||
createBoltQualName,
|
createBoltQualName,
|
||||||
createBoltCallExpr,
|
|
||||||
createBoltImportDecl,
|
|
||||||
createBoltSourceElement,
|
|
||||||
createBoltModule,
|
|
||||||
createBoltRecordDecl,
|
|
||||||
createBoltNewTypeDecl,
|
|
||||||
BoltQualName,
|
BoltQualName,
|
||||||
BoltPattern,
|
BoltPattern,
|
||||||
createBoltBindPattern,
|
createBoltBindPattern,
|
||||||
BoltImportDeclaration,
|
BoltImportDeclaration,
|
||||||
BoltTypeNode,
|
BoltTypeNode,
|
||||||
createBoltReferenceTypeNode,
|
createBoltReferenceTypeNode,
|
||||||
createJSReferenceExpression,
|
createBoltConstantExpression,
|
||||||
createBoltReferenceExpression,
|
createBoltReferenceExpression,
|
||||||
|
createBoltParameter,
|
||||||
|
BoltBindPattern,
|
||||||
|
createBoltRecordDeclaration,
|
||||||
|
createBoltRecordDeclarationField,
|
||||||
|
createBoltImportDeclaration,
|
||||||
|
BoltDeclarationModifiers,
|
||||||
|
BoltStringLiteral,
|
||||||
|
BoltImportSymbol,
|
||||||
} from "./ast"
|
} from "./ast"
|
||||||
|
|
||||||
import { stringType, intType } from "./checker"
|
import { BoltTokenStream, setOrigNodeRange } from "./util"
|
||||||
|
|
||||||
import { PrimValue } from "./evaluator"
|
|
||||||
import {BoltTokenStream} from "./util"
|
|
||||||
|
|
||||||
function describeKind(kind: SyntaxKind): string {
|
function describeKind(kind: SyntaxKind): string {
|
||||||
switch (kind) {
|
switch (kind) {
|
||||||
|
@ -99,8 +87,8 @@ function enumerate(elements: string[]) {
|
||||||
|
|
||||||
|
|
||||||
export class ParseError extends Error {
|
export class ParseError extends Error {
|
||||||
constructor(public actual: Token, public expected: SyntaxKind[]) {
|
constructor(public actual: BoltToken, public expected: SyntaxKind[]) {
|
||||||
super(`${actual.span.file.path}:${actual.span.start.line}:${actual.span.start.column}: expected ${enumerate(expected.map(e => describeKind(e)))} but got ${describeKind(actual.kind)}`)
|
super(`${actual.span!.file.origPath}:${actual.span!.start.line}:${actual.span!.start.column}: expected ${enumerate(expected.map(e => describeKind(e)))} but got ${describeKind(actual.kind)}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,6 +106,24 @@ interface OperatorInfo {
|
||||||
precedence: number;
|
precedence: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function assertToken(node: BoltToken, kind: SyntaxKind) {
|
||||||
|
if (node.kind !== kind) {
|
||||||
|
throw new ParseError(node, [kind]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const KIND_EXPRESSION_T0 = [
|
||||||
|
SyntaxKind.BoltStringLiteral,
|
||||||
|
SyntaxKind.BoltIntegerLiteral,
|
||||||
|
SyntaxKind.BoltIdentifier,
|
||||||
|
SyntaxKind.BoltOperator,
|
||||||
|
]
|
||||||
|
|
||||||
|
const KIND_STATEMENT_T0 = [
|
||||||
|
SyntaxKind.BoltReturnKeyword,
|
||||||
|
...KIND_EXPRESSION_T0,
|
||||||
|
]
|
||||||
|
|
||||||
export class Parser {
|
export class Parser {
|
||||||
|
|
||||||
operatorTable = [
|
operatorTable = [
|
||||||
|
@ -149,8 +155,14 @@ export class Parser {
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
protected assertEmpty(tokens: BoltTokenStream) {
|
||||||
|
const t0 = tokens.peek(1);
|
||||||
|
if (t0.kind !== SyntaxKind.BoltEOS) {
|
||||||
|
throw new ParseError(t0, [SyntaxKind.BoltEOS]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
parseQualName(tokens: BoltTokenStream): BoltQualName {
|
public parseQualName(tokens: BoltTokenStream): BoltQualName {
|
||||||
|
|
||||||
const path: BoltIdentifier[] = [];
|
const path: BoltIdentifier[] = [];
|
||||||
|
|
||||||
|
@ -167,221 +179,335 @@ export class Parser {
|
||||||
if (name.kind !== SyntaxKind.BoltIdentifier) {
|
if (name.kind !== SyntaxKind.BoltIdentifier) {
|
||||||
throw new ParseError(name, [SyntaxKind.BoltIdentifier]);
|
throw new ParseError(name, [SyntaxKind.BoltIdentifier]);
|
||||||
}
|
}
|
||||||
|
|
||||||
const startNode = path.length > 0 ? path[0] : name;
|
const startNode = path.length > 0 ? path[0] : name;
|
||||||
const endNode = name;
|
const endNode = name;
|
||||||
return createBoltQualName(path, name, null, [startNode, endNode]);
|
const node = createBoltQualName(path, name, null);
|
||||||
|
setOrigNodeRange(node, startNode, endNode);
|
||||||
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
parsePattern(tokens: BoltTokenStream): BoltPattern {
|
public parseBindPattern(tokens: BoltTokenStream): BoltBindPattern {
|
||||||
|
const t0 = tokens.get();
|
||||||
|
assertToken(t0, SyntaxKind.BoltIdentifier);
|
||||||
|
const node = createBoltBindPattern((t0 as BoltIdentifier).text);
|
||||||
|
setOrigNodeRange(node, t0, t0);
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
public parsePattern(tokens: BoltTokenStream): BoltPattern {
|
||||||
const t0 = tokens.peek(1);
|
const t0 = tokens.peek(1);
|
||||||
if (t0.kind === SyntaxKind.BoltIdentifier) {
|
if (t0.kind === SyntaxKind.BoltIdentifier) {
|
||||||
tokens.get();
|
return this.parseBindPattern(tokens);
|
||||||
return createBoltBindPattern(t0.text, null, [t0, t0])
|
|
||||||
} else {
|
} else {
|
||||||
throw new ParseError(t0, [SyntaxKind.BoltIdentifier])
|
throw new ParseError(t0, [SyntaxKind.BoltIdentifier])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
parseImportDecl(tokens: BoltTokenStream): BoltImportDeclaration {
|
public parseImportDeclaration(tokens: BoltTokenStream): BoltImportDeclaration {
|
||||||
|
|
||||||
// Assuming first keyword is 'import'
|
|
||||||
tokens.get();
|
|
||||||
|
|
||||||
const t0 = tokens.get();
|
const t0 = tokens.get();
|
||||||
if (t0.kind !== SyntaxKind.BoltStringLiteral) {
|
assertToken(t0, SyntaxKind.BoltImportKeyword);
|
||||||
throw new ParseError(t0, [SyntaxKind.BoltStringLiteral])
|
|
||||||
|
const t1 = tokens.get();
|
||||||
|
assertToken(t1, SyntaxKind.BoltStringLiteral);
|
||||||
|
const filename = (t1 as BoltStringLiteral).value;
|
||||||
|
|
||||||
|
const symbols: BoltImportSymbol[] = [];
|
||||||
|
// TODO implement grammar and parsing logic for symbols
|
||||||
|
|
||||||
|
const node = createBoltImportDeclaration(filename, symbols);
|
||||||
|
setOrigNodeRange(node, t0, t1);
|
||||||
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
return createBoltImportDecl(t0.value, null, t0);
|
public parseReferenceTypeNode(tokens: BoltTokenStream) {
|
||||||
|
|
||||||
|
const name = this.parseQualName(tokens)
|
||||||
|
|
||||||
|
const t1 = tokens.peek();
|
||||||
|
|
||||||
|
let typeArgs: BoltTypeNode[] | null = null;
|
||||||
|
|
||||||
|
if (t1.kind === SyntaxKind.BoltLtSign) {
|
||||||
|
tokens.get();
|
||||||
|
let first = true;
|
||||||
|
while (true) {
|
||||||
|
const t2 = tokens.peek();
|
||||||
|
if (t2.kind === SyntaxKind.BoltGtSign) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (first) {
|
||||||
|
first = false;
|
||||||
|
} else {
|
||||||
|
assertToken(t2, SyntaxKind.BoltComma);
|
||||||
|
tokens.get();
|
||||||
|
}
|
||||||
|
typeArgs!.push(this.parseTypeNode(tokens));
|
||||||
|
}
|
||||||
|
const t4 = tokens.get();
|
||||||
|
assertToken(t4, SyntaxKind.BoltGtSign);
|
||||||
}
|
}
|
||||||
|
|
||||||
parseTypeDecl(tokens: BoltTokenStream): BoltTypeNode {
|
const node = createBoltReferenceTypeNode(name, typeArgs);
|
||||||
|
setOrigNodeRange(node, name, name);
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
public parseTypeNode(tokens: BoltTokenStream): BoltTypeNode {
|
||||||
const t0 = tokens.peek();
|
const t0 = tokens.peek();
|
||||||
if (t0.kind === SyntaxKind.BoltIdentifier) {
|
if (t0.kind === SyntaxKind.BoltIdentifier) {
|
||||||
const name = this.parseQualName(tokens)
|
return this.parseReferenceTypeNode(tokens);
|
||||||
return createBoltReferenceTypeNode(name, [], null, name.origNodes)
|
|
||||||
} else {
|
} else {
|
||||||
throw new ParseError(t0, [SyntaxKind.BoltIdentifier]);
|
throw new ParseError(t0, [SyntaxKind.BoltIdentifier]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
parsePrimExpr(tokens: TokenStream): Expr {
|
public parseConstantExpression(tokens: BoltTokenStream): BoltConstantExpression {
|
||||||
const t0 = tokens.peek();
|
const t0 = tokens.get();
|
||||||
|
let value: boolean | string | bigint;
|
||||||
if (t0.kind === SyntaxKind.BoltStringLiteral) {
|
if (t0.kind === SyntaxKind.BoltStringLiteral) {
|
||||||
tokens.get();
|
value = t0.value;
|
||||||
return new ConstExpr(new PrimValue(stringType, t0.value), null, t0);
|
|
||||||
} else if (t0.kind === SyntaxKind.BoltIntegerLiteral) {
|
} else if (t0.kind === SyntaxKind.BoltIntegerLiteral) {
|
||||||
tokens.get();
|
value = t0.value;
|
||||||
return new ConstExpr(new PrimValue(intType, t0.value), null, t0);
|
} else {
|
||||||
} else if (t0.kind === SyntaxKind.BoltIdentifier) {
|
throw new ParseError(t0, [SyntaxKind.BoltStringLiteral, SyntaxKind.BoltIntegerLiteral]);
|
||||||
|
}
|
||||||
|
const node = createBoltConstantExpression(value);
|
||||||
|
setOrigNodeRange(node, t0, t0);
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
public parseReferenceExpression(tokens: BoltTokenStream): BoltReferenceExpression {
|
||||||
const name = this.parseQualName(tokens);
|
const name = this.parseQualName(tokens);
|
||||||
return createBoltReferenceExpression(name, null, name.origNode);
|
const node = createBoltReferenceExpression(name);
|
||||||
|
setOrigNodeRange(node, name, name);
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected parsePrimitiveExpression(tokens: BoltTokenStream): BoltExpression {
|
||||||
|
const t0 = tokens.peek();
|
||||||
|
if (t0.kind === SyntaxKind.BoltIntegerLiteral || t0.kind === SyntaxKind.BoltStringLiteral) {
|
||||||
|
return this.parseConstantExpression(tokens);
|
||||||
|
} else if (t0.kind === SyntaxKind.BoltIdentifier) {
|
||||||
|
return this.parseReferenceExpression(tokens);
|
||||||
} else {
|
} else {
|
||||||
throw new ParseError(t0, [SyntaxKind.BoltStringLiteral, SyntaxKind.BoltIdentifier]);
|
throw new ParseError(t0, [SyntaxKind.BoltStringLiteral, SyntaxKind.BoltIdentifier]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
parseSyntax(tokens: TokenStream): Syntax {
|
//parseSyntax(tokens: TokenStream): Syntax {
|
||||||
|
|
||||||
// Assuming first token is 'syntax'
|
// // Assuming first token is 'syntax'
|
||||||
tokens.get();
|
// const t0 = tokens.get();
|
||||||
|
// assertToken(t0, SyntaxKind.Bolt
|
||||||
|
|
||||||
const t1 = tokens.get();
|
// const t1 = tokens.get();
|
||||||
if (t1.kind !== SyntaxKind.BoltBraced) {
|
// if (t1.kind !== SyntaxKind.BoltBraced) {
|
||||||
throw new ParseError(t1, [SyntaxKind.BoltBraced])
|
// throw new ParseError(t1, [SyntaxKind.BoltBraced])
|
||||||
|
// }
|
||||||
|
|
||||||
|
// const innerTokens = t1.toTokenStream();
|
||||||
|
|
||||||
|
// const pattern = this.parsePattern(innerTokens)
|
||||||
|
|
||||||
|
// const t2 = innerTokens.get();
|
||||||
|
// if (t2.kind !== SyntaxKind.BoltRArrow) {
|
||||||
|
// throw new ParseError(t2, [SyntaxKind.BoltRArrow]);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// const body = this.parseBody(innerTokens);
|
||||||
|
|
||||||
|
// return new Macro(pattern, body)
|
||||||
|
|
||||||
|
//}
|
||||||
|
|
||||||
|
public parseExpression(tokens: BoltTokenStream): BoltExpression {
|
||||||
|
return this.parsePrimitiveExpression(tokens)
|
||||||
}
|
}
|
||||||
|
|
||||||
const innerTokens = t1.toTokenStream();
|
public parseParameter(tokens: BoltTokenStream): BoltParameter {
|
||||||
|
|
||||||
const pattern = this.parsePattern(innerTokens)
|
|
||||||
|
|
||||||
const t2 = innerTokens.get();
|
|
||||||
if (t2.kind !== SyntaxKind.BoltRArrow) {
|
|
||||||
throw new ParseError(t2, [SyntaxKind.BoltRArrow]);
|
|
||||||
}
|
|
||||||
|
|
||||||
const body = this.parseBody(innerTokens);
|
|
||||||
|
|
||||||
return new Macro(pattern, body)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
parseExpr(tokens: TokenStream): Expr {
|
|
||||||
return this.parsePrimExpr(tokens)
|
|
||||||
}
|
|
||||||
|
|
||||||
parseParam(tokens: TokenStream): Param {
|
|
||||||
|
|
||||||
let defaultValue = null;
|
let defaultValue = null;
|
||||||
let typeDecl = null;
|
let typeDecl = null;
|
||||||
|
|
||||||
const pattern = this.parsePattern(tokens)
|
const pattern = this.parsePattern(tokens)
|
||||||
|
|
||||||
const t0 = tokens.peek(1);
|
let t0 = tokens.peek(1);
|
||||||
|
let endNode: BoltSyntax = pattern;
|
||||||
if (t0.kind === SyntaxKind.BoltColon) {
|
if (t0.kind === SyntaxKind.BoltColon) {
|
||||||
tokens.get();
|
tokens.get();
|
||||||
typeDecl = this.parseTypeDecl(tokens);
|
typeDecl = this.parseTypeNode(tokens);
|
||||||
const t1 = tokens.peek(1);
|
endNode = typeDecl;
|
||||||
if (t1.kind === SyntaxKind.BoltEqSign) {
|
t0 = tokens.get();
|
||||||
tokens.get();
|
|
||||||
defaultValue = this.parseExpr(tokens);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (t0.kind === SyntaxKind.BoltEqSign) {
|
if (t0.kind === SyntaxKind.BoltEqSign) {
|
||||||
tokens.get();
|
tokens.get();
|
||||||
defaultValue = this.parseExpr(tokens);
|
defaultValue = this.parseExpression(tokens);
|
||||||
|
endNode = defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Param(pattern, typeDecl, defaultValue)
|
const node = createBoltParameter(0, pattern, typeDecl, defaultValue)
|
||||||
|
setOrigNodeRange(node, pattern, endNode);
|
||||||
|
return node;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
parseVarDecl(tokens: TokenStream): VarDecl {
|
public parseVariableDeclaration(tokens: BoltTokenStream): BoltVariableDeclaration {
|
||||||
|
|
||||||
let isMutable = false;
|
let modifiers = 0;
|
||||||
let typeDecl = null;
|
let typeDecl = null;
|
||||||
let value = null;
|
let value = null;
|
||||||
|
|
||||||
// Assuming first token is 'let'
|
const t0 = tokens.get();
|
||||||
tokens.get();
|
assertToken(t0, SyntaxKind.BoltLetKeyword);
|
||||||
|
|
||||||
const t0 = tokens.peek();
|
const t1 = tokens.peek();
|
||||||
if (t0.kind === SyntaxKind.BoltIdentifier && t0.text === 'mut') {
|
if (t1.kind === SyntaxKind.BoltMutKeyword) {
|
||||||
tokens.get();
|
tokens.get();
|
||||||
isMutable = true;
|
modifiers |= BoltDeclarationModifiers.Mutable;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bindings = this.parsePattern(tokens)
|
const bindings = this.parsePattern(tokens)
|
||||||
|
|
||||||
const t1 = tokens.peek();
|
let t2 = tokens.peek();
|
||||||
if (t1.kind === SyntaxKind.BoltColon) {
|
let lastNode: BoltSyntax = bindings;
|
||||||
|
|
||||||
|
if (t2.kind === SyntaxKind.BoltColon) {
|
||||||
tokens.get();
|
tokens.get();
|
||||||
typeDecl = this.parseTypeDecl(tokens);
|
lastNode = typeDecl = this.parseTypeNode(tokens);
|
||||||
|
t2 = tokens.peek();
|
||||||
}
|
}
|
||||||
|
|
||||||
const t2 = tokens.peek();
|
|
||||||
if (t2.kind === SyntaxKind.BoltEqSign) {
|
if (t2.kind === SyntaxKind.BoltEqSign) {
|
||||||
tokens.get();
|
tokens.get();
|
||||||
value = this.parseExpr(tokens);
|
lastNode = value = this.parseExpression(tokens);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new VarDecl(isMutable, bindings, typeDecl, value, null)
|
const node = createBoltVariableDeclaration(modifiers, bindings, typeDecl, value)
|
||||||
|
setOrigNodeRange(node, t0, lastNode);
|
||||||
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
parseRetStmt(tokens: TokenStream): RetStmt {
|
public parseReturnStatement(tokens: BoltTokenStream): BoltReturnStatement {
|
||||||
|
|
||||||
// Assuming first token is 'return'
|
|
||||||
const t0 = tokens.get();
|
const t0 = tokens.get();
|
||||||
|
assertToken(t0, SyntaxKind.BoltReturnKeyword);
|
||||||
|
|
||||||
let expr = null;
|
let expr = null;
|
||||||
|
|
||||||
const t1 = tokens.peek();
|
const t1 = tokens.peek();
|
||||||
if (t1.kind !== SyntaxKind.BoltEOS) {
|
if (t1.kind !== SyntaxKind.BoltEOS) {
|
||||||
expr = this.parseExpr(tokens)
|
expr = this.parseExpression(tokens)
|
||||||
}
|
}
|
||||||
|
|
||||||
return new RetStmt(expr, null, [t0, expr.getEndNode()]);
|
const node = createBoltReturnStatement(expr);
|
||||||
|
setOrigNodeRange(node, t0, expr !== null ? expr : t0);
|
||||||
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
parseStmt(tokens: TokenStream): Stmt {
|
protected lookaheadHasExpression(tokens: BoltTokenStream, i = 1): boolean {
|
||||||
this.parseCallExpr(tokens)
|
const t0 = tokens.peek(i);
|
||||||
|
if (t0.kind === SyntaxKind.BoltParenthesized) {
|
||||||
|
return this.lookaheadHasExpression(tokens, i+1);
|
||||||
|
}
|
||||||
|
return t0.kind === SyntaxKind.BoltIdentifier
|
||||||
|
|| t0.kind === SyntaxKind.BoltStringLiteral
|
||||||
|
|| t0.kind === SyntaxKind.BoltIntegerLiteral
|
||||||
|
|| (t0.kind === SyntaxKind.BoltOperator && this.isUnaryOperator(t0.text));
|
||||||
}
|
}
|
||||||
|
|
||||||
parseRecordDecl(tokens: TokenStream): RecordDecl {
|
public parseStatement(tokens: BoltTokenStream): BoltStatement {
|
||||||
|
const t0 = tokens.peek();
|
||||||
let isPublic = false;
|
if (t0.kind === SyntaxKind.BoltReturnKeyword) {
|
||||||
|
return this.parseReturnStatement(tokens);
|
||||||
let kw = tokens.get();
|
} else if (t0.kind === SyntaxKind.BoltLoopKeyword) {
|
||||||
if (kw.kind !== SyntaxKind.BoltIdentifier) {
|
return this.parseLoopStatement(tokens);
|
||||||
throw new ParseError(kw, [SyntaxKind.BoltPubKeyword, SyntaxKind.BoltStructKeyword]);
|
} else {
|
||||||
|
try {
|
||||||
|
return this.parseExpressionStatement(tokens);
|
||||||
|
} catch (e) {
|
||||||
|
if (!(e instanceof ParseError)) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
throw new ParseError(t0, KIND_STATEMENT_T0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (kw.text === 'pub') {
|
|
||||||
isPublic = true;
|
|
||||||
kw = tokens.get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kw.kind !== SyntaxKind.BoltIdentifier || kw.text !== 'struct') {
|
public parseRecordDeclaration(tokens: BoltTokenStream): BoltRecordDeclaration {
|
||||||
throw new ParseError(kw, [SyntaxKind.BoltStructKeyword])
|
|
||||||
|
let modifiers = 0;
|
||||||
|
|
||||||
|
let t0 = tokens.get();
|
||||||
|
const firstToken = t0;
|
||||||
|
if (t0.kind === SyntaxKind.BoltPubKeyword) {
|
||||||
|
modifiers |= BoltDeclarationModifiers.Public;
|
||||||
|
t0 = tokens.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
const name = this.parseQualName(tokens);
|
if (t0.kind !== SyntaxKind.BoltStructKeyword) {
|
||||||
|
throw new ParseError(t0, [SyntaxKind.BoltStructKeyword])
|
||||||
|
}
|
||||||
|
|
||||||
|
const name = tokens.get();
|
||||||
|
assertToken(name, SyntaxKind.BoltIdentifier);
|
||||||
|
|
||||||
const t2 = tokens.get();
|
const t2 = tokens.get();
|
||||||
|
|
||||||
if (t2.kind !== SyntaxKind.BoltBraced) {
|
if (t2.kind !== SyntaxKind.BoltBraced) {
|
||||||
throw new ParseError(kw, [SyntaxKind.BoltBraced])
|
throw new ParseError(t2, [SyntaxKind.BoltBraced])
|
||||||
}
|
}
|
||||||
|
|
||||||
let fields = [];
|
let fields: BoltRecordDeclarationField[] = [];
|
||||||
|
const innerTokens = createTokenStream(t2);
|
||||||
return new RecordDecl(isPublic, name, fields);
|
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
const t3 = innerTokens.get();
|
||||||
|
if (t3.kind === SyntaxKind.EOS) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
const name = innerTokens.get();
|
||||||
|
assertToken(name, SyntaxKind.BoltIdentifier);
|
||||||
|
const t4 = innerTokens.get();
|
||||||
|
assertToken(t4, SyntaxKind.BoltColon);
|
||||||
|
const type = this.parseTypeNode(innerTokens);
|
||||||
|
const field = createBoltRecordDeclarationField(name as BoltIdentifier, type);
|
||||||
|
setOrigNodeRange(field, name, type);
|
||||||
|
fields.push(field);
|
||||||
}
|
}
|
||||||
|
|
||||||
parseStmts(tokens: TokenStream, origNode: Syntax | null): Stmt[] {
|
const node = new RecordDecl(modifiers, name, fields);
|
||||||
// TODO
|
setOrigNodeRange(node, firstToken, t2);
|
||||||
return []
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
parseModDecl(tokens: TokenStream): Module {
|
public parseStatements(tokens: BoltTokenStream): BoltStatement[] {
|
||||||
|
const statements: BoltStatement[] = [];
|
||||||
let isPublic = false;
|
while (true) {
|
||||||
|
const t0 = tokens.peek();
|
||||||
let kw = tokens.get();
|
if (t0.kind === SyntaxKind.BoltEOS) {
|
||||||
if (kw.kind !== SyntaxKind.BoltIdentifier) {
|
break;
|
||||||
throw new ParseError(kw, [SyntaxKind.BoltPubKeyword, SyntaxKind.BoltModKeyword]);
|
|
||||||
}
|
}
|
||||||
if (kw.text === 'pub') {
|
const statement = this.parseStatement(tokens);
|
||||||
isPublic = true;
|
statements.push(statement);
|
||||||
kw = tokens.get();
|
}
|
||||||
|
return statements;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kw.kind !== SyntaxKind.BoltIdentifier || kw.text !== 'mod') {
|
public parseModuleDeclaration(tokens: BoltTokenStream): BoltModule {
|
||||||
throw new ParseError(kw, [SyntaxKind.BoltModKeyword])
|
|
||||||
|
let modifiers = 0;
|
||||||
|
|
||||||
|
let t0 = tokens.get();
|
||||||
|
const firstToken = t0;
|
||||||
|
if (t0.kind === SyntaxKind.BoltPubKeyword) {
|
||||||
|
tokens.get();
|
||||||
|
modifiers |= BoltDeclarationModifiers.Public;
|
||||||
|
t0 = tokens.peek();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (t0.kind !== SyntaxKind.BoltIdentifier || t0.text !== 'mod') {
|
||||||
|
throw new ParseError(t0, [SyntaxKind.BoltModKeyword])
|
||||||
}
|
}
|
||||||
|
|
||||||
const name = this.parseQualName(tokens);
|
const name = this.parseQualName(tokens);
|
||||||
|
@ -390,34 +516,30 @@ export class Parser {
|
||||||
if (t1.kind !== SyntaxKind.BoltBraced) {
|
if (t1.kind !== SyntaxKind.BoltBraced) {
|
||||||
throw new ParseError(t1, [SyntaxKind.BoltBraced])
|
throw new ParseError(t1, [SyntaxKind.BoltBraced])
|
||||||
}
|
}
|
||||||
|
const sentences = this.parseSentences(createTokenStream(t1));
|
||||||
|
|
||||||
return new Module(isPublic, name, t1.toSentences());
|
const node = createBoltModule(modifiers, name, sentences);
|
||||||
|
setOrigNodeRange(node, firstToken, t1);
|
||||||
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected assertEmpty(tokens: TokenStream) {
|
|
||||||
const t0 = tokens.peek(1);
|
|
||||||
if (t0.kind !== SyntaxKind.BoltEOS) {
|
|
||||||
throw new ParseError(t0, [SyntaxKind.BoltEOS]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
parseNewType(tokens: TokenSteam): NewTypeDecl {
|
public parseNewTypeDeclaration(tokens: BoltTokenSteam): BoltNewTypeDeclaration {
|
||||||
|
|
||||||
|
let modifiers = 0;
|
||||||
|
|
||||||
let isPublic = false;
|
|
||||||
let t0 = tokens.get();
|
let t0 = tokens.get();
|
||||||
if (t0.kind !== SyntaxKind.BoltIdentifier) {
|
|
||||||
throw new ParseError(t0, [SyntaxKind.BoltPubKeyword, SyntaxKind.BoltNewTypeKeyword])
|
if (t0.kind === SyntaxKind.BoltPubKeyword) {
|
||||||
}
|
tokens.get();
|
||||||
if (t0.text === 'pub') {
|
modifiers |= BoltDeclarationModifiers.Public;
|
||||||
isPublic = true;
|
t0 = tokens.peek();
|
||||||
t0 = tokens.get();
|
|
||||||
if (t0.kind !== SyntaxKind.BoltIdentifier) {
|
if (t0.kind !== SyntaxKind.BoltIdentifier) {
|
||||||
throw new ParseError(t0, [SyntaxKind.BoltNewTypeKeyword])
|
throw new ParseError(t0, [SyntaxKind.BoltNewTypeKeyword])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t0.text !== 'newtype') {
|
if (t0.kind !== SyntaxKind.BoltNewTypeKeyword) {
|
||||||
throw new ParseError(t0, [SyntaxKind.BoltNewTypeKeyword])
|
throw new ParseError(t0, [SyntaxKind.BoltNewTypeKeyword])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -426,63 +548,71 @@ export class Parser {
|
||||||
throw new ParseError(name, [SyntaxKind.BoltIdentifier])
|
throw new ParseError(name, [SyntaxKind.BoltIdentifier])
|
||||||
}
|
}
|
||||||
|
|
||||||
return new NewTypeDecl(isPublic, name)
|
const node = createBoltNewTypeDeclaration(modifiers, name)
|
||||||
|
setOrigNodeRange(node, firstToken, name);
|
||||||
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
parseFuncDecl(tokens: TokenStream, origNode: Syntax | null): FuncDecl {
|
private parseFunctionDeclarationMaybeForeign(tokens: BoltTokenStream): BoltFunctionDeclaration | BoltForeignFunctionDeclaration {
|
||||||
|
|
||||||
let target = "Bolt";
|
let target = "Bolt";
|
||||||
let isPublic = false;
|
let modifiers = 0;
|
||||||
|
|
||||||
const k0 = tokens.peek();
|
let k0 = tokens.peek();
|
||||||
if (k0.kind !== SyntaxKind.BoltIdentifier) {
|
let lastNode: BoltSyntax;
|
||||||
throw new ParseError(k0, [SyntaxKind.BoltPubKeyword, SyntaxKind.BoltForeignKeyword, SyntaxKind.BoltFnKeyword])
|
const firstToken = k0;
|
||||||
}
|
|
||||||
if (k0.text === 'pub') {
|
if (k0.kind !== SyntaxKind.BoltPubKeyword) {
|
||||||
tokens.get();
|
tokens.get();
|
||||||
isPublic = true;
|
modifiers |= BoltDeclarationModifiers.Public;
|
||||||
|
k0 = tokens.peek();
|
||||||
}
|
}
|
||||||
|
|
||||||
const k1 = tokens.peek();
|
if (k0.kind === SyntaxKind.BoltForeignKeyword) {
|
||||||
if (k1.kind !== SyntaxKind.BoltIdentifier) {
|
|
||||||
throw new ParseError(k1, [SyntaxKind.BoltForeignKeyword, SyntaxKind.BoltFnKeyword])
|
|
||||||
}
|
|
||||||
if (k1.text === 'foreign') {
|
|
||||||
tokens.get();
|
tokens.get();
|
||||||
|
modifiers |= BoltDeclarationModifiers.IsForeign;
|
||||||
const l1 = tokens.get();
|
const l1 = tokens.get();
|
||||||
if (l1.kind !== SyntaxKind.BoltStringLiteral) {
|
if (l1.kind !== SyntaxKind.BoltStringLiteral) {
|
||||||
throw new ParseError(l1, [SyntaxKind.BoltStringLiteral])
|
throw new ParseError(l1, [SyntaxKind.BoltStringLiteral])
|
||||||
}
|
}
|
||||||
target = l1.value;
|
target = l1.value;
|
||||||
}
|
k0 = tokens.peek();
|
||||||
const k2 = tokens.get();
|
|
||||||
if (k2.kind !== SyntaxKind.BoltIdentifier || k2.text !== 'fn') {
|
|
||||||
throw new ParseError(k2, [SyntaxKind.BoltFnKeyword])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let name: QualName;
|
if (k0.kind !== SyntaxKind.BoltFnKeyword) {
|
||||||
|
throw new ParseError(k0, [SyntaxKind.BoltFnKeyword])
|
||||||
|
}
|
||||||
|
|
||||||
|
tokens.get();
|
||||||
|
|
||||||
|
let name: BoltQualName;
|
||||||
let returnType = null;
|
let returnType = null;
|
||||||
let body = null;
|
let body = null;
|
||||||
let params: Param[] = [];
|
let params: BoltParameter[] = [];
|
||||||
|
|
||||||
// Parse parameters
|
// Parse parameters
|
||||||
|
|
||||||
|
let i = 0;
|
||||||
|
|
||||||
const t0 = tokens.peek(1);
|
const t0 = tokens.peek(1);
|
||||||
const t1 = tokens.peek(2);
|
const t1 = tokens.peek(2);
|
||||||
|
|
||||||
const isParamLike = (token: Token) =>
|
const isParamLike = (token: BoltToken) =>
|
||||||
token.kind === SyntaxKind.BoltIdentifier || token.kind === SyntaxKind.BoltParenthesized;
|
token.kind === SyntaxKind.BoltIdentifier || token.kind === SyntaxKind.BoltParenthesized;
|
||||||
|
|
||||||
const parseParamLike = (tokens: TokenStream) => {
|
const parseParamLike = (tokens: BoltTokenStream) => {
|
||||||
const t0 = tokens.peek(1);
|
const t0 = tokens.peek(1);
|
||||||
if (t0.kind === SyntaxKind.BoltIdentifier) {
|
if (t0.kind === SyntaxKind.BoltIdentifier) {
|
||||||
tokens.get();
|
tokens.get();
|
||||||
return new Param(new BindPatt(t0, null, t0), null, null, null, t0)
|
const bindings = createBoltBindPattern(t0 as BoltIdentifier);
|
||||||
|
setOrigNodeRange(bindings, t0, t0);
|
||||||
|
const param = createBoltParameter(i++, bindings, null, null);
|
||||||
|
setOrigNodeRange(param, t0, t0);
|
||||||
|
return param;
|
||||||
} else if (t0.kind === SyntaxKind.BoltParenthesized) {
|
} else if (t0.kind === SyntaxKind.BoltParenthesized) {
|
||||||
tokens.get();
|
tokens.get();
|
||||||
const innerTokens = t0.toTokenStream();
|
const innerTokens = createTokenStream(t0);
|
||||||
const param = this.parseParam(innerTokens)
|
const param = this.parseParameter(innerTokens, i++)
|
||||||
this.assertEmpty(innerTokens);
|
this.assertEmpty(innerTokens);
|
||||||
return param
|
return param
|
||||||
} else {
|
} else {
|
||||||
|
@ -492,14 +622,16 @@ export class Parser {
|
||||||
|
|
||||||
if (t0.kind === SyntaxKind.BoltOperator) {
|
if (t0.kind === SyntaxKind.BoltOperator) {
|
||||||
|
|
||||||
name = new QualName(t0, [], null, t0);
|
name = createBoltQualName([], t0);
|
||||||
|
setOrigNodeRange(name, t0, t0);
|
||||||
tokens.get();
|
tokens.get();
|
||||||
params.push(parseParamLike(tokens))
|
params.push(parseParamLike(tokens))
|
||||||
|
|
||||||
} else if (isParamLike(t0) && t1.kind == SyntaxKind.BoltOperator) {
|
} else if (isParamLike(t0) && t1.kind == SyntaxKind.BoltOperator) {
|
||||||
|
|
||||||
params.push(parseParamLike(tokens));
|
params.push(parseParamLike(tokens));
|
||||||
name = new QualName(t1, [], null, t1);
|
name = createBoltQualName([], t1);
|
||||||
|
setOrigNodeRange(name, t1, t1);
|
||||||
while (true) {
|
while (true) {
|
||||||
const t2 = tokens.peek();
|
const t2 = tokens.peek();
|
||||||
if (t2.kind !== SyntaxKind.BoltOperator) {
|
if (t2.kind !== SyntaxKind.BoltOperator) {
|
||||||
|
@ -517,13 +649,13 @@ export class Parser {
|
||||||
name = this.parseQualName(tokens)
|
name = this.parseQualName(tokens)
|
||||||
const t2 = tokens.get();
|
const t2 = tokens.get();
|
||||||
if (t2.kind === SyntaxKind.BoltParenthesized) {
|
if (t2.kind === SyntaxKind.BoltParenthesized) {
|
||||||
const innerTokens = t2.toTokenStream();
|
const innerTokens = createTokenStream(t2);
|
||||||
while (true) {
|
while (true) {
|
||||||
const t3 = innerTokens.peek();
|
const t3 = innerTokens.peek();
|
||||||
if (t3.kind === SyntaxKind.BoltEOS) {
|
if (t3.kind === SyntaxKind.BoltEOS) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
params.push(this.parseParam(innerTokens))
|
params.push(this.parseParameter(innerTokens, i++))
|
||||||
const t4 = innerTokens.get();
|
const t4 = innerTokens.get();
|
||||||
if (t4.kind === SyntaxKind.BoltComma) {
|
if (t4.kind === SyntaxKind.BoltComma) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -546,7 +678,7 @@ export class Parser {
|
||||||
const t2 = tokens.peek();
|
const t2 = tokens.peek();
|
||||||
if (t2.kind === SyntaxKind.BoltRArrow) {
|
if (t2.kind === SyntaxKind.BoltRArrow) {
|
||||||
tokens.get();
|
tokens.get();
|
||||||
returnType = this.parseTypeDecl(tokens);
|
returnType = this.parseTypeNode(tokens);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse function body
|
// Parse function body
|
||||||
|
@ -556,21 +688,29 @@ export class Parser {
|
||||||
tokens.get();
|
tokens.get();
|
||||||
switch (target) {
|
switch (target) {
|
||||||
case "Bolt":
|
case "Bolt":
|
||||||
body = this.parseStmts(tokens, t3);
|
body = this.parseStatements(tokens);
|
||||||
break;
|
break;
|
||||||
case "JS":
|
case "JS":
|
||||||
body = acorn.parse(t3.text).body;
|
// TODO
|
||||||
|
//body = acorn.parse(t3.text).body;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error(`Unrecognised language: ${target}`);
|
throw new Error(`Unrecognised language: ${target}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new FuncDecl(isPublic, target, name, params, returnType, body, null, origNode)
|
const node = createBoltFunctionDeclaration(
|
||||||
|
modifiers,
|
||||||
|
name,
|
||||||
|
params,
|
||||||
|
returnType,
|
||||||
|
body
|
||||||
|
);
|
||||||
|
setOrigNodeRange(node, firstToken, lastNode);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
parseSourceElement(tokens: TokenStream): SourceElement {
|
parseSourceElement(tokens: BoltTokenStream): SourceElement {
|
||||||
const t0 = tokens.peek(1);
|
const t0 = tokens.peek(1);
|
||||||
if (t0.kind === SyntaxKind.BoltIdentifier) {
|
if (t0.kind === SyntaxKind.BoltIdentifier) {
|
||||||
let i = 1;
|
let i = 1;
|
||||||
|
@ -608,7 +748,7 @@ export class Parser {
|
||||||
return this.parseVariantDecl(tokens);
|
return this.parseVariantDecl(tokens);
|
||||||
default:
|
default:
|
||||||
try {
|
try {
|
||||||
return this.parseExpr(tokens)
|
return this.parseExpression(tokens)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof ParseError) {
|
if (e instanceof ParseError) {
|
||||||
throw new ParseError(kw, [...e.expected, SyntaxKind.BoltModKeyword, SyntaxKind.BoltLetKeyword,
|
throw new ParseError(kw, [...e.expected, SyntaxKind.BoltModKeyword, SyntaxKind.BoltLetKeyword,
|
||||||
|
@ -619,7 +759,7 @@ export class Parser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return this.parseStmt(tokens)
|
return this.parseStatement(tokens)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -638,35 +778,35 @@ export class Parser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
parseBinOp(tokens: TokenStream, lhs: Expr , minPrecedence: number) {
|
//parseBinOp(tokens: TokenStream, lhs: Expr , minPrecedence: number) {
|
||||||
let lookahead = tokens.peek(1);
|
// let lookahead = tokens.peek(1);
|
||||||
while (true) {
|
// while (true) {
|
||||||
if (lookahead.kind !== SyntaxKind.BoltOperator) {
|
// if (lookahead.kind !== SyntaxKind.BoltOperator) {
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
const lookaheadDesc = this.getOperatorDesc(2, lookahead.text);
|
// const lookaheadDesc = this.getOperatorDesc(2, lookahead.text);
|
||||||
if (lookaheadDesc === null || lookaheadDesc.precedence < minPrecedence) {
|
// if (lookaheadDesc === null || lookaheadDesc.precedence < minPrecedence) {
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
const op = lookahead;
|
// const op = lookahead;
|
||||||
const opDesc = this.getOperatorDesc(2, op.text);
|
// const opDesc = this.getOperatorDesc(2, op.text);
|
||||||
tokens.get();
|
// tokens.get();
|
||||||
let rhs = this.parsePrimExpr(tokens)
|
// let rhs = this.parsePrimExpr(tokens)
|
||||||
lookahead = tokens.peek()
|
// lookahead = tokens.peek()
|
||||||
while (lookaheadDesc.arity === 2
|
// while (lookaheadDesc.arity === 2
|
||||||
&& ((lookaheadDesc.precedence > opDesc.precedence)
|
// && ((lookaheadDesc.precedence > opDesc.precedence)
|
||||||
|| lookaheadDesc.kind === OperatorKind.InfixR && lookaheadDesc.precedence === opDesc.precedence)) {
|
// || lookaheadDesc.kind === OperatorKind.InfixR && lookaheadDesc.precedence === opDesc.precedence)) {
|
||||||
rhs = this.parseBinOp(tokens, rhs, lookaheadDesc.precedence)
|
// rhs = this.parseBinOp(tokens, rhs, lookaheadDesc.precedence)
|
||||||
}
|
// }
|
||||||
lookahead = tokens.peek();
|
// lookahead = tokens.peek();
|
||||||
lhs = new CallExpr(new RefExpr(new QualName(op, [])), [lhs, rhs]);
|
// lhs = new CallExpr(new RefExpr(new QualName(op, [])), [lhs, rhs]);
|
||||||
}
|
// }
|
||||||
return lhs
|
// return lhs
|
||||||
}
|
//}
|
||||||
|
|
||||||
parseCallExpr(tokens: TokenStream): CallExpr {
|
parseCallExpr(tokens: TokenStream): CallExpr {
|
||||||
|
|
||||||
const operator = this.parsePrimExpr(tokens)
|
const operator = this.parsePrimitiveExpression(tokens)
|
||||||
const args: Expr[] = []
|
const args: Expr[] = []
|
||||||
|
|
||||||
const t2 = tokens.get();
|
const t2 = tokens.get();
|
||||||
|
@ -681,7 +821,7 @@ export class Parser {
|
||||||
if (t3.kind === SyntaxKind.BoltEOS) {
|
if (t3.kind === SyntaxKind.BoltEOS) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
args.push(this.parseExpr(innerTokens))
|
args.push(this.parseExpression(innerTokens))
|
||||||
const t4 = innerTokens.get();
|
const t4 = innerTokens.get();
|
||||||
if (t4.kind === SyntaxKind.BoltEOS) {
|
if (t4.kind === SyntaxKind.BoltEOS) {
|
||||||
break
|
break
|
||||||
|
|
|
@ -29,7 +29,6 @@ function createNode(nodeType) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
obj.span = null;
|
obj.span = null;
|
||||||
obj.origNodes = null;
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,9 +58,6 @@ for (const nodeName of Object.keys(NODE_TYPES)) {
|
||||||
if (i < args.length) {
|
if (i < args.length) {
|
||||||
node.span = args[i++];
|
node.span = args[i++];
|
||||||
}
|
}
|
||||||
if (i < args.length) {
|
|
||||||
node.origNodes = i < args.length ? args[i++] : null;
|
|
||||||
}
|
|
||||||
if (i < args.length) {
|
if (i < args.length) {
|
||||||
throw new Error(`Too many arguments provided to function create${nodeName}`);
|
throw new Error(`Too many arguments provided to function create${nodeName}`);
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,7 +112,6 @@ interface SyntaxBase {
|
||||||
kind: SyntaxKind;
|
kind: SyntaxKind;
|
||||||
parentNode: Syntax | null;
|
parentNode: Syntax | null;
|
||||||
span: TextSpan | null;
|
span: TextSpan | null;
|
||||||
origNodes: SyntaxRange | null;
|
|
||||||
}
|
}
|
||||||
`);
|
`);
|
||||||
|
|
||||||
|
@ -180,7 +179,7 @@ interface SyntaxBase {
|
||||||
for (const field of getAllFields(decl)) {
|
for (const field of getAllFields(decl)) {
|
||||||
dtsFile.write(`${field.name}: ${emitTypeScriptType(field.typeNode)}, `);
|
dtsFile.write(`${field.name}: ${emitTypeScriptType(field.typeNode)}, `);
|
||||||
}
|
}
|
||||||
dtsFile.write(`span?: TextSpan | null, origNodes?: SyntaxRange | null): ${decl.name};\n`);
|
dtsFile.write(`span?: TextSpan | null): ${decl.name};\n`);
|
||||||
}
|
}
|
||||||
|
|
||||||
dtsFile.write('\n');
|
dtsFile.write('\n');
|
||||||
|
|
Loading…
Reference in a new issue