Skip to content

Commit

Permalink
Fix scanning token of number in literal
Browse files Browse the repository at this point in the history
  • Loading branch information
goccy committed Jun 1, 2020
1 parent 4368a8b commit 0c228d5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
2 changes: 2 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ func TestParser(t *testing.T) {
"- !tag\n a: b\n c: d\n",
"v:\n- A\n- |-\n B\n C\n",
"v:\n- A\n- >-\n B\n C\n",
"v: |-\n 0\n",
"v: |-\n 0\nx: 0",
}
for _, src := range sources {
fmt.Printf(src)
Expand Down
7 changes: 6 additions & 1 deletion scanner/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,12 @@ func (c *Context) bufferedToken(pos *token.Position) *token.Token {
if len(source) == 0 {
return nil
}
tk := token.New(string(source), string(c.obuf), pos)
var tk *token.Token
if c.isDocument() {
tk = token.String(string(source), string(c.obuf), pos)
} else {
tk = token.New(string(source), string(c.obuf), pos)
}
c.resetBuffer()
return tk
}
2 changes: 1 addition & 1 deletion scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ func (s *Scanner) scanLiteral(ctx *Context, c rune) {
ctx.addBuf(c)
}
value := ctx.bufferedSrc()
ctx.addToken(token.New(string(value), string(ctx.obuf), s.pos()))
ctx.addToken(token.String(string(value), string(ctx.obuf), s.pos()))
ctx.resetBuffer()
s.progressColumn(ctx, 1)
} else if s.isNewLineChar(c) {
Expand Down
21 changes: 13 additions & 8 deletions token/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,14 +628,7 @@ func New(value string, org string, pos *Position) *Token {
}
return tk
}
return &Token{
Type: StringType,
CharacterType: CharacterTypeMiscellaneous,
Indicator: NotIndicator,
Value: value,
Origin: org,
Position: pos,
}
return String(value, org, pos)
}

// Position type for position in YAML document
Expand Down Expand Up @@ -718,6 +711,18 @@ func (t Tokens) Dump() {
}
}

// String create token for String
func String(value string, org string, pos *Position) *Token {
return &Token{
Type: StringType,
CharacterType: CharacterTypeMiscellaneous,
Indicator: NotIndicator,
Value: value,
Origin: org,
Position: pos,
}
}

// SequenceEntry create token for SequenceEntry
func SequenceEntry(org string, pos *Position) *Token {
return &Token{
Expand Down

0 comments on commit 0c228d5

Please sign in to comment.