From 3c1bb8b785f2aa4d86f83a0cd87fc1df046c60de Mon Sep 17 00:00:00 2001 From: Agniva De Sarker Date: Sun, 24 Jun 2018 22:37:16 +0530 Subject: [PATCH] godoc: accept scanner.RawString too during EBNF parsing Commit c8915a0696ddb53399e9c7ebae1cd1158f27175 changed the text/scanner package to return a scanner.RawString (rather than a scanner.String) token for raw string literals. This broke the EBNF parser which didn't look for scanner.RawString. Updated the EBNF parser code to reflect that change. Fixes golang/go#25986 Change-Id: Ib9c133a7c357dd750a4038d2ed39be86a245995c Reviewed-on: https://go-review.googlesource.com/120659 Reviewed-by: Robert Griesemer Run-TryBot: Robert Griesemer TryBot-Result: Gobot Gobot --- godoc/spec.go | 2 +- godoc/spec_test.go | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 godoc/spec_test.go diff --git a/godoc/spec.go b/godoc/spec.go index 6d6b9c23a2..9ec94278db 100644 --- a/godoc/spec.go +++ b/godoc/spec.go @@ -74,7 +74,7 @@ func (p *ebnfParser) parseTerm() bool { case scanner.Ident: p.parseIdentifier(false) - case scanner.String: + case scanner.String, scanner.RawString: p.next() const ellipsis = '…' // U+2026, the horizontal ellipsis character if p.tok == ellipsis { diff --git a/godoc/spec_test.go b/godoc/spec_test.go new file mode 100644 index 0000000000..c016516877 --- /dev/null +++ b/godoc/spec_test.go @@ -0,0 +1,22 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package godoc + +import ( + "bytes" + "strings" + "testing" +) + +func TestParseEBNFString(t *testing.T) { + var p ebnfParser + var buf bytes.Buffer + src := []byte("octal_byte_value = `\\` octal_digit octal_digit octal_digit .") + p.parse(&buf, src) + + if strings.Contains(buf.String(), "error") { + t.Error(buf.String()) + } +}