aoc-2023/day_19/grammar.js

117 lines
6.5 KiB
JavaScript
Raw Normal View History

2024-12-09 22:41:02 +09:00
// Generated automatically by nearley, version 2.20.1
// http://github.com/Hardmath123/nearley
(function () {
function id(x) { return x[0]; }
var grammar = {
Lexer: undefined,
ParserRules: [
{"name": "main", "symbols": ["rules", "eol", "materials"], "postprocess": (d) => {
return {
rules: d[0],
materials: d[2],
}
}
},
{"name": "rules$ebnf$1$subexpression$1$ebnf$1", "symbols": ["eol"], "postprocess": id},
{"name": "rules$ebnf$1$subexpression$1$ebnf$1", "symbols": [], "postprocess": function(d) {return null;}},
{"name": "rules$ebnf$1$subexpression$1", "symbols": ["rule", "rules$ebnf$1$subexpression$1$ebnf$1"]},
{"name": "rules$ebnf$1", "symbols": ["rules$ebnf$1$subexpression$1"]},
{"name": "rules$ebnf$1$subexpression$2$ebnf$1", "symbols": ["eol"], "postprocess": id},
{"name": "rules$ebnf$1$subexpression$2$ebnf$1", "symbols": [], "postprocess": function(d) {return null;}},
{"name": "rules$ebnf$1$subexpression$2", "symbols": ["rule", "rules$ebnf$1$subexpression$2$ebnf$1"]},
{"name": "rules$ebnf$1", "symbols": ["rules$ebnf$1", "rules$ebnf$1$subexpression$2"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
{"name": "rules", "symbols": ["rules$ebnf$1"], "postprocess": d=> {
return d[0].map(x=> x[0])
}
},
{"name": "rule", "symbols": ["rulename", "_", {"literal":"{"}, "_", "conditions", "_", {"literal":","}, "_", "rulename", "_", {"literal":"}"}], "postprocess": d=>{
return {
name: d[0],
rules: d[4],
always: d[8],
}
}
},
{"name": "conditions$ebnf$1", "symbols": []},
{"name": "conditions$ebnf$1$subexpression$1", "symbols": ["condition", {"literal":","}]},
{"name": "conditions$ebnf$1", "symbols": ["conditions$ebnf$1", "conditions$ebnf$1$subexpression$1"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
{"name": "conditions", "symbols": ["conditions$ebnf$1", "condition"], "postprocess": d=>{
return d[0].map(x=> x[0]).concat([d[1]])
}},
{"name": "condition", "symbols": ["cond", "_", {"literal":":"}, "_", "rulename"], "postprocess": d=>{
return {
condition: d[0],
dest:d[4]
}
}
},
{"name": "cond", "symbols": ["quality", "_", "condSymbol", "_", "int"], "postprocess": d=> {
return {
quality: d[0],
cond: d[2][0],
value: d[4]
}
} },
{"name": "condSymbol", "symbols": [{"literal":">"}]},
{"name": "condSymbol", "symbols": [{"literal":"<"}], "postprocess": d => d[0]},
{"name": "quality", "symbols": [/[xmas]/], "postprocess": d=> d[0]},
{"name": "rulename$ebnf$1", "symbols": [/[a-zA-Z]/]},
{"name": "rulename$ebnf$1", "symbols": ["rulename$ebnf$1", /[a-zA-Z]/], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
{"name": "rulename", "symbols": ["rulename$ebnf$1"], "postprocess": d=> {
return d[0].join("");
}},
{"name": "materials$ebnf$1$subexpression$1$ebnf$1", "symbols": ["eol"], "postprocess": id},
{"name": "materials$ebnf$1$subexpression$1$ebnf$1", "symbols": [], "postprocess": function(d) {return null;}},
{"name": "materials$ebnf$1$subexpression$1", "symbols": ["material", "materials$ebnf$1$subexpression$1$ebnf$1"]},
{"name": "materials$ebnf$1", "symbols": ["materials$ebnf$1$subexpression$1"]},
{"name": "materials$ebnf$1$subexpression$2$ebnf$1", "symbols": ["eol"], "postprocess": id},
{"name": "materials$ebnf$1$subexpression$2$ebnf$1", "symbols": [], "postprocess": function(d) {return null;}},
{"name": "materials$ebnf$1$subexpression$2", "symbols": ["material", "materials$ebnf$1$subexpression$2$ebnf$1"]},
{"name": "materials$ebnf$1", "symbols": ["materials$ebnf$1", "materials$ebnf$1$subexpression$2"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
{"name": "materials", "symbols": ["materials$ebnf$1"], "postprocess": d => d[0].map(x=> x[0])},
{"name": "material$ebnf$1$subexpression$1", "symbols": ["_", {"literal":","}, "_", "statement"]},
{"name": "material$ebnf$1", "symbols": ["material$ebnf$1$subexpression$1"]},
{"name": "material$ebnf$1$subexpression$2", "symbols": ["_", {"literal":","}, "_", "statement"]},
{"name": "material$ebnf$1", "symbols": ["material$ebnf$1", "material$ebnf$1$subexpression$2"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
{"name": "material$ebnf$2", "symbols": [{"literal":","}], "postprocess": id},
{"name": "material$ebnf$2", "symbols": [], "postprocess": function(d) {return null;}},
{"name": "material", "symbols": [{"literal":"{"}, "_", "statement", "material$ebnf$1", "_", "material$ebnf$2", "_", {"literal":"}"}], "postprocess": d=>{
const ret = {};
const state = d[2];
ret[state.quality] = state.value;
d[3].map(x=> x[3]).forEach(s=>{
ret[s.quality] = s.value;
});
return ret;
}
},
{"name": "statement", "symbols": ["quality", "_", {"literal":"="}, "_", "int"], "postprocess": d=>{
return {
quality: d[0],
value:d[4],
}
}
},
{"name": "_$ebnf$1", "symbols": []},
{"name": "_$ebnf$1", "symbols": ["_$ebnf$1", "wschar"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
{"name": "_", "symbols": ["_$ebnf$1"], "postprocess": d=> null},
{"name": "__$ebnf$1", "symbols": ["wschar"]},
{"name": "__$ebnf$1", "symbols": ["__$ebnf$1", "wschar"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
{"name": "__", "symbols": ["__$ebnf$1"], "postprocess": d=> null},
{"name": "wschar", "symbols": [/[ \t]/], "postprocess": id},
{"name": "eol", "symbols": [{"literal":"\n"}]},
{"name": "eol$string$1", "symbols": [{"literal":"\r"}, {"literal":"\n"}], "postprocess": function joiner(d) {return d.join('');}},
{"name": "eol", "symbols": ["eol$string$1"], "postprocess": d=> null},
{"name": "int$ebnf$1", "symbols": [/[0-9]/]},
{"name": "int$ebnf$1", "symbols": ["int$ebnf$1", /[0-9]/], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
{"name": "int", "symbols": ["int$ebnf$1"], "postprocess": d=> parseInt(d[0].join(""))}
]
, ParserStart: "main"
}
if (typeof module !== 'undefined'&& typeof module.exports !== 'undefined') {
module.exports = grammar;
} else {
globalThis.grammar = grammar;
}
})();