UNPKG

parse-vbb-station-name

Version:
284 lines (276 loc) 15.1 kB
// Generated automatically by nearley, version 2.20.1 // http://github.com/Hardmath123/nearley (function () { function id(x) { return x[0]; } const lexer = require('./lexer') const _id = ([token]) => ({ type: token.type, text: token.text, offset: token.offset, }) const collapseText = (tokens) => { return { type: 'text', text: tokens.filter(t => !!t).map(t => t.text).join(''), offset: tokens[0].offset, } } const asDifferentiator = (token) => ({ type: 'differentiator', text: token.text, offset: token.offset, }) const combineAtNotation = (tokens, raw) => ({ type: 'differentiator', text: tokens.filter(t => !!t).map(t => t.text).join(''), offset: tokens.find(t => !!t).offset, raw, }) const asSbahnUbahn = ([sU]) => ({ type: 'sbahnUbahn', text: sU.text, offset: sU.offset, }) const asLine = ([line]) => ({ type: 'line', text: line.text, offset: line.offset, }) var grammar = { Lexer: lexer, ParserRules: [ {"name": "exp", "symbols": ["text"], "postprocess": ([name]) => ({ name, }) }, {"name": "exp$ebnf$1", "symbols": [(lexer.has("comma") ? {type: "comma"} : comma)], "postprocess": id}, {"name": "exp$ebnf$1", "symbols": [], "postprocess": function(d) {return null;}}, {"name": "exp", "symbols": ["text", "exp$ebnf$1", "_", "differentiator"], "postprocess": ([name, _, __, diff]) => ({ name, differentiators: [diff], }) }, {"name": "exp", "symbols": ["text", (lexer.has("comma") ? {type: "comma"} : comma), "_", "text", "_"], "postprocess": ([group, _, __, name, ___]) => ({ name, group, }) }, {"name": "exp$ebnf$2", "symbols": [(lexer.has("comma") ? {type: "comma"} : comma)], "postprocess": id}, {"name": "exp$ebnf$2", "symbols": [], "postprocess": function(d) {return null;}}, {"name": "exp", "symbols": ["text", "_", "differentiator", "exp$ebnf$2", "_", "text"], "postprocess": ([group, _, groupDiff, __, ___, name]) => ({ name, group: {...group, differentiators: [groupDiff]}, }) }, {"name": "exp", "symbols": ["sbahnUbahn", "_", "text", "_", "differentiator", "_", "words"], "postprocess": ([sbahnUbahn, _, name, __, diff, ___, part]) => ({ sbahnUbahn, name, differentiators: [diff], part: [part], }) }, {"name": "exp", "symbols": ["text", "_", "differentiator", (lexer.has("comma") ? {type: "comma"} : comma), "_", "text", "_", "differentiator"], "postprocess": ([group, _, groupDiff, __, ___, name, ____, diff]) => ({ name, differentiators: [diff], group: {...group, differentiators: [groupDiff]}, }) }, {"name": "exp", "symbols": ["text", "_", "differentiator", (lexer.has("comma") ? {type: "comma"} : comma), "_", "text", "_", "differentiator", "_", "differentiator"], "postprocess": ([group, _, groupDiff, __, ___, name, ____, diff1, _____, diff2]) => ({ name, differentiators: [diff1, diff2], group: {...group, differentiators: [groupDiff]}, }) }, {"name": "exp", "symbols": ["text", "_", "differentiator", (lexer.has("comma") ? {type: "comma"} : comma), "_", "text", "_", "part"], "postprocess": ([group, _, groupDiff, __, ___, name, ____, part]) => ({ name, part, group: {...group, differentiators: [groupDiff]}, }) }, {"name": "exp", "symbols": ["text", (lexer.has("comma") ? {type: "comma"} : comma), "_", "text", "_", "differentiator"], "postprocess": ([name, _, __, group, ___, groupDiff]) => ({ name, group: {...group, differentiators: [groupDiff]}, }) }, {"name": "exp", "symbols": ["text", (lexer.has("comma") ? {type: "comma"} : comma), "_", "text", "_", "differentiator", "_", "differentiator"], "postprocess": ([name, _, __, group, ___, groupDiff1, ____, groupDiff2]) => ({ name, group: {...group, differentiators: [groupDiff1, groupDiff2]}, }) }, {"name": "exp", "symbols": ["sbahnUbahn", "_", "text"], "postprocess": ([sbahnUbahn, _, name]) => ({ sbahnUbahn, name, }) }, {"name": "exp", "symbols": ["sbahnUbahn", "_", "text", "_", "differentiator"], "postprocess": ([sbahnUbahn, _, name, __, diff]) => ({ sbahnUbahn, name, differentiators: [diff], }) }, {"name": "exp", "symbols": ["sbahnUbahn", "_", "text", "_", "differentiator", "_", "bhf"], "postprocess": ([sbahnUbahn, _, name, __, diff, ___, bhf]) => ({ sbahnUbahn, name, differentiators: [diff], bhf, }) }, {"name": "exp", "symbols": ["sbahnUbahn", "_", "text", "_", "differentiator", "_", "part"], "postprocess": ([sbahnUbahn, _, name, __, diff, ___, part]) => ({ sbahnUbahn, name, differentiators: [diff], part, }) }, {"name": "exp", "symbols": ["text", "_", "differentiator", "_", "part"], "postprocess": ([name, _, diff, __, part]) => ({ name, differentiators: [diff], part, }) }, {"name": "exp", "symbols": ["text", "_", "part", "_", "differentiator"], "postprocess": ([name, _, part, __, diff]) => ({ name, differentiators: [diff], part, }) }, {"name": "exp", "symbols": ["sbahnUbahn", "_", "text", "_", "part"], "postprocess": ([sbahnUbahn, _, name, __, part]) => ({ sbahnUbahn, name, part, }) }, {"name": "exp", "symbols": ["sbahnUbahn", "_", "text", "_", "part", "_", "differentiator"], "postprocess": ([sbahnUbahn, _, name, __, part, ___, diff]) => ({ sbahnUbahn, name, differentiators: [diff], part, }) }, {"name": "exp", "symbols": ["text", "_", "part"], "postprocess": ([name, _, part]) => ({ name, part, }) }, {"name": "exp", "symbols": ["text", "_", "part", (lexer.has("comma") ? {type: "comma"} : comma), "_", "text"], "postprocess": ([name, _, part, __, ___, group]) => ({ name, part, group, }) }, {"name": "exp", "symbols": ["text", "_", "part", (lexer.has("comma") ? {type: "comma"} : comma), "_", "text", "_", "differentiator"], "postprocess": ([name, _, part, __, ___, group, ____, groupDiff]) => ({ name, part, group: {...group, differentiators: [groupDiff]}, }) }, {"name": "exp", "symbols": ["text", (lexer.has("comma") ? {type: "comma"} : comma), "_", "text", "_", "part"], "postprocess": ([group, _, __, name, ___, part]) => ({ name, part, group, }) }, {"name": "exp", "symbols": ["text", (lexer.has("comma") ? {type: "comma"} : comma), "_", "text", (lexer.has("comma") ? {type: "comma"} : comma), "_", "text"], "postprocess": ([group, _, __, name, ___, ____, part]) => ({ name, part: [part], group, }) }, {"name": "differentiator", "symbols": [(lexer.has("lParen") ? {type: "lParen"} : lParen), (lexer.has("licensePlate") ? {type: "licensePlate"} : licensePlate), (lexer.has("rParen") ? {type: "rParen"} : rParen)], "postprocess": ([_, licPl]) => asDifferentiator(licPl) }, {"name": "differentiator$ebnf$1", "symbols": [(lexer.has("dot") ? {type: "dot"} : dot)], "postprocess": id}, {"name": "differentiator$ebnf$1", "symbols": [], "postprocess": function(d) {return null;}}, {"name": "differentiator", "symbols": [(lexer.has("lParen") ? {type: "lParen"} : lParen), (lexer.has("differentiator") ? {type: "differentiator"} : differentiator), "differentiator$ebnf$1", (lexer.has("rParen") ? {type: "rParen"} : rParen)], "postprocess": ([_, diff]) => asDifferentiator(diff) }, {"name": "differentiator$ebnf$2", "symbols": [(lexer.has("dot") ? {type: "dot"} : dot)], "postprocess": id}, {"name": "differentiator$ebnf$2", "symbols": [], "postprocess": function(d) {return null;}}, {"name": "differentiator", "symbols": [(lexer.has("lParen") ? {type: "lParen"} : lParen), (lexer.has("differentiator") ? {type: "differentiator"} : differentiator), "differentiator$ebnf$2"], "postprocess": ([_, diff]) => asDifferentiator(diff) }, {"name": "differentiator", "symbols": [(lexer.has("lParen") ? {type: "lParen"} : lParen), (lexer.has("atNotation") ? {type: "atNotation"} : atNotation), "_", (lexer.has("licensePlate") ? {type: "licensePlate"} : licensePlate), (lexer.has("rParen") ? {type: "rParen"} : rParen)], "postprocess": ([_, at, space, licPl]) => combineAtNotation([at, space, licPl], _id([licPl])) }, {"name": "differentiator$ebnf$3", "symbols": [(lexer.has("dot") ? {type: "dot"} : dot)], "postprocess": id}, {"name": "differentiator$ebnf$3", "symbols": [], "postprocess": function(d) {return null;}}, {"name": "differentiator", "symbols": [(lexer.has("lParen") ? {type: "lParen"} : lParen), (lexer.has("atNotation") ? {type: "atNotation"} : atNotation), "_", (lexer.has("differentiator") ? {type: "differentiator"} : differentiator), "differentiator$ebnf$3", (lexer.has("rParen") ? {type: "rParen"} : rParen)], "postprocess": ([_, at, space, diff, dot]) => combineAtNotation([at, space, diff, dot], _id([diff])) }, {"name": "differentiator$ebnf$4", "symbols": [(lexer.has("dot") ? {type: "dot"} : dot)], "postprocess": id}, {"name": "differentiator$ebnf$4", "symbols": [], "postprocess": function(d) {return null;}}, {"name": "differentiator", "symbols": [(lexer.has("atNotation") ? {type: "atNotation"} : atNotation), "_", (lexer.has("differentiator") ? {type: "differentiator"} : differentiator), "differentiator$ebnf$4"], "postprocess": ([at, space, diff, dot]) => combineAtNotation([at, space, diff, dot], _id([diff])) }, {"name": "differentiator", "symbols": [(lexer.has("atNotation") ? {type: "atNotation"} : atNotation), "_", (lexer.has("word") ? {type: "word"} : word)], "postprocess": ([at, space, word]) => combineAtNotation([at, space, word], _id([word])) }, {"name": "bhf", "symbols": [(lexer.has("station") ? {type: "station"} : station)], "postprocess": _id}, {"name": "part", "symbols": [(lexer.has("lBracket") ? {type: "lBracket"} : lBracket), (lexer.has("station") ? {type: "station"} : station), (lexer.has("rBracket") ? {type: "rBracket"} : rBracket)], "postprocess": ([_, station]) => [station] }, {"name": "part", "symbols": [(lexer.has("lBracket") ? {type: "lBracket"} : lBracket), "line", (lexer.has("rBracket") ? {type: "rBracket"} : rBracket)], "postprocess": ([_, line]) => [line] }, {"name": "part$subexpression$1", "symbols": [(lexer.has("lBracket") ? {type: "lBracket"} : lBracket)]}, {"name": "part$subexpression$1", "symbols": [(lexer.has("lParen") ? {type: "lParen"} : lParen)]}, {"name": "part$subexpression$2", "symbols": [(lexer.has("rBracket") ? {type: "rBracket"} : rBracket)]}, {"name": "part$subexpression$2", "symbols": [(lexer.has("rParen") ? {type: "rParen"} : rParen)]}, {"name": "part", "symbols": ["part$subexpression$1", "words", "part$subexpression$2"], "postprocess": ([_, words]) => [words] }, {"name": "part", "symbols": [(lexer.has("lBracket") ? {type: "lBracket"} : lBracket), "words"], "postprocess": ([_, words]) => [words] }, {"name": "part", "symbols": ["lines"], "postprocess": id}, {"name": "lines", "symbols": ["line"], "postprocess": ([line]) => [line] }, {"name": "lines", "symbols": ["line", (lexer.has("space") ? {type: "space"} : space), "lines"], "postprocess": ([line, _, lines]) => [line, ...lines] }, {"name": "line", "symbols": [(lexer.has("ubahnLine") ? {type: "ubahnLine"} : ubahnLine)], "postprocess": asLine}, {"name": "line", "symbols": [(lexer.has("sbahnLine") ? {type: "sbahnLine"} : sbahnLine)], "postprocess": asLine}, {"name": "text", "symbols": ["word", "_", "text"], "postprocess": collapseText}, {"name": "text", "symbols": ["word", "_", (lexer.has("slash") ? {type: "slash"} : slash), "_", "text"], "postprocess": collapseText}, {"name": "text", "symbols": ["word", "_", (lexer.has("dot") ? {type: "dot"} : dot), "_", "text"], "postprocess": collapseText}, {"name": "text", "symbols": ["word", "_", (lexer.has("lParen") ? {type: "lParen"} : lParen), "_", "text"], "postprocess": collapseText}, {"name": "text", "symbols": ["word", "_", (lexer.has("lParen") ? {type: "lParen"} : lParen)], "postprocess": collapseText}, {"name": "text", "symbols": ["word", "_", (lexer.has("lBracket") ? {type: "lBracket"} : lBracket), "_", "text"], "postprocess": collapseText}, {"name": "text", "symbols": ["word", "_", (lexer.has("lBracket") ? {type: "lBracket"} : lBracket)], "postprocess": collapseText}, {"name": "text", "symbols": ["word"], "postprocess": collapseText}, {"name": "word", "symbols": [(lexer.has("word") ? {type: "word"} : word)], "postprocess": id}, {"name": "word", "symbols": [(lexer.has("differentiator") ? {type: "differentiator"} : differentiator)], "postprocess": id}, {"name": "word", "symbols": [(lexer.has("station") ? {type: "station"} : station)], "postprocess": id}, {"name": "word", "symbols": [(lexer.has("licensePlate") ? {type: "licensePlate"} : licensePlate)], "postprocess": id}, {"name": "sbahnUbahn", "symbols": [(lexer.has("sbahnUbahn") ? {type: "sbahnUbahn"} : sbahnUbahn)], "postprocess": asSbahnUbahn}, {"name": "sbahnUbahn", "symbols": [(lexer.has("sbahn") ? {type: "sbahn"} : sbahn)], "postprocess": asSbahnUbahn}, {"name": "sbahnUbahn", "symbols": [(lexer.has("ubahn") ? {type: "ubahn"} : ubahn)], "postprocess": asSbahnUbahn}, {"name": "words", "symbols": [(lexer.has("word") ? {type: "word"} : word), "_", "words"], "postprocess": collapseText}, {"name": "words", "symbols": [(lexer.has("word") ? {type: "word"} : word), "_", (lexer.has("slash") ? {type: "slash"} : slash), "_", "words"], "postprocess": collapseText}, {"name": "words", "symbols": [(lexer.has("word") ? {type: "word"} : word), "_", (lexer.has("dot") ? {type: "dot"} : dot), "_", "words"], "postprocess": collapseText}, {"name": "words", "symbols": [(lexer.has("word") ? {type: "word"} : word)], "postprocess": collapseText}, {"name": "_", "symbols": [(lexer.has("space") ? {type: "space"} : space)], "postprocess": id}, {"name": "_", "symbols": [], "postprocess": () => ({type: 'text', text: ''})} ] , ParserStart: "exp" } if (typeof module !== 'undefined'&& typeof module.exports !== 'undefined') { module.exports = grammar; } else { window.grammar = grammar; } })();