diff options
Diffstat (limited to 'src/pkg/ebnf')
-rw-r--r-- | src/pkg/ebnf/ebnf_test.go | 45 | ||||
-rw-r--r-- | src/pkg/ebnf/parser.go | 8 |
2 files changed, 24 insertions, 29 deletions
diff --git a/src/pkg/ebnf/ebnf_test.go b/src/pkg/ebnf/ebnf_test.go index 69ad5fed1..e77cf64ad 100644 --- a/src/pkg/ebnf/ebnf_test.go +++ b/src/pkg/ebnf/ebnf_test.go @@ -15,31 +15,26 @@ var fset = token.NewFileSet() var grammars = []string{ -`Program = . -`, - -`Program = foo . -foo = "foo" . -`, - -`Program = "a" | "b" "c" . -`, - -`Program = "a" ... "z" . -`, - -`Program = Song . - Song = { Note } . - Note = Do | (Re | Mi | Fa | So | La) | Ti . - Do = "c" . - Re = "d" . - Mi = "e" . - Fa = "f" . - So = "g" . - La = "a" . - Ti = ti . - ti = "b" . -`, + `Program = .`, + + `Program = foo . + foo = "foo" .`, + + `Program = "a" | "b" "c" .`, + + `Program = "a" ... "z" .`, + + `Program = Song . + Song = { Note } . + Note = Do | (Re | Mi | Fa | So | La) | Ti . + Do = "c" . + Re = "d" . + Mi = "e" . + Fa = "f" . + So = "g" . + La = "a" . + Ti = ti . + ti = "b" .`, } diff --git a/src/pkg/ebnf/parser.go b/src/pkg/ebnf/parser.go index c38530177..818168e11 100644 --- a/src/pkg/ebnf/parser.go +++ b/src/pkg/ebnf/parser.go @@ -18,7 +18,7 @@ type parser struct { scanner scanner.Scanner pos token.Pos // token position tok token.Token // one token look-ahead - lit []byte // token literal + lit string // token literal } @@ -44,7 +44,7 @@ func (p *parser) errorExpected(pos token.Pos, msg string) { // make the error message more specific msg += ", found '" + p.tok.String() + "'" if p.tok.IsLiteral() { - msg += " " + string(p.lit) + msg += " " + p.lit } } p.error(pos, msg) @@ -63,7 +63,7 @@ func (p *parser) expect(tok token.Token) token.Pos { func (p *parser) parseIdentifier() *Name { pos := p.pos - name := string(p.lit) + name := p.lit p.expect(token.IDENT) return &Name{pos, name} } @@ -73,7 +73,7 @@ func (p *parser) parseToken() *Token { pos := p.pos value := "" if p.tok == token.STRING { - value, _ = strconv.Unquote(string(p.lit)) + value, _ = strconv.Unquote(p.lit) // Unquote may fail with an error, but only if the scanner found // an illegal string in the first place. In this case the error // has already been reported. |