reformatting
This commit is contained in:
parent
ae65bb0265
commit
0a9f37710c
160
os/readterm.c
160
os/readterm.c
@ -182,9 +182,8 @@ static int parse_quasi_quotations(ReadData _PL_rd ARG_LD) {
|
|||||||
#endif /*O_QUASIQUOTATIONS*/
|
#endif /*O_QUASIQUOTATIONS*/
|
||||||
|
|
||||||
#define READ_DEFS() \
|
#define READ_DEFS() \
|
||||||
PAR("comments", list_filler, READ_COMMENTS),\
|
PAR("comments", list_filler, READ_COMMENTS), \
|
||||||
PAR("module", isatom, READ_MODULE), \
|
PAR("module", isatom, READ_MODULE), PAR("priority", nat, READ_PRIORITY), \
|
||||||
PAR("priority", nat, READ_PRIORITY), \
|
|
||||||
PAR("quasi_quotations", filler, READ_QUASI_QUOTATIONS), \
|
PAR("quasi_quotations", filler, READ_QUASI_QUOTATIONS), \
|
||||||
PAR("term_position", filler, READ_TERM_POSITION), \
|
PAR("term_position", filler, READ_TERM_POSITION), \
|
||||||
PAR("syntax_errors", isatom, READ_SYNTAX_ERRORS), \
|
PAR("syntax_errors", isatom, READ_SYNTAX_ERRORS), \
|
||||||
@ -524,10 +523,8 @@ static void reset_regs(TokEntry *tokstart, FEnv *fe) {
|
|||||||
POPFET(qq);
|
POPFET(qq);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Term
|
static Term get_variables(FEnv *fe, TokEntry *tokstart) {
|
||||||
get_variables(FEnv *fe, TokEntry *tokstart)
|
Term v;
|
||||||
{
|
|
||||||
Term v;
|
|
||||||
if (fe->vp) {
|
if (fe->vp) {
|
||||||
while (true) {
|
while (true) {
|
||||||
fe->old_H = HR;
|
fe->old_H = HR;
|
||||||
@ -545,11 +542,8 @@ get_variables(FEnv *fe, TokEntry *tokstart)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Term get_varnames(FEnv *fe, TokEntry *tokstart) {
|
||||||
static Term
|
Term v;
|
||||||
get_varnames(FEnv *fe, TokEntry *tokstart)
|
|
||||||
{
|
|
||||||
Term v;
|
|
||||||
if (fe->np) {
|
if (fe->np) {
|
||||||
while (true) {
|
while (true) {
|
||||||
fe->old_H = HR;
|
fe->old_H = HR;
|
||||||
@ -567,11 +561,8 @@ get_varnames(FEnv *fe, TokEntry *tokstart)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Term get_singletons(FEnv *fe, TokEntry *tokstart) {
|
||||||
static Term
|
Term v;
|
||||||
get_singletons(FEnv *fe, TokEntry *tokstart)
|
|
||||||
{
|
|
||||||
Term v;
|
|
||||||
if (fe->sp) {
|
if (fe->sp) {
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
fe->old_H = HR;
|
fe->old_H = HR;
|
||||||
@ -587,34 +578,29 @@ get_singletons(FEnv *fe, TokEntry *tokstart)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void warn_singletons(FEnv *fe, TokEntry *tokstart) {
|
||||||
warn_singletons(FEnv *fe, TokEntry *tokstart)
|
Term v;
|
||||||
{
|
fe->sp = TermNil;
|
||||||
Term v;
|
v = get_singletons(fe, tokstart);
|
||||||
fe->sp = TermNil;
|
if (v && v != TermNil) {
|
||||||
v = get_singletons(fe, tokstart);
|
Term singls[4];
|
||||||
if (v && v != TermNil) {
|
singls[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomSingleton, 1), 1, &v);
|
||||||
Term singls[4];
|
singls[1] = MkIntegerTerm(LOCAL_SourceFileLineno);
|
||||||
singls[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomSingleton, 1), 1, &v);
|
singls[2] = MkAtomTerm(LOCAL_SourceFileName);
|
||||||
singls[1] = MkIntegerTerm(LOCAL_SourceFileLineno);
|
if (fe->t)
|
||||||
singls[2] = MkAtomTerm(LOCAL_SourceFileName);
|
singls[3] = fe->t;
|
||||||
if (fe->t)
|
else
|
||||||
singls[3] = fe->t;
|
singls[1] = TermTrue;
|
||||||
else
|
Term t = Yap_MkApplTerm(Yap_MkFunctor(AtomStyleCheck, 4), 4, singls);
|
||||||
singls[1] = TermTrue;
|
singls[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomStyleCheck, 1), 1, &t);
|
||||||
Term t = Yap_MkApplTerm(Yap_MkFunctor(AtomStyleCheck, 4), 4, singls);
|
|
||||||
singls[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomStyleCheck, 1), 1, &t);
|
|
||||||
|
|
||||||
singls[1] = v;
|
singls[1] = v;
|
||||||
Yap_PrintWarning(Yap_MkApplTerm(FunctorError, 2, singls));
|
Yap_PrintWarning(Yap_MkApplTerm(FunctorError, 2, singls));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Term get_stream_position(FEnv *fe, TokEntry *tokstart) {
|
||||||
static Term
|
Term v;
|
||||||
get_stream_position(FEnv *fe, TokEntry *tokstart)
|
|
||||||
{
|
|
||||||
Term v;
|
|
||||||
if (fe->tp) {
|
if (fe->tp) {
|
||||||
while (true) {
|
while (true) {
|
||||||
fe->old_H = HR;
|
fe->old_H = HR;
|
||||||
@ -630,11 +616,9 @@ get_stream_position(FEnv *fe, TokEntry *tokstart)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static bool complete_processing(FEnv *fe, TokEntry *tokstart) {
|
static bool complete_processing(FEnv *fe, TokEntry *tokstart) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
Term v1, v2, v3, vc, tp;
|
Term v1, v2, v3, vc, tp;
|
||||||
|
|
||||||
CurrentModule = fe->cmod;
|
CurrentModule = fe->cmod;
|
||||||
if (CurrentModule == TermProlog)
|
if (CurrentModule == TermProlog)
|
||||||
@ -656,25 +640,23 @@ static bool complete_processing(FEnv *fe, TokEntry *tokstart) {
|
|||||||
else
|
else
|
||||||
vc = 0L;
|
vc = 0L;
|
||||||
if (fe->t && fe->tp)
|
if (fe->t && fe->tp)
|
||||||
tp = get_stream_position(fe, tokstart );
|
tp = get_stream_position(fe, tokstart);
|
||||||
else
|
else
|
||||||
tp = 0L;
|
tp = 0L;
|
||||||
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
|
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
|
||||||
|
|
||||||
// trail must be ok by now.]
|
// trail must be ok by now.]
|
||||||
if ( ( !v1 || Yap_unify(v1, fe->vp) ) &&
|
if (fe->t) {
|
||||||
( !v2 || Yap_unify(v2, fe->np)) &&
|
return (!v1 || Yap_unify(v1, fe->vp)) && (!v2 || Yap_unify(v2, fe->np)) &&
|
||||||
( !v3 || Yap_unify(v3, fe->sp)) &&
|
(!v3 || Yap_unify(v3, fe->sp)) && (!tp || Yap_unify(tp, fe->tp)) &&
|
||||||
( !tp || Yap_unify(tp, fe->tp)) &&
|
(!vc || Yap_unify(vc, fe->tcomms));
|
||||||
( !vc || Yap_unify(vc, fe->tcomms)))
|
}
|
||||||
return fe->t;
|
return true;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool complete_clause_processing(FEnv *fe, TokEntry
|
static bool complete_clause_processing(FEnv *fe, TokEntry *tokstart) {
|
||||||
*tokstart) {
|
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
Term v_vp, v_vnames, v_comments, v_pos;
|
Term v_vp, v_vnames, v_comments, v_pos;
|
||||||
|
|
||||||
CurrentModule = fe->cmod;
|
CurrentModule = fe->cmod;
|
||||||
if (CurrentModule == TermProlog)
|
if (CurrentModule == TermProlog)
|
||||||
@ -695,18 +677,19 @@ static bool complete_clause_processing(FEnv *fe, TokEntry
|
|||||||
else
|
else
|
||||||
v_comments = 0L;
|
v_comments = 0L;
|
||||||
if (fe->t && fe->tp)
|
if (fe->t && fe->tp)
|
||||||
v_pos = get_stream_position(fe, tokstart );
|
v_pos = get_stream_position(fe, tokstart);
|
||||||
else
|
else
|
||||||
v_pos = 0L;
|
v_pos = 0L;
|
||||||
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
|
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
|
||||||
|
|
||||||
// trail must be ok by now.]
|
// trail must be ok by now.]
|
||||||
if ( ( !v_vp || Yap_unify(v_vp, fe->vp) ) &&
|
if (fe->t) {
|
||||||
( !v_vnames || Yap_unify(v_vnames, fe->np)) &&
|
return (!v_vp || Yap_unify(v_vp, fe->vp)) &&
|
||||||
( !v_pos || Yap_unify(v_pos, fe->tp)) &&
|
(!v_vnames || Yap_unify(v_vnames, fe->np)) &&
|
||||||
( !v_comments || Yap_unify(v_comments, fe->tcomms)))
|
(!v_pos || Yap_unify(v_pos, fe->tp)) &&
|
||||||
return fe->t;
|
(!v_comments || Yap_unify(v_comments, fe->tcomms));
|
||||||
return 0;
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static parser_state_t initParser(Term opts, FEnv *fe, REnv *re, int inp_stream,
|
static parser_state_t initParser(Term opts, FEnv *fe, REnv *re, int inp_stream,
|
||||||
@ -780,7 +763,7 @@ static parser_state_t initParser(Term opts, FEnv *fe, REnv *re, int inp_stream,
|
|||||||
fe->args = setReadEnv(opts, fe, re, inp_stream);
|
fe->args = setReadEnv(opts, fe, re, inp_stream);
|
||||||
}
|
}
|
||||||
if (fe->args == NULL) {
|
if (fe->args == NULL) {
|
||||||
if (LOCAL_Error_TYPE == DOMAIN_ERROR_OUT_OF_RANGE)
|
if (LOCAL_Error_TYPE == DOMAIN_ERROR_READ_OPTION)
|
||||||
LOCAL_Error_TYPE = DOMAIN_ERROR_READ_OPTION;
|
LOCAL_Error_TYPE = DOMAIN_ERROR_READ_OPTION;
|
||||||
if (LOCAL_Error_TYPE)
|
if (LOCAL_Error_TYPE)
|
||||||
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, NULL);
|
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, NULL);
|
||||||
@ -813,8 +796,8 @@ static parser_state_t scan(REnv *re, FEnv *fe, int inp_stream) {
|
|||||||
return YAP_PARSING;
|
return YAP_PARSING;
|
||||||
}
|
}
|
||||||
if (LOCAL_tokptr->Tok == eot_tok && LOCAL_tokptr->TokInfo == TermNl) {
|
if (LOCAL_tokptr->Tok == eot_tok && LOCAL_tokptr->TokInfo == TermNl) {
|
||||||
char *out = malloc( strlen("Empty clause" + 1 ) );
|
char *out = malloc(strlen("Empty clause" + 1));
|
||||||
strcpy( out, "Empty clause" );
|
strcpy(out, "Empty clause");
|
||||||
LOCAL_ErrorMessage = out;
|
LOCAL_ErrorMessage = out;
|
||||||
LOCAL_Error_TYPE = SYNTAX_ERROR;
|
LOCAL_Error_TYPE = SYNTAX_ERROR;
|
||||||
LOCAL_Error_Term = TermEof;
|
LOCAL_Error_Term = TermEof;
|
||||||
@ -940,6 +923,8 @@ Term Yap_read_term(int inp_stream, Term opts, int nargs) {
|
|||||||
switch (state) {
|
switch (state) {
|
||||||
case YAP_START_PARSING:
|
case YAP_START_PARSING:
|
||||||
state = initParser(opts, &fe, &re, inp_stream, nargs);
|
state = initParser(opts, &fe, &re, inp_stream, nargs);
|
||||||
|
if (state == YAP_PARSING_FINISHED)
|
||||||
|
return 0;
|
||||||
break;
|
break;
|
||||||
case YAP_SCANNING:
|
case YAP_SCANNING:
|
||||||
state = scan(&re, &fe, inp_stream);
|
state = scan(&re, &fe, inp_stream);
|
||||||
@ -953,24 +938,23 @@ Term Yap_read_term(int inp_stream, Term opts, int nargs) {
|
|||||||
case YAP_PARSING_ERROR:
|
case YAP_PARSING_ERROR:
|
||||||
state = parseError(&re, &fe, inp_stream);
|
state = parseError(&re, &fe, inp_stream);
|
||||||
break;
|
break;
|
||||||
case YAP_PARSING_FINISHED:
|
case YAP_PARSING_FINISHED: {
|
||||||
{
|
CACHE_REGS
|
||||||
CACHE_REGS
|
bool done;
|
||||||
bool done;
|
if (fe.reading_clause)
|
||||||
if (fe.reading_clause)
|
done = complete_clause_processing(&fe, LOCAL_tokptr);
|
||||||
done = complete_clause_processing(&fe, LOCAL_tokptr);
|
else
|
||||||
else
|
done = complete_processing(&fe, LOCAL_tokptr);
|
||||||
done = complete_processing(&fe, LOCAL_tokptr);
|
if (!done) {
|
||||||
if (!done) {
|
state = YAP_PARSING_ERROR;
|
||||||
state = YAP_PARSING_ERROR;
|
fe.t = 0;
|
||||||
fe.t = 0;
|
break;
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
#if EMACS
|
#if EMACS
|
||||||
first_char = tokstart->TokPos;
|
first_char = tokstart->TokPos;
|
||||||
#endif /* EMACS */
|
#endif /* EMACS */
|
||||||
return fe.t;
|
return fe.t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -996,7 +980,6 @@ static Int read_term(
|
|||||||
inp_stream = Yap_CheckTextStream(ARG1, Input_Stream_f, "read/3");
|
inp_stream = Yap_CheckTextStream(ARG1, Input_Stream_f, "read/3");
|
||||||
if (inp_stream == -1) {
|
if (inp_stream == -1) {
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
|
|
||||||
}
|
}
|
||||||
out = Yap_read_term(inp_stream, ARG3, 3);
|
out = Yap_read_term(inp_stream, ARG3, 3);
|
||||||
UNLOCK(GLOBAL_Stream[inp_stream].streamlock);
|
UNLOCK(GLOBAL_Stream[inp_stream].streamlock);
|
||||||
@ -1005,10 +988,10 @@ static Int read_term(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define READ_CLAUSE_DEFS() \
|
#define READ_CLAUSE_DEFS() \
|
||||||
PAR("comments", list_filler, READ_CLAUSE_COMMENTS), \
|
PAR("comments", list_filler, READ_CLAUSE_COMMENTS), \
|
||||||
PAR("module", isatom, READ_CLAUSE_MODULE), \
|
PAR("module", isatom, READ_CLAUSE_MODULE), \
|
||||||
PAR("variable_names", filler, READ_CLAUSE_VARIABLE_NAMES), \
|
PAR("variable_names", filler, READ_CLAUSE_VARIABLE_NAMES), \
|
||||||
PAR("variables", filler, READ_CLAUSE_VARIABLES), \
|
PAR("variables", filler, READ_CLAUSE_VARIABLES), \
|
||||||
PAR("term_position", filler, READ_CLAUSE_TERM_POSITION), \
|
PAR("term_position", filler, READ_CLAUSE_TERM_POSITION), \
|
||||||
PAR("syntax_errors", isatom, READ_CLAUSE_SYNTAX_ERRORS), \
|
PAR("syntax_errors", isatom, READ_CLAUSE_SYNTAX_ERRORS), \
|
||||||
PAR(NULL, ok, READ_CLAUSE_END)
|
PAR(NULL, ok, READ_CLAUSE_END)
|
||||||
@ -1046,7 +1029,7 @@ static xarg *setClauseReadEnv(Term opts, FEnv *fe, struct renv *re,
|
|||||||
} else {
|
} else {
|
||||||
fe->tcomms = 0L;
|
fe->tcomms = 0L;
|
||||||
}
|
}
|
||||||
fe->sp = 0;
|
fe->sp = 0;
|
||||||
fe->qq = 0;
|
fe->qq = 0;
|
||||||
if (args[READ_CLAUSE_TERM_POSITION].used) {
|
if (args[READ_CLAUSE_TERM_POSITION].used) {
|
||||||
fe->tp = args[READ_CLAUSE_TERM_POSITION].tvalue;
|
fe->tp = args[READ_CLAUSE_TERM_POSITION].tvalue;
|
||||||
@ -1105,7 +1088,6 @@ static Int read_clause2(USES_REGS1) {
|
|||||||
return rc && Yap_unify(tf, rc);
|
return rc && Yap_unify(tf, rc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @pred read_clause( +_Stream_, -_Clause_, ?_Opts) is det
|
* @pred read_clause( +_Stream_, -_Clause_, ?_Opts) is det
|
||||||
*
|
*
|
||||||
@ -1144,7 +1126,6 @@ static Int read_clause(
|
|||||||
return out && Yap_unify(tf, out);
|
return out && Yap_unify(tf, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @pred source_location( - _File_ , _Line_ )
|
* @pred source_location( - _File_ , _Line_ )
|
||||||
*
|
*
|
||||||
@ -1299,8 +1280,6 @@ Term Yap_StringToTerm(const char *s, size_t len, encoding_t *encp, int prio,
|
|||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @pred read_term_from_atom( +_Atom_ , - _T_ , + _VarNames_
|
* @pred read_term_from_atom( +_Atom_ , - _T_ , + _VarNames_
|
||||||
*
|
*
|
||||||
@ -1446,7 +1425,7 @@ Term Yap_ReadFromAtom(Atom a, Term opts) {
|
|||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
static Term readFromBuffer(const char *s, Term opts) {
|
static Term readFromBuffer(const char *s, Term opts) {
|
||||||
Term rval;
|
Term rval;
|
||||||
int sno;
|
int sno;
|
||||||
encoding_t enc = ENC_ISO_UTF8;
|
encoding_t enc = ENC_ISO_UTF8;
|
||||||
sno = Yap_open_buf_read_stream((char *)s, strlen_utf8((unsigned char *)s),
|
sno = Yap_open_buf_read_stream((char *)s, strlen_utf8((unsigned char *)s),
|
||||||
@ -1457,7 +1436,6 @@ static Term readFromBuffer(const char *s, Term opts) {
|
|||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @pred read_term_from_string( +_String_ , - _T_ , + _Options_
|
* @pred read_term_from_string( +_String_ , - _T_ , + _Options_
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user