Square up escaping.

Inline the one objFromSlice() usage.
Add dedicated escapedStringFromSlice().
Switch forbble to use backslash comments.
This commit is contained in:
Sage Vaillancourt 2022-04-26 16:23:55 -04:00 committed by Sage Vaillancourt
parent b39db34208
commit 5ab7a638af
6 changed files with 19 additions and 20 deletions

View File

@ -535,7 +535,7 @@ int runTests(int detailed, int specificTest)
int failureCount = 0; int failureCount = 0;
int passCount = 0; int passCount = 0;
int isSpecificTest = specificTest != -1; int isSpecificTest = specificTest >= 0;
if (isSpecificTest) { if (isSpecificTest) {
struct helpText h = helpTexts[specificTest]; struct helpText h = helpTexts[specificTest];
runHelpTests(h, detailed, &failureCount, &passCount); runHelpTests(h, detailed, &failureCount, &passCount);

View File

@ -154,7 +154,7 @@
)) ))
))) )))
(def comment-char "#") (def comment-char "\\")
(def fline-eval (fn (text) ( (def fline-eval (fn (text) (
(def slash-index (indexOf text comment-char)) (def slash-index (indexOf text comment-char))
(set text (set text
@ -172,14 +172,14 @@
(feval " (feval "
: sq dup * ; : sq dup * ;
# Fibonnacci sequence \\ Fibonnacci sequence
: fibinit 0 1 ; : fibinit 0 1 ;
: fib swap over + ; : fib swap over + ;
# Peek at the top of the stack \\ Peek at the top of the stack
: peek dup . ; : peek dup . ;
# Basic imperial distances (with inches as the base unit) \\ Basic imperial distances (with inches as the base unit)
: ft 12 * ; : ft 12 * ;
: yd 3 ft * ; : yd 3 ft * ;
: yds 3 ft * ; : yds 3 ft * ;
@ -187,12 +187,12 @@
: >ft 1 ft / ; : >ft 1 ft / ;
: >yds 1 yd / ; : >yds 1 yd / ;
# Convert between Farenheit and Celcius \\ Convert between Farenheit and Celcius
: f>c 32 - 5 * 9 / ; : f>c 32 - 5 * 9 / ;
: c>f 9 * 5 / 32 + ; : c>f 9 * 5 / 32 + ;
# TODO \\ TODO
# : checkTen 10 = if 1 else 0 then ; \\ : checkTen 10 = if 1 else 0 then ;
") ")
(def plf-assert (fn (test expected) ( (def plf-assert (fn (test expected) (

View File

@ -23,7 +23,7 @@ size_t hash(const char* str, const struct ObjectTable* table);
/// \return The hash value of the name used to insert /// \return The hash value of the name used to insert
size_t addToTable(struct ObjectTable* table, char* name, Object object); 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* getWithHash(struct ObjectTable* table, const char* name, size_t hash);
struct StrippedObject* getFromTable(struct ObjectTable* table, const char* name); struct StrippedObject* getFromTable(struct ObjectTable* table, const char* name);

View File

@ -669,22 +669,21 @@ inline Object boolObject(int b)
return o; 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) inline Object nullTerminated(const char* string)
{ {
return stringFromSlice(string, strlen(string)); return stringFromSlice(string, strlen(string));
} }
// TODO: Unescaped version
inline Object stringFromSlice(const char* string, int len) 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 #ifdef STANDALONE
//eprintf("ay: %s\n", string);
Object o = withLen(len, TYPE_STRING); Object o = withLen(len, TYPE_STRING);
int c = 0; int c = 0;
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {

View File

@ -272,12 +272,12 @@ Object listObject();
Object startList(Object start); Object startList(Object start);
Object objFromSlice(const char* string, int len);
Object nullTerminated(const char* string); Object nullTerminated(const char* string);
Object stringFromSlice(const char* string, int len); Object stringFromSlice(const char* string, int len);
Object escapedStringFromSlice(const char* string, int len);
Object symFromSlice(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. /// Creates a stringy object with room for a reference-count prefix and trailing null byte.

View File

@ -538,7 +538,7 @@ Result parseAtom(struct Slice* s)
return (Result) { falseObject(), s }; return (Result) { falseObject(), s };
} }
if (c == '"') { 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] == '.') { if (s->text[s->length] == '.') {
struct Slice* next = s + 2; struct Slice* next = s + 2;