aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lexer.go8
-rw-r--r--lexer_test.go10
2 files changed, 6 insertions, 12 deletions
diff --git a/lexer.go b/lexer.go
index 35daff9..85c5220 100644
--- a/lexer.go
+++ b/lexer.go
@@ -64,13 +64,7 @@ func New(src string, start StateFunc) *Lexer {
// Start begins executing the Lexer in an asynchronous manner (using a goroutine).
func (l *Lexer) Start() {
- // Take half the string length as a buffer size.
- buffSize := len(l.source) / 2
- if buffSize <= 0 {
- buffSize = 1
- }
- l.tokens = make(chan Token, buffSize)
- go l.run()
+ go l.StartSync()
}
// StartSync starts the lexer synchronously.
diff --git a/lexer_test.go b/lexer_test.go
index 1795f7b..913bade 100644
--- a/lexer_test.go
+++ b/lexer_test.go
@@ -89,7 +89,7 @@ func TestMovingThroughString(t *testing.T) {
func TestNumbers(t *testing.T) {
l := New("123", NumberState)
- l.Start()
+ l.StartSync()
tok, done := l.NextToken()
if done {
t.Fatal("Expected a token but lexer finished")
@@ -123,7 +123,7 @@ func TestNewlines(t *testing.T) {
456
789`
l := New(src, NewlineState)
- l.Start()
+ l.StartSync()
tok, done := l.NextToken()
if done {
t.Fatal("Expected done, but it wasn't.")
@@ -178,7 +178,7 @@ func TestBackup(t *testing.T) {
func TestWhitespace(t *testing.T) {
l := New(" 1", NumberState)
- l.Start()
+ l.StartSync()
l.SkipWhitespace()
tok, done := l.NextToken()
@@ -205,7 +205,7 @@ func TestMultipleTokens(t *testing.T) {
}
l := New("123.hello 675.world", NumberState)
- l.Start()
+ l.StartSync()
for _, c := range cases {
tok, done := l.NextToken()
@@ -234,7 +234,7 @@ func TestMultipleTokens(t *testing.T) {
func TestError(t *testing.T) {
l := New("notaspace", WhitespaceState)
- l.Start()
+ l.StartSync()
tok, done := l.NextToken()
if done {