Skip to content

Commit

Permalink
Refactor unexported funcs by removing unnecessary error result
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandear committed Dec 13, 2024
1 parent 7601ad3 commit 2b30585
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 16 deletions.
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

0 comments on commit 2b30585

Please sign in to comment.