Last active
December 15, 2018 01:17
-
-
Save stoplion/7991c2cdd9445ddd6c77c24da30676c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@{% | |
const flatten = d => { | |
return d.reduce( | |
(a, b) => { | |
return a.concat(b); | |
}, | |
[] | |
); | |
}; | |
const filter = d => { | |
return d.filter((token) => { | |
return token !== null; | |
}); | |
}; | |
%} | |
APP -> MULTPERC {% (a) => `(${ a.join('') }) * 100`%} | |
| ADDPERC {% (a) => flatten(a).join('') %} | |
ADDPERC -> ADD _ [-+] _ PERC {% (a) => `${a[0]} ${a[2]} ${a[4]} * (${a[0]})`%} | |
ADD -> ADD _ [+-] _ INT {% (a) => a.join('') %} | |
| INT | |
MULTPERC -> MULTPERC _ "/" _ PERC {% (a) => `${a.join(' ')}` %} | |
| MULTPERC _ "*" _ PERC {% (a) => `${a.join(' ')}` %} | |
| PERC | |
PERC -> INT "%" {% (p) => { | |
return `${p[0]}/100`; | |
} %} | |
INT -> [0-9]:+ {% | |
(d) => { | |
return `${d[0].join('')}` | |
} | |
%} | |
_ -> [\s]:* {% function(d) {return null } %} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment