UNPKG

simc-ast-builder

Version:

Parser and AST generator for SimulationCraft files

45 lines 1.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.extractAccessParts = extractAccessParts; exports.getFirstFieldText = getFirstFieldText; /** * Extracts access parts from a parser context. * Always splits on dots, so "buff.foo.up" becomes ["buff", "foo", "up"]. * This is written in a flat, explicit, and typesafe way for clarity. */ function extractAccessParts(context) { const parts = []; for (let i = 0; i < context.childCount; i++) { const child = context.getChild(i); const text = child.text; // Skip dots, semicolons, and empty strings if (!text || text === "." || text === ";") { continue; } // If the text contains dots, split it into parts if (text.includes(".")) { const splitParts = text.split("."); for (const part of splitParts) { parts.push(part); } } else { parts.push(text); } } return parts; } /** * Returns the .text of the first non-undefined result from the provided field getter functions. * Usage: getFirstFieldText(ctx, ctx.OP_GT, ctx.OP_LT, ctx.OP_GE, ctx.OP_LE) */ function getFirstFieldText(...getters) { for (const getter of getters) { const token = getter(); if (token) { return token.text; } } return undefined; } //# sourceMappingURL=fieldUtils.js.map