parse: Always use *ListNode for Term's

This commit is contained in:
Cheer Xiao 2013-10-06 14:55:28 +08:00
parent 585e047ca5
commit c925871ef4
4 changed files with 7 additions and 6 deletions

View File

@ -45,8 +45,7 @@ func evalFactor(n *parse.FactorNode) ([]string, error) {
}
}
func evalTerm(n_ parse.Node) ([]string, error) {
n := n_.(*parse.ListNode)
func evalTerm(n *parse.ListNode) ([]string, error) {
words := make([]string, 0, len(n.Nodes))
words = append(words, "")
for _, m := range n.Nodes {
@ -75,7 +74,7 @@ func evalTerm(n_ parse.Node) ([]string, error) {
func evalTermList(ln *parse.ListNode) ([]string, error) {
words := make([]string, 0, len(ln.Nodes))
for _, n := range ln.Nodes {
a, e := evalTerm(n)
a, e := evalTerm(n.(*parse.ListNode))
if e != nil {
return nil, e
}

View File

@ -89,6 +89,8 @@ func newCommand(pos Pos) *CommandNode {
return &CommandNode{ListNode: *newList(pos)}
}
// A Term is represented by a ListNode of *FactorNode's.
// FactorNode represents a Factor. The embedded Node is either *ListNode or
// *StringNode.
type FactorNode struct {

View File

@ -257,7 +257,7 @@ loop:
}
// Term = Factor { Factor }
func (t *Tree) term() Node {
func (t *Tree) term() *ListNode {
term := newList(t.peek().Pos)
term.append(t.factor())
loop:

View File

@ -41,9 +41,9 @@ func newCloseRedir(fd uintptr) *CloseRedir {
type FilenameRedir struct {
redir
Flag int
Filename Node
Filename *ListNode // a Term
}
func newFilenameRedir(fd uintptr, flag int, filename Node) *FilenameRedir {
func newFilenameRedir(fd uintptr, flag int, filename *ListNode) *FilenameRedir {
return &FilenameRedir{redir{fd}, flag, filename}
}