UNPKG

antlr-ng

Version:

Next generation ANTLR Tool

51 lines (50 loc) 2.09 kB
var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); import { Character } from "../support/Character.js"; import { IssueCode } from "../tool/Issues.js"; class RangeBorderCharactersData { constructor(lowerFrom, upperFrom, lowerTo, upperTo, mixOfLowerAndUpperCharCase) { this.lowerFrom = lowerFrom; this.upperFrom = upperFrom; this.lowerTo = lowerTo; this.upperTo = upperTo; this.mixOfLowerAndUpperCharCase = mixOfLowerAndUpperCharCase; } static { __name(this, "RangeBorderCharactersData"); } static getAndCheckCharactersData(from, to, grammar, tree, reportRangeContainsNotImpliedCharacters) { const lowerFrom = Character.toLowerCase(from); const upperFrom = Character.toUpperCase(from); const lowerTo = Character.toLowerCase(to); const upperTo = Character.toUpperCase(to); const isLowerFrom = lowerFrom === from; const isLowerTo = lowerTo === to; const mixOfLowerAndUpperCharCase = isLowerFrom && !isLowerTo || !isLowerFrom && isLowerTo; if (reportRangeContainsNotImpliedCharacters && mixOfLowerAndUpperCharCase && from <= 127 && to <= 127) { let notImpliedCharacters = ""; for (let i = from; i < to; i++) { if (!Character.isAlphabetic(i)) { notImpliedCharacters += String.fromCodePoint(i); } } if (notImpliedCharacters.length > 0) { grammar.tool.errorManager.grammarError( IssueCode.RangeProbablyContainsNotImpliedCharacter, grammar.fileName, tree.token, String.fromCodePoint(from), String.fromCodePoint(to), notImpliedCharacters.toString() ); } } return new RangeBorderCharactersData(lowerFrom, upperFrom, lowerTo, upperTo, mixOfLowerAndUpperCharCase); } isSingleRange() { return this.lowerFrom === this.upperFrom && this.lowerTo === this.upperTo || this.mixOfLowerAndUpperCharCase || this.lowerTo - this.lowerFrom !== this.upperTo - this.upperFrom; } } export { RangeBorderCharactersData };