Skip to content

Commit

Permalink
Finish reflection refactor, and implement unparsed theory terms.
Browse files Browse the repository at this point in the history
  • Loading branch information
namcsi committed Sep 8, 2023
1 parent 129c999 commit 9824984
Show file tree
Hide file tree
Showing 13 changed files with 307 additions and 201 deletions.
1 change: 1 addition & 0 deletions src/renopro/asp/ast.lp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ ast(body_literal(Id,Sign,Atom)) :- body_literal(Id,Sign,Atom).
ast(body_literals(Id,Pos,Element)) :- body_literals(Id,Pos,Element).
ast(head_agg_elements(Id,Pos,Terms,Condition)) :- head_agg_elements(Id,Pos,Terms,Condition).
ast(head_aggregate(Id,LGuard,Elements,RGuard)) :- head_aggregate(Id,LGuard,Elements,RGuard).
ast(conditional_literals(Id,Pos,CondLit)) :- conditional_literals(Id,Pos,CondLit).
ast(disjunction(Id,Pos,Element)) :- disjunction(Id,Pos,Element).
ast(rule(Id,Head,Body)) :- rule(Id,Head,Body).
ast(statements(Id,Pos,Element)) :- statements(Id,Pos,Element).
Expand Down
1 change: 1 addition & 0 deletions src/renopro/asp/defined.lp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#defined body_literals/3.
#defined head_agg_elements/4.
#defined head_aggregate/4.
#defined conditional_literals/3.
#defined disjunction/3.
#defined rule/3.
#defined statements/3.
Expand Down
61 changes: 49 additions & 12 deletions src/renopro/predicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,12 +483,10 @@ class Theory_Operators1(ComplexTerm, name="theory_operators"):
id = Identifier_Field(default=lambda: next(id_count))


class Theory_Unparsed_Term(Predicate):
"""An unparsed theory term is a tuple, each element of which
consists of a tuple of theory operators and a theory term. This
predicate represents an element of an unparsed theory term.
class Theory_Unparsed_Term_Elements(Predicate):
"""Predicate representing an element of an unparsed theory term.
id: The identifier of the unparsed theory term.
id: Identifier of the tuple of elements.
position: Integer representing position of the element
of the theory tuple, ordered by <.
operators: A tuple of theory operators.
Expand All @@ -501,6 +499,26 @@ class Theory_Unparsed_Term(Predicate):
term = TheoryTermField


class Theory_Unparsed_Term_Elements1(ComplexTerm, name="theory_unparsed_term_elements"):
"Term identifying a child tuple element of an unparsed theory term."
id = Identifier_Field(default=lambda: next(id_count))


class Theory_Unparsed_Term(Predicate):
"""Predicate representing an unparsed theory term.
An unparsed theory term consists of a tuple, each element of which
consists of a tuple of theory operators and a theory term. This
predicate represents an element of an unparsed theory term.
id: The identifier of the unparsed theory term.
elements: The tuple of aforementioned elements
forming the unparsed theory term.
"""

id = Identifier_Field(default=lambda: next(id_count))
elements = Theory_Unparsed_Term_Elements1.Field


class Theory_Unparsed_Term1(ComplexTerm, name="theory_unparsed_term"):
"Term identifying a child unparsed theory term fact."
id = Identifier_Field(default=lambda: next(id_count))
Expand Down Expand Up @@ -628,15 +646,15 @@ class Literal1(ComplexTerm, name="literal"):


class Literals(Predicate):
"""Predicate representing an element of a tuple of (conditional) literals.
"""Predicate representing an element of a tuple of literals.
id: Identifier of the tuple.
position: Integer representing position of the element the tuple, ordered by <.
element: Term identifying the element.
"""

id = Identifier_Field(default=lambda: next(id_count))
position = IntegerField # should we keep track of position?
position = IntegerField
literal = Literal1.Field


Expand Down Expand Up @@ -913,20 +931,35 @@ class Head_Aggregate1(Predicate, name="head_aggregate"):
id = Identifier_Field(default=lambda: next(id_count))


class Conditional_Literals(Predicate):
"""Predicate representing an element of a tuple of conditional literals.
id: Identifier of the tuple of conditional literals.
position: Integer representing position of the element the tuple, ordered by <.
conditional_literal: Term identifying the conditional literal element.
"""

id = Identifier_Field(default=lambda: next(id_count))
position = IntegerField
conditional_literal = Conditional_Literal1.Field


class Conditional_Literals1(ComplexTerm, name="conditional_literals"):
"Term identifying a child tuple of conditional literals."
id = Identifier_Field(default=lambda: next(id_count))


class Disjunction(Predicate):
"""Predicate representing a disjunction of (conditional) literals.
id: Identifier of the disjunction.
position: Integer representing position of the element the disjunction,
ordered by <.
element: The element of the disjunction, a conditional literal.
elements: The elements of the disjunction, a tuple of conditional literals.
A literal in a disjunction is represented as a conditional literal
with an empty condition.
"""

id = Identifier_Field(default=lambda: next(id_count))
position = IntegerField
conditional_literal = Conditional_Literal1.Field
elements = Conditional_Literals1.Field


class Disjunction1(ComplexTerm, name="disjunction"):
Expand Down Expand Up @@ -1057,6 +1090,7 @@ class Program(Predicate):
Theory_Sequence,
Theory_Function,
Theory_Operators,
Theory_Unparsed_Term_Elements,
Theory_Unparsed_Term,
Guard,
Guards,
Expand All @@ -1077,6 +1111,7 @@ class Program(Predicate):
Body_Literals,
Head_Agg_Elements,
Head_Aggregate,
Conditional_Literals,
Disjunction,
Rule,
Statements,
Expand All @@ -1099,6 +1134,7 @@ class Program(Predicate):
Theory_Sequence,
Theory_Function,
Theory_Operators,
Theory_Unparsed_Term_Elements,
Theory_Unparsed_Term,
Guard,
Guards,
Expand All @@ -1119,6 +1155,7 @@ class Program(Predicate):
Body_Literals,
Head_Agg_Elements,
Head_Aggregate,
Conditional_Literals,
Disjunction,
Rule,
Statements,
Expand Down
Loading

0 comments on commit 9824984

Please sign in to comment.