UNPKG

antlr-ng

Version:

Next generation ANTLR Tool

115 lines (114 loc) 4.48 kB
var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); import { IntervalSet } from "antlr4ng"; import { propertyAliases, propertyCodePointRanges, shortToLongPropertyNameMap, shortToLongPropertyValueMap, binaryPropertyNames } from "../generated/UnicodeData.js"; const defaultCategories = ["block", "general_category", "binary_property", "script"]; const getPropertyCodePoints = /* @__PURE__ */ __name((propertyCodeOrAlias) => { propertyCodeOrAlias = propertyCodeOrAlias.toLowerCase().replaceAll("-", "_"); let set = propertyCodePointRanges.get(propertyCodeOrAlias); if (set) { return { status: "ok", codePoints: set }; } const parts = propertyCodeOrAlias.split("="); if (parts.length === 1) { let aliasList = propertyAliases.get(propertyCodeOrAlias) ?? []; if (aliasList.length > 0) { if (aliasList.length > 1) { const entry = aliasList.find((value) => { for (const category of defaultCategories) { if (value.startsWith(`${category}=`)) { return true; } } return false; }); if (entry) { set = propertyCodePointRanges.get(entry); return { status: set !== void 0 ? "ok" : "not found", codePoints: set }; } return { status: "multiple", candidates: aliasList }; } set = propertyCodePointRanges.get(aliasList[0]); return { status: set !== void 0 ? "ok" : "not found", codePoints: set }; } if (propertyCodeOrAlias.startsWith("in")) { aliasList = propertyAliases.get(propertyCodeOrAlias.substring(2)) ?? []; if (aliasList.length > 0) { if (aliasList.length > 1) { const entry = aliasList.find((value) => { return value.startsWith("block="); }); if (entry) { set = propertyCodePointRanges.get(entry); return { status: set !== void 0 ? "ok" : "not found", codePoints: set }; } return { status: "multiple", candidates: aliasList }; } set = propertyCodePointRanges.get(aliasList[0]); return { status: set !== void 0 ? "ok" : "not found", codePoints: set }; } } const longValueList = shortToLongPropertyValueMap.get(propertyCodeOrAlias) ?? []; if (longValueList.length > 0) { if (longValueList.length > 1) { return { status: "multiple", candidates: longValueList }; } set = propertyCodePointRanges.get(longValueList[0]); return { status: set !== void 0 ? "ok" : "not found", codePoints: set }; } const longName = shortToLongPropertyNameMap.get(propertyCodeOrAlias); if (longName) { aliasList = propertyAliases.get(longName) ?? []; if (aliasList.length > 0) { if (aliasList.length > 1) { return { status: "multiple", candidates: aliasList }; } set = propertyCodePointRanges.get(aliasList[0]); return { status: set !== void 0 ? "ok" : "not found", codePoints: set }; } } } if (parts.length === 2) { const propertyName = shortToLongPropertyNameMap.get(parts[0]) ?? parts[0]; if (binaryPropertyNames.has(propertyName)) { const value = parts[1].toLowerCase(); if (value === "true" || value === "yes" || value === "t" || value === "y") { set = propertyCodePointRanges.get(parts[0]); return { status: set !== void 0 ? "ok" : "not found", codePoints: set }; } const fullSet = IntervalSet.of(0, 1114111); set = propertyCodePointRanges.get(parts[0]); set = fullSet.subtract(set); return { status: "ok", codePoints: set }; } let propertyValueList = shortToLongPropertyValueMap.get(parts[1]); if (!propertyValueList) { propertyValueList = propertyAliases.get(parts[1]); if (!propertyValueList) { const longName = shortToLongPropertyNameMap.get(parts[1]); if (longName) { propertyValueList = [`${propertyName}=${longName}`]; } } } if (propertyValueList) { const entry = propertyValueList.find((value) => { return value.startsWith(`${propertyName}=`); }); if (entry) { set = propertyCodePointRanges.get(entry); return { status: set !== void 0 ? "ok" : "not found", codePoints: set }; } } } return { status: "not found" }; }, "getPropertyCodePoints"); export { getPropertyCodePoints };