Browse Source

fix up some nodes and stuffs

master
Brett Langdon 10 years ago
parent
commit
75bcfe3de9
4 changed files with 17 additions and 13 deletions
  1. +4
    -3
      grammar/expressions.go
  2. +6
    -3
      grammar/nodes.go
  3. +3
    -3
      grammar/parser.go
  4. +4
    -4
      grammar/tests.go

+ 4
- 3
grammar/expressions.go View File

@ -8,18 +8,19 @@ type TestlistStarExpressionChild interface {
}
type TestlistStarExpression struct {
ParentNode
ListNode
}
func NewTestListStarExpression() *TestlistStarExpression {
node := &TestlistStarExpression{}
node.initBaseNode(symbol.TESTLIST_STAR_EXPR)
node.initListNode()
return node
}
func (node *TestlistStarExpression) expressionStatementChild() {}
func (node *TestlistStarExpression) SetChild(n TestlistStarExpressionChild) {
node.ParentNode.SetChild(n)
func (node *TestlistStarExpression) Append(n TestlistStarExpressionChild) {
node.ListNode.Append(n)
}
type ComparisonChild interface {


+ 6
- 3
grammar/nodes.go View File

@ -8,6 +8,7 @@ import (
)
type Node interface {
ID() symbol.SymbolID
Name() string
Repr() []interface{}
}
@ -30,6 +31,7 @@ func (node *TokenNode) fileInputChild() {}
func (node *TokenNode) shiftExpressionChild() {}
func (node *TokenNode) simpleStatementChild() {}
func (node *TokenNode) trailerChild() {}
func (node *TokenNode) ID() symbol.SymbolID { return 0 }
func (node *TokenNode) Name() string { return token.TokenNames[node.Token.ID] }
func (node *TokenNode) Repr() []interface{} {
parts := make([]interface{}, 0)
@ -39,12 +41,13 @@ func (node *TokenNode) Repr() []interface{} {
}
type BaseNode struct {
ID symbol.SymbolID
id symbol.SymbolID
child Node
}
func (node *BaseNode) initBaseNode(id symbol.SymbolID) { node.ID = id }
func (node *BaseNode) Name() string { return symbol.SymbolNames[node.ID] }
func (node *BaseNode) initBaseNode(id symbol.SymbolID) { node.id = id }
func (node *BaseNode) ID() symbol.SymbolID { return node.id }
func (node *BaseNode) Name() string { return symbol.SymbolNames[node.ID()] }
func (node *BaseNode) Repr() (parts []interface{}) { return append(parts, node.Name()) }
type ParentNode struct {


+ 3
- 3
grammar/parser.go View File

@ -391,14 +391,14 @@ func (parser *GrammarParser) parseNotTest() *NotTest {
if test == nil {
return nil
}
notTest.SetChild(test)
notTest.Append(test)
} else {
parser.unreadToken(next)
comparison := parser.parseComparison()
if comparison == nil {
return nil
}
notTest.SetChild(comparison)
notTest.Append(comparison)
}
return notTest
}
@ -489,7 +489,7 @@ func (parser *GrammarParser) parseTestlistStarExpression() *TestlistStarExpressi
if expr == nil {
return nil
}
testlistStarExpression.SetChild(expr)
testlistStarExpression.Append(expr)
return testlistStarExpression
}


+ 4
- 4
grammar/tests.go View File

@ -63,7 +63,7 @@ type NotTestChild interface {
}
type NotTest struct {
ParentNode
ListNode
}
func NewNotTest() *NotTest {
@ -72,6 +72,6 @@ func NewNotTest() *NotTest {
return node
}
func (node *NotTest) notTestChild() {}
func (node *NotTest) andTestChild() {}
func (node *NotTest) SetChild(n NotTestChild) { node.ParentNode.SetChild(n) }
func (node *NotTest) notTestChild() {}
func (node *NotTest) andTestChild() {}
func (node *NotTest) Append(n NotTestChild) { node.ListNode.Append(n) }

Loading…
Cancel
Save