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

View File

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