-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathparser.lgt
60 lines (51 loc) · 1.98 KB
/
parser.lgt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
:- object(banpipe_parser).
:- info([
version is 1:0:0,
author is 'Christian Theil Have',
date is 2012-11-13,
comment is 'Predicates for decomposing banpipe rules.']).
:- public(match_target_rule/3).
%% match_target_rule(+Target,-Type,-Rule,-Index)
:- info(match_target_rule/3,[
comment is 'Matches a dependency rule where Target is the Nth goal of the rule head',
argnames is ['Target','Rule','N']
]).
:- public(parse_guard_and_body/3).
:- public(parse_task_specification/4).
:- info(parse_task_specification/4, [
comment is 'Process different forms of specifying patterns for running a particular task within a module.',
argnames is ['TaskSpec','Task','Inputs','Options']
]).
match_target_rule(Target,TargetsList+Rule,TargetIndex) :-
{clause('<-'(Targets,Rule),true)},
term_extras::conjunction_as_list(Targets,TargetsList),
list::nth1(TargetIndex,TargetsList,Target).
:- info(parse_guard_and_body/3,[
comment is 'parse the RHS side of a rule',
argnames is ['RHS','Guard','Body']
]).
parse_guard_and_body(Spec, Guard, Body) :-
Spec = '|'(Guard, Body),
!.
parse_guard_and_body(Body, true, Body).
% case pattern example: task1([file1,file2]).
parse_task_specification(TaskSpecification,Task,Inputs,[]) :-
TaskSpecification =.. [ Task, Inputs ],
list::valid(Inputs).
% case pattern example: task([file1,file2],[opt1(foo),opt2(bar)]).
parse_task_specification(TaskSpecification,Task,Inputs,Options) :-
TaskSpecification =.. [ Task, Inputs, Options ],
list::valid(Inputs),
list::valid(Options).
% caase pattern example: task1(file,[opt1(foo)])
parse_task_specification(TaskSpecification,Task,[Inputs],Options) :-
TaskSpecification =.. [ Task, Inputs, Options ],
\+ list::valid(Inputs),
list::valid(Options),
!.
% case pattern example: task1(file1,file2).
parse_task_specification(TaskSpecification,Task,Inputs,[]) :-
TaskSpecification =.. [ Task | Inputs ],
list::valid(Inputs),
forall(list::member(L,Inputs), \+ list::valid(L)).
:- end_object.