corinthia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmke...@apache.org
Subject [1/2] incubator-corinthia git commit: Flat: Print connecting lines in Term tree output
Date Fri, 17 Jul 2015 08:19:26 GMT
Repository: incubator-corinthia
Updated Branches:
  refs/heads/master d89f89816 -> 1707a7125


Flat: Print connecting lines in Term tree output


Project: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/commit/c6a23ee0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/tree/c6a23ee0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/diff/c6a23ee0

Branch: refs/heads/master
Commit: c6a23ee023657a18384c30ddf5454e4cf43e1bb8
Parents: d89f898
Author: Peter Kelly <peter@uxproductivity.com>
Authored: Fri Jul 17 15:08:42 2015 +0700
Committer: Peter Kelly <peter@uxproductivity.com>
Committed: Fri Jul 17 15:08:42 2015 +0700

----------------------------------------------------------------------
 experiments/flat/src/Term.c | 24 ++++++++++++++++--------
 experiments/flat/src/Term.h |  2 +-
 experiments/flat/src/flat.c |  3 +--
 3 files changed, 18 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/c6a23ee0/experiments/flat/src/Term.c
----------------------------------------------------------------------
diff --git a/experiments/flat/src/Term.c b/experiments/flat/src/Term.c
index 902dfd7..359d539 100644
--- a/experiments/flat/src/Term.c
+++ b/experiments/flat/src/Term.c
@@ -52,11 +52,8 @@ void TermListPtrAppend(TermList ***listPtr, Term *term)
     *listPtr = &(**listPtr)->next;
 }
 
-void TermPrint(Term *term, const char *input, int indent)
+void TermPrint(Term *term, const char *input, const char *indent)
 {
-    for (int i = 0; i < indent; i++)
-        printf("    ");
-
     switch (ExpressionKind(term->type)) {
         case IdentExpr:
             printf("%s %s\n",ExprKindAsString(ExpressionKind(term->type)),ExprIdentValue(term->type));
@@ -88,10 +85,21 @@ void TermPrint(Term *term, const char *input, int indent)
             break;
     }
 
+    int indentLen = strlen(indent);
+    char *nextIndent = (char *)malloc(indentLen+5);
+
     for (TermList *child = term->children; child != NULL; child = child->next) {
-        if (child->next != NULL)
-            TermPrint(child->term,input,indent+1);
-        else
-            TermPrint(child->term,input,indent+1);
+        if (child->next != NULL) {
+            printf("%s|-- ",indent);
+            snprintf(nextIndent,indentLen+5,"%s|   ",indent);
+            TermPrint(child->term,input,nextIndent);
+        }
+        else {
+            printf("%s\\-- ",indent);
+            snprintf(nextIndent,indentLen+5,"%s    ",indent);
+            TermPrint(child->term,input,nextIndent);
+        }
     }
+
+    free(nextIndent);
 }

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/c6a23ee0/experiments/flat/src/Term.h
----------------------------------------------------------------------
diff --git a/experiments/flat/src/Term.h b/experiments/flat/src/Term.h
index 911396a..865618e 100644
--- a/experiments/flat/src/Term.h
+++ b/experiments/flat/src/Term.h
@@ -39,4 +39,4 @@ Term *TermNew(Expression *type, int start, int end, TermList *children);
 TermList *TermListNew(Term *term, TermList *next);
 void TermListPtrAppend(TermList ***listPtr, Term *term);
 
-void TermPrint(Term *term, const char *input, int indent);
+void TermPrint(Term *term, const char *input, const char *indent);

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/c6a23ee0/experiments/flat/src/flat.c
----------------------------------------------------------------------
diff --git a/experiments/flat/src/flat.c b/experiments/flat/src/flat.c
index 51003b8..179bd9c 100644
--- a/experiments/flat/src/flat.c
+++ b/experiments/flat/src/flat.c
@@ -63,8 +63,7 @@ int main(int argc, const char **argv)
         }
         Grammar *gram = GrammarNewBuiltin();
         Term *term = parse(gram,"Grammar",input,0,strlen(input));
-        printf("Parsed term %p\n",term);
-        TermPrint(term,input,0);
+        TermPrint(term,input,"");
         free(input);
         GrammarFree(gram);
     }


Mime
View raw message