Skip to content

Commit

Permalink
Merge with wip theory parsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
namcsi committed Dec 7, 2023
2 parents 32027fb + 19e08e4 commit 7e58c5e
Show file tree
Hide file tree
Showing 38 changed files with 1,986 additions and 362 deletions.
4 changes: 3 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
[run]
source = renopro
tests
omit = */renopro/__main__.py
omit =
*/renopro/__main__.py
src/renopro/utils/codegen.py
[report]
exclude_lines =
assert
Expand Down
10 changes: 10 additions & 0 deletions TODO.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
* Refication of location should be a method parameter, not something that's permanently set on init.

* Examine existing metaprogramming applications

- HTLB
- TLHTC
- meta-telingo
- Deontic logic
- plingo meta encoding
- unsat stuff with Susana
4 changes: 3 additions & 1 deletion src/renopro/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,22 @@ def main():
parser = get_parser()
args = parser.parse_args()
setup_logger("renopro", args.log)
rast = ReifiedAST()
if args.command == "reify":
rast = ReifiedAST(reify_location=args.reify_location)
rast.reify_files(args.infiles)
if args.commented:
print(rast.reified_string_doc)
else:
print(rast.reified_string)

elif args.command == "reflect":
rast = ReifiedAST()
rast.add_reified_files(args.infiles)
rast.reflect()
print(rast.program_string)

elif args.command == "transform":
rast = ReifiedAST(reify_location=args.reify_location)
if args.input_format == "reified":
rast.add_reified_files(args.infiles)
elif args.input_format == "reflected":
Expand Down
117 changes: 59 additions & 58 deletions src/renopro/asp/ast.lp
Original file line number Diff line number Diff line change
@@ -1,59 +1,60 @@
% tag ast facts.
ast(location(Id,position(F1,B1,E1),position(F2,B2,E2))) :- location(Id,position(F1,B1,E1),position(F2,B2,E2)).
ast(string(Id,Val)) :- string(Id,Val).
ast(number(Id,Val)) :- number(Id,Val).
ast(variable(Id,Name)) :- variable(Id,Name).
ast(unary_operation(Id,Operator,Argument)) :- unary_operation(Id,Operator,Argument).
ast(binary_operation(Id,Operator,Left,Right)) :- binary_operation(Id,Operator,Left,Right).
ast(interval(Id,Left,Right)) :- interval(Id,Left,Right).
ast(terms(Id,Pos,Element)) :- terms(Id,Pos,Element).
ast(function(Id,Name,Args)) :- function(Id,Name,Args).
ast(external_function(Id,Name,Args)) :- external_function(Id,Name,Args).
ast(pool(Id,Args)) :- pool(Id,Args).
ast(theory_terms(Id,Pos,Element)) :- theory_terms(Id,Pos,Element).
ast(theory_sequence(Id,SeqType,Terms)) :- theory_sequence(Id,SeqType,Terms).
ast(theory_function(Id,Name,Args)) :- theory_function(Id,Name,Args).
ast(theory_operators(Id,Pos,Operator)) :- theory_operators(Id,Pos,Operator).
ast(theory_unparsed_term_elements(Id,Pos,Operators,Term)) :- theory_unparsed_term_elements(Id,Pos,Operators,Term).
ast(theory_unparsed_term(Id,Elements)) :- theory_unparsed_term(Id,Elements).
ast(guard(Id,Op,Term)) :- guard(Id,Op,Term).
ast(guards(Id,Pos,Element)) :- guards(Id,Pos,Element).
ast(comparison(Id,Guards)) :- comparison(Id,Guards).
ast(boolean_constant(Id,Bool)) :- boolean_constant(Id,Bool).
ast(symbolic_atom(Id,Symbol)) :- symbolic_atom(Id,Symbol).
ast(literal(Id,Sign,Atom)) :- literal(Id,Sign,Atom).
ast(literals(Id,Pos,Element)) :- literals(Id,Pos,Element).
ast(conditional_literal(Id,Literal,Condition)) :- conditional_literal(Id,Literal,Condition).
ast(aggregate_elements(Id,Pos,Element)) :- aggregate_elements(Id,Pos,Element).
ast(aggregate(Id,LGuard,Elements,RGuard)) :- aggregate(Id,LGuard,Elements,RGuard).
ast(theory_atom_elements(Id,Pos,TheoryTerms,Condition)) :- theory_atom_elements(Id,Pos,TheoryTerms,Condition).
ast(theory_guard(Id,OpName,Term)) :- theory_guard(Id,OpName,Term).
ast(theory_atom(Id,Atom,Elements,TheoryGuard)) :- theory_atom(Id,Atom,Elements,TheoryGuard).
ast(body_aggregate_elements(Id,Pos,Terms,Condition)) :- body_aggregate_elements(Id,Pos,Terms,Condition).
ast(body_aggregate(Id,LGuard,Elements,RGuard)) :- body_aggregate(Id,LGuard,Elements,RGuard).
ast(body_literal(Id,Sign,Atom)) :- body_literal(Id,Sign,Atom).
ast(body_literals(Id,Pos,Element)) :- body_literals(Id,Pos,Element).
ast(head_aggregate_elements(Id,Pos,Terms,Condition)) :- head_aggregate_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(definition(Id,Name,Value,Default)) :- definition(Id,Name,Value,Default).
ast(show_signature(Id,Name,Arity,Positive)) :- show_signature(Id,Name,Arity,Positive).
ast(defined(Id,Name,Arity,Positive)) :- defined(Id,Name,Arity,Positive).
ast(minimize(Id,Weight,Priority,Terms,Body)) :- minimize(Id,Weight,Priority,Terms,Body).
ast(script(Id,Name,Code)) :- script(Id,Name,Code).
ast(statements(Id,Pos,Element)) :- statements(Id,Pos,Element).
ast(constants(Id,Pos,Element)) :- constants(Id,Pos,Element).
ast(program(Id,Name,Params,Statements)) :- program(Id,Name,Params,Statements).
ast(external(Atom,Body,Type)) :- external(Atom,Body,Type).
ast(edge(Id,U,V,Body)) :-edge(Id,U,V,Body).
ast(heuristic(Id,Atom,Body,Bias,Priority,Modifier)) :- heuristic(Id,Atom,Body,Bias,Priority,Modifier).
ast(project_atom(Id,Atom,Body)) :- project_atom(Id,Atom,Body).
ast(project_signature(Id,Name,Arity,Positive)) :- project_signature(Id,Name,Arity,Positive).
ast(theory_operator_definitions(Id,Pos,Name,Priority,OpType)) :- theory_operator_definitions(Id,Pos,Name,Priority,OpType).
ast(theory_term_definitions(Id,Pos,Name,Operators)) :- theory_term_definitions(Id,Pos,Name,Operators).
ast(theory_guard_definition(Id,Operators,Term)) :- theory_guard_definition(Id,Operators,Term).
ast(theory_atom_definitions(Id,Pos,AtomType,Name,Arity,Term,Guard)) :- theory_atom_definitions(Id,Pos,AtomType,Name,Arity,Term,Guard).
ast(theory_definition(Id,Name,Terms,Atoms)) :- theory_definition(Id,Name,Terms,Atoms).
% Rules to tag AST facts.

ast(string(X0,X1)) :- string(X0,X1).
ast(number(X0,X1)) :- number(X0,X1).
ast(variable(X0,X1)) :- variable(X0,X1).
ast(unary_operation(X0,X1,X2)) :- unary_operation(X0,X1,X2).
ast(binary_operation(X0,X1,X2,X3)) :- binary_operation(X0,X1,X2,X3).
ast(interval(X0,X1,X2)) :- interval(X0,X1,X2).
ast(terms(X0,X1,X2)) :- terms(X0,X1,X2).
ast(function(X0,X1,X2)) :- function(X0,X1,X2).
ast(external_function(X0,X1,X2)) :- external_function(X0,X1,X2).
ast(pool(X0,X1)) :- pool(X0,X1).
ast(theory_terms(X0,X1,X2)) :- theory_terms(X0,X1,X2).
ast(theory_sequence(X0,X1,X2)) :- theory_sequence(X0,X1,X2).
ast(theory_function(X0,X1,X2)) :- theory_function(X0,X1,X2).
ast(theory_operators(X0,X1,X2)) :- theory_operators(X0,X1,X2).
ast(theory_unparsed_term_elements(X0,X1,X2,X3)) :- theory_unparsed_term_elements(X0,X1,X2,X3).
ast(theory_unparsed_term(X0,X1)) :- theory_unparsed_term(X0,X1).
ast(guard(X0,X1,X2)) :- guard(X0,X1,X2).
ast(guards(X0,X1,X2)) :- guards(X0,X1,X2).
ast(comparison(X0,X1,X2)) :- comparison(X0,X1,X2).
ast(boolean_constant(X0,X1)) :- boolean_constant(X0,X1).
ast(symbolic_atom(X0,X1)) :- symbolic_atom(X0,X1).
ast(literal(X0,X1,X2)) :- literal(X0,X1,X2).
ast(literals(X0,X1,X2)) :- literals(X0,X1,X2).
ast(conditional_literal(X0,X1,X2)) :- conditional_literal(X0,X1,X2).
ast(aggregate_elements(X0,X1,X2)) :- aggregate_elements(X0,X1,X2).
ast(aggregate(X0,X1,X2,X3)) :- aggregate(X0,X1,X2,X3).
ast(theory_atom_elements(X0,X1,X2,X3)) :- theory_atom_elements(X0,X1,X2,X3).
ast(theory_guard(X0,X1,X2)) :- theory_guard(X0,X1,X2).
ast(theory_atom(X0,X1,X2,X3)) :- theory_atom(X0,X1,X2,X3).
ast(body_aggregate_elements(X0,X1,X2,X3)) :- body_aggregate_elements(X0,X1,X2,X3).
ast(body_aggregate(X0,X1,X2,X3,X4)) :- body_aggregate(X0,X1,X2,X3,X4).
ast(body_literal(X0,X1,X2)) :- body_literal(X0,X1,X2).
ast(body_literals(X0,X1,X2)) :- body_literals(X0,X1,X2).
ast(head_aggregate_elements(X0,X1,X2,X3)) :- head_aggregate_elements(X0,X1,X2,X3).
ast(head_aggregate(X0,X1,X2,X3,X4)) :- head_aggregate(X0,X1,X2,X3,X4).
ast(conditional_literals(X0,X1,X2)) :- conditional_literals(X0,X1,X2).
ast(disjunction(X0,X1)) :- disjunction(X0,X1).
ast(rule(X0,X1,X2)) :- rule(X0,X1,X2).
ast(definition(X0,X1,X2,X3)) :- definition(X0,X1,X2,X3).
ast(show_signature(X0,X1,X2,X3)) :- show_signature(X0,X1,X2,X3).
ast(defined(X0,X1,X2,X3)) :- defined(X0,X1,X2,X3).
ast(show_term(X0,X1,X2)) :- show_term(X0,X1,X2).
ast(minimize(X0,X1,X2,X3,X4)) :- minimize(X0,X1,X2,X3,X4).
ast(script(X0,X1,X2)) :- script(X0,X1,X2).
ast(statements(X0,X1,X2)) :- statements(X0,X1,X2).
ast(constants(X0,X1,X2)) :- constants(X0,X1,X2).
ast(program(X0,X1,X2,X3)) :- program(X0,X1,X2,X3).
ast(external(X0,X1,X2,X3)) :- external(X0,X1,X2,X3).
ast(edge(X0,X1,X2,X3)) :- edge(X0,X1,X2,X3).
ast(heuristic(X0,X1,X2,X3,X4,X5)) :- heuristic(X0,X1,X2,X3,X4,X5).
ast(project_atom(X0,X1,X2)) :- project_atom(X0,X1,X2).
ast(project_signature(X0,X1,X2,X3)) :- project_signature(X0,X1,X2,X3).
ast(theory_operator_definitions(X0,X1,X2,X3,X4)) :- theory_operator_definitions(X0,X1,X2,X3,X4).
ast(theory_term_definitions(X0,X1,X2,X3)) :- theory_term_definitions(X0,X1,X2,X3).
ast(theory_guard_definition(X0,X1,X2)) :- theory_guard_definition(X0,X1,X2).
ast(theory_atom_definitions(X0,X1,X2,X3,X4,X5,X6)) :- theory_atom_definitions(X0,X1,X2,X3,X4,X5,X6).
ast(theory_definition(X0,X1,X2,X3)) :- theory_definition(X0,X1,X2,X3).
ast(location(X0,X1,X2)) :- location(X0,X1,X2).
Loading

0 comments on commit 7e58c5e

Please sign in to comment.