antlr-ng
Version:
Next generation ANTLR Tool
67 lines (66 loc) • 3.14 kB
TypeScript
import { GrammarAST } from "../tool/ast/GrammarAST.js";
import { AttributeDict } from "../tool/AttributeDict.js";
import { IssueCode } from "../tool/Issues.js";
import { Grammar } from "../tool/Grammar.js";
import { Rule } from "../tool/Rule.js";
import { SymbolCollector } from "./SymbolCollector.js";
/**
* Check for symbol problems; no side-effects. Inefficient to walk rules
* and such multiple times, but I like isolating all error checking outside
* of code that actually defines symbols etc...
*
* Side-effect: strip away redef'd rules.
*/
export declare class SymbolChecks {
protected g: Grammar;
protected collector: SymbolCollector;
protected nameToRuleMap: Map<string, Rule>;
protected tokenIDs: Set<string>;
protected actionScopeToActionNames: Map<string, Set<string>>;
protected readonly reservedNames: Set<string>;
constructor(g: Grammar, collector: SymbolCollector);
process(): void;
checkActionRedefinitions(actions: GrammarAST[]): void;
/**
* Make sure a label doesn't conflict with another symbol.
* Labels must not conflict with: rules, tokens, scope names,
* return values, parameters, and rule-scope dynamic attributes
* defined in surrounding rule. Also they must have same type
* for repeated defs.
*/
checkForLabelConflicts(rules: Rule[]): void;
checkForLabelConflict(r: Rule, labelID: GrammarAST): void;
checkForAttributeConflicts(r: Rule): void;
checkForModeConflicts(g: Grammar): void;
/**
* Algorithm steps:
* 1. Collect all simple string literals (i.e. 'asdf', 'as' 'df', but not [a-z]+, 'a'..'z')
* for all lexer rules in each mode except of autogenerated tokens ({@link getSingleTokenValues})
* 2. Compare every string literal with each other ({@link checkForOverlap})
* and throw TOKEN_UNREACHABLE warning if the same string found.
* Complexity: O(m * n^2 / 2), approximately equals to O(n^2)
* where m - number of modes, n - average number of lexer rules per mode.
* See also testUnreachableTokens unit test for details.
*/
checkForUnreachableTokens(g: Grammar): void;
checkRuleArgs(g: Grammar, ruleRefs: GrammarAST[]): void;
checkForQualifiedRuleIssues(g: Grammar, qualifiedRuleRefs: GrammarAST[]): void;
protected checkDeclarationRuleConflicts(r: Rule, attributes: AttributeDict | undefined, ruleNames: Set<string>, errorType: IssueCode): void;
protected checkLocalConflictingDeclarations(r: Rule, attributes: AttributeDict | undefined, referenceAttributes: AttributeDict | undefined, errorType: IssueCode): void;
protected checkReservedNames(rules: Rule[]): void;
private checkLabelPairs;
private findAltLabelName;
private checkForTypeMismatch;
/**
* {@return} list of simple string literals for rule {@param rule}
*/
private getSingleTokenValues;
/**
* For same rule compare values from next index:
* TOKEN_WITH_SAME_VALUES: 'asdf' | 'asdf';
* For different rules compare from start value:
* TOKEN1: 'asdf';
* TOKEN2: 'asdf';
*/
private checkForOverlap;
}