Read Term From A Stream¶
Define:¶
Functions:¶
1. static Term is_output_list(Term t):
1. static void clean_vars(VarEntry *p):
1. static Term add_output(Term t, Term tail):
1. static Term add_names(Term t, Term tail):
1. static Term add_priority(Term t, Term tail):
1. static Term tokToPair(TokEntry *tok):
1. static Int scan_stream(USES_REGS1): : "scan_stream( +Stream, -Tokens " )
@class scan_stream_2
Generate a list of tokens from a scan of the (input) stream, Tokens are of the form:
-
atom
(Atom) -
<QQ>
(Text) -
number
(Number) -
var
(VarName) -
string
(String) -
'EOF''
-
symbols, including
(
,)
,,
,;
1. char * Yap_syntax_error__(const char file, const char function, int lineno, Term t, int sno, TokEntry start, TokEntry err, char *msg,...): : Syntax Error Handler.
par: tokptrU3aUU20UtheU20UsequenceU20UofU20Utoke_s par: snoU3aUU20UtheU20UstreamU20Unumb_t
Implicit arguments:
1. static xarg * setClauseReadEnv(Term opts, FEnv fe, struct renv re, int inp_stream):
1. static xarg * setReadEnv(Term opts, FEnv fe, struct renv re, int inp_stream):
1. Int Yap_FirstLineInParse(void):
1. static void reset_regs(TokEntry tokstart, FEnv fe):
1. static Term get_variables(FEnv fe, TokEntry tokstart):
1. static Term get_varnames(FEnv fe, TokEntry tokstart):
1. static Term get_singletons(FEnv fe, bool var_only, TokEntry tokstart):
1. static void warn_singletons(FEnv fe, int sno, TokEntry tokstart):
1. static Term get_stream_position(FEnv fe, TokEntry tokstart):
1. static bool is_goal(Term t):
1. static Term scan_to_list(TokEntry *t):
1. static bool complete_processing(FEnv fe, int sno, TokEntry tokstart):
1. static bool complete_clause_processing(FEnv fe, int sno, TokEntry tokstart):
1. static parser_state_t initparser(Term opts, FEnv fe, REnv re, int inp_stream, bool clause):
1. static parser_state_t parse(REnv re, FEnv fe, int inp_stream):
1. static parser_state_t scanError(REnv re, FEnv fe, int inp_stream):
1. static parser_state_t scan(REnv re, FEnv fe, int inp_stream):
1. static parser_state_t scanEOF(FEnv fe, int inp_stream, TokEntry tokstart):
1. static Term add_comment(FEnv *fe, Term comms, Term v):
1. static parser_state_t parseError(REnv re, FEnv fe, int inp_stream):
1. static Term exit_parser(int sno, yhandle_t y0, yap_error_descriptor_t new, yap_error_descriptor_t old, Term rc): : dome with the parser, off we go...
1. Term Yap_read_term(int sno, Term opts, bool clause): : generic routine to read terms from a stream
-
inp_stream: where we read from
-
: opts, a list with options
-
: if called from read_term, arity called from read_clause, -arity
return:
the term or 0 in case of error.
Implementation uses a state machine: default is init, scan, parse, complete.
1. static Int read_ter/2(USES_REGS1):
1. static Int read_term(USES_REGS1):
1. static Int read_claus/2(USES_REGS1): : "read_clause( +Stream, -Clause, ?Opts" ) is det
@class read_clause_3
x * Same as read_clause_51 "read_clause/3", but from the standard input stream.
1. static Int read_clause(USES_REGS1): : "read_clause( +Stream, -Clause, ?Opts" ) is det
@class read_clause_3
This predicate receives a set of options OPts based on read_term_51 "read_term/3", but specific to readin clauses. The following options are considered:
-
The
comments
option unifies its argument with the comments in the term, represented as strings -
The
process_comments
option calls a hook, it is current ignored by YAP. -
The
term_position
unifies its argument with a term describing the position of the term. -
The
syntax_errors
flag controls response to syntactic errors, the default isdec10
.
The next two options are called implicitly:
-
The
module
option is initialized to the current source module, by default. -
The
singletons
option is set from the single var flag
1. static Int source_location(USES_REGS1): : start input for a meta-clause.
Should obtain:
-
predicate name
-
predicate arity
-
address for 256 cluses.
ARG1input stream
ARG2Adress of predicate.
ARG3Term read.
return:
[description] @class source_location_3
"source_location( - File , Line, Offset " )
unify File and Line wuth the position of the last term read, if the term comes from a stream created by opening a file-system path with open_51 "open/3" and friends. It ignores user_input or sockets.
-File
-Line
note:
SWI-Prolog built-in.
1. static Int rea/2(USES_REGS1): : "read(+ Stream, -Term " ) is iso
@class read_2
Reads term T from the stream S instead of from the current input stream.
-Stream -Term
1. static Int rea/1(USES_REGS1):
1. static Int style_checker(USES_REGS1):
1. Term Yap_BufferToTerm(const char *s, Term opts):
1. Term Yap_UBufferToTerm(const unsigned char *s, Term opts):
1. X_API Term Yap_BufferToTermWithPrioBindings(const char *s, Term ctl, Term bindings, size_t len, int prio):
1. static Int read_term_from_atom(USES_REGS1): : "read_term_from_atom( +Atom , -T , +Options " )
@class read_term_from_atom_3
read a term T stored in constant Atom according to Options
_Atom_the source Atom _T_the output term T, may be any term _Options_read_term_51 "read_term/3" options.
@note Originally from SWI-Prolog, in YAP only works with internalised atoms Check @ref read_term_from_atomic_51 @"read_term_from_atomic/3" for the general version. Also, the built-in is supposed to use YAP's internal encoding, so please avoid the @ref encoding_49 @"encoding/1" option.
1. static Int read_term_from_atomic(USES_REGS1): : "read_term_from_atomic( +Atomic , - T , +Options " )
@class read_term_from_atomic_3
read a term T stored in text Atomic according to Options
_Atomic_the source may be an atom, string, list of codes, or list of chars.
_T_the output term T, may be any term
_Options_read_term_51 "read_term/3" options.
note:
Idea originally from SWI-Prolog, but in YAP we separate atomic and atom. Encoding is fixed in atoms and strings.
1. static Int read_term_from_string(USES_REGS1): : "read_term_from_string( +String , - T , + Options " )
@class read_term_from_string_3
read a term T stored in constant String according to Options
_String_the source String _T_the output term T, may be any term _Options_read_term_51 "read_term/3" options.
Idea from SWI-Prolog, in YAP only works with strings
Check @ref read_term_from_atomic_51 @"read_term_from_atomic/3" for the general version.
1. static Int read_term_from_chars(USES_REGS1): : "read_term_from_chars( +String , - T , + Options " )
@class read_term_from_chars_3
read a term T stored in a list of characters String according to Options
_String_the source String _T_the output term T, may be any term _Options_read_term_51 "read_term/3" options.
Idea from SWI-Prolog, in YAP only works with strings
Check @ref read_term_from_atomic_51 @"read_term_from_atomic/3" for the general version.
1. static Int read_term_from_codes(USES_REGS1): : "read_term_from_chars( +String , - T , + Options " )
@class read_term_from_chars_3
read a term T stored in a list of characters String according to Options
_String_the source String _T_the output term T, may be any term _Options_read_term_51 "read_term/3" options.
Idea from SWI-Prolog, in YAP only works with strings
Check @ref read_term_from_atomic_51 @"read_term_from_atomic/3" for the general version.
1. static Int atom_to_term(USES_REGS1):
1. static Int atomic_to_term(USES_REGS1):
1. static Int string_to_term(USES_REGS1):
1. void Yap_InitReadTPreds(void):
Var:¶
1. const param_t read_defs[][]:
Typedef:¶
1. typedef enum read_enum_choices read_choices_t: