aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Hanley <felix@userspace.com.au>2020-07-31 03:42:25 +0000
committerFelix Hanley <felix@userspace.com.au>2020-07-31 03:42:25 +0000
commit3995bd02a8fc232eaf705588c61dbbc085ad23a5 (patch)
treec14e23405c55762b763be261c95c0f228cb4a7d7
parent78cfd8633bdf1f77b40a10929556d30042cb5dff (diff)
downloadlexer-master.tar.gz
lexer-master.tar.bz2
Synchronous testsHEADmaster
-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 {