chore: remove unused methods

This commit is contained in:
Steven 2023-12-14 00:24:41 +08:00
parent 5266a62685
commit 3edce174d6
5 changed files with 15 additions and 50 deletions

View file

@ -8,29 +8,17 @@ type Node interface {
// This method is used for debugging.
String() string
// GetParent returns a parent node of this node.
GetParent() Node
// GetPrevSibling returns a previous sibling node of this node.
GetPrevSibling() Node
// GetNextSibling returns a next sibling node of this node.
GetNextSibling() Node
// GetChildren returns children nodes of this node.
GetChildren() []Node
// SetParent sets a parent node to this node.
SetParent(Node)
// SetPrevSibling sets a previous sibling node to this node.
SetPrevSibling(Node)
// SetNextSibling sets a next sibling node to this node.
SetNextSibling(Node)
// SetChildren sets children nodes to this node.
SetChildren([]Node)
}
type NodeType int
@ -49,17 +37,9 @@ func NewNodeType(name string) NodeType {
}
type BaseNode struct {
parent Node
prevSibling Node
nextSibling Node
children []Node
}
func (n *BaseNode) GetParent() Node {
return n.parent
}
func (n *BaseNode) GetPrevSibling() Node {
@ -70,14 +50,6 @@ func (n *BaseNode) GetNextSibling() Node {
return n.nextSibling
}
func (n *BaseNode) GetChildren() []Node {
return n.children
}
func (n *BaseNode) SetParent(node Node) {
n.parent = node
}
func (n *BaseNode) SetPrevSibling(node Node) {
n.prevSibling = node
}
@ -85,7 +57,3 @@ func (n *BaseNode) SetPrevSibling(node Node) {
func (n *BaseNode) SetNextSibling(node Node) {
n.nextSibling = node
}
func (n *BaseNode) SetChildren(nodes []Node) {
n.children = nodes
}

View file

@ -42,11 +42,11 @@ func (p *BlockquoteParser) Parse(tokens []*tokenizer.Token) (ast.Node, error) {
}
contentTokens := tokens[2:size]
blockquote := &ast.Blockquote{}
children, err := ParseInline(blockquote, contentTokens)
children, err := ParseInline(contentTokens)
if err != nil {
return nil, err
}
blockquote.Children = children
return blockquote, nil
return &ast.Blockquote{
Children: children,
}, nil
}

View file

@ -65,13 +65,12 @@ func (p *HeadingParser) Parse(tokens []*tokenizer.Token) (ast.Node, error) {
}
contentTokens := tokens[level+1 : size]
heading := &ast.Heading{
Level: level,
}
children, err := ParseInline(heading, contentTokens)
children, err := ParseInline(contentTokens)
if err != nil {
return nil, err
}
heading.Children = children
return heading, nil
return &ast.Heading{
Level: level,
Children: children,
}, nil
}

View file

@ -39,11 +39,11 @@ func (p *ParagraphParser) Parse(tokens []*tokenizer.Token) (ast.Node, error) {
}
contentTokens := tokens[:size]
paragraph := &ast.Paragraph{}
children, err := ParseInline(paragraph, contentTokens)
children, err := ParseInline(contentTokens)
if err != nil {
return nil, err
}
paragraph.Children = children
return paragraph, nil
return &ast.Paragraph{
Children: children,
}, nil
}

View file

@ -73,7 +73,7 @@ var defaultInlineParsers = []InlineParser{
NewTextParser(),
}
func ParseInline(parent ast.Node, tokens []*tokenizer.Token) ([]ast.Node, error) {
func ParseInline(tokens []*tokenizer.Token) ([]ast.Node, error) {
nodes := []ast.Node{}
var prevNode ast.Node
for len(tokens) > 0 {
@ -86,8 +86,8 @@ func ParseInline(parent ast.Node, tokens []*tokenizer.Token) ([]ast.Node, error)
}
tokens = tokens[size:]
node.SetParent(parent)
if prevNode != nil {
// Merge text nodes if possible.
if prevNode.Type() == ast.NodeTypeText && node.Type() == ast.NodeTypeText {
prevNode.(*ast.Text).Content += node.(*ast.Text).Content
break
@ -96,13 +96,11 @@ func ParseInline(parent ast.Node, tokens []*tokenizer.Token) ([]ast.Node, error)
prevNode.SetNextSibling(node)
node.SetPrevSibling(prevNode)
}
nodes = append(nodes, node)
prevNode = node
break
}
}
}
parent.SetChildren(nodes)
return nodes, nil
}