further op stuff

This commit is contained in:
Vítor Santos Costa 2016-03-05 12:18:43 +00:00
parent 87c58493d4
commit 52f949d3f9
2 changed files with 29 additions and 33 deletions

View File

@ -152,7 +152,7 @@ typedef struct read_data_t {
} read_data, *ReadData;
Term Yap_read_term(int inp_stream, Term opts, int nargs);
Term Yap_Parse(UInt prio);
Term Yap_Parse(UInt prio, Term cmod);
void init_read_data(ReadData _PL_rd, struct stream_desc *s);

View File

@ -95,6 +95,7 @@ static char SccsId[] = "%W% %G%";
#define SYSTEM_STAT stat
#endif
static Term syntax_error(TokEntry *errtok, int sno, Term cmod);
static Term readFromBuffer(const char *s, Term opts);
static void clean_vars(VarEntry *p) {
@ -215,7 +216,7 @@ static const param_t read_defs[] = {READ_DEFS()};
* Implicit arguments:
* +
*/
Term Yap_syntax_error(TokEntry *errtok, int sno) {
static Term syntax_error(TokEntry *errtok, int sno, Term cmod) {
CACHE_REGS
Term info;
Term startline, errline, endline;
@ -288,25 +289,25 @@ Term Yap_syntax_error(TokEntry *errtok, int sno) {
} break;
case String_tok: {
Term t0 =
Yap_CharsToTDQ((char *)info, CurrentModule, ENC_ISO_LATIN1 PASS_REGS);
Yap_CharsToTDQ((char *)info, cmod, ENC_ISO_LATIN1 PASS_REGS);
if (!t0) {
return 0;
}
ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &t0);
} break;
case WString_tok: {
Term t0 = Yap_WCharsToTDQ((wchar_t *)info, CurrentModule PASS_REGS);
Term t0 = Yap_WCharsToTDQ((wchar_t *)info, cmod PASS_REGS);
if (!t0)
return 0;
ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &t0);
} break;
case BQString_tok: {
Term t0 =
Yap_CharsToTBQ((char *)info, CurrentModule, ENC_ISO_LATIN1 PASS_REGS);
Yap_CharsToTBQ((char *)info, cmod, ENC_ISO_LATIN1 PASS_REGS);
ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &t0);
} break;
case WBQString_tok: {
Term t0 = Yap_WCharsToTBQ((wchar_t *)info, CurrentModule PASS_REGS);
Term t0 = Yap_WCharsToTBQ((wchar_t *)info, cmod PASS_REGS);
ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &t0);
} break;
case Error_tok: {
@ -362,6 +363,10 @@ Term Yap_syntax_error(TokEntry *errtok, int sno) {
return terr;
}
Term Yap_syntax_error(TokEntry *errtok, int sno) {
return syntax_error(errtok, sno, CurrentModule);
}
typedef struct FEnv {
Term qq, tp, sp, np, vp, ce;
Term tpos; /// initial position of the term to be read.
@ -398,7 +403,6 @@ static xarg *setReadEnv(Term opts, FEnv *fe, struct renv *re, int inp_stream) {
CACHE_REGS
LOCAL_VarTable = NULL;
LOCAL_AnonVarTable = NULL;
fe->cmod = CurrentModule;
fe->enc = GLOBAL_Stream[inp_stream].encoding;
xarg *args = Yap_ArgListToVector(opts, read_defs, READ_END);
if (args == NULL) {
@ -407,9 +411,13 @@ static xarg *setReadEnv(Term opts, FEnv *fe, struct renv *re, int inp_stream) {
re->bq = getBackQuotesFlag();
if (args[READ_MODULE].used) {
CurrentModule = args[READ_MODULE].tvalue;
fe->cmod = args[READ_MODULE].tvalue;
} else {
fe->cmod = CurrentModule;
}
if (args[READ_BACKQUOTED_STRING].used) {
if (fe->cmod == TermProlog)
fe->cmod = PROLOG_MODULE;
if (args[READ_BACKQUOTED_STRING].used) {
if (!setBackQuotesFlag(args[READ_BACKQUOTED_STRING].tvalue))
return false;
}
@ -420,9 +428,7 @@ static xarg *setReadEnv(Term opts, FEnv *fe, struct renv *re, int inp_stream) {
}
if (args[READ_COMMENTS].used) {
fe->tcomms = args[READ_COMMENTS].tvalue;
if (fe->tcomms == TermProlog)
fe->tcomms = PROLOG_MODULE;
} else {
} else {
fe->tcomms = 0;
}
if (args[READ_TERM_POSITION].used) {
@ -451,7 +457,7 @@ static xarg *setReadEnv(Term opts, FEnv *fe, struct renv *re, int inp_stream) {
fe->np = 0;
}
if (args[READ_CHARACTER_ESCAPES].used ||
Yap_CharacterEscapes(CurrentModule)) {
Yap_CharacterEscapes(fe->cmod)) {
fe->ce = true;
} else {
fe->ce = false;
@ -625,9 +631,6 @@ static bool complete_processing(FEnv *fe, TokEntry *tokstart) {
CACHE_REGS
Term v1, v2, v3, vc, tp;
CurrentModule = fe->cmod;
if (CurrentModule == TermProlog)
CurrentModule = PROLOG_MODULE;
if (fe->t && fe->vp)
v1 = get_variables(fe, tokstart);
else
@ -663,9 +666,6 @@ static bool complete_clause_processing(FEnv *fe, TokEntry *tokstart) {
CACHE_REGS
Term v_vp, v_vnames, v_comments, v_pos;
CurrentModule = fe->cmod;
if (CurrentModule == TermProlog)
CurrentModule = PROLOG_MODULE;
if (fe->t && fe->vp)
v_vp = get_variables(fe, tokstart);
else
@ -865,7 +865,7 @@ static parser_state_t parseError(REnv *re, FEnv *fe, int inp_stream) {
LOCAL_Error_TYPE = YAP_NO_ERROR;
return YAP_PARSING_FINISHED;
} else {
Term terr = Yap_syntax_error(fe->toklast, inp_stream);
Term terr = syntax_error(fe->toklast, inp_stream, fe->cmod);
if (ParserErrorStyle == TermError) {
LOCAL_ErrorMessage = NULL;
LOCAL_Error_TYPE = SYNTAX_ERROR;
@ -886,7 +886,7 @@ static parser_state_t parse(REnv *re, FEnv *fe, int inp_stream) {
TokEntry *tokstart = LOCAL_tokptr;
encoding_t e = LOCAL_encoding;
LOCAL_encoding = fe->enc;
fe->t = Yap_Parse(re->prio);
fe->t = Yap_Parse(re->prio, fe->cmod);
LOCAL_encoding = e;
fe->toklast = LOCAL_tokptr;
LOCAL_tokptr = tokstart;
@ -1022,17 +1022,15 @@ static xarg *setClauseReadEnv(Term opts, FEnv *fe, struct renv *re,
if (args == NULL) {
return NULL;
}
if (args[READ_CLAUSE_MODULE].used) {
fe->cmod = args[READ_CLAUSE_MODULE].tvalue;
} else {
fe->cmod = LOCAL_SourceModule;
if (fe->cmod == TermProlog)
fe->cmod = PROLOG_MODULE;
}
re->bq = getBackQuotesFlag();
fe->enc = GLOBAL_Stream[inp_stream].encoding;
fe->cmod = CurrentModule;
CurrentModule = LOCAL_SourceModule;
if (CurrentModule == TermProlog)
CurrentModule = PROLOG_MODULE;
if (args[READ_CLAUSE_MODULE].used) {
fe->tcomms = args[READ_CLAUSE_MODULE].tvalue;
} else {
fe->tcomms = 0L;
}
fe->sp = 0;
fe->qq = 0;
if (args[READ_CLAUSE_TERM_POSITION].used) {
@ -1043,8 +1041,6 @@ static xarg *setClauseReadEnv(Term opts, FEnv *fe, struct renv *re,
fe->sp = 0;
if (args[READ_CLAUSE_COMMENTS].used) {
fe->tcomms = args[READ_CLAUSE_COMMENTS].tvalue;
if (fe->tcomms == TermProlog)
fe->tcomms = PROLOG_MODULE;
} else {
fe->tcomms = 0L;
}
@ -1064,7 +1060,7 @@ static xarg *setClauseReadEnv(Term opts, FEnv *fe, struct renv *re,
} else {
fe->vp = 0;
}
fe->ce = Yap_CharacterEscapes(CurrentModule);
fe->ce = Yap_CharacterEscapes(fe->cmod);
re->seekable = (GLOBAL_Stream[inp_stream].status & Seekable_Stream_f) != 0;
if (re->seekable) {
#if HAVE_FGETPOS