Skip to content

Commit

Permalink
Merge pull request #8 from yokljo/master
Browse files Browse the repository at this point in the history
Generated parser compiles with TypeScript's strict mode
  • Loading branch information
pjmolina committed Jan 29, 2018
2 parents de78193 + ac79b11 commit 6f68ff5
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 103 deletions.
4 changes: 2 additions & 2 deletions examples/arithmetics.pegjs
Expand Up @@ -5,15 +5,15 @@

Expression
= head:Term tail:(_ ("+" / "-") _ Term)* {
return tail.reduce(function(result, element) {
return tail.reduce(function(result: number, element: any[]) {
if (element[1] === "+") { return result + element[3]; }
if (element[1] === "-") { return result - element[3]; }
}, head);
}

Term
= head:Factor tail:(_ ("*" / "/") _ Factor)* {
return tail.reduce(function(result, element) {
return tail.reduce(function(result: number, element: any[]) {
if (element[1] === "*") { return result * element[3]; }
if (element[1] === "/") { return result / element[3]; }
}, head);
Expand Down
2 changes: 1 addition & 1 deletion src/passes/generate-bytecode-ts.js
Expand Up @@ -200,7 +200,7 @@ function generateBytecode(ast) {

function addFunctionConst(params, code) {
return addConst(
"function(" + params.join(", ") + ") {" + code + "}"
"function(" + params.map(v => v + ": any").join(", ") + ") {" + code + "}"
);
}

Expand Down

0 comments on commit 6f68ff5

Please sign in to comment.