Fix some type-checking errors
This commit is contained in:
parent
f8918bfa79
commit
12c9317ea0
3 changed files with 41 additions and 11 deletions
|
@ -240,6 +240,7 @@ node BoltRecordDeclarationField {
|
||||||
node BoltSourceElement;
|
node BoltSourceElement;
|
||||||
|
|
||||||
node BoltRecordDeclaration > BoltDeclaration {
|
node BoltRecordDeclaration > BoltDeclaration {
|
||||||
|
modifiers: BoltDeclarationModifiers,
|
||||||
name: BoltQualName,
|
name: BoltQualName,
|
||||||
fields: Vec<BoltRecordDeclarationField>,
|
fields: Vec<BoltRecordDeclarationField>,
|
||||||
}
|
}
|
||||||
|
|
3
src/ast.d.ts
vendored
3
src/ast.d.ts
vendored
|
@ -540,6 +540,7 @@ export type BoltSourceElement
|
||||||
|
|
||||||
export interface BoltRecordDeclaration extends SyntaxBase {
|
export interface BoltRecordDeclaration extends SyntaxBase {
|
||||||
kind: SyntaxKind.BoltRecordDeclaration;
|
kind: SyntaxKind.BoltRecordDeclaration;
|
||||||
|
modifiers: BoltDeclarationModifiers;
|
||||||
name: BoltQualName;
|
name: BoltQualName;
|
||||||
fields: BoltRecordDeclarationField[];
|
fields: BoltRecordDeclarationField[];
|
||||||
}
|
}
|
||||||
|
@ -946,7 +947,7 @@ export function createBoltVariableDeclaration(modifiers: BoltDeclarationModifier
|
||||||
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;
|
||||||
export function createBoltRecordDeclarationField(name: BoltIdentifier, type: BoltTypeNode, span?: TextSpan | null): BoltRecordDeclarationField;
|
export function createBoltRecordDeclarationField(name: BoltIdentifier, type: BoltTypeNode, span?: TextSpan | null): BoltRecordDeclarationField;
|
||||||
export function createBoltRecordDeclaration(name: BoltQualName, fields: BoltRecordDeclarationField[], span?: TextSpan | null): BoltRecordDeclaration;
|
export function createBoltRecordDeclaration(modifiers: BoltDeclarationModifiers, name: BoltQualName, fields: BoltRecordDeclarationField[], span?: TextSpan | null): BoltRecordDeclaration;
|
||||||
export function createJSOperator(text: string, span?: TextSpan | null): JSOperator;
|
export function createJSOperator(text: string, span?: TextSpan | null): JSOperator;
|
||||||
export function createJSIdentifier(text: string, span?: TextSpan | null): JSIdentifier;
|
export function createJSIdentifier(text: string, span?: TextSpan | null): JSIdentifier;
|
||||||
export function createJSBindPattern(name: JSIdentifier, span?: TextSpan | null): JSBindPattern;
|
export function createJSBindPattern(name: JSIdentifier, span?: TextSpan | null): JSBindPattern;
|
||||||
|
|
|
@ -10,6 +10,7 @@ import {
|
||||||
BoltRecordDeclaration,
|
BoltRecordDeclaration,
|
||||||
BoltStatement,
|
BoltStatement,
|
||||||
BoltDeclaration,
|
BoltDeclaration,
|
||||||
|
BoltParameter,
|
||||||
BoltSourceElement,
|
BoltSourceElement,
|
||||||
createBoltQualName,
|
createBoltQualName,
|
||||||
BoltQualName,
|
BoltQualName,
|
||||||
|
@ -31,6 +32,19 @@ import {
|
||||||
BoltCallExpression,
|
BoltCallExpression,
|
||||||
BoltExpressionStatement,
|
BoltExpressionStatement,
|
||||||
createBoltExpressionStatement,
|
createBoltExpressionStatement,
|
||||||
|
BoltVariableDeclaration,
|
||||||
|
BoltSyntax,
|
||||||
|
createBoltVariableDeclaration,
|
||||||
|
BoltReturnStatement,
|
||||||
|
createBoltReturnStatement,
|
||||||
|
BoltRecordDeclarationField,
|
||||||
|
BoltModule,
|
||||||
|
createBoltModule,
|
||||||
|
BoltNewTypeDeclaration,
|
||||||
|
createBoltNewTypeDeclaration,
|
||||||
|
BoltFunctionDeclaration,
|
||||||
|
createBoltFunctionDeclaration,
|
||||||
|
createBoltCallExpression,
|
||||||
} from "./ast"
|
} from "./ast"
|
||||||
|
|
||||||
import { BoltTokenStream, setOrigNodeRange } from "./util"
|
import { BoltTokenStream, setOrigNodeRange } from "./util"
|
||||||
|
@ -226,7 +240,7 @@ export class Parser {
|
||||||
public parseBindPattern(tokens: BoltTokenStream): BoltBindPattern {
|
public parseBindPattern(tokens: BoltTokenStream): BoltBindPattern {
|
||||||
const t0 = tokens.get();
|
const t0 = tokens.get();
|
||||||
assertToken(t0, SyntaxKind.BoltIdentifier);
|
assertToken(t0, SyntaxKind.BoltIdentifier);
|
||||||
const node = createBoltBindPattern((t0 as BoltIdentifier).text);
|
const node = createBoltBindPattern(t0 as BoltIdentifier);
|
||||||
setOrigNodeRange(node, t0, t0);
|
setOrigNodeRange(node, t0, t0);
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
@ -442,6 +456,11 @@ export class Parser {
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected isUnaryOperator(name: string) {
|
||||||
|
// TODO
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
protected lookaheadHasExpression(tokens: BoltTokenStream, i = 1): boolean {
|
protected lookaheadHasExpression(tokens: BoltTokenStream, i = 1): boolean {
|
||||||
const t0 = tokens.peek(i);
|
const t0 = tokens.peek(i);
|
||||||
if (t0.kind === SyntaxKind.BoltParenthesized) {
|
if (t0.kind === SyntaxKind.BoltParenthesized) {
|
||||||
|
@ -493,8 +512,9 @@ export class Parser {
|
||||||
throw new ParseError(t0, [SyntaxKind.BoltStructKeyword])
|
throw new ParseError(t0, [SyntaxKind.BoltStructKeyword])
|
||||||
}
|
}
|
||||||
|
|
||||||
const name = tokens.get();
|
const t1 = tokens.get();
|
||||||
assertToken(name, SyntaxKind.BoltIdentifier);
|
assertToken(t1, SyntaxKind.BoltIdentifier);
|
||||||
|
const name = createBoltQualName([], t1 as BoltIdentifier);
|
||||||
|
|
||||||
const t2 = tokens.get();
|
const t2 = tokens.get();
|
||||||
|
|
||||||
|
@ -507,7 +527,7 @@ export class Parser {
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const t3 = innerTokens.get();
|
const t3 = innerTokens.get();
|
||||||
if (t3.kind === SyntaxKind.EOS) {
|
if (t3.kind === SyntaxKind.BoltEOS) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
const name = innerTokens.get();
|
const name = innerTokens.get();
|
||||||
|
@ -520,7 +540,7 @@ export class Parser {
|
||||||
fields.push(field);
|
fields.push(field);
|
||||||
}
|
}
|
||||||
|
|
||||||
const node = new RecordDecl(modifiers, name, fields);
|
const node = createBoltRecordDeclaration(modifiers, name, fields);
|
||||||
setOrigNodeRange(node, firstToken, t2);
|
setOrigNodeRange(node, firstToken, t2);
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
@ -568,11 +588,12 @@ export class Parser {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public parseNewTypeDeclaration(tokens: BoltTokenSteam): BoltNewTypeDeclaration {
|
public parseNewTypeDeclaration(tokens: BoltTokenStream): BoltNewTypeDeclaration {
|
||||||
|
|
||||||
let modifiers = 0;
|
let modifiers = 0;
|
||||||
|
|
||||||
let t0 = tokens.get();
|
let t0 = tokens.get();
|
||||||
|
const firstToken = t0;
|
||||||
|
|
||||||
if (t0.kind === SyntaxKind.BoltPubKeyword) {
|
if (t0.kind === SyntaxKind.BoltPubKeyword) {
|
||||||
tokens.get();
|
tokens.get();
|
||||||
|
@ -597,13 +618,13 @@ export class Parser {
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
private parseFunctionDeclaration(tokens: BoltTokenStream): BoltFunctionDeclaration | BoltForeignFunctionDeclaration {
|
private parseFunctionDeclaration(tokens: BoltTokenStream): BoltFunctionDeclaration {
|
||||||
|
|
||||||
let target = "Bolt";
|
let target = "Bolt";
|
||||||
let modifiers = 0;
|
let modifiers = 0;
|
||||||
|
|
||||||
let k0 = tokens.peek();
|
let k0 = tokens.peek();
|
||||||
let lastNode: BoltSyntax;
|
let lastToken: BoltSyntax;
|
||||||
const firstToken = k0;
|
const firstToken = k0;
|
||||||
|
|
||||||
if (k0.kind !== SyntaxKind.BoltPubKeyword) {
|
if (k0.kind !== SyntaxKind.BoltPubKeyword) {
|
||||||
|
@ -717,10 +738,15 @@ export class Parser {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (params.length > 0) {
|
||||||
|
lastToken = params[params.length-1];
|
||||||
|
}
|
||||||
|
|
||||||
// Parse return type
|
// Parse return type
|
||||||
|
|
||||||
const t2 = tokens.peek();
|
const t2 = tokens.peek();
|
||||||
if (t2.kind === SyntaxKind.BoltRArrow) {
|
if (t2.kind === SyntaxKind.BoltRArrow) {
|
||||||
|
lastToken = t2;
|
||||||
tokens.get();
|
tokens.get();
|
||||||
returnType = this.parseTypeNode(tokens);
|
returnType = this.parseTypeNode(tokens);
|
||||||
}
|
}
|
||||||
|
@ -729,6 +755,7 @@ export class Parser {
|
||||||
|
|
||||||
const t3 = tokens.peek();
|
const t3 = tokens.peek();
|
||||||
if (t3.kind === SyntaxKind.BoltBraced) {
|
if (t3.kind === SyntaxKind.BoltBraced) {
|
||||||
|
lastToken = t3;
|
||||||
tokens.get();
|
tokens.get();
|
||||||
switch (target) {
|
switch (target) {
|
||||||
case "Bolt":
|
case "Bolt":
|
||||||
|
@ -745,12 +772,13 @@ export class Parser {
|
||||||
|
|
||||||
const node = createBoltFunctionDeclaration(
|
const node = createBoltFunctionDeclaration(
|
||||||
modifiers,
|
modifiers,
|
||||||
|
target,
|
||||||
name,
|
name,
|
||||||
params,
|
params,
|
||||||
returnType,
|
returnType,
|
||||||
body
|
body
|
||||||
);
|
);
|
||||||
setOrigNodeRange(node, firstToken, lastNode);
|
setOrigNodeRange(node, firstToken, lastToken!);
|
||||||
return node;
|
return node;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -875,7 +903,7 @@ export class Parser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new CallExpr(operator, args, null)
|
return createBoltCallExpression(operator, args, null)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue