Commit e3bc9095 authored by Siebers, Michael's avatar Siebers, Michael
Browse files

move common types to type definitions file

parent a17089b9
......@@ -5,7 +5,10 @@
:- use_module(src/theory_bg).
% Error handling
:- consult(error_handling).
:- ensure_loaded(error_handling).
% Item definition
:- ensure_loaded(type_defs).
/**
......@@ -65,25 +68,3 @@ all_items_external(Items) :-
all_items_external_(_Key-Value,Item) :-
is_dict(Value, Type),
parse_type(Value, dict([type:atom=Type]), Item, [extra_keys(add)]).
%! item_type(-Type) is det.
%
% Generates the type definition for an item (that is a file or a directory). Type is a valid type as defined by types:check_type_def/1.
item_type(anyof([DirectoryType,FileType])) :-
abs_path_type(AbsPathType),
CommonKeys=[
abs_path: AbsPathType,
creation_time: integer
],
FileType = dict([
type: atom('^file$'),
file_size: positive_integer,
media_type: atom,
filename_extension: atom,
modification_time: integer,
access_time: integer,
change_time: integer
| CommonKeys
]),
DirectoryType = dict([type:atom('^directory$')|CommonKeys]).
:- ensure_loaded(requests).
:- ensure_loaded(error_handling).
:- ensure_loaded(type_defs).
:- use_module(src/explanations).
:- multifile user:irrelevant/1.
......@@ -9,7 +10,8 @@
% True if the item associated with the absolute path given in Parameters
% is irrelevant. The absolute path is accessed using the dict key `abs_path`.
% An error is thrown if the dict does not contain this key, if its value
% is not an atom or if the dict contains any other keys.
% is not an atom representing an absolute file path, or if the dict contains
% any other keys.
%
% @throws parse_error(Reason, Location) if Parameters cannot be parsed
% @error api_error(_, parameter_error) if the format of Parameters is erroneous,
......@@ -17,7 +19,7 @@
% value read is unbound.
% @error api_error(_, implementation_error) if checking the irrelevance itself
% throws an exception.
do_handle_irrelevant_file(Parameters,AbsPath) :-
do_handle_irrelevant_file(Parameters, AbsPath) :-
abs_path_type(AbsPathType),
parse_parameters(Parameters,
dict([abs_path:AbsPathType]),
......@@ -67,8 +69,9 @@ do_handle_irrelevant_file(Parameters,AbsPath) :-
% any value read from Parameters is
% unbound, or Result or More are bound
do_handle_explain(Parameters, Result, More) :-
abs_path_type(AbsPathType),
parse_parameters(Parameters,
dict([abs_path:atom, limit:positive_integer=5]),
dict([abs_path:AbsPathType, limit:positive_integer=5]),
Parsed),
( var(Result)
-> true
......
......@@ -99,8 +99,3 @@ parse_parameters(In, Type, Out) :-
throw(Exception)
)
).
%! abs_path_type(-Type) is det.
%
% Return the type definition for an absolute path used to identify items.
abs_path_type(atom('^(/|.*[^/])$')).
%! abs_path_type(-Type) is det.
%
% Return the type definition for an absolute path used to identify items. Type
% is a valid type as defined by types:check_type_def/1.
abs_path_type(atom('^(/|.*[^/])$')).
%! item_type(-Type) is det.
%
% Generates the type definition for an item (that is a file or a directory).
% Type is a valid type as defined by types:check_type_def/1.
item_type(anyof([DirectoryType,FileType])) :-
directory_type(DirectoryType),
file_type(FileType).
%! file_type(-Type) is det.
%
% Generates the type definition for a file. Type is a valid type as defined by
% types:check_type_def/1.
file_type(dict([
abs_path: AbsPathType,
type: atom('^file$'),
file_size: positive_integer,
media_type: atom,
filename_extension: atom,
creation_time: integer,
modification_time: integer,
access_time: integer,
change_time: integer
])) :- abs_path_type(AbsPathType).
%! directory_type(-Type) is det.
%
% Generates the type definition for a directory. Type is a valid type as defined
% by types:check_type_def/1.
directory_type(dict([
abs_path: AbsPathType,
creation_time: integer,
type:atom('^directory$')
])) :- abs_path_type(AbsPathType).
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment