Read a term from a Prolog source-file. Options is a option list
that is forwarded to read_clause/3.
This 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).
- Arguments:
-
Term | - Term read |
Expanded | - Result of term-expansion on the term |
- See also
- - read_source_term_at_location/3 for reading at an
arbitrary location.
Try to read a Prolog term form an arbitrary location inside a
file. Due to Prolog's dynamic syntax, e.g., due to operator
declarations that may change anywhere inside the file, this is
theoreticaly impossible. Therefore, this predicate is
fundamentally heuristic and may fail. This predicate is used
by e.g., clause_info/4 and by PceEmacs to colour the current
clause.
This 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.
- line(+Line)
- If present, start reading at line Line.
- offset(+Characters)
- Use seek/4 to go to the indicated location. See seek/4
for limitations of seeking in text-files.
- module(+Module)
- Use syntax from the given module. Default is the current
`source module'.
- operators(+List)
- List of additional operator declarations to enforce while
reading the term.
- error(-Error)
- If no correct parse can be found, unify Error with a term
Offset:Message that indicates the (character) location of
the error and the related message. Adding this option
makes read_source_term_at_location/3 deterministic (
det
).
- See also
- - Use read_source_term/4 to read a file from the start.
- - alternate_syntax/4 for locally scoped operators.
Define an alternative syntax to try reading a term at an
arbitrary location in module Module.
Calls the hook alternate_syntax/4 with the same signature
to allow for user-defined extensions.
- Arguments:
-
Setup | - is a deterministic goal to enable this syntax in
module. |
Restore | - is a deterministic goal to revert the actions of
Setup. |
True when the quasi quotation syntax Syntax can be loaded from
Library. Library must be a valid first argument for
use_module/2.
This multifile hook is used by library(prolog_source) to load
quasi quotation handlers on demand.
Open source with given canonical id (see
prolog_canonical_source/2) and remove the #! line if any.
Streams opened using this predicate must be closed using
prolog_close_source/1. Typically using the skeleton below. Using
this skeleton, operator and style-check options are
automatically restored to the values before opening the source.
process_source(Src) :-
prolog_open_source(Src, In),
call_cleanup(process(Src), prolog_close_source(In)).
Translate between a path represented as a/b/c and an atom
representing the same path. For example:
?- 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.
True when Files is a sorted list of Prolog source files in Dir.
Options:
- recursive(boolean)
- If
true
(default false
), recurse into subdirectories
- if Condition
- If
true
(default loaded
), only report loaded files.
Other options are passed to absolute_file_name/3, unless
loaded(true)
is passed.