-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: case-insensitive antlr parsing (#9)
* chore: case-insensitive antlr parsing * chore: remove unused `errorListener` option
- Loading branch information
Showing
3 changed files
with
117 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { CharStream } from 'antlr4ts'; | ||
import { Interval } from 'antlr4ts/misc/Interval'; | ||
|
||
export class LowerCaseCharStream implements CharStream { | ||
private readonly stream: CharStream; | ||
|
||
/** | ||
* Constructs a new LowerCaseCharStream wrapping the given {@link CharStream} forcing all | ||
* characters to lower case. | ||
* @param {CharStream} stream The stream to wrap. | ||
*/ | ||
constructor(stream: CharStream) { | ||
this.stream = stream; | ||
} | ||
|
||
getText(interval: Interval): string { | ||
return this.stream.getText(interval); | ||
} | ||
|
||
consume(): void { | ||
this.stream.consume(); | ||
} | ||
|
||
LA(i: number): number { | ||
const c = this.stream.LA(i); | ||
if (c <= 0) { | ||
return c; | ||
} | ||
const char = String.fromCharCode(c).toLowerCase(); | ||
return char.codePointAt(0) ?? char.charCodeAt(0); | ||
} | ||
|
||
mark(): number { | ||
return this.stream.mark(); | ||
} | ||
|
||
release(marker: number): void { | ||
this.stream.release(marker); | ||
} | ||
seek(index: number): void { | ||
this.stream.seek(index); | ||
} | ||
|
||
get index(): number { | ||
return this.stream.index; | ||
} | ||
|
||
get size(): number { | ||
return this.stream.size; | ||
} | ||
|
||
get sourceName(): string { | ||
return this.stream.sourceName; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters