aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lexer.c4
-rw-r--r--src/parser.c27
2 files changed, 23 insertions, 8 deletions
diff --git a/src/lexer.c b/src/lexer.c
index 613e161..41d5fc4 100644
--- a/src/lexer.c
+++ b/src/lexer.c
@@ -109,6 +109,10 @@ void lexer_do_reg(lexer_t* lexer) {
void lexer_do_tag(lexer_t* lexer) {
switch (*lexer->src) {
+ case SYNTAX_LIST_DELIM:
+ lexer_add_current_char(lexer, TOKEN_LIST_DELIM);
+ lexer->state = LEXER_STATE_REG;
+ break;
case SYNTAX_SET:
lexer_add_current_char(lexer, TOKEN_SET);
lexer->state = LEXER_STATE_REG;
diff --git a/src/parser.c b/src/parser.c
index 6eb1125..1ed43b8 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -121,9 +121,11 @@ tree_t* parser_parse_tag(parser_t* parser) {
tag = tree_init(TREE_TYPE_TAG);
+ if (parser->token->type != TOKEN_TAG) { return NULL; }
+
tag->data.tag.val = parser->token->val;
parser->token->val = NULL;
- tag->data.tag.nxt = (parser_nxt_token_match(parser, TOKEN_TAG) ? parser_parse_tag(parser) : NULL);
+ parser_nxt_token(parser) && (tag->data.tag.nxt = parser_parse_tag(parser));
return tag;
}
@@ -133,12 +135,14 @@ tree_t* parser_parse_darg(parser_t* parser) {
darg = tree_init(TREE_TYPE_DARG);
+ if (parser->token->type != TOKEN_TAG) { return NULL; }
+
darg->data.darg.tag = parser_parse_tag(parser);
- /*darg->data.darg.nxt = (parser_nxt_token_match(parser, TOKEN_LIST_DELIM) && parser_nxt_token_match(parser, TOKEN_TAG) ? parser_parse_darg(parser) : NULL);*/
- (! parser_nxt_token_match(parser, TOKEN_LIST_DELIM)) && (darg->data.darg.nxt = NULL);
- (! parser_nxt_token_match(parser, TOKEN_TAG)) && (darg->data.darg.nxt = NULL);
-
+ log_war("%d", parser->token->type);
+
+ if (parser->token->type != TOKEN_LIST_DELIM) { darg->data.darg.nxt = NULL; }
+ else { parser_nxt_token(parser) && (darg->data.darg.nxt = parser_parse_darg(parser)); }
return darg;
}
@@ -149,10 +153,17 @@ tree_t* parser_parse_def(parser_t* parser) {
def = tree_init(TREE_TYPE_DEF);
def->data.def.tag = parser_parse_tag(parser);
- def->data.def.arg = ((parser->token->type == TOKEN_APPLY) && (parser_nxt_token_match(parser, TOKEN_TAG))) ? parser_parse_darg(parser) : NULL;
- def->data.def.val = ((parser->token->type == TOKEN_SET) && parser_nxt_token(parser)) ? parser_parse_expr(parser) : NULL;
+ if (parser->token->type != TOKEN_APPLY) { goto finish; }
+ else { parser_nxt_token(parser); }
+
+ def->data.def.arg = parser_parse_darg(parser);
+ if (parser->token->type != TOKEN_SET) { goto finish; }
+ else { parser_nxt_token(parser); }
+
+ def->data.def.val = parser_parse_expr(parser);
- return def;
+ finish:
+ return def;
}
tree_t* parser_parse_carg(parser_t* parser) {