Fix even more errors
This commit is contained in:
parent
824cf57c13
commit
f8918bfa79
4 changed files with 160 additions and 120 deletions
11
spec/ast.txt
11
spec/ast.txt
|
@ -51,6 +51,7 @@ node BoltLetKeyword > BoltToken, BoltKeyword;
|
||||||
node BoltReturnKeyword > BoltToken, BoltKeyword;
|
node BoltReturnKeyword > BoltToken, BoltKeyword;
|
||||||
node BoltLoopKeyword > BoltToken, BoltKeyword;
|
node BoltLoopKeyword > BoltToken, BoltKeyword;
|
||||||
node BoltYieldKeyword > BoltToken, BoltKeyword;
|
node BoltYieldKeyword > BoltToken, BoltKeyword;
|
||||||
|
node BoltMatchKeyword > 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;
|
||||||
|
@ -205,20 +206,12 @@ node BoltModule > BoltDeclaration {
|
||||||
}
|
}
|
||||||
|
|
||||||
node BoltFunctionDeclaration > BoltDeclaration {
|
node BoltFunctionDeclaration > BoltDeclaration {
|
||||||
modifiers: BoltDeclarationModifiers,
|
|
||||||
name: BoltSymbol,
|
|
||||||
params: Vec<BoltParameter>,
|
|
||||||
returnType: Option<BoltTypeNode>,
|
|
||||||
body: BoltExpression,
|
|
||||||
}
|
|
||||||
|
|
||||||
node BoltForeignFunctionDeclaration > BoltDeclaration {
|
|
||||||
modifiers: BoltDeclarationModifiers,
|
modifiers: BoltDeclarationModifiers,
|
||||||
target: String,
|
target: String,
|
||||||
name: BoltSymbol,
|
name: BoltSymbol,
|
||||||
params: Vec<BoltParameter>,
|
params: Vec<BoltParameter>,
|
||||||
returnType: Option<BoltTypeNode>,
|
returnType: Option<BoltTypeNode>,
|
||||||
body: FunctionBody,
|
body: Vec<BoltStatement>,
|
||||||
}
|
}
|
||||||
|
|
||||||
node BoltVariableDeclaration > BoltDeclaration {
|
node BoltVariableDeclaration > BoltDeclaration {
|
||||||
|
|
105
src/ast.d.ts
vendored
105
src/ast.d.ts
vendored
|
@ -22,44 +22,44 @@ export const enum SyntaxKind {
|
||||||
BoltReturnKeyword = 25,
|
BoltReturnKeyword = 25,
|
||||||
BoltLoopKeyword = 26,
|
BoltLoopKeyword = 26,
|
||||||
BoltYieldKeyword = 27,
|
BoltYieldKeyword = 27,
|
||||||
BoltImportKeyword = 28,
|
BoltMatchKeyword = 28,
|
||||||
BoltPubKeyword = 29,
|
BoltImportKeyword = 29,
|
||||||
BoltModKeyword = 30,
|
BoltPubKeyword = 30,
|
||||||
BoltMutKeyword = 31,
|
BoltModKeyword = 31,
|
||||||
BoltEnumKeyword = 32,
|
BoltMutKeyword = 32,
|
||||||
BoltStructKeyword = 33,
|
BoltEnumKeyword = 33,
|
||||||
BoltNewTypeKeyword = 34,
|
BoltStructKeyword = 34,
|
||||||
BoltParenthesized = 36,
|
BoltNewTypeKeyword = 35,
|
||||||
BoltBraced = 37,
|
BoltParenthesized = 37,
|
||||||
BoltBracketed = 38,
|
BoltBraced = 38,
|
||||||
BoltSourceFile = 39,
|
BoltBracketed = 39,
|
||||||
BoltQualName = 40,
|
BoltSourceFile = 40,
|
||||||
BoltSentence = 41,
|
BoltQualName = 41,
|
||||||
BoltReferenceTypeNode = 43,
|
BoltSentence = 42,
|
||||||
BoltBindPattern = 45,
|
BoltReferenceTypeNode = 44,
|
||||||
BoltTypePattern = 46,
|
BoltBindPattern = 46,
|
||||||
BoltExpressionPattern = 47,
|
BoltTypePattern = 47,
|
||||||
BoltTuplePatternElement = 48,
|
BoltExpressionPattern = 48,
|
||||||
BoltTuplePattern = 49,
|
BoltTuplePatternElement = 49,
|
||||||
BoltRecordPatternField = 50,
|
BoltTuplePattern = 50,
|
||||||
BoltRecordPattern = 51,
|
BoltRecordPatternField = 51,
|
||||||
BoltReferenceExpression = 53,
|
BoltRecordPattern = 52,
|
||||||
BoltCallExpression = 54,
|
BoltReferenceExpression = 54,
|
||||||
BoltYieldExpression = 55,
|
BoltCallExpression = 55,
|
||||||
BoltMatchArm = 56,
|
BoltYieldExpression = 56,
|
||||||
BoltMatchExpression = 57,
|
BoltMatchArm = 57,
|
||||||
BoltCase = 58,
|
BoltMatchExpression = 58,
|
||||||
BoltCaseExpression = 59,
|
BoltCase = 59,
|
||||||
BoltBlockExpression = 60,
|
BoltCaseExpression = 60,
|
||||||
BoltConstantExpression = 61,
|
BoltBlockExpression = 61,
|
||||||
BoltReturnStatement = 63,
|
BoltConstantExpression = 62,
|
||||||
BoltResumeStatement = 64,
|
BoltReturnStatement = 64,
|
||||||
BoltExpressionStatement = 65,
|
BoltResumeStatement = 65,
|
||||||
BoltParameter = 66,
|
BoltExpressionStatement = 66,
|
||||||
BoltNewTypeDeclaration = 69,
|
BoltParameter = 67,
|
||||||
BoltModule = 70,
|
BoltNewTypeDeclaration = 70,
|
||||||
BoltFunctionDeclaration = 71,
|
BoltModule = 71,
|
||||||
BoltForeignFunctionDeclaration = 72,
|
BoltFunctionDeclaration = 72,
|
||||||
BoltVariableDeclaration = 73,
|
BoltVariableDeclaration = 73,
|
||||||
BoltPlainImportSymbol = 75,
|
BoltPlainImportSymbol = 75,
|
||||||
BoltImportDeclaration = 76,
|
BoltImportDeclaration = 76,
|
||||||
|
@ -124,6 +124,7 @@ export type BoltToken
|
||||||
| BoltReturnKeyword
|
| BoltReturnKeyword
|
||||||
| BoltLoopKeyword
|
| BoltLoopKeyword
|
||||||
| BoltYieldKeyword
|
| BoltYieldKeyword
|
||||||
|
| BoltMatchKeyword
|
||||||
| BoltImportKeyword
|
| BoltImportKeyword
|
||||||
| BoltPubKeyword
|
| BoltPubKeyword
|
||||||
| BoltModKeyword
|
| BoltModKeyword
|
||||||
|
@ -212,6 +213,7 @@ export type BoltKeyword
|
||||||
| BoltReturnKeyword
|
| BoltReturnKeyword
|
||||||
| BoltLoopKeyword
|
| BoltLoopKeyword
|
||||||
| BoltYieldKeyword
|
| BoltYieldKeyword
|
||||||
|
| BoltMatchKeyword
|
||||||
| BoltImportKeyword
|
| BoltImportKeyword
|
||||||
| BoltPubKeyword
|
| BoltPubKeyword
|
||||||
| BoltModKeyword
|
| BoltModKeyword
|
||||||
|
@ -245,6 +247,10 @@ export interface BoltYieldKeyword extends SyntaxBase {
|
||||||
kind: SyntaxKind.BoltYieldKeyword;
|
kind: SyntaxKind.BoltYieldKeyword;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface BoltMatchKeyword extends SyntaxBase {
|
||||||
|
kind: SyntaxKind.BoltMatchKeyword;
|
||||||
|
}
|
||||||
|
|
||||||
export interface BoltImportKeyword extends SyntaxBase {
|
export interface BoltImportKeyword extends SyntaxBase {
|
||||||
kind: SyntaxKind.BoltImportKeyword;
|
kind: SyntaxKind.BoltImportKeyword;
|
||||||
}
|
}
|
||||||
|
@ -459,7 +465,6 @@ export type BoltDeclaration
|
||||||
= BoltNewTypeDeclaration
|
= BoltNewTypeDeclaration
|
||||||
| BoltModule
|
| BoltModule
|
||||||
| BoltFunctionDeclaration
|
| BoltFunctionDeclaration
|
||||||
| BoltForeignFunctionDeclaration
|
|
||||||
| BoltVariableDeclaration
|
| BoltVariableDeclaration
|
||||||
| BoltImportDeclaration
|
| BoltImportDeclaration
|
||||||
| BoltRecordDeclaration
|
| BoltRecordDeclaration
|
||||||
|
@ -484,20 +489,11 @@ export interface BoltModule extends SyntaxBase {
|
||||||
export interface BoltFunctionDeclaration extends SyntaxBase {
|
export interface BoltFunctionDeclaration extends SyntaxBase {
|
||||||
kind: SyntaxKind.BoltFunctionDeclaration;
|
kind: SyntaxKind.BoltFunctionDeclaration;
|
||||||
modifiers: BoltDeclarationModifiers;
|
modifiers: BoltDeclarationModifiers;
|
||||||
name: BoltSymbol;
|
|
||||||
params: BoltParameter[];
|
|
||||||
returnType: BoltTypeNode | null;
|
|
||||||
body: BoltExpression;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface BoltForeignFunctionDeclaration extends SyntaxBase {
|
|
||||||
kind: SyntaxKind.BoltForeignFunctionDeclaration;
|
|
||||||
modifiers: BoltDeclarationModifiers;
|
|
||||||
target: string;
|
target: string;
|
||||||
name: BoltSymbol;
|
name: BoltSymbol;
|
||||||
params: BoltParameter[];
|
params: BoltParameter[];
|
||||||
returnType: BoltTypeNode | null;
|
returnType: BoltTypeNode | null;
|
||||||
body: FunctionBody;
|
body: BoltStatement[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface BoltVariableDeclaration extends SyntaxBase {
|
export interface BoltVariableDeclaration extends SyntaxBase {
|
||||||
|
@ -537,7 +533,6 @@ export type BoltSourceElement
|
||||||
| BoltNewTypeDeclaration
|
| BoltNewTypeDeclaration
|
||||||
| BoltModule
|
| BoltModule
|
||||||
| BoltFunctionDeclaration
|
| BoltFunctionDeclaration
|
||||||
| BoltForeignFunctionDeclaration
|
|
||||||
| BoltVariableDeclaration
|
| BoltVariableDeclaration
|
||||||
| BoltImportDeclaration
|
| BoltImportDeclaration
|
||||||
| BoltRecordDeclaration
|
| BoltRecordDeclaration
|
||||||
|
@ -729,6 +724,7 @@ export type BoltSyntax
|
||||||
| BoltReturnKeyword
|
| BoltReturnKeyword
|
||||||
| BoltLoopKeyword
|
| BoltLoopKeyword
|
||||||
| BoltYieldKeyword
|
| BoltYieldKeyword
|
||||||
|
| BoltMatchKeyword
|
||||||
| BoltImportKeyword
|
| BoltImportKeyword
|
||||||
| BoltPubKeyword
|
| BoltPubKeyword
|
||||||
| BoltModKeyword
|
| BoltModKeyword
|
||||||
|
@ -766,7 +762,6 @@ export type BoltSyntax
|
||||||
| BoltNewTypeDeclaration
|
| BoltNewTypeDeclaration
|
||||||
| BoltModule
|
| BoltModule
|
||||||
| BoltFunctionDeclaration
|
| BoltFunctionDeclaration
|
||||||
| BoltForeignFunctionDeclaration
|
|
||||||
| BoltVariableDeclaration
|
| BoltVariableDeclaration
|
||||||
| BoltPlainImportSymbol
|
| BoltPlainImportSymbol
|
||||||
| BoltImportDeclaration
|
| BoltImportDeclaration
|
||||||
|
@ -820,6 +815,7 @@ export type Syntax
|
||||||
| BoltReturnKeyword
|
| BoltReturnKeyword
|
||||||
| BoltLoopKeyword
|
| BoltLoopKeyword
|
||||||
| BoltYieldKeyword
|
| BoltYieldKeyword
|
||||||
|
| BoltMatchKeyword
|
||||||
| BoltImportKeyword
|
| BoltImportKeyword
|
||||||
| BoltPubKeyword
|
| BoltPubKeyword
|
||||||
| BoltModKeyword
|
| BoltModKeyword
|
||||||
|
@ -857,7 +853,6 @@ export type Syntax
|
||||||
| BoltNewTypeDeclaration
|
| BoltNewTypeDeclaration
|
||||||
| BoltModule
|
| BoltModule
|
||||||
| BoltFunctionDeclaration
|
| BoltFunctionDeclaration
|
||||||
| BoltForeignFunctionDeclaration
|
|
||||||
| BoltVariableDeclaration
|
| BoltVariableDeclaration
|
||||||
| BoltPlainImportSymbol
|
| BoltPlainImportSymbol
|
||||||
| BoltImportDeclaration
|
| BoltImportDeclaration
|
||||||
|
@ -909,6 +904,7 @@ export function createBoltLetKeyword(span?: TextSpan | null): BoltLetKeyword;
|
||||||
export function createBoltReturnKeyword(span?: TextSpan | null): BoltReturnKeyword;
|
export function createBoltReturnKeyword(span?: TextSpan | null): BoltReturnKeyword;
|
||||||
export function createBoltLoopKeyword(span?: TextSpan | null): BoltLoopKeyword;
|
export function createBoltLoopKeyword(span?: TextSpan | null): BoltLoopKeyword;
|
||||||
export function createBoltYieldKeyword(span?: TextSpan | null): BoltYieldKeyword;
|
export function createBoltYieldKeyword(span?: TextSpan | null): BoltYieldKeyword;
|
||||||
|
export function createBoltMatchKeyword(span?: TextSpan | null): BoltMatchKeyword;
|
||||||
export function createBoltImportKeyword(span?: TextSpan | null): BoltImportKeyword;
|
export function createBoltImportKeyword(span?: TextSpan | null): BoltImportKeyword;
|
||||||
export function createBoltPubKeyword(span?: TextSpan | null): BoltPubKeyword;
|
export function createBoltPubKeyword(span?: TextSpan | null): BoltPubKeyword;
|
||||||
export function createBoltModKeyword(span?: TextSpan | null): BoltModKeyword;
|
export function createBoltModKeyword(span?: TextSpan | null): BoltModKeyword;
|
||||||
|
@ -945,8 +941,7 @@ export function createBoltExpressionStatement(expression: BoltExpression, span?:
|
||||||
export function createBoltParameter(index: number, bindings: BoltPattern, type: BoltTypeNode | null, defaultValue: BoltExpression | null, span?: TextSpan | null): BoltParameter;
|
export function createBoltParameter(index: number, bindings: BoltPattern, type: BoltTypeNode | null, defaultValue: BoltExpression | null, span?: TextSpan | null): BoltParameter;
|
||||||
export function createBoltNewTypeDeclaration(modifiers: BoltDeclarationModifiers, name: BoltIdentifier, span?: TextSpan | null): BoltNewTypeDeclaration;
|
export function createBoltNewTypeDeclaration(modifiers: BoltDeclarationModifiers, name: BoltIdentifier, span?: TextSpan | null): BoltNewTypeDeclaration;
|
||||||
export function createBoltModule(modifiers: BoltDeclarationModifiers, name: BoltQualName, elements: BoltSourceElement[], span?: TextSpan | null): BoltModule;
|
export function createBoltModule(modifiers: BoltDeclarationModifiers, name: BoltQualName, elements: BoltSourceElement[], span?: TextSpan | null): BoltModule;
|
||||||
export function createBoltFunctionDeclaration(modifiers: BoltDeclarationModifiers, name: BoltSymbol, params: BoltParameter[], returnType: BoltTypeNode | null, body: BoltExpression, span?: TextSpan | null): BoltFunctionDeclaration;
|
export function createBoltFunctionDeclaration(modifiers: BoltDeclarationModifiers, target: string, name: BoltSymbol, params: BoltParameter[], returnType: BoltTypeNode | null, body: BoltStatement[], span?: TextSpan | null): BoltFunctionDeclaration;
|
||||||
export function createBoltForeignFunctionDeclaration(modifiers: BoltDeclarationModifiers, target: string, name: BoltSymbol, params: BoltParameter[], returnType: BoltTypeNode | null, body: FunctionBody, span?: TextSpan | null): BoltForeignFunctionDeclaration;
|
|
||||||
export function createBoltVariableDeclaration(modifiers: BoltDeclarationModifiers, bindings: BoltPattern, type: BoltTypeNode | null, value: BoltExpression | null, span?: TextSpan | null): BoltVariableDeclaration;
|
export function createBoltVariableDeclaration(modifiers: BoltDeclarationModifiers, bindings: BoltPattern, type: BoltTypeNode | null, value: BoltExpression | null, span?: TextSpan | null): BoltVariableDeclaration;
|
||||||
export function createBoltPlainImportSymbol(name: BoltQualName, span?: TextSpan | null): BoltPlainImportSymbol;
|
export function createBoltPlainImportSymbol(name: BoltQualName, span?: TextSpan | null): BoltPlainImportSymbol;
|
||||||
export function createBoltImportDeclaration(file: string, symbols: BoltImportSymbol[], span?: TextSpan | null): BoltImportDeclaration;
|
export function createBoltImportDeclaration(file: string, symbols: BoltImportSymbol[], span?: TextSpan | null): BoltImportDeclaration;
|
||||||
|
@ -998,6 +993,7 @@ export function isBoltLetKeyword(value: any): value is BoltLetKeyword;
|
||||||
export function isBoltReturnKeyword(value: any): value is BoltReturnKeyword;
|
export function isBoltReturnKeyword(value: any): value is BoltReturnKeyword;
|
||||||
export function isBoltLoopKeyword(value: any): value is BoltLoopKeyword;
|
export function isBoltLoopKeyword(value: any): value is BoltLoopKeyword;
|
||||||
export function isBoltYieldKeyword(value: any): value is BoltYieldKeyword;
|
export function isBoltYieldKeyword(value: any): value is BoltYieldKeyword;
|
||||||
|
export function isBoltMatchKeyword(value: any): value is BoltMatchKeyword;
|
||||||
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;
|
||||||
|
@ -1041,7 +1037,6 @@ export function isBoltDeclaration(value: any): value is BoltDeclaration;
|
||||||
export function isBoltNewTypeDeclaration(value: any): value is BoltNewTypeDeclaration;
|
export function isBoltNewTypeDeclaration(value: any): value is BoltNewTypeDeclaration;
|
||||||
export function isBoltModule(value: any): value is BoltModule;
|
export function isBoltModule(value: any): value is BoltModule;
|
||||||
export function isBoltFunctionDeclaration(value: any): value is BoltFunctionDeclaration;
|
export function isBoltFunctionDeclaration(value: any): value is BoltFunctionDeclaration;
|
||||||
export function isBoltForeignFunctionDeclaration(value: any): value is BoltForeignFunctionDeclaration;
|
|
||||||
export function isBoltVariableDeclaration(value: any): value is BoltVariableDeclaration;
|
export function isBoltVariableDeclaration(value: any): value is BoltVariableDeclaration;
|
||||||
export function isBoltImportSymbol(value: any): value is BoltImportSymbol;
|
export function isBoltImportSymbol(value: any): value is BoltImportSymbol;
|
||||||
export function isBoltPlainImportSymbol(value: any): value is BoltPlainImportSymbol;
|
export function isBoltPlainImportSymbol(value: any): value is BoltPlainImportSymbol;
|
||||||
|
|
|
@ -142,6 +142,9 @@ export class TypeChecker {
|
||||||
this.symbols[getFullName(node.name)] = new PrimType();
|
this.symbols[getFullName(node.name)] = new PrimType();
|
||||||
return noneType;
|
return noneType;
|
||||||
|
|
||||||
|
case SyntaxKind.BoltExpressionStatement:
|
||||||
|
return voidType;
|
||||||
|
|
||||||
case SyntaxKind.BoltFunctionDeclaration:
|
case SyntaxKind.BoltFunctionDeclaration:
|
||||||
let returnType = anyType;
|
let returnType = anyType;
|
||||||
if (node.returnType !== null) {
|
if (node.returnType !== null) {
|
||||||
|
@ -217,6 +220,10 @@ export class TypeChecker {
|
||||||
case SyntaxKind.BoltNewTypeDeclaration:
|
case SyntaxKind.BoltNewTypeDeclaration:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SyntaxKind.BoltExpressionStatement:
|
||||||
|
this.check(node.expression);
|
||||||
|
break;
|
||||||
|
|
||||||
case SyntaxKind.BoltFunctionDeclaration:
|
case SyntaxKind.BoltFunctionDeclaration:
|
||||||
if (node.body !== null) {
|
if (node.body !== null) {
|
||||||
if (Array.isArray(node.body)) {
|
if (Array.isArray(node.body)) {
|
||||||
|
|
157
src/parser.ts
157
src/parser.ts
|
@ -9,6 +9,8 @@ import {
|
||||||
BoltExpression,
|
BoltExpression,
|
||||||
BoltRecordDeclaration,
|
BoltRecordDeclaration,
|
||||||
BoltStatement,
|
BoltStatement,
|
||||||
|
BoltDeclaration,
|
||||||
|
BoltSourceElement,
|
||||||
createBoltQualName,
|
createBoltQualName,
|
||||||
BoltQualName,
|
BoltQualName,
|
||||||
BoltPattern,
|
BoltPattern,
|
||||||
|
@ -26,6 +28,9 @@ import {
|
||||||
BoltDeclarationModifiers,
|
BoltDeclarationModifiers,
|
||||||
BoltStringLiteral,
|
BoltStringLiteral,
|
||||||
BoltImportSymbol,
|
BoltImportSymbol,
|
||||||
|
BoltCallExpression,
|
||||||
|
BoltExpressionStatement,
|
||||||
|
createBoltExpressionStatement,
|
||||||
} from "./ast"
|
} from "./ast"
|
||||||
|
|
||||||
import { BoltTokenStream, setOrigNodeRange } from "./util"
|
import { BoltTokenStream, setOrigNodeRange } from "./util"
|
||||||
|
@ -44,6 +49,12 @@ function describeKind(kind: SyntaxKind): string {
|
||||||
return "'fn'"
|
return "'fn'"
|
||||||
case SyntaxKind.BoltForeignKeyword:
|
case SyntaxKind.BoltForeignKeyword:
|
||||||
return "'foreign'"
|
return "'foreign'"
|
||||||
|
case SyntaxKind.BoltMatchKeyword:
|
||||||
|
return "'match'";
|
||||||
|
case SyntaxKind.BoltYieldKeyword:
|
||||||
|
return "'yield'";
|
||||||
|
case SyntaxKind.BoltReturnKeyword:
|
||||||
|
return "'return'";
|
||||||
case SyntaxKind.BoltPubKeyword:
|
case SyntaxKind.BoltPubKeyword:
|
||||||
return "'pub'"
|
return "'pub'"
|
||||||
case SyntaxKind.BoltLetKeyword:
|
case SyntaxKind.BoltLetKeyword:
|
||||||
|
@ -64,6 +75,8 @@ function describeKind(kind: SyntaxKind): string {
|
||||||
return "'struct'"
|
return "'struct'"
|
||||||
case SyntaxKind.BoltEnumKeyword:
|
case SyntaxKind.BoltEnumKeyword:
|
||||||
return "'enum'"
|
return "'enum'"
|
||||||
|
case SyntaxKind.BoltNewTypeKeyword:
|
||||||
|
return "'newtype'";
|
||||||
case SyntaxKind.BoltBraced:
|
case SyntaxKind.BoltBraced:
|
||||||
return "'{' .. '}'"
|
return "'{' .. '}'"
|
||||||
case SyntaxKind.BoltBracketed:
|
case SyntaxKind.BoltBracketed:
|
||||||
|
@ -81,7 +94,7 @@ function enumerate(elements: string[]) {
|
||||||
if (elements.length === 1) {
|
if (elements.length === 1) {
|
||||||
return elements[0]
|
return elements[0]
|
||||||
} else {
|
} else {
|
||||||
return elements.slice(0, elements.length-1).join(',') + ' or ' + elements[elements.length-1]
|
return elements.slice(0, elements.length-1).join(', ') + ' or ' + elements[elements.length-1]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,13 +130,37 @@ const KIND_EXPRESSION_T0 = [
|
||||||
SyntaxKind.BoltIntegerLiteral,
|
SyntaxKind.BoltIntegerLiteral,
|
||||||
SyntaxKind.BoltIdentifier,
|
SyntaxKind.BoltIdentifier,
|
||||||
SyntaxKind.BoltOperator,
|
SyntaxKind.BoltOperator,
|
||||||
]
|
SyntaxKind.BoltMatchKeyword,
|
||||||
|
SyntaxKind.BoltYieldKeyword,
|
||||||
|
]
|
||||||
|
|
||||||
const KIND_STATEMENT_T0 = [
|
const KIND_STATEMENT_T0 = [
|
||||||
SyntaxKind.BoltReturnKeyword,
|
SyntaxKind.BoltReturnKeyword,
|
||||||
...KIND_EXPRESSION_T0,
|
...KIND_EXPRESSION_T0,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
const KIND_DECLARATION_KEYWORD = [
|
||||||
|
SyntaxKind.BoltFnKeyword,
|
||||||
|
SyntaxKind.BoltEnumKeyword,
|
||||||
|
SyntaxKind.BoltLetKeyword,
|
||||||
|
SyntaxKind.BoltNewTypeKeyword,
|
||||||
|
SyntaxKind.BoltModKeyword,
|
||||||
|
SyntaxKind.BoltStructKeyword,
|
||||||
|
]
|
||||||
|
|
||||||
|
const KIND_DECLARATION_T0 = [
|
||||||
|
SyntaxKind.BoltPubKeyword,
|
||||||
|
SyntaxKind.BoltForeignKeyword,
|
||||||
|
...KIND_DECLARATION_KEYWORD,
|
||||||
|
]
|
||||||
|
|
||||||
|
const KIND_SOURCEELEMENT_T0 = [
|
||||||
|
SyntaxKind.BoltModKeyword,
|
||||||
|
...KIND_EXPRESSION_T0,
|
||||||
|
...KIND_STATEMENT_T0,
|
||||||
|
...KIND_DECLARATION_T0,
|
||||||
|
]
|
||||||
|
|
||||||
export class Parser {
|
export class Parser {
|
||||||
|
|
||||||
operatorTable = [
|
operatorTable = [
|
||||||
|
@ -416,6 +453,13 @@ export class Parser {
|
||||||
|| (t0.kind === SyntaxKind.BoltOperator && this.isUnaryOperator(t0.text));
|
|| (t0.kind === SyntaxKind.BoltOperator && this.isUnaryOperator(t0.text));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public parseExpressionStatement(tokens: BoltTokenStream): BoltExpressionStatement {
|
||||||
|
const expression = this.parseExpression(tokens)
|
||||||
|
const node = createBoltExpressionStatement(expression)
|
||||||
|
setOrigNodeRange(node, expression, expression);
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
public parseStatement(tokens: BoltTokenStream): BoltStatement {
|
public parseStatement(tokens: BoltTokenStream): BoltStatement {
|
||||||
const t0 = tokens.peek();
|
const t0 = tokens.peek();
|
||||||
if (t0.kind === SyntaxKind.BoltReturnKeyword) {
|
if (t0.kind === SyntaxKind.BoltReturnKeyword) {
|
||||||
|
@ -553,7 +597,7 @@ export class Parser {
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
private parseFunctionDeclarationMaybeForeign(tokens: BoltTokenStream): BoltFunctionDeclaration | BoltForeignFunctionDeclaration {
|
private parseFunctionDeclaration(tokens: BoltTokenStream): BoltFunctionDeclaration | BoltForeignFunctionDeclaration {
|
||||||
|
|
||||||
let target = "Bolt";
|
let target = "Bolt";
|
||||||
let modifiers = 0;
|
let modifiers = 0;
|
||||||
|
@ -707,63 +751,66 @@ export class Parser {
|
||||||
body
|
body
|
||||||
);
|
);
|
||||||
setOrigNodeRange(node, firstToken, lastNode);
|
setOrigNodeRange(node, firstToken, lastNode);
|
||||||
|
return node;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
parseSourceElement(tokens: BoltTokenStream): SourceElement {
|
public parseDeclaration(tokens: BoltTokenStream): BoltDeclaration {
|
||||||
const t0 = tokens.peek(1);
|
let t0 = tokens.peek(1);
|
||||||
if (t0.kind === SyntaxKind.BoltIdentifier) {
|
let i = 1;
|
||||||
let i = 1;
|
if (t0.kind === SyntaxKind.BoltPubKeyword) {
|
||||||
let kw: Token = t0;
|
t0 = tokens.peek(i++);
|
||||||
if (t0.text === 'pub') {
|
if (t0.kind !== SyntaxKind.BoltForeignKeyword) {
|
||||||
i++;
|
if (KIND_DECLARATION_KEYWORD.indexOf(t0.kind) === -1) {
|
||||||
kw = tokens.peek(i);
|
throw new ParseError(t0, KIND_DECLARATION_KEYWORD);
|
||||||
if (kw.kind !== SyntaxKind.BoltIdentifier) {
|
|
||||||
throw new ParseError(kw, [SyntaxKind.BoltForeignKeyword, SyntaxKind.BoltModKeyword,
|
|
||||||
SyntaxKind.BoltLetKeyword, SyntaxKind.BoltFnKeyword, SyntaxKind.BoltEnumKeyword, SyntaxKind.BoltStructKeyword])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (t0.text === 'foreign') {
|
}
|
||||||
i += 2;
|
if (t0.kind === SyntaxKind.BoltForeignKeyword) {
|
||||||
kw = tokens.peek(i);
|
i += 2;
|
||||||
if (kw.kind !== SyntaxKind.BoltIdentifier) {
|
t0 = tokens.peek(i);
|
||||||
throw new ParseError(kw, [SyntaxKind.BoltModKeyword, SyntaxKind.BoltLetKeyword,
|
if (KIND_DECLARATION_KEYWORD.indexOf(t0.kind) === -1) {
|
||||||
SyntaxKind.BoltFnKeyword, SyntaxKind.BoltEnumKeyword, SyntaxKind.BoltStructKeyword])
|
throw new ParseError(t0, KIND_DECLARATION_KEYWORD);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
switch (t0.kind) {
|
||||||
|
case SyntaxKind.BoltNewTypeKeyword:
|
||||||
|
return this.parseNewTypeDeclaration(tokens);
|
||||||
|
case SyntaxKind.BoltModKeyword:
|
||||||
|
return this.parseModuleDeclaration(tokens);
|
||||||
|
case SyntaxKind.BoltFnKeyword:
|
||||||
|
return this.parseFunctionDeclaration(tokens);
|
||||||
|
case SyntaxKind.BoltLetKeyword:
|
||||||
|
return this.parseVariableDeclaration(tokens);
|
||||||
|
case SyntaxKind.BoltStructKeyword:
|
||||||
|
return this.parseRecordDeclaration(tokens);
|
||||||
|
case SyntaxKind.BoltStructKeyword:
|
||||||
|
return this.parseVariableDeclaration(tokens);
|
||||||
|
default:
|
||||||
|
throw new ParseError(t0, KIND_DECLARATION_T0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public parseSourceElement(tokens: BoltTokenStream): BoltSourceElement {
|
||||||
|
const t0 = tokens.peek();
|
||||||
|
try {
|
||||||
|
return this.parseDeclaration(tokens)
|
||||||
|
} catch (e) {
|
||||||
|
if (!(e instanceof ParseError)) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return this.parseStatement(tokens);
|
||||||
|
} catch (e) {
|
||||||
|
if (!(e instanceof ParseError)) {
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
|
throw new ParseError(t0, KIND_SOURCEELEMENT_T0)
|
||||||
}
|
}
|
||||||
switch (kw.text) {
|
|
||||||
case 'newtype':
|
|
||||||
return this.parseNewType(tokens);
|
|
||||||
case 'syntax':
|
|
||||||
return this.parseSyntax(tokens);
|
|
||||||
case 'mod':
|
|
||||||
return this.parseModDecl(tokens);
|
|
||||||
case 'fn':
|
|
||||||
return this.parseFuncDecl(tokens, null);
|
|
||||||
case 'let':
|
|
||||||
return this.parseVarDecl(tokens);
|
|
||||||
case 'struct':
|
|
||||||
return this.parseRecordDecl(tokens);
|
|
||||||
case 'enum':
|
|
||||||
return this.parseVariantDecl(tokens);
|
|
||||||
default:
|
|
||||||
try {
|
|
||||||
return this.parseExpression(tokens)
|
|
||||||
} catch (e) {
|
|
||||||
if (e instanceof ParseError) {
|
|
||||||
throw new ParseError(kw, [...e.expected, SyntaxKind.BoltModKeyword, SyntaxKind.BoltLetKeyword,
|
|
||||||
SyntaxKind.BoltFnKeyword, SyntaxKind.BoltEnumKeyword, SyntaxKind.BoltStructKeyword])
|
|
||||||
} else {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return this.parseStatement(tokens)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getOperatorDesc(seekArity: number, seekName: string): OperatorInfo {
|
protected getOperatorDesc(seekArity: number, seekName: string): OperatorInfo {
|
||||||
for (let i = 0; i < this.operatorTable.length; ++i) {
|
for (let i = 0; i < this.operatorTable.length; ++i) {
|
||||||
for (const [kind, arity, name] of this.operatorTable[i]) {
|
for (const [kind, arity, name] of this.operatorTable[i]) {
|
||||||
if (arity == seekArity && name === seekName) {
|
if (arity == seekArity && name === seekName) {
|
||||||
|
@ -804,17 +851,15 @@ export class Parser {
|
||||||
// return lhs
|
// return lhs
|
||||||
//}
|
//}
|
||||||
|
|
||||||
parseCallExpr(tokens: TokenStream): CallExpr {
|
public parseCallExpression(tokens: BoltTokenStream): BoltCallExpression {
|
||||||
|
|
||||||
const operator = this.parsePrimitiveExpression(tokens)
|
const operator = this.parsePrimitiveExpression(tokens)
|
||||||
const args: Expr[] = []
|
const args: BoltExpression[] = []
|
||||||
|
|
||||||
const t2 = tokens.get();
|
const t2 = tokens.get();
|
||||||
if (t2.kind !== SyntaxKind.BoltParenthesized) {
|
assertToken(t2, SyntaxKind.BoltParenthesized);
|
||||||
throw new ParseError(t2, [SyntaxKind.BoltParenthesized])
|
|
||||||
}
|
|
||||||
|
|
||||||
const innerTokens = t2.toTokenStream();
|
const innerTokens = createTokenStream(t2);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const t3 = innerTokens.peek();
|
const t3 = innerTokens.peek();
|
||||||
|
|
Loading…
Reference in a new issue