1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    2%% parseDomainPDDL.pl
    3%%   Simple parser of PDDL domain file into prolog syntax.
    4%% Author: Robert Sasak, Charles University in Prague
    5%%
    6%% Example: 
    7%% ?-parseDomainPDDL('blocks_world.pddl', O).
    8%%   O = domain(blocks,
    9%%        [strips, typing, 'action-costs'],
   10%%        [block],
   11%%        _G4108,
   12%%        [ on(block(?x), block(?y)),
   13%%	         ontable(block(?x)),
   14%%	         clear(block(?x)),
   15%%	         handempty,
   16%%	         holding(block(?x)) ],
   17%%        [number(f('total-cost', []))],
   18%%        _G4108,
   19%%        [ action('pick-up', [block(?x)],       %parameters
   20%%		      [clear(?x), ontable(?x), handempty], %preconditions
   21%%		      [holding(?x)],                       %positiv effects
   22%%          [ontable(?x), clear(?x), handempty], %negativ effects
   23%%          [increase('total-cost', 2)]),        %numeric effects
   24%%         ...],
   25%%       ...)
   26%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   27
   28% Support for reading file as a list.
   29
   30:- ensure_loaded('readFileI').   31
   32% parseDomainPDDL(+File, -Output).
   33% Parse PDDL domain File and return it rewritten prolog syntax.   
   34parseDomainPDDL(F, O):-
   35	view([domainPDDLFile,F]),
   36	parseDomainPDDL(F, O, _).
   37
   38% parseDomainPDDL(+File, -Output, -RestOfFile)
   39% The same as above and also return rest of file. Can be useful when domain and problem are in one file.
   40parseDomainPDDL(File, Output, R) :-
   41		read_file(File, List),
   43		domainPDDL(Output, List, R)
   43.
   44
   45% List of DCG rules describing structure of domain file in language PDDL.
   46% BNF description was obtain from http://www.cs.yale.edu/homes/dvm/papers/pddl-bnf.pdf
   47% This parser do not fully NOT support PDDL 3.0
   48% However you will find comment out lines ready for futher development.
   49domainPDDL(domain(N, R, T, P, F, S))
   50			--> ['(','define', '(','domain'], name(N), [')'],
   51                             (require_def(R)	; []),
   52                             (types_def(T)    	; []), %:typing
   54                             (predicates_def(P)	; []),
   55                             (functions_def(F)	; []), %:fluents
   57                             zeroOrMore(structure_def, S),
   58			     [')']
   58.
   59
   60:- ensure_loaded('sharedPDDL2.2Domain').