Skip to content

Commit

Permalink
Correct some struct names
Browse files Browse the repository at this point in the history
  • Loading branch information
sonda2208 committed Apr 19, 2019
1 parent 27cd28d commit 849ba25
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
14 changes: 7 additions & 7 deletions ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ type Expr interface {
Type() string
}

type ExprExpr struct {
type ParentExpr struct {
Expr Expr
}

func (e *ExprExpr) String() string {
func (e *ParentExpr) String() string {
return fmt.Sprintf("(%s)", e.Expr.String())
}

func (e *ExprExpr) Type() string {
func (e *ParentExpr) Type() string {
return "nested expression"
}

Expand All @@ -38,15 +38,15 @@ func (e *BinaryExpr) Type() string {
return "binary expression"
}

type Var struct {
type Ident struct {
Val string
}

func (v *Var) String() string {
func (v *Ident) String() string {
return v.Val
}

func (v *Var) Type() string {
func (v *Ident) Type() string {
return "variable"
}

Expand Down Expand Up @@ -153,7 +153,7 @@ func walk(expr Expr, fn WalkFunc) error {
if err != nil {
return err
}
case *ExprExpr:
case *ParentExpr:
err = walk(e.Expr, fn)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func evaluate(expr Expr, params map[string]interface{}) (Expr, error) {
}

switch e := expr.(type) {
case *ExprExpr:
case *ParentExpr:
return evaluate(e.Expr, params)
case *BinaryExpr:
l, err := evaluate(e.LHS, params)
Expand All @@ -44,7 +44,7 @@ func evaluate(expr Expr, params map[string]interface{}) (Expr, error) {
}

return compute(e.Op, l, r)
case *Var:
case *Ident:
varName := e.Val
varVal, ok := params[varName]
if !ok {
Expand Down
4 changes: 2 additions & 2 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func parseExpr(rule *Rule) (Expr, error) {
}
}

return &ExprExpr{Expr: res}, nil
return &ParentExpr{Expr: res}, nil
}

l, err := toLiteral(rule.Val)
Expand All @@ -99,7 +99,7 @@ func parseExpr(rule *Rule) (Expr, error) {

return &BinaryExpr{
Op: rule.Op,
LHS: &Var{rule.Var},
LHS: &Ident{rule.Var},
RHS: l,
}, nil
}
Expand Down

0 comments on commit 849ba25

Please sign in to comment.