Skip to content

Commit

Permalink
fix: broken dependencies (#65)
Browse files Browse the repository at this point in the history
* fix broken dependencies

* revert ebnf upgrade

* revert grammar changes

* revert grammar changes
  • Loading branch information
menduz authored Aug 5, 2020
1 parent f1bc4cd commit fcffc40
Show file tree
Hide file tree
Showing 54 changed files with 1,008 additions and 1,729 deletions.
366 changes: 243 additions & 123 deletions package-lock.json

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,36 +30,36 @@
"dependencies": {
"@webassemblyjs/ast": "^1.9.0",
"@webassemblyjs/wast-printer": "^1.9.0",
"arg": "^4.1.2",
"binaryen": "^91.0.0",
"ebnf": "^1.8.0",
"arg": "^4.1.3",
"binaryen": "^95.0.0",
"ebnf": "^1.7.4",
"utf8-bytes": "0.0.1",
"wabt": "^1.0.13"
"wabt": "^1.0.19"
},
"devDependencies": {
"@types/chai": "^4.2.6",
"@types/chai": "^4.2.12",
"@types/git-rev-sync": "^1.12.0",
"@types/glob": "^7.1.1",
"@types/node": "^12.12.16",
"@types/node-fetch": "^2.5.4",
"@types/semver": "^6.2.0",
"@types/glob": "^7.1.3",
"@types/node": "^12.12.53",
"@types/node-fetch": "^2.5.7",
"@types/semver": "^6.2.1",
"chai": "^4.2.0",
"dcl-tslint-config-standard": "^1.1.0",
"expect": "^24.9.0",
"git-rev-sync": "^1.12.0",
"glob": "^7.1.6",
"istanbul": "^0.4.5",
"mocha": "^6.2.2",
"mocha-junit-reporter": "^1.23.1",
"mocha": "^6.2.3",
"mocha-junit-reporter": "^1.23.3",
"mocha-performance": "^0.1.1",
"node-fetch": "^2.6.0",
"nyc": "^14.1.1",
"semver": "^6.3.0",
"source-map-support": "^0.5.16",
"ts-node": "^8.7.0",
"tslint": "^5.20.1",
"source-map-support": "^0.5.19",
"ts-node": "^8.10.2",
"tslint": "^6.1.3",
"tslint-language-service": "^0.9.9",
"typescript": "^3.8.3"
"typescript": "^3.9.7"
},
"nyc": {
"extension": [
Expand Down
56 changes: 31 additions & 25 deletions src/compiler/phases/canonicalPhase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const visitor = {
return ret;
},
ImplDirective(astNode: Nodes.ASTNode) {
const references = astNode.children.filter($ => $.type === 'Reference');
const references = astNode.children.filter(($) => $.type === 'Reference');

// the last Reference is the target
const target = visit(references.pop()!);
Expand Down Expand Up @@ -141,7 +141,7 @@ const visitor = {
const list = findChildrenType(astNode, 'EffectElementList');

if (list) {
ret.elements = list.children.map($ => visit($));
ret.elements = list.children.map(($) => visit($));
} else {
// TODO: warn
}
Expand All @@ -159,7 +159,7 @@ const visitor = {
throw new PositionCapableError('Missing param list in function declaration', astNode);
}

ret.parameters = params.children.map($ => visit($));
ret.parameters = params.children.map(($) => visit($));

return ret;
},
Expand Down Expand Up @@ -232,7 +232,7 @@ const visitor = {

const typeDeclElements = findChildrenType(astNode, 'TypeDeclElements');

const declarations = typeDeclElements ? typeDeclElements.children.map($ => visit($)) : [];
const declarations = typeDeclElements ? typeDeclElements.children.map(($) => visit($)) : [];

const ret = new Nodes.EnumDirectiveNode(astNode, variableName, declarations);
ret.isPublic = isPublic;
Expand All @@ -254,9 +254,9 @@ const visitor = {

const typeDeclElements = findChildrenType(astNode, 'TraitDeclElements');

const declarations = typeDeclElements ? typeDeclElements.children.map($ => visit($)) : [];
const declarations = typeDeclElements ? typeDeclElements.children.map(($) => visit($)) : [];

declarations.forEach($ => {
declarations.forEach(($) => {
if ($ instanceof Nodes.FunDirectiveNode && !$.functionNode.body) {
$.functionNode.annotate(new annotations.SignatureDeclaration());
}
Expand Down Expand Up @@ -287,7 +287,7 @@ const visitor = {
throw new PositionCapableError('Missing param list in function declaration', astNode);
}

fun.parameters = params.children.map($ => visit($));
fun.parameters = params.children.map(($) => visit($));

const body = findChildrenType(astNode, 'FunAssignExpression');

Expand Down Expand Up @@ -325,7 +325,7 @@ const visitor = {
return ret;
},
CodeBlock(astNode: Nodes.ASTNode) {
const statements = astNode.children.map($ => visit($)).filter($ => !!$);
const statements = astNode.children.map(($) => visit($)).filter(($) => !!$);
return new Nodes.BlockNode(astNode, statements);
},
Parameter(astNode: Nodes.ASTNode) {
Expand Down Expand Up @@ -368,7 +368,7 @@ const visitor = {
const doesItHaveMemberExpression = currentNode && currentNode.type === 'MemberExpression';

if (doesItHaveCallArguments) {
const argumentsNode = currentNode.children.map($ => visit($));
const argumentsNode = currentNode.children.map(($) => visit($));
const fnCall = new Nodes.FunctionCallNode(currentNode, ret, argumentsNode);
fnCall.isInfix = true;
ret = fnCall;
Expand All @@ -394,7 +394,7 @@ const visitor = {
},
MatchExpression(astNode: Nodes.ASTNode) {
const lhs = visit(astNode.children[0]);
const matchingSet = astNode.children[1].children.map($ => visit($));
const matchingSet = astNode.children[1].children.map(($) => visit($));

return new Nodes.PatternMatcherNode(astNode, lhs, matchingSet);
},
Expand Down Expand Up @@ -422,7 +422,7 @@ const visitor = {
FunctionTypeLiteral(child: Nodes.ASTNode) {
const parametersNode = findChildrenType(child, 'FunctionTypeParameters');

const ret = new Nodes.FunctionTypeNode(child, parametersNode ? parametersNode.children.map($ => visit($)) : []);
const ret = new Nodes.FunctionTypeNode(child, parametersNode ? parametersNode.children.map(($) => visit($)) : []);

ret.returnType = visitChildTypeOrNull(child, 'Type') as Nodes.TypeNode;

Expand Down Expand Up @@ -458,7 +458,7 @@ const visitor = {
const deconstruct = findChildrenType(x, 'DeconstructStruct');

if (deconstruct) {
ret.deconstructorNames = deconstruct.children.map($ => visit($));
ret.deconstructorNames = deconstruct.children.map(($) => visit($));
}

return ret;
Expand Down Expand Up @@ -509,9 +509,15 @@ const visitor = {
return new Nodes.HexLiteral(x, typeName);
},
StringLiteral(x: Nodes.ASTNode) {
const ret = new Nodes.StringLiteral(x, 'string');
ret.value = JSON.parse(x.text);
return ret;
try {
const ret = new Nodes.StringLiteral(x, 'string');
ret.value = JSON.parse(x.text);
return ret;
} catch (e) {
const err = 'Cannot parse string: ' + x.text;
console.log(err);
return new PositionCapableError(err, x);
}
},
BinNegExpression(x: Nodes.ASTNode) {
return new Nodes.UnaryExpressionNode(x, Nodes.NameIdentifierNode.fromString('~', x), visit(x.children[0]));
Expand All @@ -527,7 +533,7 @@ const visitor = {
},
Document(astNode: Nodes.ASTNode) {
const doc = new Nodes.DocumentNode(astNode);
astNode.children.forEach($ => doc.directives.push(visit($)));
astNode.children.forEach(($) => doc.directives.push(visit($)));

return doc;
},
Expand Down Expand Up @@ -566,7 +572,7 @@ const visitor = {
},
StructLiteral(astNode: Nodes.ASTNode) {
const parametersNode = findChildrenTypeOrFail(astNode, 'StructParamsList');
const parameters = parametersNode.children.filter($ => $.type === 'Parameter').map($ => visit($));
const parameters = parametersNode.children.filter(($) => $.type === 'Parameter').map(($) => visit($));
return new Nodes.StructTypeNode(astNode, parameters);
},
StackLiteral(astNode: Nodes.ASTNode) {
Expand All @@ -588,16 +594,16 @@ const visitor = {

const params = findChildrenType(astNode, 'FunctionParamsList');

return new Nodes.StructDeclarationNode(astNode, declaredName, params ? params.children.map($ => visit($)) : []);
return new Nodes.StructDeclarationNode(astNode, declaredName, params ? params.children.map(($) => visit($)) : []);
},
UnionType(astNode: Nodes.ASTNode) {
const ret = new Nodes.UnionTypeNode(astNode);
ret.of = astNode.children.map($ => visit($));
ret.of = astNode.children.map(($) => visit($));
return ret;
},
IntersectionType(astNode: Nodes.ASTNode) {
const ret = new Nodes.IntersectionTypeNode(astNode);
ret.of = astNode.children.map($ => visit($));
ret.of = astNode.children.map(($) => visit($));
return ret;
},
TypeParen(astNode: Nodes.ASTNode) {
Expand All @@ -606,14 +612,14 @@ const visitor = {
return ret;
},
WasmExpression(astNode: Nodes.ASTNode) {
const atoms = astNode.children.map($ => visit($));
const atoms = astNode.children.map(($) => visit($));
return new Nodes.WasmExpressionNode(astNode, atoms);
},
SExpression(astNode: Nodes.ASTNode) {
const children = astNode.children.slice();
const symbol = children.shift() as any;

const newChildren = children.map($ => visit($) as Nodes.ExpressionNode);
const newChildren = children.map(($) => visit($) as Nodes.ExpressionNode);

const ret = new Nodes.WasmAtomNode(astNode, symbol.text, newChildren);

Expand All @@ -639,7 +645,7 @@ const visitor = {
}

return ret;
}
},
};

function visit<T extends Nodes.Node>(astNode: Nodes.ASTNode): T & any {
Expand All @@ -661,13 +667,13 @@ function visit<T extends Nodes.Node>(astNode: Nodes.ASTNode): T & any {
}

function findChildrenTypeOrFail(token: Nodes.ASTNode, type: string, message?: string) {
const ret = token.children.find($ => $.type === type);
const ret = token.children.find(($) => $.type === type);
if (!ret) throw new PositionCapableError(message || `Cannot find child node of type ${type}`, token);
return ret;
}

function findChildrenType(token: Nodes.ASTNode, type: string) {
return token.children.find($ => $.type === type);
return token.children.find(($) => $.type === type);
}

function visitChildTypeOrNull(token: Nodes.ASTNode, type: string) {
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/phases/codeGenerationPhase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -542,11 +542,11 @@ export class CodeGenerationPhaseResult {
}> {
let text = print(this.programAST);

await wabt.ready;
let wabtModule: ReturnType<typeof wabt.parseWat>;
const theWabt = await wabt;
let wabtModule: ReturnType<typeof theWabt.parseWat>;

try {
wabtModule = wabt.parseWat(this.document.moduleName, text, {});
wabtModule = theWabt.parseWat(this.document.moduleName, text, {});
} catch (e) {
const invalidFile = this.parsingContext.system.resolvePath(this.parsingContext.system.getCurrentDirectory(), 'failed_debug_wat.wat')
this.parsingContext.system.writeFile(invalidFile, text)
Expand Down
2 changes: 1 addition & 1 deletion src/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ PostfixNumber ::= (HexLiteral | NumberLiteral) Reference? {pin=1,simplifyWhe
NumberLiteral ::= !('0x') ("0" | [1-9] [0-9]*) ("." [0-9]+)? (("e" | "E") ( "-" | "+" )? ("0" | [1-9] [0-9]*))? {pin=2}
NegNumberLiteral ::= '-'? NumberLiteral {pin=2}
HexLiteral ::= "0x" [0-9A-Fa-f]+ {pin=1}
StringLiteral ::= STRING_DELIMITER ((![\\\\"] [#x20-#xFFFF])* | ('\\\\' (STRING_DELIMITER | '\\\\' | '/' | 'b' | 'f' | 'n' | 'r' | 't' | 'u' HEXDIG HEXDIG HEXDIG HEXDIG)?))* STRING_DELIMITER
StringLiteral ::= STRING_DELIMITER ((![\\\\"] [#x20-#xFFFF])* | ('\\' (STRING_DELIMITER | '\\' | '/' | 'b' | 'f' | 'n' | 'r' | 't' | 'u' HEXDIG HEXDIG HEXDIG HEXDIG)?))* STRING_DELIMITER {pin=1}
Literal ::= StringLiteral
| PostfixNumber
| BooleanLiteral {fragment=true}
Expand Down
2 changes: 1 addition & 1 deletion test/Canonical.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('Canonical', function() {

// add the last literal
result += literals[literals.length - 1];
testParseToken(result, getFileName(), 'Document', async () => void 0, phases);
testParseToken(result, getFileName(), async () => void 0, phases);
}

test`var a = 1`;
Expand Down
31 changes: 24 additions & 7 deletions test/Parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { nodeSystem } from '../dist/support/NodeSystem';
import { printErrors } from '../dist/utils/errorPrinter';

describe('Parser', () => {
const phases = function(txt: string, fileName: string) {
const phases = function (txt: string, fileName: string) {
const parsingContext = new ParsingContext(nodeSystem);

parsingContext.paths.push(nodeSystem.resolvePath(__dirname, '../stdlib'));
Expand All @@ -18,7 +18,7 @@ describe('Parser', () => {

return {
document: parsingContext.getParsingPhaseForContent(fileName, moduleName, txt),
parsingContext
parsingContext,
};
};
describe('Failing examples', () => {
Expand Down Expand Up @@ -46,7 +46,7 @@ describe('Parser', () => {
return `tests/parser_tests_${testCount++}.lys`;
}

describe('Basic sanity tests', function() {
describe('Basic sanity tests', function () {
function test(literals: any, ...placeholders: any[]) {
let result = '';

Expand All @@ -58,7 +58,7 @@ describe('Parser', () => {

// add the last literal
result += literals[literals.length - 1];
testParseToken(result, getFileName(), 'Document', async () => void 0, phases);
testParseToken(result, getFileName(),async () => void 0, phases);
}

function testEquivalence(a: string, b: string) {
Expand All @@ -67,7 +67,6 @@ describe('Parser', () => {
testParseToken(
a,
getFileName(),
'Document',
async (doc, err) => {
if (err) throw err;
if (!doc) throw new Error('No result');
Expand All @@ -78,7 +77,6 @@ describe('Parser', () => {
testParseToken(
b,
getFileName(),
'Document',
async (doc, err) => {
if (err) throw err;
if (!doc) throw new Error('No result');
Expand Down Expand Up @@ -675,6 +673,25 @@ describe('Parser', () => {
});

describe('Literals', () => {
function testLiteral(text: string) {
testParseToken(
'var a = ' + text,
getFileName(),
async (result, e) => {
if (e) throw e;
if (!result) throw new Error('No result');
},
phases
);
}

testLiteral(JSON.stringify('\\'));
testLiteral(JSON.stringify('\"'));
testLiteral(JSON.stringify('A string'));
testLiteral(JSON.stringify('A string'));
testLiteral(JSON.stringify("asdasd`\"`'''`\\\""));
testLiteral(JSON.stringify(213422342344234));

test`
var a = 1
var b = 2.0
Expand All @@ -687,7 +704,7 @@ describe('Parser', () => {

test`
fun x(): string = "\\"'\`\\\\"
`
`;

// test`
// fun x(): string = "// a comment inside a string"
Expand Down
Loading

0 comments on commit fcffc40

Please sign in to comment.