94 ConfigNode *root = serverconfig_parse(parser, cx_strn(buf.space, buf.size)); |
95 ConfigNode *root = serverconfig_parse(parser, cx_strn(buf.space, buf.size)); |
95 cxBufferDestroy(&buf); |
96 cxBufferDestroy(&buf); |
96 return root; |
97 return root; |
97 } |
98 } |
98 |
99 |
99 static int scfg_char_is_delim(char c) { |
100 static int scfg_char_is_delim(ConfigParser2 *parser, char c) { |
100 static const char *scfg_tokenizer_delim = "()/*%"; |
101 size_t len = strlen(parser->delim); |
101 for(int i=0;i<sizeof(scfg_tokenizer_delim)-1;i++) { |
102 for(int i=0;i<len;i++) { |
102 if(c == scfg_tokenizer_delim[i]) { |
103 if(c == parser->delim[i]) { |
103 return 1; |
104 return 1; |
104 } |
105 } |
105 } |
106 } |
106 return 0; |
107 return 0; |
107 } |
108 } |
108 |
109 |
109 static CFGToken get_next_token(cxstring content, int *pos) { |
110 static CFGToken get_next_token(ConfigParser2 *parser, cxstring content, int *pos) { |
110 CFGToken token = { {NULL, 0}, CFG_NO_TOKEN }; |
111 CFGToken token = { {NULL, 0}, CFG_NO_TOKEN }; |
111 CFGTokenType type = CFG_TOKEN; |
112 CFGTokenType type = CFG_TOKEN; |
112 |
113 |
113 int start = *pos; |
114 int start = *pos; |
114 |
115 |
246 |
247 |
247 ConfigNode* serverconfig_parse(ConfigParser2 *parser, cxstring content) { |
248 ConfigNode* serverconfig_parse(ConfigParser2 *parser, cxstring content) { |
248 CxMempool *mp = parser->mp; |
249 CxMempool *mp = parser->mp; |
249 CxAllocator *a = (CxAllocator*)mp->allocator; |
250 CxAllocator *a = (CxAllocator*)mp->allocator; |
250 |
251 |
|
252 if(!parser->delim) { |
|
253 parser->delim = ""; |
|
254 } |
|
255 |
251 // PARSE: |
256 // PARSE: |
252 // first non space/comment token is directive/object name |
257 // first non space/comment token is directive/object name |
253 // following tokens are arguments |
258 // following tokens are arguments |
254 // newline starts new directive |
259 // newline starts new directive |
255 // '{' converts directive to object and following directives will |
260 // '{' converts directive to object and following directives will |
269 ConfigNode *obj = NULL; |
274 ConfigNode *obj = NULL; |
270 int obj_closed = 0; |
275 int obj_closed = 0; |
271 |
276 |
272 int text_start = 0; |
277 int text_start = 0; |
273 int err = 0; |
278 int err = 0; |
274 while((token = get_next_token(content, &pos)).type != CFG_NO_TOKEN) { |
279 while((token = get_next_token(parser, content, &pos)).type != CFG_NO_TOKEN) { |
275 //printf("%s [%.*s]\n", token_type_str(token.type), (int)token.content.length, token.content.ptr); |
280 //printf("%s [%.*s]\n", token_type_str(token.type), (int)token.content.length, token.content.ptr); |
276 |
281 |
277 switch(token.type) { |
282 switch(token.type) { |
278 case CFG_NO_TOKEN: break; |
283 case CFG_NO_TOKEN: break; |
279 case CFG_TOKEN_COMMENT: { |
284 case CFG_TOKEN_COMMENT: { |