hashtable prettyprinting
parent
a8975900bd
commit
22dc78433c
|
@ -28,7 +28,6 @@
|
|||
|
||||
- listener: if too many things popped off the stack, complain
|
||||
- gracefully handle non-working cfactor
|
||||
- don't show listener on certain commands
|
||||
- NPE in ErrorHighlight
|
||||
- some way to not have previous definitions from a source file
|
||||
clutter the namespace
|
||||
|
@ -64,7 +63,6 @@
|
|||
objects
|
||||
- worddef props
|
||||
- prettyprint: when unparse called due to recursion, write a link
|
||||
- prettyprinter should output {{ ... }} syntax for hashtables
|
||||
- FORGET: and forget
|
||||
|
||||
+ httpd:
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
} //}}}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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 ;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 ;
|
||||
|
|
Loading…
Reference in New Issue