UNPKG

@scinorandex/sparse

Version:

Yet another parser generator

62 lines 2.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GrammarTokenType = exports.hydrateProduction = exports.dehydateProduction = void 0; const slex_1 = require("@scinorandex/slex"); const dehydateGrammarToken = ({ column, lexeme, line, type }) => { return { column, lexeme, line, type }; }; const hydrateGrammarToken = (token) => { return new slex_1.Token(token.type, token.lexeme, new slex_1.ColumnAndRow(token.line, token.column), {}); }; const dehydateProduction = (opts) => { const { lhs, identifier, rhs, originalProductionIndex, name } = opts; return { lhs: dehydateGrammarToken(lhs), identifier, name, originalProductionIndex, rhs: rhs.map(({ type, token, identifier, name }) => ({ type, token: dehydateGrammarToken(token), identifier, name, })), }; }; exports.dehydateProduction = dehydateProduction; const hydrateProduction = (production) => { return { lhs: hydrateGrammarToken(production.lhs), identifier: production.identifier, originalProductionIndex: production.originalProductionIndex, name: production.name, rhs: production.rhs.map(({ type, token, name }) => ({ type, token: hydrateGrammarToken(token), identifier: token.lexeme, name, })), }; }; exports.hydrateProduction = hydrateProduction; var GrammarTokenType; (function (GrammarTokenType) { GrammarTokenType[GrammarTokenType["IDENTIFIER"] = 0] = "IDENTIFIER"; GrammarTokenType[GrammarTokenType["L_ANGLE"] = 1] = "L_ANGLE"; GrammarTokenType[GrammarTokenType["R_ANGLE"] = 2] = "R_ANGLE"; GrammarTokenType[GrammarTokenType["L_BRACKET"] = 3] = "L_BRACKET"; GrammarTokenType[GrammarTokenType["R_BRACKET"] = 4] = "R_BRACKET"; GrammarTokenType[GrammarTokenType["L_PAREN"] = 5] = "L_PAREN"; GrammarTokenType[GrammarTokenType["R_PAREN"] = 6] = "R_PAREN"; GrammarTokenType[GrammarTokenType["PIPE"] = 7] = "PIPE"; GrammarTokenType[GrammarTokenType["QUESTION_MARK"] = 8] = "QUESTION_MARK"; GrammarTokenType[GrammarTokenType["COLON"] = 9] = "COLON"; GrammarTokenType[GrammarTokenType["SEMICOLON"] = 10] = "SEMICOLON"; GrammarTokenType[GrammarTokenType["NUMBER"] = 11] = "NUMBER"; GrammarTokenType[GrammarTokenType["EQUALS"] = 12] = "EQUALS"; GrammarTokenType[GrammarTokenType["COMMA"] = 13] = "COMMA"; GrammarTokenType[GrammarTokenType["EOF"] = 14] = "EOF"; GrammarTokenType[GrammarTokenType["PRODUCTION_NAME"] = 15] = "PRODUCTION_NAME"; GrammarTokenType[GrammarTokenType["TOKEN_NAME"] = 16] = "TOKEN_NAME"; })(GrammarTokenType || (exports.GrammarTokenType = GrammarTokenType = {})); //# sourceMappingURL=common.js.map