Square up escaping.
Inline the one objFromSlice() usage. Add dedicated escapedStringFromSlice(). Switch forbble to use backslash comments.
This commit is contained in:
parent
b39db34208
commit
5ab7a638af
|
@ -535,7 +535,7 @@ int runTests(int detailed, int specificTest)
|
|||
int failureCount = 0;
|
||||
int passCount = 0;
|
||||
|
||||
int isSpecificTest = specificTest != -1;
|
||||
int isSpecificTest = specificTest >= 0;
|
||||
if (isSpecificTest) {
|
||||
struct helpText h = helpTexts[specificTest];
|
||||
runHelpTests(h, detailed, &failureCount, &passCount);
|
||||
|
|
|
@ -154,7 +154,7 @@
|
|||
))
|
||||
)))
|
||||
|
||||
(def comment-char "#")
|
||||
(def comment-char "\\")
|
||||
(def fline-eval (fn (text) (
|
||||
(def slash-index (indexOf text comment-char))
|
||||
(set text
|
||||
|
@ -172,14 +172,14 @@
|
|||
(feval "
|
||||
: sq dup * ;
|
||||
|
||||
# Fibonnacci sequence
|
||||
\\ Fibonnacci sequence
|
||||
: fibinit 0 1 ;
|
||||
: fib swap over + ;
|
||||
|
||||
# Peek at the top of the stack
|
||||
\\ Peek at the top of the stack
|
||||
: peek dup . ;
|
||||
|
||||
# Basic imperial distances (with inches as the base unit)
|
||||
\\ Basic imperial distances (with inches as the base unit)
|
||||
: ft 12 * ;
|
||||
: yd 3 ft * ;
|
||||
: yds 3 ft * ;
|
||||
|
@ -187,12 +187,12 @@
|
|||
: >ft 1 ft / ;
|
||||
: >yds 1 yd / ;
|
||||
|
||||
# Convert between Farenheit and Celcius
|
||||
\\ Convert between Farenheit and Celcius
|
||||
: f>c 32 - 5 * 9 / ;
|
||||
: c>f 9 * 5 / 32 + ;
|
||||
|
||||
# TODO
|
||||
# : checkTen 10 = if 1 else 0 then ;
|
||||
\\ TODO
|
||||
\\ : checkTen 10 = if 1 else 0 then ;
|
||||
")
|
||||
|
||||
(def plf-assert (fn (test expected) (
|
||||
|
|
|
@ -23,7 +23,7 @@ size_t hash(const char* str, const struct ObjectTable* table);
|
|||
/// \return The hash value of the name used to insert
|
||||
size_t addToTable(struct ObjectTable* table, char* name, Object object);
|
||||
|
||||
/// \todo
|
||||
/// TODO
|
||||
struct StrippedObject* getWithHash(struct ObjectTable* table, const char* name, size_t hash);
|
||||
|
||||
struct StrippedObject* getFromTable(struct ObjectTable* table, const char* name);
|
||||
|
|
15
src/object.c
15
src/object.c
|
@ -669,22 +669,21 @@ inline Object boolObject(int b)
|
|||
return o;
|
||||
}
|
||||
|
||||
/// Skips first and last chars! Assumed to be '"'
|
||||
inline Object objFromSlice(const char* string, int len)
|
||||
{
|
||||
return stringFromSlice(&string[1], len - 1);
|
||||
}
|
||||
|
||||
inline Object nullTerminated(const char* string)
|
||||
{
|
||||
return stringFromSlice(string, strlen(string));
|
||||
}
|
||||
|
||||
// TODO: Unescaped version
|
||||
inline Object stringFromSlice(const char* string, int len)
|
||||
{
|
||||
Object object = symFromSlice(string, len);
|
||||
object.type = TYPE_STRING;
|
||||
return object;
|
||||
}
|
||||
|
||||
inline Object escapedStringFromSlice(const char* string, int len)
|
||||
{
|
||||
#ifdef STANDALONE
|
||||
//eprintf("ay: %s\n", string);
|
||||
Object o = withLen(len, TYPE_STRING);
|
||||
int c = 0;
|
||||
for (int i = 0; i < len; i++) {
|
||||
|
|
|
@ -272,12 +272,12 @@ Object listObject();
|
|||
|
||||
Object startList(Object start);
|
||||
|
||||
Object objFromSlice(const char* string, int len);
|
||||
|
||||
Object nullTerminated(const char* string);
|
||||
|
||||
Object stringFromSlice(const char* string, int len);
|
||||
|
||||
Object escapedStringFromSlice(const char* string, int len);
|
||||
|
||||
Object symFromSlice(const char* string, int len);
|
||||
|
||||
/// Creates a stringy object with room for a reference-count prefix and trailing null byte.
|
||||
|
|
|
@ -538,7 +538,7 @@ Result parseAtom(struct Slice* s)
|
|||
return (Result) { falseObject(), s };
|
||||
}
|
||||
if (c == '"') {
|
||||
return (Result) { objFromSlice(s->text, s->length), s };
|
||||
return (Result) { escapedStringFromSlice(&s->text[1], s->length - 1), s };
|
||||
}
|
||||
if (s->text[s->length] == '.') {
|
||||
struct Slice* next = s + 2;
|
||||
|
|
Loading…
Reference in New Issue