Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions runtime/Go/antlr/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ const (
LexerMaxCharValue = 0x10FFFF
)

func (b *BaseLexer) reset() {
func (b *BaseLexer) Reset() {
// wack Lexer state variables
if b.input != nil {
b.input.Seek(0) // rewind the input
Expand Down Expand Up @@ -282,7 +282,7 @@ func (b *BaseLexer) inputStream() CharStream {
func (b *BaseLexer) SetInputStream(input CharStream) {
b.input = nil
b.tokenFactorySourcePair = &TokenSourceCharStreamPair{b, b.input}
b.reset()
b.Reset()
b.input = input
b.tokenFactorySourcePair = &TokenSourceCharStreamPair{b, b.input}
}
Expand Down
35 changes: 35 additions & 0 deletions runtime/Go/antlr/testing_api_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Run via "go test"

package antlr

import (
"testing"
)

func next(t *testing.T, lexer *LexerB, want string) {
var token = lexer.NextToken()
var got = token.String()
if got != want {
t.Errorf("got %q, wanted %q", got, want)
}
}

func TestString(t *testing.T){
str := NewInputStream("a b c 1 2 3")
lexer := NewLexerB(str)
next(t, lexer, "[@-1,0:0='a',<1>,1:0]")
next(t, lexer, "[@-1,1:1=' ',<7>,1:1]")
next(t, lexer, "[@-1,2:2='b',<1>,1:2]")
next(t, lexer, "[@-1,3:3=' ',<7>,1:3]")
next(t, lexer, "[@-1,4:4='c',<1>,1:4]")
next(t, lexer, "[@-1,5:5=' ',<7>,1:5]")
next(t, lexer, "[@-1,6:6='1',<2>,1:6]")
next(t, lexer, "[@-1,7:7=' ',<7>,1:7]")
next(t, lexer, "[@-1,8:8='2',<2>,1:8]")
next(t, lexer, "[@-1,9:9=' ',<7>,1:9]")
next(t, lexer, "[@-1,10:10='3',<2>,1:10]")
next(t, lexer, "[@-1,11:10='<EOF>',<-1>,1:11]")
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be a test on Reset method as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, looks like I missed that. Thanks.




1 change: 1 addition & 0 deletions runtime/Go/antlr/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type Token interface {

GetTokenSource() TokenSource
GetInputStream() CharStream
String() string
}

type BaseToken struct {
Expand Down