
prolog_source.pl -- Examine Prolog source-filesThis module provides predicates to open, close and read terms from Prolog source-files. This may seem easy, but there are a couple of problems that must be taken care of.
This module concentrates these issues in a single library. Intended users of the library are:
prolog_read_source_term(+In, -Term, -Expanded, +Options) is detThis predicate is intended to read the file from the start. It tracks directives to update its notion of the currently effective syntax (e.g., declared operators).
requires_library(+Term, -Library)[multifile]
load_quasi_quotation_syntax(:Path, +Syntax) is semidet
read_source_term_at_location(+Stream, -Term, +Options) is semidetThis predicate has two ways to find the right syntax. If the file is loaded, it can be passed the module using the module option. This deals with module files that define the used operators globally for the file. Second, there is a hook alternate_syntax/4 that can be used to temporary redefine the syntax.
The options below are processed in addition to the options of
read_term/3. Note that the line and offset options are
mutually exclusive.
det).
prolog:quasi_quotation_syntax(+Syntax, -Library) is semidet[multifile]This multifile hook is used by library(prolog_source) to load quasi quotation handlers on demand.
prolog_file_directives(+File, -Directives, +Options) is dettrue (default false), do not report syntax errors and
other errors.
prolog_open_source(+CanonicalId:atomic, -Stream:stream) is det
process_source(Src) :-
prolog_open_source(Src, In),
call_cleanup(process(Src), prolog_close_source(In)).
prolog:xref_open_source(+SourceID, -Stream)[multifile]
prolog_close_source(+In:stream) is detexpand_term(end_of_file, _) to allow expansion
modules to clean-up.
prolog:xref_close_source(+SourceID, +Stream) is semidet[multifile]force(true) is used.
prolog_canonical_source(+SourceSpec:ground, -Id:atomic) is semidet
file_name_on_path(+File:atom, -OnPath) is det
file_alias_path(-Alias, ?Dir) is nondet
path_segments_atom(+Segments, -Atom) is det?- path_segments_atom(a/b/c, X). X = 'a/b/c'. ?- path_segments_atom(S, 'a/b/c'), display(S). /(/(a,b),c) S = a/b/c.
This predicate is part of the Prolog source library because SWI-Prolog allows writing paths as /-nested terms and source-code analysis programs often need this.
directory_source_files(+Dir, -Files, +Options) is dettrue (default false), recurse into subdirectoriestrue (default loaded), only report loaded files.
Other options are passed to absolute_file_name/3, unless
loaded(true) is passed.
valid_term_position(@Term, @TermPos) is semidet
If a position in TermPos is a variable, the validation of the
corresponding part of Term succeeds. This matches the
term_expansion/4 treats "unknown" layout information. If part of a
TermPos is given, then all its "from" and "to" information must be
specified; for example, string_position(X,Y) is an error but
string_position(0,5) succeeds. The position values are checked for
being plausible -- e.g., string_position(5,0) will fail.
This should always succeed:
read_term(Term, [subterm_positions(TermPos)]), valid_term_position(Term, TermPos)