Skip to content

Commit

Permalink
Merge pull request souffle-lang#1728 from mmcgr/astOutput
Browse files Browse the repository at this point in the history
Print infix operators correctly from AST
  • Loading branch information
mmcgr authored Nov 5, 2020
2 parents 16293a9 + 8132bc8 commit fbb4c4b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/ast/BinaryConstraint.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ class BinaryConstraint : public Constraint {

protected:
void print(std::ostream& os) const override {
os << *lhs << " " << operation << " " << *rhs;
if (isInfixFunctorOp(operation)) {
os << *lhs << " " << operation << " " << *rhs;
} else {
os << operation << "(" << *lhs << ", " << *rhs << ")";
}
}

bool equal(const Node& node) const override {
Expand Down
15 changes: 15 additions & 0 deletions src/include/souffle/BinaryConstraintOps.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,21 @@ inline bool isOrderedBinaryConstraintOp(const BinaryConstraintOp op) {
UNREACHABLE_BAD_CASE_ANALYSIS
}

/**
* Determines whether a functor should be written using infix notation (e.g. `a + b + c`)
* or prefix notation (e.g. `+(a,b,c)`)
*/
inline bool isInfixFunctorOp(const BinaryConstraintOp op) {
switch (op) {
case BinaryConstraintOp::MATCH:
case BinaryConstraintOp::NOT_MATCH:
case BinaryConstraintOp::CONTAINS:
case BinaryConstraintOp::NOT_CONTAINS: return false;

default: return true;
}
}

/**
* Get type binary constraint operates on.
**/
Expand Down

0 comments on commit fbb4c4b

Please sign in to comment.