1
0
Fork 0

Manifest: Add string object-declarations and booleans

master
Marrub 2016-10-21 17:13:29 -04:00
parent 2ede2f4928
commit f69a1e8412
2 changed files with 30 additions and 15 deletions

View File

@ -17,7 +17,8 @@
#include <stdbool.h> #include <stdbool.h>
#define Lth_isidenti(ch) \ #define Lth_isidenti(ch) \
(isalpha(ch) || isdigit(ch) || ch == '_' || ch == '$' || ch == '\'') (isalpha(ch) || isdigit(ch) || ch == '_' || ch == '$' || ch == '\'' || \
ch >= 0x80)
// Post-for. Sort of. // Post-for. Sort of.
#define Lth_pfor(cond, expr) while((cond) && ((expr), true)) #define Lth_pfor(cond, expr) while((cond) && ((expr), true))

View File

@ -45,15 +45,20 @@
} }
#define GenValueGetter(name, value, setexpr) \ #define GenValueGetter(name, value, setexpr) \
if(repr->manifest.size + 1 > repr->manifest.bufsz) \ if(1) \
repr->manifest.data = realloc(repr->manifest.data, \ { \
sizeof(Lth_Manifest) * (repr->manifest.bufsz += 32)); \ if(repr->manifest.size + 1 > repr->manifest.bufsz) \
\ repr->manifest.data = realloc(repr->manifest.data, \
repr->manifest.data[repr->manifest.size++] = (Lth_Manifest){ \ sizeof(Lth_Manifest) * (repr->manifest.bufsz += 32)); \
.type = Lth_ResourceType_##name, \ \
.keyhash = key, \ repr->manifest.data[repr->manifest.size++] = (Lth_Manifest){ \
.value = (setexpr) \ .type = Lth_ResourceType_##name, \
} .keyhash = key, \
.value = (setexpr) \
}; \
} \
else \
((void)0)
#define ManifestError(repr, str) \ #define ManifestError(repr, str) \
if(1) \ if(1) \
@ -176,6 +181,10 @@ static void ManifestGetInitializer(ManifestState *repr, size_t key)
case Lth_TOK_String: case Lth_TOK_String:
ManifestGetStrng(repr, key, Lth_TokenStreamBump(repr->stream)->str); ManifestGetStrng(repr, key, Lth_TokenStreamBump(repr->stream)->str);
break; break;
case Lth_TOK_Identi:
__with(char const *str = Lth_TokenStreamBump(repr->stream)->str;)
if(strcmp(str, "true") == 0) GenValueGetter(Integ, integ, 1);
else if(strcmp(str, "false") == 0) GenValueGetter(Integ, integ, 0);
default: default:
ManifestError(repr, "expected initializer"); ManifestError(repr, "expected initializer");
break; break;
@ -187,16 +196,21 @@ static void ManifestGetInitializer(ManifestState *repr, size_t key)
// //
static void ManifestGetDecl_Object(ManifestState *repr) static void ManifestGetDecl_Object(ManifestState *repr)
{ {
// obj-decl-terminator: // object-name:
// identifier
// string-constant
// object-decl-terminator:
// '\n' // '\n'
// ; // ;
// object-declaration: // object-declaration:
// identifier = initializer obj-decl-terminator // object-name = initializer object-decl-terminator
// identifier // identifier
if(Lth_TokenStreamPeek(repr->stream)->type != Lth_TOK_Identi) if(Lth_TokenStreamPeek(repr->stream)->type != Lth_TOK_String &&
ManifestError(repr, "exptected declarator"); Lth_TokenStreamPeek(repr->stream)->type != Lth_TOK_Identi)
ManifestError(repr, "exptected object-name");
// Build the key name. Format is: "blockname.identifier" // Build the key name. Format is: "blockname.identifier"
__with(char const *name = Lth_TokenStreamBump(repr->stream)->str;) __with(char const *name = Lth_TokenStreamBump(repr->stream)->str;)
@ -219,7 +233,7 @@ static void ManifestGetDecl_Object(ManifestState *repr)
// initializer // initializer
ManifestGetInitializer(repr, key); ManifestGetInitializer(repr, key);
// obj-decl-terminator // object-decl-terminator
if(!Lth_TokenStreamDrop(repr->stream, Lth_TOK_LnEnd) && if(!Lth_TokenStreamDrop(repr->stream, Lth_TOK_LnEnd) &&
!Lth_TokenStreamDrop(repr->stream, Lth_TOK_Semico)) !Lth_TokenStreamDrop(repr->stream, Lth_TOK_Semico))
ManifestError(repr, "expected newline or ';'"); ManifestError(repr, "expected newline or ';'");