]> gitweb.factorcode.org Git - factor.git/commitdiff
plugin fixes
authorSlava Pestov <slava@factorcode.org>
Sun, 19 Dec 2004 06:48:31 +0000 (06:48 +0000)
committerSlava Pestov <slava@factorcode.org>
Sun, 19 Dec 2004 06:48:31 +0000 (06:48 +0000)
TODO.FACTOR.txt
factor/DefaultVocabularyLookup.java
factor/ExternalFactor.java
factor/VocabularyLookup.java
factor/jedit/FactorParsedData.java
factor/jedit/FactorSideKickParser.java
library/generic/generic.factor
library/math/complex.factor
library/tools/listener.factor

index 550f700affb6fb7df6caf371030d72ea17d6473f..704879bc5a3af739879e6185d2a54491593aaeb8 100644 (file)
 + listener/plugin:\r
 \r
 - faster completion\r
-- word added >1 if external instance dies\r
 - sidekick: still parsing too much\r
 - errors don't always disappear\r
-- console: wrong history\r
-- listener: if too many things popped off the stack, complain\r
 - NPE in ErrorHighlight\r
-- some way to not have previous definitions from a source file\r
-  clutter the namespace\r
 - maple-like: press enter at old commands to evaluate there\r
 - completion in the listener\r
 - special completion for USE:/IN:\r
index 98386a7d485b0cba0f007ab6d9af839e81ceae62..3492910c792374279cfe36d576e8cb49fedf73a2 100644 (file)
@@ -188,6 +188,14 @@ public class DefaultVocabularyLookup implements VocabularyLookup
                }
        } //}}}
 
+       //{{{ forget() method
+       public void forget(FactorWord word)
+       {
+               Map vocab = (Map)vocabularies.get(word.vocabulary);
+               if(vocab != null)
+                       vocab.remove(word.name);
+       } //}}}
+
        //{{{ getVocabularies() method
        public Cons getVocabularies()
        {
index 7da37df413462350132a49ede0bfcac8218d99ae..d6f34771a16f65303ad087c3db233e0fffaf6cce 100644 (file)
@@ -185,34 +185,34 @@ public class ExternalFactor extends DefaultVocabularyLookup
        public synchronized FactorWord searchVocabulary(Cons vocabulary, String name)
        {
                FactorWord w = super.searchVocabulary(vocabulary,name);
+
                if(w != null)
                        return w;
 
+               if(closed)
+                       return define("#<unknown>",name);
+
                try
                {
-                       if(!closed)
-                       {
-                               Cons result = parseObject(eval(FactorReader.unparseObject(name)
-                                       + " "
-                                       + FactorReader.unparseObject(vocabulary)
-                                       + " jedit-lookup ."));
-                               if(result.car == null)
-                                       return null;
-       
-                               result = (Cons)result.car;
-                               w = new FactorWord(
-                                       (String)result.car,
-                                       (String)result.next().car);
-                               w.stackEffect = (String)result.next().next().car;
-                               return w;
-                       }
+                       Cons result = parseObject(eval(FactorReader.unparseObject(name)
+                               + " "
+                               + FactorReader.unparseObject(vocabulary)
+                               + " jedit-lookup ."));
+                       if(result.car == null)
+                               return null;
+
+                       result = (Cons)result.car;
+                       w = new FactorWord(
+                               (String)result.car,
+                               (String)result.next().car);
+                       w.stackEffect = (String)result.next().next().car;
+                       return w;
                }
                catch(Exception e)
                {
                        Log.log(Log.ERROR,this,e);
+                       return null;
                }
-
-               return new FactorWord("unknown",name);
        } //}}}
 
        //{{{ getCompletions() method
index 02849acd71c868c3af2398690a003b16e6fd9f7d..60ec6ada3651dd510f655d756a8517e085c70674 100644 (file)
@@ -36,9 +36,12 @@ public interface VocabularyLookup
 {
        public FactorWord define(String in, String word)
                throws Exception;
+
        public FactorWord searchVocabulary(Cons use, String word)
                throws Exception;
 
+       public void forget(FactorWord word);
+
        /**
         * @param vocab The vocabulary name
         * @param word A substring of the word name to complete
index d42102851dd775949d7ab732a205120f69a3005d..fa55778c63db45e2fdae334ce7a58d332f602ecf 100644 (file)
@@ -37,7 +37,7 @@ public class FactorParsedData extends SideKickParsedData
        public FactorSideKickParser parser;
        public String in;
        public Cons use;
-       
+
        FactorParsedData(FactorSideKickParser parser, String fileName)
        {
                super(fileName);
index 603b447663efe2bf4f7bbe8182b636284974d64d..fe7e19a1d3abe1265b956597083af4ba07e7f7e0 100644 (file)
@@ -40,14 +40,12 @@ import sidekick.*;
 
 public class FactorSideKickParser extends SideKickParser
 {
-       private Map previewMap;
-
        /**
-        * When we parse a file, we store the <word,worddef> pairs in this
-        * map, so that completion popups show the latest stack effects,
-        * and not whatever they were the last time the source was run-file'd.
+        * We store the file's parse tree in this property.
         */
-       private Map worddefs;
+       public static String PARSED_PROPERTY = "factor-parsed";
+
+       private Map previewMap;
 
        //{{{ FactorSideKickParser constructor
        public FactorSideKickParser()
@@ -100,6 +98,9 @@ public class FactorSideKickParser extends SideKickParser
        public SideKickParsedData parse(Buffer buffer,
                DefaultErrorSource errorSource)
        {
+               Cons parsed = (Cons)buffer.getProperty(PARSED_PROPERTY);
+               removeWordDefinitions(parsed);
+
                FactorParsedData d = new FactorParsedData(
                        this,buffer.getPath());
 
@@ -126,12 +127,14 @@ public class FactorSideKickParser extends SideKickParser
                                errorSource);
                        FactorReader r = new FactorReader(scanner,
                                false,FactorPlugin.getExternalInstance());
-       
-                       Cons parsed = r.parse();
-       
+
+                       parsed = r.parse();
+
                        d.in = r.getIn();
                        d.use = r.getUse();
        
+                       buffer.setProperty(PARSED_PROPERTY,parsed);
+
                        addWordDefNodes(d,parsed,buffer);
                }
                catch(FactorParseException pe)
@@ -151,9 +154,23 @@ public class FactorSideKickParser extends SideKickParser
                return d;
        } //}}}
 
+       //{{{ removeWordDefinitions() method
+       private void removeWordDefinitions(Cons parsed)
+       {
+               while(parsed != null)
+               {
+                       Object obj = parsed.car;
+                       if(obj instanceof FactorWordDefinition)
+                       {
+                               FactorPlugin.getExternalInstance().forget(
+                                       ((FactorWordDefinition)obj).word);
+                       }
+                       parsed = parsed.next();
+               }
+       } //}}}
+
        //{{{ addWordDefNodes() method
-       private void addWordDefNodes(SideKickParsedData d, Cons parsed,
-               Buffer buffer)
+       private void addWordDefNodes(FactorParsedData d, Cons parsed, Buffer buffer)
        {
                FactorAsset last = null;
 
@@ -171,10 +188,8 @@ public class FactorSideKickParser extends SideKickParser
                                int startLine = Math.min(
                                        buffer.getLineCount() - 1,
                                        word.line - 1);
-                               int startLineLength = buffer.getLineLength(
-                                       startLine);
-                               int startCol = Math.min(word.col,
-                                       startLineLength);
+                               int startLineLength = buffer.getLineLength(startLine);
+                               int startCol = Math.min(word.col,startLineLength);
 
                                int start = buffer.getLineStartOffset(startLine)
                                        + startCol;
index a756b949c674097e5f65436d658b2dfe1472397e..785a0a4d189afb3a9aa6eb005f88f13638a049cf 100644 (file)
@@ -40,6 +40,9 @@ USE: math-internals
 
 ! A simple single-dispatch generic word system.
 
+! "if I say I'd rather eat cheese than shit... doesn't mean
+! those are the only two things I can eat." - Tac
+
 : predicate-word ( word -- word )
     word-name "?" cat2 "in" get create ;
 
index 808c60d808ad41a9f4fb9dc08dccbe475e6997cd..fe5ab31fad26cfa03d0f1c487480f687087a26f7 100644 (file)
@@ -31,7 +31,7 @@ USE: kernel
 USE: math
 USE: math-internals
 
-: >rect ( x -- xr xi ) dup real swap imaginary ;
+: >rect ( x -- xr xi ) dup real swap imaginary ; inline
 
 : conjugate ( z -- z* )
     >rect neg rect> ;
@@ -53,7 +53,7 @@ IN: math-internals
 
 : 2>rect ( x y -- xr yr xi yi )
     [ swap real swap real ] 2keep
-    swap imaginary swap imaginary ;
+    swap imaginary swap imaginary ; inline
 
 M: complex number= ( x y -- ? )
     2>rect number= [ number= ] [ 2drop f ] ifte ;
index 97ff6c200d03fd4cfa15dfcf9de1e4b60c597957..022f5c5e05c23e00ba3d589a794d172a383583f7 100644 (file)
@@ -62,7 +62,7 @@ global [
 : (read-multiline) ( quot depth -- quot ? )
     #! Flag indicates EOF.
     >r read dup [
-        (parse) depth r> dup >r = [
+        (parse) depth r> dup >r <= [
             ( we're done ) r> drop t
         ] [
             ( more input needed ) r> cont-prompt get prompt.