diff options
-rw-r--r-- | src/mds-kbdc/make-tree.c | 30 | ||||
-rw-r--r-- | test-files/mds-kbdc/make-tree/valid/map | 112 |
2 files changed, 136 insertions, 6 deletions
diff --git a/src/mds-kbdc/make-tree.c b/src/mds-kbdc/make-tree.c index 533b028..883d1a8 100644 --- a/src/mds-kbdc/make-tree.c +++ b/src/mds-kbdc/make-tree.c @@ -261,6 +261,15 @@ /** + * Check whether a character ends a strings, whilst not being being a quote + * + * @param c:char The character + */ +#define IS_END(c) \ + strchr("([{< >}])", c) + + +/** * Take next parameter, which should be a string or numeral, * and store it in the current node * @@ -298,7 +307,7 @@ call_end = arg_end + get_end_of_call(arg_end, 0, strlen(arg_end)); \ } \ else if (quote) quote = (c != '"'); \ - else if (c == ' ') { arg_end--; break; } \ + else if (IS_END(c)) { arg_end--; break; } \ else quote = (c == '"'); \ } \ prev_end_char = *arg_end, *arg_end = '\0', end = arg_end; \ @@ -444,7 +453,7 @@ else if (quote) quote = (c != '"'); \ else if (c == '\"') quote = 1; \ else if (c == '>') triangle = 0; \ - else if ((c == ' ') && !triangle) { arg_end--; break; } \ + else if (IS_END(c) && !triangle) { arg_end--; break; } \ } \ prev_end_char = *arg_end, *arg_end = '\0', end = arg_end; \ if (*line == '<') \ @@ -521,6 +530,7 @@ #define SEQUENCE \ do /* for(;;) */ \ { \ + *end = prev_end_char; \ while (*line && (*line == ' ')) \ line++; \ if ((*line == '\0') || (*line == ':')) \ @@ -972,21 +982,24 @@ int parse_to_tree(const char* restrict filename, mds_kbdc_tree_t** restrict resu size_t stack_orig = stack_ptr + 1; #define node supernode #define inner sequence - NEW_NODE(map, MAP); /* FIXME memory leak */ + NEW_NODE(map, MAP); node->loc_end = node->loc_start; BRANCH(":"); #undef inner #undef node SEQUENCE; SEQUENCE_FULLY_POPPED(stack_orig); +#define node supernode +#define inner result stack_ptr--; *end = prev_end_char; while (*line && (*line == ' ')) line++; if (*line++ != ':') - continue; /* Not an error in macros. */ -#define node supernode -#define inner result + { + LEAF; + continue; /* Not an error in macros. */ + } BRANCH(":"); #undef inner #undef node @@ -996,6 +1009,9 @@ int parse_to_tree(const char* restrict filename, mds_kbdc_tree_t** restrict resu *end = prev_end_char; while (*line && (*line == ' ')) line++; +#define node supernode + LEAF; +#undef node if (*line == '\0') continue; end = line + strlen(line), prev_end_char = *end; @@ -1072,6 +1088,8 @@ int parse_to_tree(const char* restrict filename, mds_kbdc_tree_t** restrict resu #undef QUOTES #undef END #undef CHARS +#undef IS_END +#undef NO_JUMP #undef NAMES_1 #undef NO_PARAMETERS #undef LEAF diff --git a/test-files/mds-kbdc/make-tree/valid/map b/test-files/mds-kbdc/make-tree/valid/map new file mode 100644 index 0000000..e678555 --- /dev/null +++ b/test-files/mds-kbdc/make-tree/valid/map @@ -0,0 +1,112 @@ +"a" +"b" : "c" +"1" : "2" "3" +"x" "y" : "X" "Y" +"z" : "V" "W" +<dead compose> "f" "s" : "ſ" +<dead compose> ("<" "=") : "≤" +<dead compose> "N" ["G" "g"] : "Ŋ" +<dead compose> (["a" "b" .] "c") : "d" + +# (map (@ 1 0-0) +# (.sequence +# (string (@ 1 0-3) ‘"a"’) +# ) +# (.result nil) +# ) +# (map (@ 2 0-0) +# (.sequence +# (string (@ 2 0-3) ‘"b"’) +# ) +# (.result +# (string (@ 2 6-9) ‘"c"’) +# ) +# ) +# (map (@ 3 0-0) +# (.sequence +# (string (@ 3 0-3) ‘"1"’) +# ) +# (.result +# (string (@ 3 6-9) ‘"2"’) +# (string (@ 3 10-13) ‘"3"’) +# ) +# ) +# (map (@ 4 0-0) +# (.sequence +# (string (@ 4 0-3) ‘"x"’) +# (string (@ 4 4-7) ‘"y"’) +# ) +# (.result +# (string (@ 4 10-13) ‘"X"’) +# (string (@ 4 14-17) ‘"Y"’) +# ) +# ) +# (map (@ 5 0-0) +# (.sequence +# (string (@ 5 0-3) ‘"z"’) +# ) +# (.result +# (string (@ 5 6-9) ‘"V"’) +# (string (@ 5 10-13) ‘"W"’) +# ) +# ) +# (map (@ 6 0-0) +# (.sequence +# (keys (@ 6 0-14) ‘<dead compose>’) +# (string (@ 6 15-18) ‘"f"’) +# (string (@ 6 19-22) ‘"s"’) +# ) +# (.result +# (string (@ 6 25-29) ‘"ſ"’) +# ) +# ) +# (map (@ 7 0-0) +# (.sequence +# (keys (@ 7 0-14) ‘<dead compose>’) +# (unordered (@ 7 15-16) +# (.inner +# (string (@ 7 16-19) ‘"<"’) +# (string (@ 7 20-23) ‘"="’) +# ) +# ) +# ) +# (.result +# (string (@ 7 27-32) ‘"≤"’) +# ) +# ) +# (map (@ 8 0-0) +# (.sequence +# (keys (@ 8 0-14) ‘<dead compose>’) +# (string (@ 8 15-18) ‘"N"’) +# (alternation (@ 8 19-20) +# (.inner +# (string (@ 8 20-23) ‘"G"’) +# (string (@ 8 24-27) ‘"g"’) +# ) +# ) +# ) +# (.result +# (string (@ 8 31-35) ‘"Ŋ"’) +# ) +# ) +# (map (@ 9 0-0) +# (.sequence +# (keys (@ 9 0-14) ‘<dead compose>’) +# (unordered (@ 9 15-16) +# (.inner +# (alternation (@ 9 16-17) +# (.inner +# (string (@ 9 17-20) ‘"a"’) +# (string (@ 9 21-24) ‘"b"’) +# (nothing (@ 9 25-26)) +# ) +# ) +# (string (@ 9 28-31) ‘"c"’) +# ) +# ) +# ) +# (.result +# (string (@ 9 35-38) ‘"d"’) +# ) +# ) + |