diff --git a/ast/expressions.go b/ast/expressions.go index cd1edd2..cd82ea4 100644 --- a/ast/expressions.go +++ b/ast/expressions.go @@ -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) +} diff --git a/ast/smallstatements.go b/ast/smallstatements.go index a7156e4..7460ce2 100644 --- a/ast/smallstatements.go +++ b/ast/smallstatements.go @@ -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) } diff --git a/ast/statements.go b/ast/statements.go index 51a103f..2474025 100644 --- a/ast/statements.go +++ b/ast/statements.go @@ -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() {} diff --git a/ast/tests.go b/ast/tests.go index a3a5ba0..9a188fd 100644 --- a/ast/tests.go +++ b/ast/tests.go @@ -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) } diff --git a/parser/parser.go b/parser/parser.go index 8fa0795..00b2b6e 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -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()