Browse Source

setup better parent/child interface naming

master
Brett Langdon 10 years ago
parent
commit
9a6c39b455
5 changed files with 46 additions and 17 deletions
  1. +6
    -2
      ast/expressions.go
  2. +4
    -4
      ast/smallstatements.go
  3. +5
    -5
      ast/statements.go
  4. +22
    -3
      ast/tests.go
  5. +9
    -3
      parser/parser.go

+ 6
- 2
ast/expressions.go View File

@ -1,8 +1,8 @@
package ast
type ExpressionNode interface {
type TestlistStarExpressionChildNode interface {
Node
exprNode()
testlistStarExpressionChild()
}
type TestlistStarExpression struct {
@ -14,3 +14,7 @@ func NewTestListStarExpression() *TestlistStarExpression {
node.initBaseNode(TESTLIST_STAR_EXPR)
return node
}
func (node *TestlistStarExpression) SetChild(n TestlistStarExpressionChildNode) {
node.ParentNode.SetChild(n)
}

+ 4
- 4
ast/smallstatements.go View File

@ -1,8 +1,8 @@
package ast
type SmallStatementNode interface {
type SmallStatementChildNode interface {
Node
smallStmtNode()
smallStmtChildNode()
}
type SmallStatement struct {
@ -15,7 +15,7 @@ func NewSmallStatement() *SmallStatement {
return node
}
func (node *SmallStatement) SetChild(n SmallStatementNode) { node.ParentNode.SetChild(n) }
func (node *SmallStatement) SetChild(n SmallStatementChildNode) { node.ParentNode.SetChild(n) }
type ExpressionStatement struct {
ParentNode
@ -28,5 +28,5 @@ func NewExpressionStatement() *ExpressionStatement {
return node
}
func (node *ExpressionStatement) smallStmtNode() {}
func (node *ExpressionStatement) smallStmtChildNode() {}
func (node *ExpressionStatement) SetChild(n *TestlistStarExpression) { node.ParentNode.SetChild(n) }

+ 5
- 5
ast/statements.go View File

@ -1,8 +1,8 @@
package ast
type StatementNode interface {
type StatementChildNode interface {
Node
stmtNode()
stmtChildNode()
}
type Statement struct {
@ -15,7 +15,7 @@ func NewStatement() *Statement {
return node
}
func (node *Statement) SetChild(n StatementNode) { node.ParentNode.SetChild(n) }
func (node *Statement) SetChild(n StatementChildNode) { node.ParentNode.SetChild(n) }
type SimpleStatement struct {
ListNode
@ -28,7 +28,7 @@ func NewSimpleStatement() *SimpleStatement {
return node
}
func (node *SimpleStatement) stmtNode() {}
func (node *SimpleStatement) stmtChildNode() {}
func (node *SimpleStatement) Append(n *SmallStatement) { node.ListNode.Append(n) }
type CompoundStatement struct {
@ -40,4 +40,4 @@ func NewCompoundStatement() *CompoundStatement {
node.initBaseNode(COMPOUND_STMT)
return node
}
func (node *CompoundStatement) stmtNode() {}
func (node *CompoundStatement) stmtChildNode() {}

+ 22
- 3
ast/tests.go View File

@ -1,8 +1,8 @@
package ast
type TestNode interface {
type TestChildNode interface {
Node
test()
testChild()
}
type Test struct {
@ -15,4 +15,23 @@ func NewTest() *Test {
return node
}
func (node *Test) SetChild(n TestNode) { node.ParentNode.SetChild(n) }
func (node *Test) testlistStarExpressionChild() {}
func (node *Test) SetChild(n TestChildNode) { node.ParentNode.SetChild(n) }
type OrTestChildNode interface {
Node
orTestChild()
}
type OrTest struct {
ListNode
}
func NewOrTest() *OrTest {
node := &OrTest{}
node.initBaseNode(OR_TEST)
return node
}
func (node *OrTest) testChild() {}
func (node *OrTest) Append(n OrTestChildNode) { node.ListNode.Append(n) }

+ 9
- 3
parser/parser.go View File

@ -50,6 +50,12 @@ func (parser *Parser) parseCompoundStatement() *ast.CompoundStatement {
return compoundStmt
}
// or_test: and_test ('or' and_test)*
func (parser *Parser) parseOrTest() *ast.OrTest {
orTest := ast.NewOrTest()
return orTest
}
// test: or_test ['if' or_test 'else' test] | lambdef
func (parser *Parser) parseTest() *ast.Test {
test := ast.NewTest()
@ -60,7 +66,7 @@ func (parser *Parser) parseTest() *ast.Test {
func (parser *Parser) parseTestlistStarExpression() *ast.TestlistStarExpression {
testlistStarExpression := ast.NewTestListStarExpression()
var expr ast.Node
var expr ast.TestlistStarExpressionChildNode
expr = parser.parseTest()
if expr == nil {
return nil
@ -86,7 +92,7 @@ func (parser *Parser) parseExpressionStatement() *ast.ExpressionStatement {
func (parser *Parser) parseSmallStatment() *ast.SmallStatement {
smallStmt := ast.NewSmallStatement()
var stmt ast.SmallStatementNode
var stmt ast.SmallStatementChildNode
stmt = parser.parseExpressionStatement()
if stmt != nil {
smallStmt.SetChild(stmt)
@ -124,7 +130,7 @@ func (parser *Parser) parseSimpleStatement() *ast.SimpleStatement {
// stmt: simple_stmt | compound_stmt
func (parser *Parser) parseStatement() *ast.Statement {
var next ast.StatementNode
var next ast.StatementChildNode
next = parser.parseSimpleStatement()
if next == nil {
next = parser.parseCompoundStatement()


Loading…
Cancel
Save