diff --git a/lexer/lexer_test.go b/lexer/lexer_test.go index 658ff88b..9cae3f17 100644 --- a/lexer/lexer_test.go +++ b/lexer/lexer_test.go @@ -3133,6 +3133,14 @@ a: |invalid`, name: "invalid document header option number", src: "a: >3\n 1", }, + { + name: "use reserved character @", + src: "key: [@val]", + }, + { + name: "use reserved character `", + src: "key: [`val]", + }, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { diff --git a/parser/parser_test.go b/parser/parser_test.go index 281cd945..34369c1b 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -1212,6 +1212,18 @@ a: ^ 6 | d: e`, }, + { + "key: [@val]", + ` +[1:7] found invalid token +> 1 | key: [@val] + ^ +`, + }, + { + "key: [`val]", + "\n[1:7] found invalid token\n> 1 | key: [`val]\n ^\n", + }, } for _, test := range tests { t.Run(test.source, func(t *testing.T) { diff --git a/scanner/scanner.go b/scanner/scanner.go index 7d7cbbd2..746b8c78 100644 --- a/scanner/scanner.go +++ b/scanner/scanner.go @@ -976,6 +976,19 @@ func (s *Scanner) scanAlias(ctx *Context) bool { return true } +func (s *Scanner) scanReservedChar(ctx *Context, c rune) error { + if ctx.existsBuffer() { + return nil + } + + ctx.addBuf(c) + ctx.addOriginBuf(c) + err := ErrInvalidToken("%q is a reserved character", token.Invalid(string(ctx.obuf), s.pos())) + s.progressColumn(ctx, 1) + ctx.clear() + return err +} + func (s *Scanner) scan(ctx *Context) error { for ctx.next() { c := ctx.currentChar() @@ -1103,6 +1116,10 @@ func (s *Scanner) scan(ctx *Context) error { if s.scanWhiteSpace(ctx) { continue } + case '@', '`': + if err := s.scanReservedChar(ctx, c); err != nil { + return err + } } ctx.addBuf(c) ctx.addOriginBuf(c)