]> gitweb.factorcode.org Git - factor.git/commitdiff
hashtable prettyprinting
authorSlava Pestov <slava@factorcode.org>
Fri, 26 Nov 2004 01:37:05 +0000 (01:37 +0000)
committerSlava Pestov <slava@factorcode.org>
Fri, 26 Nov 2004 01:37:05 +0000 (01:37 +0000)
TODO.FACTOR.txt
factor/ExternalFactor.java
factor/jedit/EditWordDialog.java
factor/jedit/FactorCompletion.java
factor/jedit/FactorPlugin.java
factor/jedit/FactorSideKickParser.java
library/syntax/prettyprint.factor
library/test/errors.factor
library/tools/debugger.factor

index 7d0fcc48737d17b797f2724835ae94bdf65347d3..8191667d9a5f9ef46e135b288f1de400e760220b 100644 (file)
@@ -28,7 +28,6 @@
 \r
 - listener: if too many things popped off the stack, complain\r
 - gracefully handle non-working cfactor\r
-- don't show listener on certain commands\r
 - NPE in ErrorHighlight\r
 - some way to not have previous definitions from a source file\r
   clutter the namespace\r
@@ -64,7 +63,6 @@
   objects\r
 - worddef props\r
 - prettyprint: when unparse called due to recursion, write a link\r
-- prettyprinter should output {{ ... }} syntax for hashtables\r
 - FORGET: and forget\r
 \r
 + httpd:\r
index b053554164af2ab896807673501c95fdebfaf049..21641c32db44ca442b5db89336ebc204055eba2a 100644 (file)
@@ -172,7 +172,7 @@ public class ExternalFactor extends DefaultVocabularyLookup
        } //}}}
 
        //{{{ getCompletions() method
-       public void getCompletions(String vocab, String word, List completions,
+       public void getCompletions(String vocab, String word, Set completions,
                boolean anywhere)
        {
                super.getCompletions(vocab,word,completions,anywhere);
@@ -193,8 +193,10 @@ public class ExternalFactor extends DefaultVocabularyLookup
                        while(moreCompletions != null)
                        {
                                Cons completion = (Cons)moreCompletions.car;
-                               completions.add(searchVocabulary(completion.next(),
-                                       (String)completion.car));
+                               FactorWord w = searchVocabulary(completion.next(),
+                                       (String)completion.car);
+                               if(w != null)
+                                       completions.add(w);
                                moreCompletions = moreCompletions.next();
                        }
                }
index cf9e29fea780798628c89f55e63323a31147b769..265999fd546d14cfb769b75aa6ef387f4406e021 100644 (file)
@@ -117,13 +117,11 @@ public class EditWordDialog extends WordListDialog
        //{{{ updateList() method
        private void updateList()
        {
-               List completions = FactorPlugin.getCompletions(
-                       field.getText(),true);
-               FactorWord[] completionArray
-                       = (FactorWord[])completions.toArray(
-                       new FactorWord[completions.size()]);
-               list.setListData(completionArray);
-               if(completionArray.length != 0)
+               FactorWord[] completions = FactorPlugin.toWordArray(
+                       FactorPlugin.getCompletions(
+                       field.getText(),true));
+               list.setListData(completions);
+               if(completions.length != 0)
                {
                        list.setSelectedIndex(0);
                        list.ensureIndexIsVisible(0);
index ae14cb83457957eb66436c6e85ad3e024549f229..3ee9e50b5f4a3ea020b6fa2257288eb0262d77e9 100644 (file)
@@ -44,12 +44,12 @@ public class FactorCompletion extends SideKickCompletion
        private FactorParsedData data;
 
        //{{{ FactorCompletion constructor
-       public FactorCompletion(View view, List items,
+       public FactorCompletion(View view, FactorWord[] items,
                String word, FactorParsedData data)
        {
                this.view = view;
                textArea = view.getTextArea();
-               this.items = items;
+               this.items = Arrays.asList(items);
                this.word = word;
                this.data = data;
        } //}}}
index a25565d03d76b988556b1625b2e40156f29f9758..d20d22049780a005815612445080cc9c9cf7b084 100644 (file)
@@ -200,6 +200,16 @@ public class FactorPlugin extends EditPlugin
                        evalInWire(word + " " + op);
        } //}}}
 
+       //{{{ toWordArray() method
+       public static FactorWord[] toWordArray(Set completions)
+       {
+               FactorWord[] w = (FactorWord[])completions.toArray(new FactorWord[
+                       completions.size()]);
+               Arrays.sort(w,new MiscUtilities.StringICaseCompare());
+
+               return w;
+       } //}}}
+       
        //{{{ getCompletions() method
        /**
         * Returns all words in all vocabularies.
@@ -207,7 +217,7 @@ public class FactorPlugin extends EditPlugin
         * @param anywhere If true, matches anywhere in the word name are
         * returned; otherwise, only matches from beginning.
         */
-       public static List getCompletions(String word, boolean anywhere)
+       public static Set getCompletions(String word, boolean anywhere)
        {
                try
                {
@@ -225,11 +235,11 @@ public class FactorPlugin extends EditPlugin
         * @param anywhere If true, matches anywhere in the word name are
         * returned; otherwise, only matches from beginning.
         */
-       public static List getCompletions(Cons use, String word, boolean anywhere)
+       public static Set getCompletions(Cons use, String word, boolean anywhere)
        {
                try
                {
-                       List completions = new ArrayList();
+                       Set completions = new HashSet();
        
                        while(use != null)
                        {
@@ -238,10 +248,7 @@ public class FactorPlugin extends EditPlugin
                                        vocab,word,completions,anywhere);
                                use = use.next();
                        }
-                       
-                       Collections.sort(completions,
-                               new MiscUtilities.StringICaseCompare());
-       
+
                        return completions;
                }
                catch(Exception e)
index b0dd9f0dfcf764f64cd167c8a653f2377e672991..603b447663efe2bf4f7bbe8182b636284974d64d 100644 (file)
@@ -274,10 +274,11 @@ public class FactorSideKickParser extends SideKickParser
                if(word.length() == 0)
                        return null;
 
-               List completions = FactorPlugin.getCompletions(
-                       data.use,word,false);
+               FactorWord[] completions = FactorPlugin.toWordArray(
+                       FactorPlugin.getCompletions(
+                       data.use,word,false));
 
-               if(completions.size() == 0)
+               if(completions.length == 0)
                        return null;
                else
                {
index a16e198f193e0abbdecb2afa02fa9edef8498278..0298dffd25b73cf33d4f7326983219829e070c34 100644 (file)
@@ -34,7 +34,6 @@ USE: logic
 USE: lists
 USE: math
 USE: namespaces
-USE: prettyprint
 USE: stack
 USE: stdio
 USE: strings
@@ -42,6 +41,7 @@ USE: presentation
 USE: unparser
 USE: vectors
 USE: words
+USE: hashtables
 
 : tab-size
     #! Change this to suit your tastes.
@@ -82,10 +82,10 @@ DEFER: prettyprint*
     ] unless ;
 
 : prettyprint-[ ( indent -- indent )
-    "[" write <prettyprint ;
+        \ [ prettyprint-word <prettyprint ;
 
 : prettyprint-] ( indent -- indent )
-    prettyprint> "]" write ;
+        prettyprint> \ ] prettyprint-word ;
 
 : prettyprint-list ( indent list -- indent )
     #! Pretty-print a list, without [ and ].
@@ -104,10 +104,10 @@ DEFER: prettyprint*
     swap prettyprint-[ swap prettyprint-list prettyprint-] ;
 
 : prettyprint-{ ( indent -- indent )
-    "{" write <prettyprint ;
+    \ { prettyprint-word <prettyprint ;
 
 : prettyprint-} ( indent -- indent )
-    prettyprint> "}" write ;
+    prettyprint> \ } prettyprint-word ;
 
 : prettyprint-vector ( indent list -- indent )
     #! Pretty-print a vector, without { and }.
@@ -115,11 +115,24 @@ DEFER: prettyprint*
 
 : prettyprint-{} ( indent vector -- indent )
     dup vector-length 0 = [
-        drop "{ }" write
+        drop prettyprint-{ prettyprint-}
     ] [
         swap prettyprint-{ swap prettyprint-vector prettyprint-}
     ] ifte ;
 
+: prettyprint-{{ ( indent -- indent )
+        \ {{ prettyprint-word <prettyprint ;
+
+: prettyprint-}} ( indent -- indent )
+        prettyprint> \ }} prettyprint-word ;
+
+: prettyprint-{{}} ( indent hashtable -- indent )
+    hash>alist dup length 0 = [
+        drop prettyprint-{{ prettyprint-}}
+    ] [
+        swap prettyprint-{{ swap prettyprint-list prettyprint-}}
+    ] ifte ;
+
 : trim-newline ( str -- str )
     dup ends-with-newline? dup [ nip ] [ drop ] ifte ;
 
@@ -168,11 +181,12 @@ DEFER: prettyprint*
         unparse write
     ] [
         [
-            [ f =       ] [ prettyprint-object ]
-            [ cons?     ] [ prettyprint-[] ]
-            [ vector?   ] [ prettyprint-{} ]
-            [ word?     ] [ prettyprint-word ]
-            [ drop t    ] [ prettyprint-object ]
+            [ f =        ] [ prettyprint-object ]
+            [ cons?      ] [ prettyprint-[] ]
+            [ hashtable? ] [ prettyprint-{{}} ]
+            [ vector?    ] [ prettyprint-{} ]
+            [ word?      ] [ prettyprint-word ]
+            [ drop t     ] [ prettyprint-object ]
         ] cond
     ] ifte ;
 
index 3f999d88c1c0e359e4a7984f760c5cf8fcbabf83..7c3a6904a5de7bdbcc672329498c7873fa35fab1 100644 (file)
@@ -4,6 +4,7 @@ USE: kernel
 USE: namespaces
 USE: stack
 USE: test
+USE: lists
 
 [ f ] [ [ ] [ ] catch ] unit-test
 
@@ -14,3 +15,6 @@ USE: test
     global [ "error" get ] bind
     "Hello" =
 ] unit-test
+
+[ ] [ [ ] print-error ] unit-test
+[ ] [ [ 2 car ] print-error ] unit-test
index 1ce352252cd7fb8997bb03cfe0be477fb6f38fc8..3a3934c8113c492ff3f5490572618f86bc301389 100644 (file)
@@ -76,4 +76,4 @@ USE: unparser
 : print-error ( quot -- )
     #! Execute a quotation, and if it throws an error, print it
     #! and return to the caller.
-    [ [ default-error-handler drop ] when* ] catch ;
+    [ [ default-error-handler ] when* ] catch ;