Skip to content

Commit

Permalink
Expand unop and binop source to include args (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelocantos authored May 14, 2020
1 parent 452302e commit a2ebd62
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions syntax/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,12 @@ func (pc ParseContext) compileUnop(b ast.Branch, c ast.Children) rel.Expr {
for i := len(ops) - 1; i >= 0; i-- {
op := ops[i].One("").(ast.Leaf).Scanner()
f := unops[op.String()]
result = f(op, result)
source, err := parser.MergeScanners(op, result.Source())
if err != nil {
// TODO: Figure out why some exprs don't have usable sources (could be native funcs).
source = op
}
result = f(source, result)
}
return result
}
Expand All @@ -241,7 +246,13 @@ func (pc ParseContext) compileBinop(b ast.Branch, c ast.Children) rel.Expr {
for i, arg := range args[1:] {
op := ops[i].One("").(ast.Leaf).Scanner()
f := binops[op.String()]
result = f(op, result, pc.CompileExpr(arg.(ast.Branch)))
rhs := pc.CompileExpr(arg.(ast.Branch))
source, err := parser.MergeScanners(op, result.Source(), rhs.Source())
if err != nil {
// TODO: Figure out why some exprs don't have usable sources (could be native funcs).
source = op
}
result = f(source, result, rhs)
}
return result
}
Expand Down

0 comments on commit a2ebd62

Please sign in to comment.