diff options
Diffstat (limited to 'yy/main.c')
-rw-r--r-- | yy/main.c | 42 |
1 files changed, 42 insertions, 0 deletions
@@ -6,6 +6,44 @@ #include "kalmia.lex.h" +void print_attrs(struct kai_attr_t *attr) +{ + while(attr != NULL) { + printf("%s=\"%s\" ", attr->key, attr->value); + attr = attr->next; + } +} + + +void print_tag(char *indent, struct kai_tag_t *tag) +{ + printf("%s%s[ ", indent, tag->type); + print_attrs(tag->attrs); + printf("]\n"); +} + + +void print_level(int indent_level, struct kai_tag_t *tag) +{ + char indent[64]; + for (int i=0; i<indent_level; i++) { + indent[i] = '\t'; + } + indent[indent_level] = 0; + + while (tag != NULL) { + print_tag(indent, tag); + if (tag->children != NULL) { + print_level(indent_level+1, tag->children); + } + if (tag->content != NULL) { + printf("%s\t%s\n", indent, tag->content); + } + tag = tag->next; + } +} + + int main(int argc, char **argv) { if (argc < 2) { @@ -25,5 +63,9 @@ int main(int argc, char **argv) kalmiaset_in(in, scanner); kalmiaparse(scanner, &result); kalmialex_destroy(scanner); + + print_tag("", result.tag); + print_level(1, result.tag->children); + return 0; } |