1
0
mirror of https://github.com/Baidicoot/rpncalc-v4 synced 2024-12-04 15:29:54 +00:00

added parsing for push operator

This commit is contained in:
Aidan K. Ewart 2020-05-20 11:57:26 +01:00
parent c0bfda2c39
commit 9a700aca35
2 changed files with 14 additions and 1 deletions

0
ast.js
View File

View File

@ -170,6 +170,19 @@ const parseName = (stream) => {
return {parsed:id.parsed.val, stream:syn.stream};
}
/* takes in stream, outputs parsed item or null - FAILABLE */
const parsePush = (stream) => {
let syn = attempt(parseSyntax("'"));
if (syn.parsed === null) {
return {parsed:null, stream:syn.stream};
}
let id = parseIdent(syn.stream);
if (id.parsed === null) {
return {parsed:null, stream:id.stream};
}
return {parsed:{type:"push", elem:id.parsed}, stream:id.stream};
}
/* takes in stream, outputs parsed item or null - FAILABLE */
const parseLambda = (stream) => {
let name = attempt(parseName)(stream);
@ -189,7 +202,7 @@ const parseLambda = (stream) => {
}
/* takes in stream, outputs parsed item or null */
const parseExpr = or(parseBuiltin, or(parseIdent, or(parseInteger, attempt(parens(parseLambda)))));
const parseExpr = or(parseBuiltin, or(parseIdent, or(parseInteger, or(parsePush, attempt(parens(parseLambda))))));
/* takes in stream, outputs parsed items */
export const parseExprs = many(parseExpr);