aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-11-11 01:51:06 +0100
committerMattias Andrée <maandree@operamail.com>2014-11-11 01:51:06 +0100
commite736a832c860fa5041869ff5b2e218e26aa9bdc0 (patch)
treea47d54ff4d22f2a92a45613390abb0315c7dcb73
parentmds-kbdc: if, else if and else (diff)
downloadmds-e736a832c860fa5041869ff5b2e218e26aa9bdc0.tar.gz
mds-e736a832c860fa5041869ff5b2e218e26aa9bdc0.tar.bz2
mds-e736a832c860fa5041869ff5b2e218e26aa9bdc0.tar.xz
mds-kbdc: for
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r--src/mds-kbdc/make-tree.c62
1 files changed, 58 insertions, 4 deletions
diff --git a/src/mds-kbdc/make-tree.c b/src/mds-kbdc/make-tree.c
index 1e85094..c3bdc81 100644
--- a/src/mds-kbdc/make-tree.c
+++ b/src/mds-kbdc/make-tree.c
@@ -310,6 +310,49 @@
CHARS_END
+/**
+ * Check that the next word is a specific keyword
+ *
+ * @parma KEYWORD:const char* The keyword
+ */
+#define TEST_FOR_KEYWORD(KEYWORD) \
+ do \
+ { \
+ if (too_few) \
+ break; \
+ line += strlen(line); \
+ *end = prev_end_char, prev_end_char = '\0'; \
+ while (*line && (*line == ' ')) \
+ line++; \
+ if (*line == '\0') \
+ { \
+ line = original, end = line + strlen(line); \
+ NEW_ERROR(1, ERROR, "too few parameters"); \
+ line = end, too_few = 1; \
+ } \
+ else \
+ { \
+ int ok = (strstr(line, KEYWORD) == line); \
+ line += strlen(KEYWORD); \
+ ok = ok && ((*line == '\0') || (*line == ' ')); \
+ if (ok) \
+ { \
+ end = line; \
+ prev_end_char = *end, *end = '\0'; \
+ break; \
+ } \
+ line -= strlen(KEYWORD); \
+ end = line; \
+ while (*end && (*end != ' ')) \
+ end++; \
+ prev_end_char = *end, *end = '\0'; \
+ NEW_ERROR(1, ERROR, "expecting keyword ‘%s’", KEYWORD); \
+ } \
+ } \
+ while (0)
+
+
+
/**
* Parse a file into a syntex tree
@@ -504,9 +547,19 @@ int parse_to_tree(const char* restrict filename, mds_kbdc_tree_t** restrict resu
NEW_ERROR(1, ERROR, "expecting nothing or ‘if’");
}
}
- else if (!strcmp(line, "for")) ;
- else if (!strcmp(line, "let")) ;
- else if (!strcmp(line, "have")) ;
+ else if (!strcmp(line, "for"))
+ {
+ NEW_NODE(for, FOR);
+ CHARS(first);
+ TEST_FOR_KEYWORD("to");
+ CHARS(last);
+ TEST_FOR_KEYWORD("as");
+ CHARS(variable);
+ CHARS_END;
+ BRANCH("for");
+ }
+ else if (!strcmp(line, "let")) ; /* TODO */
+ else if (!strcmp(line, "have")) ; /* TODO */
else if (!strcmp(line, "have_chars"))
{
NEW_NODE(assumption_have_chars, ASSUMPTION_HAVE_CHARS);
@@ -545,7 +598,7 @@ int parse_to_tree(const char* restrict filename, mds_kbdc_tree_t** restrict resu
tree_stack[stack_ptr] = &(tree_stack[stack_ptr][0]->next);
}
else if (strchr("\"<([", *line) || strchr(line, '('))
- ;
+ ; /* TODO */
else
{
/* TODO not a keyword if it contains special characters */
@@ -576,6 +629,7 @@ int parse_to_tree(const char* restrict filename, mds_kbdc_tree_t** restrict resu
+#undef TEST_FOR_KEYWORD
#undef QUOTES_1
#undef QUOTES
#undef CHARS_END