Skip to content

Commit

Permalink
Fixed bug that created additional lexer action entries.
Browse files Browse the repository at this point in the history
The subtleties wrt. to object equality vs. reference equality between Java and TypeScript are a constant source of tricky bugs. However, there's not need to always use a OrderedHashMap if the key is a standard type (a type without equals/hashMap methods) as the standard Map already maintains insertion order.
  • Loading branch information
mike-lischke committed Dec 30, 2024
1 parent a92c36c commit 5799e87
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/analysis/LeftRecursiveRuleAnalyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ enum Associativity {
export class LeftRecursiveRuleAnalyzer extends LeftRecursiveRuleWalker {

public tool: Tool;
public binaryAlts = new OrderedHashMap<number, LeftRecursiveRuleAltInfo>();
public ternaryAlts = new OrderedHashMap<number, LeftRecursiveRuleAltInfo>();
public suffixAlts = new OrderedHashMap<number, LeftRecursiveRuleAltInfo>();
public binaryAlts = new Map<number, LeftRecursiveRuleAltInfo>();
public ternaryAlts = new Map<number, LeftRecursiveRuleAltInfo>();
public suffixAlts = new Map<number, LeftRecursiveRuleAltInfo>();
public prefixAndOtherAlts = new Array<LeftRecursiveRuleAltInfo>();

/** Pointer to ID node of ^(= ID element) */
Expand Down
6 changes: 3 additions & 3 deletions src/automata/LexerATNFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
/* eslint-disable jsdoc/require-param, jsdoc/require-returns */

import {
ActionTransition, ATN, ATNState, AtomTransition, BasicState, CodePointTransitions, CommonToken, IntervalSet,
IntStream, Lexer, LexerAction, LexerChannelAction, LexerCustomAction, LexerModeAction, LexerMoreAction,
ActionTransition, ATN, ATNState, AtomTransition, BasicState, CodePointTransitions, CommonToken, HashMap,
IntervalSet, IntStream, Lexer, LexerAction, LexerChannelAction, LexerCustomAction, LexerModeAction, LexerMoreAction,
LexerPopModeAction, LexerPushModeAction, LexerSkipAction, LexerTypeAction, NotSetTransition, SetTransition, Token,
TokensStartState, Transition
} from "antlr4ng";
Expand Down Expand Up @@ -122,7 +122,7 @@ export class LexerATNFactory extends ParserATNFactory {
/**
* Maps from a {@link LexerAction} object to the action index.
*/
private actionToIndexMap = new Map<LexerAction, number>();
private actionToIndexMap = new HashMap<LexerAction, number>();

private readonly ruleCommands = new Array<string>();

Expand Down
3 changes: 1 addition & 2 deletions src/tool/Grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import { TokenVocabParser } from "../parse/TokenVocabParser.js";
import { GrammarType } from "../support/GrammarType.js";
import type { IGrammar, ITool } from "../types.js";

import { OrderedHashMap } from "../misc/OrderedHashMap.js";
import type { CommonTree } from "../tree/CommonTree.js";
import { ANTLRMessage } from "./ANTLRMessage.js";
import { ANTLRToolListener } from "./ANTLRToolListener.js";
Expand Down Expand Up @@ -151,7 +150,7 @@ export class Grammar implements IGrammar, AttributeResolver {
* All rules defined in this specific grammar, not imported. Also does
* not include lexical rules if combined.
*/
public rules = new OrderedHashMap<string, Rule>();
public rules = new Map<string, Rule>();

public indexToRule = new Array<Rule>(); // used to invent rule names for 'keyword', ';', ... (0..n-1)

Expand Down
2 changes: 1 addition & 1 deletion src/tool/LeftRecursiveRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class LeftRecursiveRule extends Rule {
/** Get -&gt; labels from those alts we deleted for left-recursive rules. */

public override getAltLabels(): Map<string, Array<[number, AltAST]>> | null {
const labels = new OrderedHashMap<string, Array<[number, AltAST]>>();
const labels = new Map<string, Array<[number, AltAST]>>();
const normalAltLabels = super.getAltLabels();
if (normalAltLabels !== null) {
normalAltLabels.forEach((value, key) => {
Expand Down

0 comments on commit 5799e87

Please sign in to comment.