single_quotes
This commit is contained in:
parent
8ab38125db
commit
b54439d909
86
C/flags.c
86
C/flags.c
@ -51,7 +51,9 @@ static Term indexer(Term inp);
|
||||
static Term stream(Term inp);
|
||||
static bool getenc(Term inp);
|
||||
static bool typein(Term inp);
|
||||
static bool dqf(Term t2);
|
||||
static bool dqs(Term t2);
|
||||
static bool bqs(Term t2);
|
||||
static bool sqf(Term t2);
|
||||
static bool set_error_stream(Term inp);
|
||||
static bool set_input_stream(Term inp);
|
||||
static bool set_output_stream(Term inp);
|
||||
@ -125,7 +127,7 @@ static bool dqf1(ModEntry *new, Term t2 USES_REGS) {
|
||||
}
|
||||
}
|
||||
|
||||
static bool dqf(Term t2) {
|
||||
static bool dqs(Term t2) {
|
||||
CACHE_REGS
|
||||
ModEntry *new = Yap_GetModuleEntry(CurrentModule);
|
||||
return dqf1(new, t2 PASS_REGS);
|
||||
@ -159,6 +161,48 @@ static bool bqf1(ModEntry *new, Term t2 USES_REGS) {
|
||||
}
|
||||
}
|
||||
|
||||
static bool bqs(Term t2) {
|
||||
CACHE_REGS
|
||||
ModEntry *new = Yap_GetModuleEntry(CurrentModule);
|
||||
return bqf1(new, t2 PASS_REGS);
|
||||
}
|
||||
|
||||
|
||||
static bool sqf1(ModEntry *new, Term t2 USES_REGS) {
|
||||
new->flags &= ~(SNGQ_CHARS | SNGQ_CODES | SNGQ_ATOM | SNGQ_STRING);
|
||||
if (IsAtomTerm(t2)) {
|
||||
if (t2 == TermString) {
|
||||
new->flags |= SNGQ_STRING;
|
||||
return true;
|
||||
} else if (t2 == TermAtom) {
|
||||
new->flags |= SNGQ_ATOM;
|
||||
return true;
|
||||
} else if (t2 == TermCodes) {
|
||||
new->flags |= SNGQ_CODES;
|
||||
return true;
|
||||
} else if (t2 == TermChars) {
|
||||
new->flags |= SNGQ_CHARS;
|
||||
return true;
|
||||
}
|
||||
Yap_Error(DOMAIN_ERROR_OUT_OF_RANGE, t2, "bad option %s for backquoted "
|
||||
"string flag, use one string, "
|
||||
"atom, codes or chars",
|
||||
RepAtom(AtomOfTerm(t2))->StrOfAE);
|
||||
return false;
|
||||
} else {
|
||||
Yap_Error(TYPE_ERROR_ATOM, t2, "flag %s is not module-scoped",
|
||||
RepAtom(AtomOfTerm(t2))->StrOfAE);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static bool sqf(Term t2) {
|
||||
CACHE_REGS
|
||||
ModEntry *new = Yap_GetModuleEntry(CurrentModule);
|
||||
return sqf1(new, t2 PASS_REGS);
|
||||
}
|
||||
|
||||
static Term isaccess(Term inp) {
|
||||
if (inp == TermReadWrite || inp == TermReadOnly)
|
||||
return inp;
|
||||
@ -715,9 +759,11 @@ static bool setYapFlagInModule(Term tflag, Term t2, Term mod) {
|
||||
"bad option %s for character_escapes flag, use true or false",
|
||||
RepAtom(AtomOfTerm(tflag))->StrOfAE);
|
||||
return false;
|
||||
} else if (fv->FlagOfVE == BACKQUOTED_STRING_FLAG) {
|
||||
} else if (fv->FlagOfVE == BACK_QUOTES_FLAG) {
|
||||
return bqf1(me, t2 PASS_REGS);
|
||||
;
|
||||
} else if (fv->FlagOfVE == SINGLE_QUOTES_FLAG) {
|
||||
return sqf1(me, t2 PASS_REGS);
|
||||
|
||||
}
|
||||
// bad key?
|
||||
return false;
|
||||
@ -744,7 +790,7 @@ static Term getYapFlagInModule(Term tflag, Term mod) {
|
||||
} else if (fv->FlagOfVE == CHARACTER_ESCAPES_FLAG) {
|
||||
if (me->flags & M_CHARESCAPE)
|
||||
return TermTrue;
|
||||
} else if (fv->FlagOfVE == BACKQUOTED_STRING_FLAG) {
|
||||
} else if (fv->FlagOfVE == BACK_QUOTES_FLAG) {
|
||||
if (me->flags & BCKQ_CHARS)
|
||||
return TermChars;
|
||||
if (me->flags & BCKQ_CODES)
|
||||
@ -752,6 +798,14 @@ static Term getYapFlagInModule(Term tflag, Term mod) {
|
||||
if (me->flags & BCKQ_ATOM)
|
||||
return TermAtom;
|
||||
return TermString;
|
||||
} else if (fv->FlagOfVE == SINGLE_QUOTES_FLAG) {
|
||||
if (me->flags & SNGQ_CHARS)
|
||||
return TermChars;
|
||||
if (me->flags & SNGQ_CODES)
|
||||
return TermCodes;
|
||||
if (me->flags & SNGQ_ATOM)
|
||||
return TermAtom;
|
||||
return TermString;
|
||||
} else if (fv->FlagOfVE == DOUBLE_QUOTES_FLAG) {
|
||||
if (me->flags & DBLQ_CHARS)
|
||||
return TermChars;
|
||||
@ -777,7 +831,9 @@ static Int cont_yap_flag(USES_REGS1) {
|
||||
Term modt = CurrentModule;
|
||||
tflag = Yap_StripModule(tflag, &modt);
|
||||
while (i != gmax && i != UNKNOWN_FLAG && i != CHARACTER_ESCAPES_FLAG &&
|
||||
i != BACKQUOTED_STRING_FLAG)
|
||||
i != BACK_QUOTES_FLAG &&
|
||||
i != SINGLE_QUOTES_FLAG &&
|
||||
i != DOUBLE_QUOTES_FLAG)
|
||||
i++;
|
||||
if (i == gmax)
|
||||
cut_fail();
|
||||
@ -982,13 +1038,13 @@ void Yap_setModuleFlags(ModEntry *new, ModEntry *cme) {
|
||||
Atom at = new->AtomOfME;
|
||||
if (at == AtomProlog || CurrentModule == PROLOG_MODULE) {
|
||||
new->flags =
|
||||
M_SYSTEM | UNKNOWN_ERROR | M_CHARESCAPE | DBLQ_CODES | BCKQ_STRING;
|
||||
M_SYSTEM | UNKNOWN_ERROR | M_CHARESCAPE | DBLQ_CODES | BCKQ_STRING |SNGQ_ATOM;
|
||||
if (at == AtomUser)
|
||||
new->flags = UNKNOWN_ERROR | M_CHARESCAPE | DBLQ_CODES | BCKQ_STRING;
|
||||
new->flags = UNKNOWN_ERROR | M_CHARESCAPE | DBLQ_CODES | BCKQ_STRING |SNGQ_ATOM;
|
||||
} else if (cme && cme->flags && cme != new) {
|
||||
new->flags = cme->flags;
|
||||
} else {
|
||||
new->flags = (UNKNOWN_ERROR | M_CHARESCAPE | DBLQ_CODES | BCKQ_STRING);
|
||||
new->flags = (UNKNOWN_ERROR | M_CHARESCAPE | DBLQ_CODES | BCKQ_STRING |SNGQ_ATOM);
|
||||
}
|
||||
// printf("cme=%s new=%s flags=%x\n",cme,at->StrOfAE,new->flags);
|
||||
}
|
||||
@ -1034,7 +1090,9 @@ bool setYapFlag(Term tflag, Term t2) {
|
||||
switch (fv->FlagOfVE) {
|
||||
case UNKNOWN_FLAG:
|
||||
case CHARACTER_ESCAPES_FLAG:
|
||||
case BACKQUOTED_STRING_FLAG:
|
||||
case BACK_QUOTES_FLAG:
|
||||
case DOUBLE_QUOTES_FLAG:
|
||||
case SINGLE_QUOTES_FLAG:
|
||||
return setYapFlagInModule(tflag, t2, CurrentModule);
|
||||
default:
|
||||
tarr = GLOBAL_Flags;
|
||||
@ -1420,7 +1478,9 @@ do_prolog_flag_property(Term tflag,
|
||||
if (fv->global) {
|
||||
if (fv->FlagOfVE == UNKNOWN_FLAG ||
|
||||
fv->FlagOfVE == CHARACTER_ESCAPES_FLAG ||
|
||||
fv->FlagOfVE == BACKQUOTED_STRING_FLAG)
|
||||
fv->FlagOfVE == SINGLE_QUOTES_FLAG ||
|
||||
fv->FlagOfVE == DOUBLE_QUOTES_FLAG ||
|
||||
fv->FlagOfVE == BACK_QUOTES_FLAG)
|
||||
Yap_unify(TermModule, args[PROLOG_FLAG_PROPERTY_SCOPE].tvalue);
|
||||
rc = rc &&
|
||||
Yap_unify(TermGlobal, args[PROLOG_FLAG_PROPERTY_SCOPE].tvalue);
|
||||
@ -1453,7 +1513,9 @@ static Int cont_prolog_flag_property(USES_REGS1) { /* current_prolog_flag */
|
||||
lab = MkAtomTerm(Yap_LookupAtom(local_flags_setup[i - gmax].name));
|
||||
} else {
|
||||
if (i == UNKNOWN_FLAG || i == CHARACTER_ESCAPES_FLAG ||
|
||||
i == BACKQUOTED_STRING_FLAG) {
|
||||
i == SINGLE_QUOTES_FLAG ||
|
||||
i == DOUBLE_QUOTES_FLAG ||
|
||||
i == BACK_QUOTES_FLAG) {
|
||||
Term labs[2];
|
||||
labs[0] = MkVarTerm();
|
||||
labs[1] = MkAtomTerm(Yap_LookupAtom(global_flags_setup[i].name));
|
||||
|
38
H/YapFlags.h
38
H/YapFlags.h
@ -162,19 +162,6 @@ static inline Term list_filler(Term inp) {
|
||||
return TermZERO;
|
||||
}
|
||||
|
||||
static Term bqs(Term inp) {
|
||||
if (inp == TermCodes || inp == TermString || inp == TermSymbolChar)
|
||||
return inp;
|
||||
|
||||
if (IsAtomTerm(inp)) {
|
||||
Yap_Error(DOMAIN_ERROR_OUT_OF_RANGE, inp,
|
||||
"set_prolog_flag in {codes,string}");
|
||||
return TermZERO;
|
||||
}
|
||||
Yap_Error(TYPE_ERROR_ATOM, inp, "set_prolog_flag in {codes,string}");
|
||||
return TermZERO;
|
||||
}
|
||||
|
||||
// INLINE_ONLY inline EXTERN Term isatom( Term inp );
|
||||
|
||||
static inline Term isatom(Term inp) {
|
||||
@ -342,17 +329,26 @@ static inline Term getSyntaxErrorsFlag(void) {
|
||||
return LOCAL_Flags[SYNTAX_ERRORS_FLAG].at;
|
||||
}
|
||||
|
||||
static inline bool setBackQuotesFlag(Term val) {
|
||||
if (!bqs(val))
|
||||
return false;
|
||||
if (val == TermSymbolChar)
|
||||
val = TermString;
|
||||
GLOBAL_Flags[BACKQUOTED_STRING_FLAG].at = val;
|
||||
// used to overwrite singletons quoteFunc flag
|
||||
static inline bool setReadTermBackQuotesFlag(Term val) {
|
||||
|
||||
GLOBAL_Flags[BACK_QUOTES_FLAG].at = val;
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline Term getBackQuotesFlag(void) {
|
||||
return GLOBAL_Flags[BACKQUOTED_STRING_FLAG].at;
|
||||
static inline Term getReadTermBackQuotesFlag(void) {
|
||||
Term val;
|
||||
unsigned int flags = Yap_GetModuleEntry(CurrentModule)->flags;
|
||||
if (flags & BCKQ_ATOM) {
|
||||
val = TermAtom;
|
||||
} else if (flags & BCKQ_STRING) {
|
||||
val = TermString;
|
||||
} else if (flags & BCKQ_CHARS) {
|
||||
val = TermChars;
|
||||
} else {
|
||||
val = TermCodes;
|
||||
}
|
||||
return GLOBAL_Flags[BACK_QUOTES_FLAG].at = val;
|
||||
}
|
||||
|
||||
static inline Term indexingMode(void) { return GLOBAL_Flags[INDEX_FLAG].at; }
|
||||
|
@ -90,9 +90,9 @@ running on an Apple machine.
|
||||
YAP_FLAG(ARGV_FLAG, "argv", false, argv, "@boot", NULL),
|
||||
YAP_FLAG(ARITHMETIC_EXCEPTIONS_FLAG, "arithmetic_exceptions", true,
|
||||
booleanFlag, "true", NULL),
|
||||
YAP_FLAG(BACKQUOTED_STRING_FLAG, "backquoted_string", true, isatom,
|
||||
"string", ), /**>
|
||||
If _Value_ is unbound, tell whether a double quoted list of characters
|
||||
YAP_FLAG(BACK_QUOTES_FLAG, "back_quotes", true, isatom,
|
||||
"string", bqs), /**>
|
||||
If _Value_ is unbound, tell whether a back quoted list of characters
|
||||
token is converted to a list of atoms, `chars`, to a list of integers,
|
||||
`codes`, or to a single atom, `atom`. If _Value_ is bound, set to
|
||||
the corresponding behavior. The default value is `string`
|
||||
@ -174,7 +174,7 @@ If `off` (default) consider the character `$` a control character, if
|
||||
`on` consider `$` a lower case character.
|
||||
*/
|
||||
YAP_FLAG(DOUBLE_QUOTES_FLAG, "double_quotes", true, isatom, "codes",
|
||||
dqf), /**< `double_quotes is iso `
|
||||
dqs), /**< `double_quotes is iso `
|
||||
|
||||
If _Value_ is unbound, tell whether a double quoted list of characters
|
||||
token is converted to a list of atoms, `chars`, to a list of integers,
|
||||
@ -383,6 +383,9 @@ Name of the environment variable used by the system to search for shared
|
||||
objects.
|
||||
|
||||
*/
|
||||
YAP_FLAG(SINGLE_QUOTES_FLAG, "single_quotes", true, isatom, "atom",
|
||||
sqf), /**< `single_quoted text is usuallly interpreted as atoms. This flagTerm allows other inerpretations such as strings_contains_strings */
|
||||
|
||||
YAP_FLAG(SIGNALS_FLAG, "signals", true, booleanFlag, "true",
|
||||
NULL), /**< `signals`
|
||||
|
||||
|
42
H/YapText.h
42
H/YapText.h
@ -440,8 +440,33 @@ static inline seq_type_t mod_to_type(Term mod USES_REGS) {
|
||||
}
|
||||
|
||||
// string type depends on current module
|
||||
static inline seq_type_t mod_to_bqtype(Term mod USES_REGS) {
|
||||
static inline seq_type_t mod_to_atype(Term mod USES_REGS) {
|
||||
|
||||
// see pl-incl.h
|
||||
unsigned int flags = Yap_GetModuleEntry(mod)->flags;
|
||||
if (flags & SNGQ_ATOM) {
|
||||
return YAP_STRING_ATOM | YAP_STRING_OUTPUT_TERM;
|
||||
} else if (flags & SNGQ_STRING) {
|
||||
return YAP_STRING_STRING;
|
||||
} else if (flags & SNGQ_CHARS) {
|
||||
return YAP_STRING_ATOMS;
|
||||
}
|
||||
return YAP_STRING_CODES;
|
||||
}
|
||||
|
||||
// string type depends on current module
|
||||
static inline seq_type_t mod_to_bqtype(Term mod USES_REGS) {
|
||||
Term t2;
|
||||
if ((t2 = GLOBAL_Flags[BACK_QUOTES_FLAG].at)) {
|
||||
if (t2 == TermString) {
|
||||
return YAP_STRING_STRING;
|
||||
} else if (t2 == TermAtom) {
|
||||
return YAP_STRING_ATOM | YAP_STRING_OUTPUT_TERM;
|
||||
} else if (t2 == TermCodes) {
|
||||
return YAP_STRING_CODES;
|
||||
}
|
||||
return YAP_STRING_ATOMS;
|
||||
}
|
||||
// see pl-incl.h
|
||||
unsigned int flags = Yap_GetModuleEntry(mod)->flags;
|
||||
if (flags & BCKQ_ATOM) {
|
||||
@ -906,6 +931,21 @@ static inline char *Yap_AtomToUTF8Text(Atom at USES_REGS) {
|
||||
return RepAtom(at)->StrOfAE;
|
||||
}
|
||||
|
||||
static inline Term Yap_CharsToTAQ(const char *s, Term mod,
|
||||
encoding_t enc USES_REGS) {
|
||||
seq_tv_t inp, out;
|
||||
|
||||
inp.val.c0 = s;
|
||||
inp.type = YAP_STRING_CHARS;
|
||||
inp.mod = mod;
|
||||
inp.enc = enc;
|
||||
out.type = mod_to_atype(mod PASS_REGS);
|
||||
out.val.uc = NULL;
|
||||
if (!Yap_CVT_Text(&inp, &out PASS_REGS))
|
||||
return 0L;
|
||||
return out.val.t;
|
||||
}
|
||||
|
||||
static inline Term Yap_CharsToTDQ(const char *s, Term mod,
|
||||
encoding_t enc USES_REGS) {
|
||||
seq_tv_t inp, out;
|
||||
|
@ -279,6 +279,11 @@ INLINE_ONLY inline EXTERN bool IsModProperty(int flags) {
|
||||
#define UNKNOWN_MASK \
|
||||
(UNKNOWN_ERROR | UNKNOWN_WARNING | UNKNOWN_FAIL | UNKNOWN_FAST_FAIL | \
|
||||
UNKNOWN_ABORT | UNKNOWN_HALT)
|
||||
#define SNGQ_CHARS (0x10000) /* 'ab' --> [a, b] */
|
||||
#define SNGQ_ATOM (0x20000) /* 'ab' --> ab */
|
||||
#define SNGQ_STRING (0x40000) /* 'ab' --> "ab" */
|
||||
#define SNGQ_CODES (0x80000) /* 'ab' --> [0'a, 0'b] */
|
||||
#define SNGQ_MASK (BCKQ_CHARS | BCKQ_ATOM | BCKQ_STRING | BCKQ_CODES)
|
||||
|
||||
Term Yap_getUnknownModule(ModEntry *m);
|
||||
void Yap_setModuleFlags(ModEntry *n, ModEntry *o);
|
||||
|
File diff suppressed because one or more lines are too long
@ -68,8 +68,7 @@ set (MPI_YAP_SOURCES
|
||||
# pass to the MPI program.
|
||||
#
|
||||
|
||||
add_executable (yap_mpi ${MPI_YAP_SOURCES} Yaplib ../../console/yap.c)
|
||||
|
||||
add_executable (yap_mpi ${MPI_YAP_SOURCES} ../../console/yap.c)
|
||||
target_link_libraries(yap_mpi libYap ${MPI_C_LIBRARIES})
|
||||
|
||||
set_target_properties (yap_mpi PROPERTIES PREFIX "")
|
||||
@ -77,10 +76,11 @@ set (MPI_YAP_SOURCES
|
||||
include_directories (${MPI_C_INCLUDE_PATH})
|
||||
|
||||
add_definitions (-DHAVE_MPI_H=1)
|
||||
target_compile_definitions(yap_mpi ${MPI_C_COMPILE_FLAGS})
|
||||
target_compile_definitions(yap_mpi
|
||||
PRIVATE ${MPI_C_COMPILE_FLAGS})
|
||||
|
||||
install(TARGETS yap_mpi
|
||||
RUNTIME DESTINATION ${YAP_INSTALL_BDIR}
|
||||
RUNTIME DESTINATION ${bindir}
|
||||
)
|
||||
|
||||
endif (MPI_C_FOUND)
|
||||
|
@ -466,7 +466,7 @@ static xarg *setReadEnv(Term opts, FEnv *fe, struct renv *re, int inp_stream) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
re->bq = getBackQuotesFlag();
|
||||
re->bq = getReadTermBackQuotesFlag();
|
||||
if (args[READ_OUTPUT].used) {
|
||||
fe->t0 = args[READ_OUTPUT].tvalue;
|
||||
} else {
|
||||
@ -480,7 +480,7 @@ static xarg *setReadEnv(Term opts, FEnv *fe, struct renv *re, int inp_stream) {
|
||||
fe->cmod = PROLOG_MODULE;
|
||||
}
|
||||
if (args[READ_BACKQUOTED_STRING].used) {
|
||||
if (!setBackQuotesFlag(args[READ_BACKQUOTED_STRING].tvalue)) {
|
||||
if (!setReadTermBackQuotesFlag(args[READ_BACKQUOTED_STRING].tvalue)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -1109,7 +1109,7 @@ static xarg *setClauseReadEnv(Term opts, FEnv *fe, struct renv *re, int sno) {
|
||||
if (fe->cmod == TermProlog)
|
||||
fe->cmod = PROLOG_MODULE;
|
||||
}
|
||||
re->bq = getBackQuotesFlag();
|
||||
re->bq = getReadTermBackQuotesFlag();
|
||||
fe->enc = GLOBAL_Stream[sno].encoding;
|
||||
fe->sp = 0;
|
||||
fe->qq = 0;
|
||||
|
@ -251,12 +251,8 @@ initialize_prolog :-
|
||||
:- c_compile( 'modules.yap' ).
|
||||
:- c_compile( 'grammar.yap' ).
|
||||
|
||||
:- start_low_level_trace.
|
||||
|
||||
:- ['absf.yap'].
|
||||
|
||||
:- stop_low_level_trace.
|
||||
|
||||
:- use_module('error.yap').
|
||||
|
||||
:- [
|
||||
|
Reference in New Issue
Block a user