Skip to content

Commit 2406774

Browse files
jimidleparrt
authored andcommitted
fix: Allow CommonTokenStream to reset properly
- There is a flag in CommonTokenStream that indicates whether EOF has already been fetched/seen. This was not being reset when a new TokenSource was given to an existing CommonTokenStream and there was no Reset() function which was unfortunately not exported and not part of the interface for TokenStream. - Reset the flag when a new source is provided - Export the Reset() function so that a TokenStream can be rewound Signed-off-by: Jim.Idle <[email protected]>
1 parent 3aff09a commit 2406774

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

runtime/Go/antlr/v4/common_token_stream.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ func (c *CommonTokenStream) Mark() int {
6666

6767
func (c *CommonTokenStream) Release(_ int) {}
6868

69-
func (c *CommonTokenStream) reset() {
69+
func (c *CommonTokenStream) Reset() {
70+
c.fetchedEOF = false
71+
c.tokens = make([]Token, 0)
7072
c.Seek(0)
7173
}
7274

@@ -196,6 +198,7 @@ func (c *CommonTokenStream) SetTokenSource(tokenSource TokenSource) {
196198
c.tokenSource = tokenSource
197199
c.tokens = make([]Token, 0)
198200
c.index = -1
201+
c.fetchedEOF = false
199202
}
200203

201204
// NextTokenOnChannel returns the index of the next token on channel given a

runtime/Go/antlr/v4/token_stream.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ type TokenStream interface {
88
IntStream
99

1010
LT(k int) Token
11+
Reset()
1112

1213
Get(index int) Token
1314
GetTokenSource() TokenSource

runtime/Go/antlr/v4/tokenstream_rewriter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ func (tsr *TokenStreamRewriter) RollbackDefault(instructionIndex int) {
304304
tsr.Rollback(DefaultProgramName, instructionIndex)
305305
}
306306

307-
// DeleteProgram reset the program so that no instructions exist
307+
// DeleteProgram Reset the program so that no instructions exist
308308
func (tsr *TokenStreamRewriter) DeleteProgram(programName string) {
309309
tsr.Rollback(programName, MinTokenIndex) //TODO: double test on that cause lower bound is not included
310310
}

0 commit comments

Comments
 (0)