expression-compiler
Advanced tools
Comparing version 0.3.0 to 0.3.1
{ | ||
"name": "expression-compiler", | ||
"repository": "git@github.com:uniphil/expression-compiler.git", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "", | ||
@@ -6,0 +6,0 @@ "main": "func.js", |
30
parse.js
@@ -131,3 +131,3 @@ var R = require('ramda'); | ||
var pullOps = function(symbol, ary, funcName) { | ||
var pullOps = function(symbol, ary, funcName, options) { | ||
var arys = { | ||
@@ -137,2 +137,10 @@ unary: function(tL, t, tR) { | ||
{ key: funcName, template: t.repr + '#' }); | ||
if (options.binarify && | ||
tL && // it's not the first token | ||
!(tL.type === 'token' && tL.token === 'operator') && // thing before isn't an op | ||
!(tL.type === 'astNode' && tL.node === 'func')) { // thing before isn't an op | ||
var injectedToken = lex.token('operator', options.binarify); | ||
injectedToken.repr = ''; | ||
return [[tL, injectedToken, node], null]; | ||
} | ||
return [[tL, node], null]; | ||
@@ -164,19 +172,2 @@ }, | ||
var injectToken = function(tokenToInject, options) { | ||
return function(tokens) { | ||
return R.reduce.idx(function(out, token, i, tokens) { | ||
if (token.type === 'ASTNode' && token.node === 'func' && | ||
token.options.key === options.beforeOpNode && | ||
tokens[i - 1]) { | ||
var injectedToken = lex.token('operator', tokenToInject); | ||
injectedToken.repr = ''; | ||
out.push(injectedToken); | ||
} | ||
out.push(token); | ||
return out; | ||
}, [], tokens); | ||
}; | ||
}; | ||
var pullFunctions = stepTrios(function(tL, t, tR) { | ||
@@ -261,4 +252,3 @@ // find [name, expr]s, and swap as fn(key=name, children=expr.children) | ||
pullOps('^', 'binary', 'pow'), | ||
pullOps('-', 'unary', 'neg'), | ||
injectToken('+', {beforeOpNode: 'neg'}), | ||
pullOps('-', 'unary', 'neg', {binarify: '+'}), | ||
pullOps('*', 'nary', 'product'), | ||
@@ -265,0 +255,0 @@ pullOps('/', 'binary', 'div'), |
@@ -220,2 +220,5 @@ require('mocha'); | ||
}); | ||
it('should work for unary negation after operators like 1+-1', function() { | ||
assert.doesNotThrow(function() { parse('1+-1'); }, parse.ParseError); | ||
}); | ||
it('should error on dangling close paren', function() { | ||
@@ -222,0 +225,0 @@ assert.throws(function() { parse('1)'); }, parse.ParseError); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36499
773