Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor unexported funcs by removing unnecessary error result #589

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions parser/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"github.com/goccy/go-yaml/token"
)

func newMappingNode(ctx *context, tk *Token, isFlow bool, values ...*ast.MappingValueNode) (*ast.MappingNode, error) {
func newMappingNode(ctx *context, tk *Token, isFlow bool, values ...*ast.MappingValueNode) *ast.MappingNode {
node := ast.Mapping(tk.RawToken(), isFlow, values...)
node.SetPath(ctx.path)
return node, nil
return node
}

func newMappingValueNode(ctx *context, tk *Token, key ast.MapKeyNode, value ast.Node) (*ast.MappingValueNode, error) {
Expand Down
10 changes: 2 additions & 8 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,7 @@ func (p *parser) parseScalarValue(ctx *context, tk *Token) (ast.ScalarNode, erro
}

func (p *parser) parseFlowMap(ctx *context) (*ast.MappingNode, error) {
node, err := newMappingNode(ctx, ctx.currentToken(), true)
if err != nil {
return nil, err
}
node := newMappingNode(ctx, ctx.currentToken(), true)
ctx.goNext() // skip MappingStart token

isFirst := true
Expand Down Expand Up @@ -466,10 +463,7 @@ func (p *parser) parseMap(ctx *context) (*ast.MappingNode, error) {
}
keyValueNode = node
}
mapNode, err := newMappingNode(ctx, &Token{Token: keyValueNode.GetToken()}, false, keyValueNode)
if err != nil {
return nil, err
}
mapNode := newMappingNode(ctx, &Token{Token: keyValueNode.GetToken()}, false, keyValueNode)
var tk *Token
if ctx.isComment() {
tk = ctx.nextNotCommentToken()
Expand Down
9 changes: 3 additions & 6 deletions parser/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,7 @@ func createGroupedTokens(tokens token.Tokens) ([]*Token, error) {
var err error
tks := newTokens(tokens)
tks = createLineCommentTokenGroups(tks)
tks, err = createLiteralAndFoldedTokenGroups(tks)
if err != nil {
return nil, err
}
tks = createLiteralAndFoldedTokenGroups(tks)
tks, err = createAnchorAndAliasTokenGroups(tks)
if err != nil {
return nil, err
Expand Down Expand Up @@ -260,7 +257,7 @@ func createLineCommentTokenGroups(tokens []*Token) []*Token {
return ret
}

func createLiteralAndFoldedTokenGroups(tokens []*Token) ([]*Token, error) {
func createLiteralAndFoldedTokenGroups(tokens []*Token) []*Token {
ret := make([]*Token, 0, len(tokens))
for i := 0; i < len(tokens); i++ {
tk := tokens[i]
Expand Down Expand Up @@ -293,7 +290,7 @@ func createLiteralAndFoldedTokenGroups(tokens []*Token) ([]*Token, error) {
ret = append(ret, tk)
}
}
return ret, nil
return ret
}

func createAnchorAndAliasTokenGroups(tokens []*Token) ([]*Token, error) {
Expand Down
Loading