Fix some errors while parsing and checking stdlib
This commit is contained in:
parent
d0aed2405f
commit
ec746b655d
7 changed files with 80 additions and 35 deletions
20
package-lock.json
generated
20
package-lock.json
generated
|
@ -15,6 +15,11 @@
|
||||||
"resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz",
|
||||||
"integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ=="
|
"integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ=="
|
||||||
},
|
},
|
||||||
|
"@types/events": {
|
||||||
|
"version": "3.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/events/-/events-3.0.0.tgz",
|
||||||
|
"integrity": "sha512-EaObqwIvayI5a8dCzhFrjKzVwKLxjoG9T6Ppd5CEo07LRKfQ8Yokw54r5+Wq7FaBQ+yXRvQAYPrHwya1/UFt9g=="
|
||||||
|
},
|
||||||
"@types/fs-extra": {
|
"@types/fs-extra": {
|
||||||
"version": "9.0.1",
|
"version": "9.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-9.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-9.0.1.tgz",
|
||||||
|
@ -23,11 +28,26 @@
|
||||||
"@types/node": "*"
|
"@types/node": "*"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"@types/glob": {
|
||||||
|
"version": "7.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/glob/-/glob-7.1.1.tgz",
|
||||||
|
"integrity": "sha512-1Bh06cbWJUHMC97acuD6UMG29nMt0Aqz1vF3guLfG+kHHJhy3AyohZFFxYk2f7Q1SQIrNwvncxAE0N/9s70F2w==",
|
||||||
|
"requires": {
|
||||||
|
"@types/events": "*",
|
||||||
|
"@types/minimatch": "*",
|
||||||
|
"@types/node": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"@types/microtime": {
|
"@types/microtime": {
|
||||||
"version": "2.1.0",
|
"version": "2.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/@types/microtime/-/microtime-2.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/@types/microtime/-/microtime-2.1.0.tgz",
|
||||||
"integrity": "sha1-rb2Z9QGoXIhpXrHv01FYEPJWOTI="
|
"integrity": "sha1-rb2Z9QGoXIhpXrHv01FYEPJWOTI="
|
||||||
},
|
},
|
||||||
|
"@types/minimatch": {
|
||||||
|
"version": "3.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.3.tgz",
|
||||||
|
"integrity": "sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA=="
|
||||||
|
},
|
||||||
"@types/minimist": {
|
"@types/minimist": {
|
||||||
"version": "1.2.0",
|
"version": "1.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/@types/minimist/-/minimist-1.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/@types/minimist/-/minimist-1.2.0.tgz",
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
"repository": "https://github.com/samvv/Bolt",
|
"repository": "https://github.com/samvv/Bolt",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/fs-extra": "^9.0.1",
|
"@types/fs-extra": "^9.0.1",
|
||||||
|
"@types/glob": "^7.1.1",
|
||||||
"@types/microtime": "^2.1.0",
|
"@types/microtime": "^2.1.0",
|
||||||
"@types/minimist": "^1.2.0",
|
"@types/minimist": "^1.2.0",
|
||||||
"@types/node": "^14.0.5",
|
"@types/node": "^14.0.5",
|
||||||
|
|
|
@ -56,6 +56,7 @@ node BoltVBar > BoltToken, BoltOperatorLike;
|
||||||
|
|
||||||
node BoltKeyword;
|
node BoltKeyword;
|
||||||
|
|
||||||
|
node BoltWhereKeyword > BoltToken, BoltKeyword;
|
||||||
node BoltQuoteKeyword > BoltToken, BoltKeyword;
|
node BoltQuoteKeyword > BoltToken, BoltKeyword;
|
||||||
node BoltFnKeyword > BoltToken, BoltKeyword;
|
node BoltFnKeyword > BoltToken, BoltKeyword;
|
||||||
node BoltForeignKeyword > BoltToken, BoltKeyword;
|
node BoltForeignKeyword > BoltToken, BoltKeyword;
|
||||||
|
@ -257,6 +258,7 @@ node BoltFunctionDeclaration > BoltFunctionBodyElement, BoltDeclaration {
|
||||||
name: BoltSymbol,
|
name: BoltSymbol,
|
||||||
params: Vec<BoltParameter>,
|
params: Vec<BoltParameter>,
|
||||||
returnType: Option<BoltTypeExpression>,
|
returnType: Option<BoltTypeExpression>,
|
||||||
|
typeParams: Option<Vec<BoltTypeParameter>>,
|
||||||
body: Vec<BoltFunctionBodyElement>,
|
body: Vec<BoltFunctionBodyElement>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
3
src/ast.d.ts
vendored
3
src/ast.d.ts
vendored
|
@ -784,6 +784,7 @@ export interface BoltFunctionDeclaration extends SyntaxBase<SyntaxKind.BoltFunct
|
||||||
name: BoltSymbol;
|
name: BoltSymbol;
|
||||||
params: BoltParameter[];
|
params: BoltParameter[];
|
||||||
returnType: BoltTypeExpression | null;
|
returnType: BoltTypeExpression | null;
|
||||||
|
typeParams: BoltTypeParameter[] | null;
|
||||||
body: BoltFunctionBodyElement[];
|
body: BoltFunctionBodyElement[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1659,7 +1660,7 @@ export function createBoltResumeStatement(value: BoltExpression, span?: TextSpan
|
||||||
export function createBoltExpressionStatement(expression: BoltExpression, span?: TextSpan | null): BoltExpressionStatement;
|
export function createBoltExpressionStatement(expression: BoltExpression, span?: TextSpan | null): BoltExpressionStatement;
|
||||||
export function createBoltParameter(index: number, bindings: BoltPattern, type: BoltTypeExpression | null, defaultValue: BoltExpression | null, span?: TextSpan | null): BoltParameter;
|
export function createBoltParameter(index: number, bindings: BoltPattern, type: BoltTypeExpression | null, defaultValue: BoltExpression | null, span?: TextSpan | null): BoltParameter;
|
||||||
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, target: string, name: BoltSymbol, params: BoltParameter[], returnType: BoltTypeExpression | null, body: BoltFunctionBodyElement[], span?: TextSpan | null): BoltFunctionDeclaration;
|
export function createBoltFunctionDeclaration(modifiers: BoltDeclarationModifiers, target: string, name: BoltSymbol, params: BoltParameter[], returnType: BoltTypeExpression | null, typeParams: BoltTypeParameter[] | null, body: BoltFunctionBodyElement[], span?: TextSpan | null): BoltFunctionDeclaration;
|
||||||
export function createBoltVariableDeclaration(modifiers: BoltDeclarationModifiers, bindings: BoltPattern, type: BoltTypeExpression | null, value: BoltExpression | null, span?: TextSpan | null): BoltVariableDeclaration;
|
export function createBoltVariableDeclaration(modifiers: BoltDeclarationModifiers, bindings: BoltPattern, type: BoltTypeExpression | 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;
|
||||||
|
|
|
@ -223,6 +223,24 @@ export class TypeChecker {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case SyntaxKind.BoltTypeAliasDeclaration:
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case SyntaxKind.BoltTraitDeclaration:
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case SyntaxKind.BoltImplDeclaration:
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case SyntaxKind.BoltFunctionDeclaration:
|
case SyntaxKind.BoltFunctionDeclaration:
|
||||||
{
|
{
|
||||||
let fnReturnType: Type = createAnyType();
|
let fnReturnType: Type = createAnyType();
|
||||||
|
|
|
@ -783,40 +783,33 @@ export class Parser {
|
||||||
|
|
||||||
public parseGenericTypeParameter(tokens: BoltTokenStream): BoltTypeParameter {
|
public parseGenericTypeParameter(tokens: BoltTokenStream): BoltTypeParameter {
|
||||||
const t0 = tokens.peek();
|
const t0 = tokens.peek();
|
||||||
if (t0.kind === SyntaxKind.BoltIdentifier) {
|
|
||||||
tokens.get();
|
tokens.get();
|
||||||
const node = createBoltTypeParameter(0, t0, null)
|
assertToken(t0, SyntaxKind.BoltIdentifier);
|
||||||
|
let typeBound = null;
|
||||||
|
const t1 = tokens.peek();
|
||||||
|
if (t1.kind === SyntaxKind.BoltColon) {
|
||||||
|
tokens.get();
|
||||||
|
typeBound = this.parseTypeExpression(tokens);
|
||||||
|
}
|
||||||
|
const node = createBoltTypeParameter(0, t0 as BoltIdentifier, typeBound)
|
||||||
setOrigNodeRange(node, t0, t0);
|
setOrigNodeRange(node, t0, t0);
|
||||||
return node;
|
return node;
|
||||||
} else {
|
|
||||||
throw new ParseError(t0, [SyntaxKind.BoltIdentifier]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private parseGenericTypeParameters(tokens: BoltTokenStream): BoltTypeParameter[] {
|
private parseGenericTypeParameters(tokens: BoltTokenStream): BoltTypeParameter[] {
|
||||||
let typeParams: BoltTypeParameter[] = [];
|
let typeParams: BoltTypeParameter[] = [];
|
||||||
const t0 = tokens.get();
|
|
||||||
assertToken(t0, SyntaxKind.BoltLtSign);
|
|
||||||
while (true) {
|
while (true) {
|
||||||
let t1 = tokens.peek();
|
let t1 = tokens.peek();
|
||||||
if (t1.kind === SyntaxKind.BoltGtSign) {
|
if (t1.kind !== SyntaxKind.BoltIdentifier) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (t1.kind === SyntaxKind.EndOfFile) {
|
|
||||||
throw new ParseError(t1, [SyntaxKind.BoltGtSign, SyntaxKind.BoltIdentifier, SyntaxKind.BoltComma]);
|
|
||||||
}
|
|
||||||
if (typeParams.length > 0) {
|
|
||||||
tokens.get();
|
|
||||||
assertToken(t1, SyntaxKind.BoltComma);
|
|
||||||
t1 = tokens.peek();
|
|
||||||
}
|
|
||||||
if (t1.kind === SyntaxKind.EndOfFile) {
|
|
||||||
throw new ParseError(t1, [SyntaxKind.BoltGtSign, SyntaxKind.BoltIdentifier]);
|
|
||||||
}
|
|
||||||
typeParams.push(this.parseGenericTypeParameter(tokens));
|
typeParams.push(this.parseGenericTypeParameter(tokens));
|
||||||
|
const t2 = tokens.peek();
|
||||||
|
if (t2.kind !== SyntaxKind.BoltComma) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
tokens.get();
|
||||||
}
|
}
|
||||||
const t3 = tokens.get();
|
|
||||||
assertToken(t3, SyntaxKind.BoltGtSign);
|
|
||||||
return typeParams;
|
return typeParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -849,7 +842,10 @@ export class Parser {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t2.kind === SyntaxKind.BoltLtSign) {
|
if (t2.kind === SyntaxKind.BoltLtSign) {
|
||||||
|
tokens.get();
|
||||||
typeParams = this.parseGenericTypeParameters(tokens);
|
typeParams = this.parseGenericTypeParameters(tokens);
|
||||||
|
const t3 = tokens.get();
|
||||||
|
assertToken(t3, SyntaxKind.BoltGtSign);
|
||||||
t2 = tokens.peek();
|
t2 = tokens.peek();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -963,7 +959,10 @@ export class Parser {
|
||||||
|
|
||||||
const t2 = tokens.peek();
|
const t2 = tokens.peek();
|
||||||
if (t2.kind === SyntaxKind.BoltLtSign) {
|
if (t2.kind === SyntaxKind.BoltLtSign) {
|
||||||
|
tokens.get();
|
||||||
typeParams = this.parseGenericTypeParameters(tokens);
|
typeParams = this.parseGenericTypeParameters(tokens);
|
||||||
|
const t3 = tokens.get();
|
||||||
|
assertToken(t3, SyntaxKind.BoltGtSign);
|
||||||
}
|
}
|
||||||
|
|
||||||
const t3 = tokens.get();
|
const t3 = tokens.get();
|
||||||
|
@ -982,7 +981,6 @@ export class Parser {
|
||||||
let modifiers = 0;
|
let modifiers = 0;
|
||||||
|
|
||||||
let k0 = tokens.peek();
|
let k0 = tokens.peek();
|
||||||
let lastToken: BoltSyntax;
|
|
||||||
const firstToken = k0;
|
const firstToken = k0;
|
||||||
|
|
||||||
if (k0.kind === SyntaxKind.BoltPubKeyword) {
|
if (k0.kind === SyntaxKind.BoltPubKeyword) {
|
||||||
|
@ -1012,6 +1010,7 @@ export class Parser {
|
||||||
let returnType = null;
|
let returnType = null;
|
||||||
let body: any = null; // FIXME type-checking should not be disabled
|
let body: any = null; // FIXME type-checking should not be disabled
|
||||||
let params: BoltParameter[] = [];
|
let params: BoltParameter[] = [];
|
||||||
|
let typeParams = null;
|
||||||
|
|
||||||
// Parse parameters
|
// Parse parameters
|
||||||
|
|
||||||
|
@ -1095,24 +1094,26 @@ 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.parseTypeExpression(tokens);
|
returnType = this.parseTypeExpression(tokens);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parse second possible version of generic type parameters
|
||||||
|
|
||||||
|
const t4 = tokens.peek();
|
||||||
|
if (t4.kind === SyntaxKind.BoltWhereKeyword) {
|
||||||
|
tokens.get();
|
||||||
|
typeParams = this.parseGenericTypeParameters(tokens);
|
||||||
|
}
|
||||||
|
|
||||||
// Parse function body
|
// Parse function body
|
||||||
|
|
||||||
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":
|
||||||
|
@ -1136,9 +1137,10 @@ export class Parser {
|
||||||
name,
|
name,
|
||||||
params,
|
params,
|
||||||
returnType,
|
returnType,
|
||||||
|
typeParams,
|
||||||
body
|
body
|
||||||
);
|
);
|
||||||
setOrigNodeRange(result, firstToken, lastToken!);
|
setOrigNodeRange(result, firstToken, t3);
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1160,7 +1162,9 @@ export class Parser {
|
||||||
let elements = null;
|
let elements = null;
|
||||||
if (t2.kind === SyntaxKind.BoltLtSign || t2.kind === SyntaxKind.BoltBraced) {
|
if (t2.kind === SyntaxKind.BoltLtSign || t2.kind === SyntaxKind.BoltBraced) {
|
||||||
if (t2.kind === SyntaxKind.BoltLtSign) {
|
if (t2.kind === SyntaxKind.BoltLtSign) {
|
||||||
|
tokens.get();
|
||||||
typeParams = this.parseGenericTypeParameters(tokens);
|
typeParams = this.parseGenericTypeParameters(tokens);
|
||||||
|
tokens.get();
|
||||||
}
|
}
|
||||||
const t3 = tokens.get();
|
const t3 = tokens.get();
|
||||||
assertToken(t3, SyntaxKind.BoltBraced);
|
assertToken(t3, SyntaxKind.BoltBraced);
|
||||||
|
|
|
@ -27,10 +27,9 @@ fn (a: N) * (b: N) -> N where N: Num {
|
||||||
// precedence a + b < a * b;
|
// precedence a + b < a * b;
|
||||||
|
|
||||||
pub fn fac(n: I) -> I where I: int {
|
pub fn fac(n: I) -> I where I: int {
|
||||||
if n == 0 {
|
match n {
|
||||||
return 1
|
0 => 1,
|
||||||
} else {
|
i => i * fac(i-1),
|
||||||
return fac(n-1)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue