Fix issue in launch.json
This commit is contained in:
parent
5fc5a95ed4
commit
f765ba6115
11 changed files with 146 additions and 127 deletions
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
|
@ -11,7 +11,7 @@
|
||||||
"outputCapture": "std",
|
"outputCapture": "std",
|
||||||
"skipFiles": [
|
"skipFiles": [
|
||||||
"${workspaceFolder}/node_modules/**/*.js",
|
"${workspaceFolder}/node_modules/**/*.js",
|
||||||
"${workspaceFolder}/lib/***/*.js",
|
"${workspaceFolder}/lib/**/*.js",
|
||||||
"<node_internals>/**"
|
"<node_internals>/**"
|
||||||
],
|
],
|
||||||
"program": "${workspaceFolder}/lib/bin/bolt.js",
|
"program": "${workspaceFolder}/lib/bin/bolt.js",
|
||||||
|
|
|
@ -103,7 +103,8 @@ node BoltModulePath {
|
||||||
node BoltTypeExpression;
|
node BoltTypeExpression;
|
||||||
|
|
||||||
node BoltReferenceTypeExpression > BoltTypeExpression {
|
node BoltReferenceTypeExpression > BoltTypeExpression {
|
||||||
path: BoltModulePath,
|
modulePath: Option<BoltModulePath>,
|
||||||
|
name: BoltIdentifier,
|
||||||
arguments: Option<Vec<BoltTypeExpression>>,
|
arguments: Option<Vec<BoltTypeExpression>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +116,7 @@ node BoltFunctionTypeExpression > BoltTypeExpression {
|
||||||
node BoltTypeParameter {
|
node BoltTypeParameter {
|
||||||
index: usize,
|
index: usize,
|
||||||
name: BoltIdentifier,
|
name: BoltIdentifier,
|
||||||
typeNode: BoltTypeExpression,
|
typeNode: Option<BoltTypeExpression>,
|
||||||
defaultType: Option<BoltTypeExpression>,
|
defaultType: Option<BoltTypeExpression>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
9
src/ast.d.ts
vendored
9
src/ast.d.ts
vendored
|
@ -2393,7 +2393,8 @@ export type BoltTypeExpression
|
||||||
|
|
||||||
export interface BoltReferenceTypeExpression extends SyntaxBase {
|
export interface BoltReferenceTypeExpression extends SyntaxBase {
|
||||||
kind: SyntaxKind.BoltReferenceTypeExpression;
|
kind: SyntaxKind.BoltReferenceTypeExpression;
|
||||||
path: BoltModulePath;
|
modulePath: BoltModulePath | null;
|
||||||
|
name: BoltIdentifier;
|
||||||
arguments: BoltTypeExpression[] | null;
|
arguments: BoltTypeExpression[] | null;
|
||||||
parentNode: BoltReferenceTypeExpressionParent;
|
parentNode: BoltReferenceTypeExpressionParent;
|
||||||
getChildNodes(): IterableIterator<BoltReferenceTypeExpressionChild>
|
getChildNodes(): IterableIterator<BoltReferenceTypeExpressionChild>
|
||||||
|
@ -2513,7 +2514,7 @@ export interface BoltTypeParameter extends SyntaxBase {
|
||||||
kind: SyntaxKind.BoltTypeParameter;
|
kind: SyntaxKind.BoltTypeParameter;
|
||||||
index: number;
|
index: number;
|
||||||
name: BoltIdentifier;
|
name: BoltIdentifier;
|
||||||
typeNode: BoltTypeExpression;
|
typeNode: BoltTypeExpression | null;
|
||||||
defaultType: BoltTypeExpression | null;
|
defaultType: BoltTypeExpression | null;
|
||||||
parentNode: BoltTypeParameterParent;
|
parentNode: BoltTypeParameterParent;
|
||||||
getChildNodes(): IterableIterator<BoltTypeParameterChild>
|
getChildNodes(): IterableIterator<BoltTypeParameterChild>
|
||||||
|
@ -6952,9 +6953,9 @@ export function createBoltBracketed(text: string, span?: TextSpan | null): BoltB
|
||||||
export function createBoltSourceFile(elements: BoltSourceElement[], package: Package, span?: TextSpan | null): BoltSourceFile;
|
export function createBoltSourceFile(elements: BoltSourceElement[], package: Package, span?: TextSpan | null): BoltSourceFile;
|
||||||
export function createBoltQualName(modulePath: BoltModulePath | null, name: BoltSymbol, span?: TextSpan | null): BoltQualName;
|
export function createBoltQualName(modulePath: BoltModulePath | null, name: BoltSymbol, span?: TextSpan | null): BoltQualName;
|
||||||
export function createBoltModulePath(isAbsolute: boolean, elements: BoltIdentifier[], span?: TextSpan | null): BoltModulePath;
|
export function createBoltModulePath(isAbsolute: boolean, elements: BoltIdentifier[], span?: TextSpan | null): BoltModulePath;
|
||||||
export function createBoltReferenceTypeExpression(path: BoltModulePath, arguments: BoltTypeExpression[] | null, span?: TextSpan | null): BoltReferenceTypeExpression;
|
export function createBoltReferenceTypeExpression(modulePath: BoltModulePath | null, name: BoltIdentifier, arguments: BoltTypeExpression[] | null, span?: TextSpan | null): BoltReferenceTypeExpression;
|
||||||
export function createBoltFunctionTypeExpression(params: BoltParameter[], returnType: BoltTypeExpression | null, span?: TextSpan | null): BoltFunctionTypeExpression;
|
export function createBoltFunctionTypeExpression(params: BoltParameter[], returnType: BoltTypeExpression | null, span?: TextSpan | null): BoltFunctionTypeExpression;
|
||||||
export function createBoltTypeParameter(index: number, name: BoltIdentifier, typeNode: BoltTypeExpression, defaultType: BoltTypeExpression | null, span?: TextSpan | null): BoltTypeParameter;
|
export function createBoltTypeParameter(index: number, name: BoltIdentifier, typeNode: BoltTypeExpression | null, defaultType: BoltTypeExpression | null, span?: TextSpan | null): BoltTypeParameter;
|
||||||
export function createBoltBindPattern(name: BoltIdentifier, span?: TextSpan | null): BoltBindPattern;
|
export function createBoltBindPattern(name: BoltIdentifier, span?: TextSpan | null): BoltBindPattern;
|
||||||
export function createBoltTypePattern(type: BoltTypeExpression, nestedPattern: BoltPattern, span?: TextSpan | null): BoltTypePattern;
|
export function createBoltTypePattern(type: BoltTypeExpression, nestedPattern: BoltPattern, span?: TextSpan | null): BoltTypePattern;
|
||||||
export function createBoltExpressionPattern(expression: BoltExpression, span?: TextSpan | null): BoltExpressionPattern;
|
export function createBoltExpressionPattern(expression: BoltExpression, span?: TextSpan | null): BoltExpressionPattern;
|
||||||
|
|
|
@ -56,7 +56,7 @@ export class Package {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getLanguage(node: Syntax): string {
|
export function getNodeLanguage(node: Syntax): string {
|
||||||
const kindStr = kindToString(node.kind);
|
const kindStr = kindToString(node.kind);
|
||||||
for (const prefix of BOLT_SUPPORTED_LANGUAGES) {
|
for (const prefix of BOLT_SUPPORTED_LANGUAGES) {
|
||||||
if (kindStr.startsWith(prefix)) {
|
if (kindStr.startsWith(prefix)) {
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
|
|
||||||
export function connectToInspector(address: string) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -15,8 +15,11 @@ export class Emitter {
|
||||||
|
|
||||||
case SyntaxKind.BoltQualName:
|
case SyntaxKind.BoltQualName:
|
||||||
if (node.modulePath !== null) {
|
if (node.modulePath !== null) {
|
||||||
for (const element of node.modulePath) {
|
if (node.modulePath.isAbsolute) {
|
||||||
out += '.' + element.text;
|
out += '::'
|
||||||
|
}
|
||||||
|
for (const element of node.modulePath.elements) {
|
||||||
|
out += '::' + element.text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out += this.emit(node.name);
|
out += this.emit(node.name);
|
||||||
|
|
|
@ -4,31 +4,38 @@ import { FastStringMap, assert } from "./util"
|
||||||
import { emitNode } from "./emitter";
|
import { emitNode } from "./emitter";
|
||||||
import { Type, TypeChecker, RecordType } from "./types";
|
import { Type, TypeChecker, RecordType } from "./types";
|
||||||
|
|
||||||
//export class Record {
|
export class Record {
|
||||||
|
|
||||||
// private fields: Map<string, Value>;
|
private fields: Map<string, Value>;
|
||||||
|
|
||||||
// constructor(fields: Iterable<[string, Value]>) {
|
constructor(fields: Iterable<[string, Value]>) {
|
||||||
// this.fields = new Map(fields);
|
this.fields = new Map(fields);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// public clone(): Record {
|
public clone(): Record {
|
||||||
// return new Record(this.fields);
|
return new Record(this.fields);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// public addField(name: string, value: Value): void {
|
public getFieldValue(name: string): Value {
|
||||||
// this.fields.set(name, value);
|
if (!this.fields.has(name)) {
|
||||||
// }
|
throw new Error(`Trying to access non-existent field ${name} of a record.`);
|
||||||
|
}
|
||||||
|
return this.fields.get(name);
|
||||||
|
}
|
||||||
|
|
||||||
// public deleteField(name: string): void {
|
public addField(name: string, value: Value): void {
|
||||||
// this.fields.delete(name);
|
this.fields.set(name, value);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// public clear(): void {
|
public deleteField(name: string): void {
|
||||||
// this.fields.clear();
|
this.fields.delete(name);
|
||||||
// }
|
}
|
||||||
|
|
||||||
//}
|
public clear(): void {
|
||||||
|
this.fields.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
export type Value
|
export type Value
|
||||||
= string
|
= string
|
||||||
|
@ -108,14 +115,14 @@ export class Evaluator {
|
||||||
|
|
||||||
case SyntaxKind.BoltRecordPattern:
|
case SyntaxKind.BoltRecordPattern:
|
||||||
{
|
{
|
||||||
if (!(value.data instanceof Record)) {
|
if (!(value instanceof Record)) {
|
||||||
throw new EvaluationError(`A deconstructing record pattern received a value that is not a record.`);
|
throw new EvaluationError(`A deconstructing record pattern received a value that is not a record.`);
|
||||||
}
|
}
|
||||||
const record = value.data.clone();
|
const record = value.clone();
|
||||||
for (const fieldPatt of node.fields) {
|
for (const fieldPatt of node.fields) {
|
||||||
if (fieldPatt.isRest) {
|
if (fieldPatt.isRest) {
|
||||||
if (fieldPatt.name !== null) {
|
if (fieldPatt.name !== null) {
|
||||||
env.setValue(fieldPatt.name.text, { data: fields.clone() });
|
env.setValue(fieldPatt.name.text, { data: record.clone() });
|
||||||
}
|
}
|
||||||
record.clear();
|
record.clear();
|
||||||
} else {
|
} else {
|
||||||
|
@ -136,7 +143,7 @@ export class Evaluator {
|
||||||
case SyntaxKind.BoltTypePattern:
|
case SyntaxKind.BoltTypePattern:
|
||||||
{
|
{
|
||||||
const expectedType = this.checker.getTypeOfNode(node.type);
|
const expectedType = this.checker.getTypeOfNode(node.type);
|
||||||
if (!this.checker.isTypeAssignableTo(expectedType, getTypeOfValue(value))) {
|
if (!this.checker.isTypeAssignableTo(expectedType, this.checker.getTypeOfValue(value))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -9,7 +9,7 @@ import { emitNode } from "./emitter"
|
||||||
import { Syntax, BoltSourceFile, SourceFile, NodeVisitor, createBoltConditionalCase } from "./ast"
|
import { Syntax, BoltSourceFile, SourceFile, NodeVisitor, createBoltConditionalCase } from "./ast"
|
||||||
import { getFileStem, MapLike } from "./util"
|
import { getFileStem, MapLike } from "./util"
|
||||||
import { verbose, memoize } from "./util"
|
import { verbose, memoize } from "./util"
|
||||||
import { Container, Newable } from "./di"
|
import { Container, Newable } from "./ioc"
|
||||||
import ExpandBoltTransform from "./transforms/expand"
|
import ExpandBoltTransform from "./transforms/expand"
|
||||||
import CompileBoltToJSTransform from "./transforms/boltToJS"
|
import CompileBoltToJSTransform from "./transforms/boltToJS"
|
||||||
import ConstFoldTransform from "./transforms/constFold"
|
import ConstFoldTransform from "./transforms/constFold"
|
||||||
|
@ -19,6 +19,8 @@ import { TypeChecker } from "./types"
|
||||||
import { checkServerIdentity } from "tls"
|
import { checkServerIdentity } from "tls"
|
||||||
import { CheckInvalidFilePaths, CheckTypeAssignments, CheckReferences } from "./checks"
|
import { CheckInvalidFilePaths, CheckTypeAssignments, CheckReferences } from "./checks"
|
||||||
import { SymbolResolver, BoltSymbolResolutionStrategy } from "./resolver"
|
import { SymbolResolver, BoltSymbolResolutionStrategy } from "./resolver"
|
||||||
|
import { Evaluator } from "./evaluator"
|
||||||
|
import { getNodeLanguage } from "./common"
|
||||||
|
|
||||||
const targetExtensions: MapLike<string> = {
|
const targetExtensions: MapLike<string> = {
|
||||||
'JS': '.mjs',
|
'JS': '.mjs',
|
||||||
|
@ -71,20 +73,8 @@ export class Frontend {
|
||||||
this.timing = new Timing();
|
this.timing = new Timing();
|
||||||
}
|
}
|
||||||
|
|
||||||
//@memoize(filepath => path.resolve(filepath))
|
|
||||||
//public getPackage(filepath: string) {
|
|
||||||
// const file = this.getTextFile(filepath)
|
|
||||||
// const projectFile = upsearchSync('Boltfile', path.dirname(file.fullPath));
|
|
||||||
// if (projectFile === null) {
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
// const projectDir = path.resolve(path.dirname(projectFile));
|
|
||||||
// return new Package(projectDir);
|
|
||||||
//}
|
|
||||||
|
|
||||||
public check(program: Program) {
|
public check(program: Program) {
|
||||||
|
|
||||||
|
|
||||||
const resolver = new SymbolResolver(program, new BoltSymbolResolutionStrategy);
|
const resolver = new SymbolResolver(program, new BoltSymbolResolutionStrategy);
|
||||||
const checker = new TypeChecker(resolver);
|
const checker = new TypeChecker(resolver);
|
||||||
|
|
||||||
|
@ -144,12 +134,15 @@ export class Frontend {
|
||||||
}
|
}
|
||||||
|
|
||||||
private mapToTargetFile(node: SourceFile) {
|
private mapToTargetFile(node: SourceFile) {
|
||||||
return path.join('.bolt-work', getFileStem(node.span!.file.fullPath) + getDefaultExtension(getLanguage(node)));
|
return path.join('.bolt-work', getFileStem(node.span!.file.fullPath) + getDefaultExtension(getNodeLanguage(node)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public eval(program: Program) {
|
public eval(program: Program) {
|
||||||
|
const resolver = new SymbolResolver(program, new BoltSymbolResolutionStrategy);
|
||||||
|
const checker = new TypeChecker(resolver);
|
||||||
|
const evaluator = new Evaluator(checker)
|
||||||
for (const sourceFile of program.getAllSourceFiles()) {
|
for (const sourceFile of program.getAllSourceFiles()) {
|
||||||
this.evaluator.eval(sourceFile)
|
evaluator.eval(sourceFile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
157
src/parser.ts
157
src/parser.ts
|
@ -202,46 +202,51 @@ export class Parser {
|
||||||
return (this as any)['parse' + kindToString(kind).substring('Bolt'.length)](tokens);
|
return (this as any)['parse' + kindToString(kind).substring('Bolt'.length)](tokens);
|
||||||
}
|
}
|
||||||
|
|
||||||
public parseModulePath(tokens: BoltTokenStream): BoltModulePath {
|
public parseModulePath(tokens: BoltTokenStream): BoltModulePath | null {
|
||||||
|
|
||||||
|
let firstToken = tokens.peek();;
|
||||||
|
let lastToken: Token;
|
||||||
let isAbsolute = false;
|
let isAbsolute = false;
|
||||||
let elements = [];
|
let elements = [];
|
||||||
|
|
||||||
while (true) {
|
const t0 = tokens.peek();
|
||||||
const t1 = tokens.get();
|
if (t0.kind === SyntaxKind.BoltColonColon) {
|
||||||
assertToken(t1, SyntaxKind.BoltIdentifier);
|
isAbsolute = true;
|
||||||
elements.push(t1 as BoltIdentifier)
|
|
||||||
const t2 = tokens.peek();
|
|
||||||
if (t2.kind !== SyntaxKind.BoltColonColon) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
tokens.get();
|
tokens.get();
|
||||||
|
lastToken = t0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tokens.peek(2).kind === SyntaxKind.BoltColonColon) {
|
||||||
|
while (true) {
|
||||||
|
const t1 = tokens.get();
|
||||||
|
assertToken(t1, SyntaxKind.BoltIdentifier);
|
||||||
|
elements.push(t1 as BoltIdentifier)
|
||||||
|
const t2 = tokens.get();
|
||||||
|
if (tokens.peek(2).kind !== SyntaxKind.BoltColonColon) {
|
||||||
|
lastToken = t2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isAbsolute && elements.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
const result = createBoltModulePath(isAbsolute, elements);
|
const result = createBoltModulePath(isAbsolute, elements);
|
||||||
setOrigNodeRange(result, elements[0], elements[elements.length-1]);
|
setOrigNodeRange(result, firstToken, lastToken!);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public parseQualName(tokens: BoltTokenStream): BoltQualName {
|
public parseQualName(tokens: BoltTokenStream): BoltQualName {
|
||||||
|
|
||||||
let modulePath = null;
|
let modulePath = null;
|
||||||
|
|
||||||
if (tokens.peek(2).kind === SyntaxKind.BoltDot) {
|
if (tokens.peek(2).kind === SyntaxKind.BoltDot) {
|
||||||
modulePath = [];
|
modulePath = this.parseModulePath(tokens);
|
||||||
while (true) {
|
|
||||||
modulePath.push(tokens.get() as BoltIdentifier)
|
|
||||||
tokens.get();
|
|
||||||
const t0 = tokens.peek(2);
|
|
||||||
if (t0.kind !== SyntaxKind.BoltDot) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const name = tokens.get();
|
const name = tokens.get();
|
||||||
assertToken(name, SyntaxKind.BoltIdentifier);
|
assertToken(name, SyntaxKind.BoltIdentifier);
|
||||||
const startNode = modulePath !== null ? modulePath[0] : name;
|
const startNode = modulePath !== null ? modulePath : name;
|
||||||
const endNode = name;
|
const endNode = name;
|
||||||
const node = createBoltQualName(modulePath, name as BoltIdentifier, null);
|
const node = createBoltQualName(modulePath, name as BoltIdentifier, null);
|
||||||
setOrigNodeRange(node, startNode, endNode);
|
setOrigNodeRange(node, startNode, endNode);
|
||||||
|
@ -343,7 +348,7 @@ export class Parser {
|
||||||
const t1 = tokens.get();
|
const t1 = tokens.get();
|
||||||
assertToken(t1, SyntaxKind.BoltStringLiteral);
|
assertToken(t1, SyntaxKind.BoltStringLiteral);
|
||||||
|
|
||||||
const symbols: BoltImportSymbol[] = null;
|
const symbols: BoltImportSymbol[] = [];
|
||||||
const t2 = tokens.get();
|
const t2 = tokens.get();
|
||||||
if (t2.kind === SyntaxKind.BoltParenthesized) {
|
if (t2.kind === SyntaxKind.BoltParenthesized) {
|
||||||
// TODO implement grammar and parsing logic for symbols
|
// TODO implement grammar and parsing logic for symbols
|
||||||
|
@ -389,13 +394,19 @@ export class Parser {
|
||||||
|
|
||||||
public parseReferenceTypeExpression(tokens: BoltTokenStream): BoltReferenceTypeExpression {
|
public parseReferenceTypeExpression(tokens: BoltTokenStream): BoltReferenceTypeExpression {
|
||||||
|
|
||||||
const path = this.parseModulePath(tokens)
|
const firstToken = tokens.peek();
|
||||||
const t1 = tokens.peek();
|
let modulePath = null;
|
||||||
|
if (tokens.peek(2).kind === SyntaxKind.BoltColonColon) {
|
||||||
|
modulePath = this.parseModulePath(tokens)
|
||||||
|
}
|
||||||
|
|
||||||
|
const t1 = tokens.get();
|
||||||
|
assertToken(t1, SyntaxKind.BoltIdentifier);
|
||||||
|
let lastToken = t1;
|
||||||
|
|
||||||
let typeArgs: BoltTypeExpression[] | null = null;
|
let typeArgs: BoltTypeExpression[] | null = null;
|
||||||
let lastToken: BoltToken = path.elements[path.elements.length-1];
|
|
||||||
|
|
||||||
if (t1.kind === SyntaxKind.BoltLtSign) {
|
if (tokens.peek().kind === SyntaxKind.BoltLtSign) {
|
||||||
typeArgs = [];
|
typeArgs = [];
|
||||||
tokens.get();
|
tokens.get();
|
||||||
let first = true;
|
let first = true;
|
||||||
|
@ -417,8 +428,8 @@ export class Parser {
|
||||||
lastToken = t4;
|
lastToken = t4;
|
||||||
}
|
}
|
||||||
|
|
||||||
const node = createBoltReferenceTypeExpression(path, typeArgs);
|
const node = createBoltReferenceTypeExpression(modulePath, t1 as BoltIdentifier, typeArgs);
|
||||||
setOrigNodeRange(node, path.elements[0], lastToken);
|
setOrigNodeRange(node, firstToken, lastToken);
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -433,40 +444,45 @@ export class Parser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private parseTypeExpressionOperators(tokens: BoltTokenStream, lhs: BoltTypeExpression, minPrecedence: number): BoltTypeExpression {
|
//private parseTypeExpressionOperators(tokens: BoltTokenStream, lhs: BoltTypeExpression, minPrecedence: number): BoltTypeExpression {
|
||||||
while (true) {
|
// while (true) {
|
||||||
const t0 = tokens.peek();
|
// const t0 = tokens.peek();
|
||||||
if (!isBoltOperatorLike(t0)) {
|
// if (!isBoltOperatorLike(t0)) {
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
let desc0 = this.typeOperatorTable.lookup(emitNode(t0));
|
// let desc0 = this.typeOperatorTable.lookup(emitNode(t0));
|
||||||
if (desc0 === null || desc0.arity !== 2 || desc0.precedence < minPrecedence) {
|
// if (desc0 === null || desc0.arity !== 2 || desc0.precedence < minPrecedence) {
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
tokens.get();
|
// tokens.get();
|
||||||
let rhs = this.parsePrimTypeExpression(tokens);
|
// let rhs = this.parsePrimTypeExpression(tokens);
|
||||||
while (true) {
|
// while (true) {
|
||||||
const t1 = tokens.peek()
|
// const t1 = tokens.peek()
|
||||||
if (!isBoltOperatorLike(t1.kind)) {
|
// if (!isBoltOperatorLike(t1.kind)) {
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
const desc1 = this.typeOperatorTable.lookup(emitNode(t1))
|
// const desc1 = this.typeOperatorTable.lookup(emitNode(t1))
|
||||||
if (desc1 === null || desc1.arity !== 2 || desc1.precedence < desc0.precedence || !isRightAssoc(desc1.kind)) {
|
// if (desc1 === null || desc1.arity !== 2 || desc1.precedence < desc0.precedence || !isRightAssoc(desc1.kind)) {
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
rhs = this.parseTypeExpressionOperators(tokens, rhs, desc1.precedence);
|
// rhs = this.parseTypeExpressionOperators(tokens, rhs, desc1.precedence);
|
||||||
}
|
// }
|
||||||
const name = createBoltQualName([], t0);
|
// const name = emitNode(t0);
|
||||||
setOrigNodeRange(name, t0, t0);
|
// switch (name) {
|
||||||
lhs = createBoltReferenceTypeExpression(name, [lhs, rhs]);
|
// case '|':
|
||||||
setOrigNodeRange(lhs, t0, rhs);
|
// return createBoltFunctionTypeExpression();
|
||||||
}
|
// )
|
||||||
return lhs
|
// }
|
||||||
}
|
// lhs = createBoltReferenceTypeExpression(null, t0, [lhs, rhs]);
|
||||||
|
// setOrigNodeRange(lhs, t0, rhs);
|
||||||
|
// }
|
||||||
|
// return lhs
|
||||||
|
//}
|
||||||
|
|
||||||
public parseTypeExpression(tokens: BoltTokenStream) {
|
public parseTypeExpression(tokens: BoltTokenStream) {
|
||||||
const lhs = this.parsePrimTypeExpression(tokens);
|
//const lhs = this.parsePrimTypeExpression(tokens);
|
||||||
return this.parseTypeExpressionOperators(tokens, lhs, 0);
|
//return this.parseTypeExpressionOperators(tokens, lhs, 0);
|
||||||
|
return this.parsePrimTypeExpression(tokens);
|
||||||
}
|
}
|
||||||
|
|
||||||
public parseConstantExpression(tokens: BoltTokenStream): BoltConstantExpression {
|
public parseConstantExpression(tokens: BoltTokenStream): BoltConstantExpression {
|
||||||
|
@ -744,7 +760,7 @@ export class Parser {
|
||||||
const t1 = tokens.peek();
|
const t1 = tokens.peek();
|
||||||
if (t1.kind === SyntaxKind.BoltMutKeyword) {
|
if (t1.kind === SyntaxKind.BoltMutKeyword) {
|
||||||
tokens.get();
|
tokens.get();
|
||||||
modifiers |= BoltModifiers.Mutable;
|
modifiers |= BoltModifiers.IsMutable;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bindings = this.parsePattern(tokens)
|
const bindings = this.parsePattern(tokens)
|
||||||
|
@ -1268,8 +1284,6 @@ export class Parser {
|
||||||
return this.parseTraitDeclaration(tokens);
|
return this.parseTraitDeclaration(tokens);
|
||||||
case SyntaxKind.BoltTypeKeyword:
|
case SyntaxKind.BoltTypeKeyword:
|
||||||
return this.parseTypeAliasDeclaration(tokens);
|
return this.parseTypeAliasDeclaration(tokens);
|
||||||
case SyntaxKind.BoltModKeyword:
|
|
||||||
return this.parseModuleDeclaration(tokens);
|
|
||||||
case SyntaxKind.BoltFnKeyword:
|
case SyntaxKind.BoltFnKeyword:
|
||||||
return this.parseFunctionDeclaration(tokens);
|
return this.parseFunctionDeclaration(tokens);
|
||||||
case SyntaxKind.BoltLetKeyword:
|
case SyntaxKind.BoltLetKeyword:
|
||||||
|
@ -1317,14 +1331,19 @@ export class Parser {
|
||||||
if (this.lookaheadIsMacroCall(tokens)) {
|
if (this.lookaheadIsMacroCall(tokens)) {
|
||||||
return this.parseMacroCall(tokens);
|
return this.parseMacroCall(tokens);
|
||||||
}
|
}
|
||||||
const t0 = this.getFirstTokenAfterModifiers(tokens);
|
const t0 = tokens.peek();
|
||||||
if (t0.kind === SyntaxKind.BoltImportKeyword) {
|
const t1 = this.getFirstTokenAfterModifiers(tokens);
|
||||||
|
if (t1.kind === SyntaxKind.BoltImportKeyword) {
|
||||||
return this.parseImportDirective(tokens);
|
return this.parseImportDirective(tokens);
|
||||||
} else if (KIND_STATEMENT_T0.indexOf(t0.kind) !== -1) {
|
} else if (t1.kind === SyntaxKind.BoltModKeyword) {
|
||||||
|
return this.parseModuleDeclaration(tokens);
|
||||||
|
} else if (KIND_STATEMENT_T0.indexOf(t1.kind) !== -1) {
|
||||||
return this.parseStatement(tokens);
|
return this.parseStatement(tokens);
|
||||||
|
} else if (KIND_DECLARATION_KEYWORD.indexOf(t1.kind) !== -1) {
|
||||||
|
return this.parseDeclaration(tokens);
|
||||||
|
} else {
|
||||||
|
throw new ParseError(t0, KIND_SOURCEELEMENT_T0);
|
||||||
}
|
}
|
||||||
// FIXME This should only parse when the tokens are valid and otherwise display a friendly error message.
|
|
||||||
return this.parseDeclaration(tokens);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public parseFunctionBodyElement(tokens: BoltTokenStream): BoltFunctionBodyElement {
|
public parseFunctionBodyElement(tokens: BoltTokenStream): BoltFunctionBodyElement {
|
||||||
|
@ -1561,6 +1580,8 @@ import { TextFile, TextSpan, TextPos } from "./text"
|
||||||
import * as fs from "fs"
|
import * as fs from "fs"
|
||||||
import {JSScanner} from "./foreign/js/scanner";
|
import {JSScanner} from "./foreign/js/scanner";
|
||||||
import {emitNode} from "./emitter";
|
import {emitNode} from "./emitter";
|
||||||
|
import { timingSafeEqual } from "crypto";
|
||||||
|
import { isatty } from "tty";
|
||||||
|
|
||||||
export function parseSourceFile(filepath: string, pkg: Package): BoltSourceFile {
|
export function parseSourceFile(filepath: string, pkg: Package): BoltSourceFile {
|
||||||
const file = new TextFile(filepath);
|
const file = new TextFile(filepath);
|
||||||
|
|
|
@ -13,9 +13,9 @@ import {
|
||||||
|
|
||||||
import { TypeChecker } from "../types"
|
import { TypeChecker } from "../types"
|
||||||
import { BoltTokenStream, Parser, isModifierKeyword } from "../parser"
|
import { BoltTokenStream, Parser, isModifierKeyword } from "../parser"
|
||||||
import { Evaluator, TRUE, FALSE } from "../evaluator"
|
import { Evaluator } from "../evaluator"
|
||||||
import { Transformer, TransformManager } from "./index"
|
import { Transformer, TransformManager } from "./index"
|
||||||
import { inject } from "../di"
|
import { inject } from "../ioc"
|
||||||
import { SourceFile } from "../ast"
|
import { SourceFile } from "../ast"
|
||||||
|
|
||||||
interface SyntaxTransformer {
|
interface SyntaxTransformer {
|
||||||
|
@ -63,10 +63,8 @@ export class ExpandBoltTransform implements Transformer {
|
||||||
|
|
||||||
private expand(node: BoltSyntax) {
|
private expand(node: BoltSyntax) {
|
||||||
|
|
||||||
for (const identNode of node.findAllChildrenOfKind(SyntaxKind.BoltIdentifier)) {
|
for (const macroCall of node.findAllChildrenOfKind(SyntaxKind.BoltMacroCall)) {
|
||||||
if (identNode.text.endsWith('1')) {
|
this.toExpand.push(macroCall);
|
||||||
this.toExpand.push(node.parentNode!);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME
|
// FIXME
|
||||||
|
|
Loading…
Reference in a new issue