diff --git a/parser/parser_test.go b/parser/parser_test.go index 5577f964..1e6d556d 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -158,6 +158,14 @@ r: s - b - c - d - e - f +`, + }, + { + ` +a: 0 - 1 +`, + ` +a: 0 - 1 `, }, {` diff --git a/scanner/context.go b/scanner/context.go index d7f70df2..0ca04e14 100644 --- a/scanner/context.go +++ b/scanner/context.go @@ -8,26 +8,28 @@ import ( // Context context at scanning type Context struct { - idx int - size int - src []rune - buf []rune - obuf []rune - tokens token.Tokens - isRawFolded bool - isLiteral bool - isFolded bool - literalOpt string + idx int + size int + src []rune + buf []rune + obuf []rune + tokens token.Tokens + isRawFolded bool + isLiteral bool + isFolded bool + isSingleLine bool + literalOpt string } func newContext(src []rune) *Context { return &Context{ - idx: 0, - size: len(src), - src: src, - tokens: token.Tokens{}, - buf: make([]rune, 0, len(src)), - obuf: make([]rune, 0, len(src)), + idx: 0, + size: len(src), + src: src, + tokens: token.Tokens{}, + buf: make([]rune, 0, len(src)), + obuf: make([]rune, 0, len(src)), + isSingleLine: true, } } diff --git a/scanner/scanner.go b/scanner/scanner.go index fdcffe87..dc686593 100644 --- a/scanner/scanner.go +++ b/scanner/scanner.go @@ -303,6 +303,7 @@ func (s *Scanner) scanNewLine(ctx *Context, c rune) { } ctx.addBuf(' ') ctx.addOriginBuf(c) + ctx.isSingleLine = false s.progressLine(ctx) } @@ -378,6 +379,13 @@ func (s *Scanner) scan(ctx *Context) (pos int) { s.progressColumn(ctx, 1) continue } + if ctx.bufferedSrc() != "" && ctx.isSingleLine { + // '-' is literal + ctx.addBuf(c) + ctx.addOriginBuf(c) + s.progressColumn(ctx, 1) + continue + } nc := ctx.nextChar() if nc == ' ' { s.addBufferedTokenIfExists(ctx)