make eof token type private

This commit is contained in:
Brian Picciano 2014-10-18 12:25:16 -04:00
parent 6fa4b3b11d
commit af6d4dc3c3
2 changed files with 12 additions and 12 deletions

View File

@ -16,7 +16,7 @@ const (
OpenParen OpenParen
CloseParen CloseParen
Err Err
EOF eof
) )
var invalidBareStringRunes = map[rune]bool{ var invalidBareStringRunes = map[rune]bool{
@ -79,7 +79,7 @@ func (l *Lexer) spin() {
func (l *Lexer) Next() *Token { func (l *Lexer) Next() *Token {
t := <-l.ch t := <-l.ch
if t.Type == EOF { if t.Type == eof {
return nil return nil
} }
return t return t
@ -118,7 +118,7 @@ func (l *Lexer) readRune() (rune, error) {
func (l *Lexer) err(err error) lexerFunc { func (l *Lexer) err(err error) lexerFunc {
if err == io.EOF { if err == io.EOF {
l.ch <- &Token{EOF, ""} l.ch <- &Token{eof, ""}
} else { } else {
l.ch <- &Token{Err, err.Error()} l.ch <- &Token{Err, err.Error()}
} }

View File

@ -7,34 +7,34 @@ import (
func TestLexer(t *T) { func TestLexer(t *T) {
m := map[string][]Token{ m := map[string][]Token{
"": {{EOF, ""}}, "": {{eof, ""}},
" \t": {{EOF, ""}}, " \t": {{eof, ""}},
"a b c": {{BareString, "a"}, "a b c": {{BareString, "a"},
{BareString, "b"}, {BareString, "b"},
{BareString, "c"}, {BareString, "c"},
{EOF, ""}}, {eof, ""}},
"\"foo\" bar": {{QuotedString, "\"foo\""}, "\"foo\" bar": {{QuotedString, "\"foo\""},
{BareString, "bar"}, {BareString, "bar"},
{EOF, ""}}, {eof, ""}},
"\"foo\nbar\" baz": {{QuotedString, "\"foo\nbar\""}, "\"foo\nbar\" baz": {{QuotedString, "\"foo\nbar\""},
{BareString, "baz"}, {BareString, "baz"},
{EOF, ""}}, {eof, ""}},
"( foo bar ) baz": {{OpenParen, "("}, "( foo bar ) baz": {{OpenParen, "("},
{BareString, "foo"}, {BareString, "foo"},
{BareString, "bar"}, {BareString, "bar"},
{CloseParen, ")"}, {CloseParen, ")"},
{BareString, "baz"}, {BareString, "baz"},
{EOF, ""}}, {eof, ""}},
"((foo-bar))": {{OpenParen, "("}, "((foo-bar))": {{OpenParen, "("},
{OpenParen, "("}, {OpenParen, "("},
{BareString, "foo-bar"}, {BareString, "foo-bar"},
{CloseParen, ")"}, {CloseParen, ")"},
{CloseParen, ")"}, {CloseParen, ")"},
{EOF, ""}}, {eof, ""}},
"(\"foo\nbar\")": {{OpenParen, "("}, "(\"foo\nbar\")": {{OpenParen, "("},
{QuotedString, "\"foo\nbar\""}, {QuotedString, "\"foo\nbar\""},
{CloseParen, ")"}, {CloseParen, ")"},
{EOF, ""}}, {eof, ""}},
} }
for input, output := range m { for input, output := range m {
@ -43,7 +43,7 @@ func TestLexer(t *T) {
for i := range output { for i := range output {
tok := l.Next() tok := l.Next()
if tok == nil { if tok == nil {
if output[i].Type == EOF { if output[i].Type == eof {
continue continue
} }
t.Fatalf("input: %q (%d) %#v != %#v", input, i, output[i], tok) t.Fatalf("input: %q (%d) %#v != %#v", input, i, output[i], tok)