Merge pull request #146 from hashicorp/b-comment
hcl/scanner: single line '//' commments verify second '/'
This commit is contained in:
commit
05be7a778d
@ -214,4 +214,5 @@ func (c *CommentGroup) Pos() token.Pos {
|
|||||||
// GoStringer
|
// GoStringer
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
|
|
||||||
func (o *ObjectKey) GoString() string { return fmt.Sprintf("*%#v", *o) }
|
func (o *ObjectKey) GoString() string { return fmt.Sprintf("*%#v", *o) }
|
||||||
|
func (o *ObjectList) GoString() string { return fmt.Sprintf("*%#v", *o) }
|
||||||
|
@ -398,13 +398,14 @@ func TestParse_inline(t *testing.T) {
|
|||||||
{"v\nN{{}}", true},
|
{"v\nN{{}}", true},
|
||||||
{"v=/\n[,", true},
|
{"v=/\n[,", true},
|
||||||
{"v=10kb", true},
|
{"v=10kb", true},
|
||||||
|
{"v=/foo", true},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
t.Logf("Testing: %q", tc.Value)
|
t.Logf("Testing: %q", tc.Value)
|
||||||
_, err := Parse([]byte(tc.Value))
|
ast, err := Parse([]byte(tc.Value))
|
||||||
if (err != nil) != tc.Err {
|
if (err != nil) != tc.Err {
|
||||||
t.Fatalf("Input: %q\n\nError: %s\n\nAST: %s", tc.Value, err)
|
t.Fatalf("Input: %q\n\nError: %s\n\nAST: %#v", tc.Value, err, ast)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -224,6 +224,11 @@ func (s *Scanner) Scan() token.Token {
|
|||||||
func (s *Scanner) scanComment(ch rune) {
|
func (s *Scanner) scanComment(ch rune) {
|
||||||
// single line comments
|
// single line comments
|
||||||
if ch == '#' || (ch == '/' && s.peek() != '*') {
|
if ch == '#' || (ch == '/' && s.peek() != '*') {
|
||||||
|
if ch == '/' && s.peek() != '/' {
|
||||||
|
s.err("expected '/' for comment")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
ch = s.next()
|
ch = s.next()
|
||||||
for ch != '\n' && ch >= 0 && ch != eof {
|
for ch != '\n' && ch >= 0 && ch != eof {
|
||||||
ch = s.next()
|
ch = s.next()
|
||||||
|
@ -496,6 +496,7 @@ func TestError(t *testing.T) {
|
|||||||
testError(t, `"abc`, "1:5", "literal not terminated", token.STRING)
|
testError(t, `"abc`, "1:5", "literal not terminated", token.STRING)
|
||||||
testError(t, `"abc`+"\n", "2:1", "literal not terminated", token.STRING)
|
testError(t, `"abc`+"\n", "2:1", "literal not terminated", token.STRING)
|
||||||
testError(t, `/*/`, "1:4", "comment not terminated", token.COMMENT)
|
testError(t, `/*/`, "1:4", "comment not terminated", token.COMMENT)
|
||||||
|
testError(t, `/foo`, "1:1", "expected '/' for comment", token.COMMENT)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testError(t *testing.T, src, pos, msg string, tok token.Type) {
|
func testError(t *testing.T, src, pos, msg string, tok token.Type) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user