You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
argh/parse_tree.go

58 lines
791 B

package argh
import "fmt"
type ParseTree struct {
Nodes []Node `json:"nodes"`
}
func (pt *ParseTree) typedAST() []TypedNode {
ret := []TypedNode{}
for _, node := range pt.Nodes {
if _, ok := node.(ArgDelimiter); ok {
continue
}
if _, ok := node.(StopFlag); ok {
continue
}
ret = append(
ret,
TypedNode{
Type: fmt.Sprintf("%T", node),
Node: node,
},
)
}
return ret
}
func (pt *ParseTree) ast() []Node {
ret := []Node{}
for _, node := range pt.Nodes {
if _, ok := node.(ArgDelimiter); ok {
continue
}
if _, ok := node.(StopFlag); ok {
continue
}
if v, ok := node.(CompoundShortFlag); ok {
for _, subNode := range v.Nodes {
ret = append(ret, subNode)
}
continue
}
ret = append(ret, node)
}
return ret
}