Pierre Carbonnelle avatar Pierre Carbonnelle committed 3043bfb

Refactor head <= body parsing

Comments (0)

Files changed (1)

pyDatalog/pyParser.py

             pyEngine.add_expr_to_predicate(literal.lua.pred, operator, expr)
             return literal
 
+    @property
+    def literals(self):
+        return [self]
+    
     def __le__(self, body):
         " head <= body"
-        if isinstance(body, Literal):
-            newBody = body.pre_calculations & body
-            if isinstance(body, HeadLiteral):
+        if not isinstance(body, (Literal, Body)):
+            raise pyDatalog.DatalogError("Invalid body for clause", None, None)
+        newBody = Body()
+        for literal in body.literals:
+            if isinstance(literal, HeadLiteral):
                 raise pyDatalog.DatalogError("Aggregation cannot appear in the body of a clause", None, None)
-        else:
-            if not isinstance(body, Body):
-                raise pyDatalog.DatalogError("Invalid body for clause", None, None)
-            newBody = Body()
-            for literal in body.literals:
-                if isinstance(literal, HeadLiteral):
-                    raise pyDatalog.DatalogError("Aggregation cannot appear in the body of a clause", None, None)
-                newBody = newBody & literal.pre_calculations & literal
+            newBody = newBody & literal.pre_calculations & literal
         result = pyDatalog.add_clause(self, newBody)
         if not result: 
             raise pyDatalog.DatalogError("Can't create clause", None, None)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.