Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add basic formatters #531

Merged
merged 2 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 5 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
IndentWidth: '4'
ColumnLimit: '120'
IndentCaseLabels: 'true'
...
1 change: 0 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -421,4 +421,3 @@ CheckOptions:
- key: llvm-else-after-return.WarnOnUnfixable
value: 'false'
...

28 changes: 28 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
fail_fast: true
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
exclude: ^.github/

- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
args: ["--profile", "black"]
exclude: ^.github/

- repo: https://github.com/psf/black
rev: 24.4.0
hooks:
- id: black
exclude: ^.github/

- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v18.1.8
hooks:
- id: clang-format
exclude: /_clingo\.c$
types_or: [c++, c, cuda]
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@

## gringo/clingo 4.2

* added clingo
* added clingo
* supports very flexible scripting support
* can cover iclingo and oclingo functionality now
* added stack traces to lua error messages
Expand Down
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -324,4 +324,3 @@ if (NOT CLINGO_BUILD_STATIC AND (CLINGO_BUILD_SHARED OR Python_Development_FOUND
set_target_properties(${target} PROPERTIES POSITION_INDEPENDENT_CODE ON)
endforeach()
endif()

15 changes: 7 additions & 8 deletions app/clingo/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,29 @@
// }}}

#ifdef CLINGO_WITH_PYTHON
# include <pyclingo.h>
#include <pyclingo.h>
#endif
#ifdef CLINGO_WITH_LUA
# include <luaclingo.h>
#include <luaclingo.h>
#endif

#include <clingo.h>
#include <iostream>

extern "C" CLINGO_VISIBILITY_DEFAULT int clingo_main_(int argc, char *argv[]);

int main(int argc, char** argv) {
# ifdef CLINGO_WITH_PYTHON
int main(int argc, char **argv) {
#ifdef CLINGO_WITH_PYTHON
if (!clingo_register_python_()) {
std::cerr << clingo_error_message() << std::endl;
return 1;
}
# endif
# ifdef CLINGO_WITH_LUA
#endif
#ifdef CLINGO_WITH_LUA
if (!clingo_register_lua_(nullptr)) {
std::cerr << clingo_error_message() << std::endl;
return 1;
}
# endif
#endif
return clingo_main_(argc, argv);
}

6 changes: 3 additions & 3 deletions app/clingo/tests/lp/aggregates.lp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ asstwo(S,u):-arg(S),ass(S,u),saturate.
sattwo(S):-arg(S),ass(S,u),saturate.
:-not saturate.
#show ass/2.

:-ass(s1, 0),ass(s2, 0),ass(s3, 0).
:-ass(s1, 1),ass(s2, 0),ass(s3, 1).
%unfounded: saturate, asstwo(s1,0), asstwo(s1,0)

%unfounded: saturate, asstwo(s1,0), asstwo(s1,0)
3 changes: 0 additions & 3 deletions app/clingo/tests/lp/elevator.lp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,3 @@ x(A,D,t) :- h(a(A,F),t-1), o(A,G+D,D), p(A,D), i(a(A,G)), D*F < D*G,

#show.
#show h/2.



2 changes: 0 additions & 2 deletions app/clingo/tests/lp/project.lp
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@

1 { p(1..2) } 1.
1 { q(1..2) } 1.


1 change: 0 additions & 1 deletion app/clingo/tests/lp/show.lp
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ q(k+1), k < 3.

{show} :- k == 3.
#show p(1..4) : show, k == 3.

1 change: 0 additions & 1 deletion app/clingo/tests/lua/add_minimize.lp
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,3 @@ end

2 { a; b; c }.
2 { b; c; d }.

1 change: 0 additions & 1 deletion app/clingo/tests/lua/add_weight.lp
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,3 @@ end
#end.

{ a; b; c }.

23 changes: 11 additions & 12 deletions app/clingo/tests/lua/conformant1.lp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#script (lua)
#script (lua)
function main(prg)
local step = 0
local check = false
Expand Down Expand Up @@ -29,7 +29,7 @@ function main(prg)
if ret.satisfiable then
break
end
else
else
break
end
end
Expand Down Expand Up @@ -60,7 +60,7 @@ contradict(F) :- complement(F,L,M), effect(A,L,N1), effect(A,M,N2),
{ holds(F,0) } :- complement(F,L,M), not initially(L), not initially(M).
holds(F,0) :- initially(L), complement(F,L,M).

holds_oneof(N,B) :-
holds_oneof(N,B) :-
initially_oneof(N,_,B);
not holds(F,0) : initially_oneof(N,M,B), complement(F,L,M);
holds(F,0) : initially_oneof(N,L,B), complement(F,L,M).
Expand All @@ -80,7 +80,7 @@ holds(L,t) :- occurs(A,t), effect(A,L,N), holds(C,t-1) : condition(A,C,N).
holds(L,t) :- holds(L,t-1), complement(L,M), not holds(M,t).
:- contradict(F), complement(F,L,M), holds((L),t), holds((M),t).

caused(L,t) :- occurs(A,t), effect(A,L,N),
caused(L,t) :- occurs(A,t), effect(A,L,N),
not holds(F',t-1) : condition(A,M',N), complement(F',L',M');
holds(F',t-1) : condition(A,L',N), complement(F',L',M').
holds(F,t) :- caused(L,t), complement(F,L,M).
Expand Down Expand Up @@ -126,9 +126,9 @@ pos_executable(T,t) :- occurs(A,T), alt_holds(C,T-1,t) : executable(A,C), C !=
pos_goal_or(N,t) :- goal_or(N,L,B), alt_holds(L,t,t), vol(t).
pos_goal_or(N,t) :- goal_or(N,L,B), goal(L), vol(t).

bottom(t) :- pos_goal_or(N,t) : goal_or(N,_,_);
bottom(t) :- pos_goal_or(N,t) : goal_or(N,_,_);
alt_holds(L,t,t) : goal(L);
pos_executable(R,t) : R = 1..t;
pos_executable(R,t) : R = 1..t;
not_contradict(F,S,t) : contradict(F), S = 1..t;
vol(t).

Expand Down Expand Up @@ -159,7 +159,7 @@ fluent(cpa_coin_at(cpa_c0, cpa_f1, cpa_p1)).
fluent(cpa_coin_at(cpa_c1, cpa_f1, cpa_p0)).
fluent(cpa_coin_at(cpa_c1, cpa_f1, cpa_p1)).

%% actions ------
%% actions ------

action(cpa_collect(cpa_c0, cpa_f0, cpa_p0)).
action(cpa_collect(cpa_c0, cpa_f0, cpa_p1)).
Expand All @@ -186,7 +186,7 @@ action(cpa_step_out(cpa_e0, cpa_f1, cpa_p0)).
action(cpa_step_out(cpa_e1, cpa_f0, cpa_p1)).
action(cpa_step_out(cpa_e1, cpa_f1, cpa_p1)).

%% executable ------
%% executable ------

executable(cpa_collect(cpa_c0, cpa_f0, cpa_p0),cpa_at(cpa_f0, cpa_p0)).
executable(cpa_collect(cpa_c0, cpa_f0, cpa_p1),cpa_at(cpa_f0, cpa_p1)).
Expand All @@ -209,7 +209,7 @@ executable(cpa_step_out(cpa_e0, cpa_f1, cpa_p0),cpa_inside(cpa_e0)).
executable(cpa_step_out(cpa_e1, cpa_f0, cpa_p1),cpa_inside(cpa_e1)).
executable(cpa_step_out(cpa_e1, cpa_f1, cpa_p1),cpa_inside(cpa_e1)).

%% effects ------
%% effects ------

effect(cpa_collect(cpa_c0, cpa_f1, cpa_p0),cpa_have(cpa_c0),1).
effect(cpa_collect(cpa_c0, cpa_f1, cpa_p0),neg(cpa_coin_at(cpa_c0, cpa_f1, cpa_p0)),1).
Expand Down Expand Up @@ -268,7 +268,7 @@ effect(cpa_step_out(cpa_e1, cpa_f1, cpa_p1),cpa_at(cpa_f1, cpa_p1),1).
effect(cpa_step_out(cpa_e1, cpa_f1, cpa_p1),neg(cpa_inside(cpa_e1)),1).
condition(cpa_step_out(cpa_e1, cpa_f1, cpa_p1),cpa_in(cpa_e1, cpa_f1),1).

%% initial state ------
%% initial state ------

initially(cpa_at(cpa_f0, cpa_p0)).
initially(neg(cpa_at(cpa_f0, cpa_p1))).
Expand All @@ -287,8 +287,7 @@ initially_oneof(3,cpa_coin_at(cpa_c1, cpa_f1, cpa_p0),1).
initially_oneof(3,cpa_coin_at(cpa_c0, cpa_f1, cpa_p1),2).
initially_oneof(3,cpa_coin_at(cpa_c1, cpa_f1, cpa_p1),2).

%% goal state ----------
%% goal state ----------

goal(cpa_have(cpa_c0)).
goal(cpa_have(cpa_c1)).

23 changes: 11 additions & 12 deletions app/clingo/tests/lua/conformant2.lp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#script (lua)
#script (lua)
function main(prg)
local step = 0
local check = false
Expand Down Expand Up @@ -29,7 +29,7 @@ function main(prg)
if ret.satisfiable then
break
end
else
else
break
end
end
Expand Down Expand Up @@ -60,7 +60,7 @@ contradict(F) :- complement(F,L,M), effect(A,L,N1), effect(A,M,N2),
{ holds(F,0) } :- complement(F,L,M), not initially(L), not initially(M).
holds(F,0) :- initially(L), complement(F,L,M).

holds_oneof(N,B) :-
holds_oneof(N,B) :-
initially_oneof(N,_,B);
not holds(F,0) : initially_oneof(N,M,B), complement(F,L,M);
holds(F,0) : initially_oneof(N,L,B), complement(F,L,M).
Expand All @@ -80,7 +80,7 @@ holds(L,t) :- occurs(A,t), effect(A,L,N), holds(C,t-1) : condition(A,C,N).
holds(L,t) :- holds(L,t-1), complement(L,M), not holds(M,t).
:- contradict(F), complement(F,L,M), holds((L),t), holds((M),t).

caused(L,t) :- occurs(A,t), effect(A,L,N),
caused(L,t) :- occurs(A,t), effect(A,L,N),
not holds(F',t-1) : condition(A,M',N), complement(F',L',M');
holds(F',t-1) : condition(A,L',N), complement(F',L',M').
holds(F,t) :- caused(L,t), complement(F,L,M).
Expand Down Expand Up @@ -126,9 +126,9 @@ pos_executable(T,t) :- occurs(A,T), alt_holds(C,T-1,t) : executable(A,C), C !=
pos_goal_or(N,t) :- goal_or(N,L,B), alt_holds(L,t,t), vol(t).
pos_goal_or(N,t) :- goal_or(N,L,B), goal(L), vol(t).

bottom(t) :- pos_goal_or(N,t) : goal_or(N,_,_);
bottom(t) :- pos_goal_or(N,t) : goal_or(N,_,_);
alt_holds(L,t,t) : goal(L);
pos_executable(R,t) : R = 1..t;
pos_executable(R,t) : R = 1..t;
not_contradict(F,S,t) : contradict(F), S = 1..t;
vol(t).

Expand All @@ -148,7 +148,7 @@ fluent(cpa_visited(cpa_n2)).
fluent(cpa_at(cpa_n1)).
fluent(cpa_at(cpa_n2)).

%% actions ------
%% actions ------

action(cpa_start(cpa_n1)).
action(cpa_start(cpa_n2)).
Expand All @@ -157,7 +157,7 @@ action(cpa_travel(cpa_n1, cpa_n2)).
action(cpa_travel(cpa_n2, cpa_n1)).
action(cpa_travel(cpa_n2, cpa_n2)).

%% executable ------
%% executable ------

executable(cpa_start(cpa_n1),true).
executable(cpa_start(cpa_n2),true).
Expand All @@ -166,7 +166,7 @@ executable(cpa_travel(cpa_n1, cpa_n2),cpa_started).
executable(cpa_travel(cpa_n2, cpa_n1),cpa_started).
executable(cpa_travel(cpa_n2, cpa_n2),cpa_started).

%% effects ------
%% effects ------

effect(cpa_start(cpa_n1),cpa_started,1).
effect(cpa_start(cpa_n1),cpa_visited(cpa_n1),1).
Expand All @@ -183,16 +183,15 @@ effect(cpa_travel(cpa_n2, cpa_n1),cpa_at(cpa_n1),1).
effect(cpa_travel(cpa_n2, cpa_n1),neg(cpa_at(cpa_n2)),1).
condition(cpa_travel(cpa_n2, cpa_n1),cpa_at(cpa_n2),1).

%% initial state ------
%% initial state ------

initially(neg(cpa_visited(cpa_n1))).
initially(neg(cpa_visited(cpa_n2))).
initially(neg(cpa_started)).
initially_oneof(1,cpa_at(cpa_n1),1).
initially_oneof(1,cpa_at(cpa_n2),2).

%% goal state ----------
%% goal state ----------

goal(cpa_visited(cpa_n1)).
goal(cpa_visited(cpa_n2)).

Loading
Loading