Skip to content

Instantly share code, notes, and snippets.

@stoplion
Last active December 15, 2018 01:17
Show Gist options
  • Save stoplion/7991c2cdd9445ddd6c77c24da30676c2 to your computer and use it in GitHub Desktop.
Save stoplion/7991c2cdd9445ddd6c77c24da30676c2 to your computer and use it in GitHub Desktop.
@{%
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