UNPKG

antlr-ng

Version:

Next generation ANTLR Tool

98 lines (97 loc) 2.75 kB
var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); import { IntervalSet, Token } from "antlr4ng"; import { CharSupport } from "../misc/CharSupport.js"; import { Character } from "./Character.js"; const isTokenName = /* @__PURE__ */ __name((id) => { return Character.isUpperCase(id.charCodeAt(0)); }, "isTokenName"); const isCodeBlockForOuterMostAlt = /* @__PURE__ */ __name((obj) => { return "codeBlockLevel" in obj && "treeLevel" in obj; }, "isCodeBlockForOuterMostAlt"); const convertMapToString = /* @__PURE__ */ __name((map) => { const entries = []; map.forEach((value, key) => { entries.push(`${key}=${value}`); }); return `{${entries.join(", ")}}`; }, "convertMapToString"); const convertArrayToString = /* @__PURE__ */ __name((a, separator = ", ") => { return "[" + a.join(separator) + "]"; }, "convertArrayToString"); const dupTree = /* @__PURE__ */ __name((t, parent) => { const newTree = t.dupNode(); newTree.childIndex = t.childIndex; if (parent) { newTree.parent = parent; } const n = t.children.length; for (let i = 0; i < n; i++) { const child = t.children[i]; const newSubTree = dupTree(child, t); newTree.addChild(newSubTree); } return newTree; }, "dupTree"); const getTokenDisplayName = /* @__PURE__ */ __name((ttype, vocabulary, isLexer) => { if (isLexer) { return CharSupport.getANTLRCharLiteralForChar(ttype); } if (ttype === Token.EOF) { return "EOF"; } if (ttype === Token.INVALID_TYPE) { return "<INVALID>"; } const result = vocabulary.getDisplayName(ttype); if (result !== null) { return result; } return String(ttype); }, "getTokenDisplayName"); const format = /* @__PURE__ */ __name((formatString, ...args) => { return formatString.replace(/%([xXdfs])/g, (match, format2) => { const value = args.shift(); switch (format2) { case "x": { return Number(value).toString(16); } case "X": { return Number(value).toString(16).toUpperCase(); } case "f": { return Number(value).toFixed(6); } case "s": case "d": { return String(value); } default: { return match; } } }); }, "format"); const disjoint = /* @__PURE__ */ __name((altLook) => { const combined = new IntervalSet(); for (const look of altLook) { if (look === void 0) { return false; } if (look.and(combined).length !== 0) { return false; } combined.addSet(look); } return true; }, "disjoint"); export { convertArrayToString, convertMapToString, disjoint, dupTree, format, getTokenDisplayName, isCodeBlockForOuterMostAlt, isTokenName };