]> gitweb.factorcode.org Git - factor.git/commitdiff
minor fixes
authorSlava Pestov <slava@factorcode.org>
Fri, 29 Oct 2004 03:58:23 +0000 (03:58 +0000)
committerSlava Pestov <slava@factorcode.org>
Fri, 29 Oct 2004 03:58:23 +0000 (03:58 +0000)
TODO.FACTOR.txt
contrib/stack-effect.factor [new file with mode: 0644]
factor/jedit/FactorSideKickParser.java
factor/jedit/WordPreview.java
library/httpd/file-responder.factor
library/lists.factor
library/test/lists/lists.factor

index 73ef6a0d0c4f487866dc2c3af0580197971d573f..1079c0608e3bf20a473cff7be2aaecb9149bbccc 100644 (file)
@@ -1,11 +1,9 @@
 FFI:\r
 \r
-- wordpreview: don't show for string literals and comments\r
 - listener: use console shell api\r
 - add a socket timeout\r
 - fix error postoning -- not all errors thrown by i/o code are\r
   postponed\r
-- file responder: don't show full path in title\r
 - quit responder breaks with multithreading\r
 \r
 + compiler/ffi:\r
diff --git a/contrib/stack-effect.factor b/contrib/stack-effect.factor
new file mode 100644 (file)
index 0000000..99fcca6
--- /dev/null
@@ -0,0 +1,56 @@
+IN: stack-effect
+USE: lists
+USE: stack
+USE: math
+USE: combinators
+USE: kernel
+USE: test
+USE: errors
+
+: s* ( [ a | b ] [ c | d ] )
+    #! Stack effect composition.
+    >r uncons r> uncons >r -
+    dup 0 < [ neg + r> cons ] [ r> + cons ] ifte ;
+
+: list* ( list [ a | b ] -- list )
+    #! Right composition with a list and stack effect.
+    swap [ over s* ] map nip prune ;
+
+: *list ( [ a | b ] list -- list )
+    #! Left composition with a list and stack effect.
+    [ dupd s* ] map nip prune ;
+
+: <> ( [ a | b ] )
+    #! Stack height equivelence.
+    uncons - ;
+
+: balanced? ( list -- ? )
+    #! Is this a balanced set?
+    [ unswons <> swap [ <> over = ] all? nip ] [ t ] ifte* ;
+
+: car> ( [ a | b ] [ c | d ] )
+    swap car swap car > ;
+
+: car-max ( [ a | b ] [ c | d ] )
+    2dup car> [ drop ] [ nip ] ifte ;
+
+: point ( list -- [ a | b ] )
+    #! The point of a balanced set.
+    [ -1 | -1 ] swap [ car-max ] each ;
+
+: s+ ( [ a | b ] [ c | d ] -- )
+    #! Stack effect addition.
+    2list dup balanced? [ point ] [ "Not balanced" throw ] ifte ;
+
+[ t ] [ [ [ 1 | 2 ] [ 3 | 4 ] ] balanced? ] unit-test
+[ f ] [ [ [ 4 | 2 ] [ 3 | 4 ] ] balanced? ] unit-test
+[ t ] [ [ [ 1 | 5 ] ] balanced? ] unit-test
+[ t ] [ [ ] balanced? ] unit-test
+[ [ 3 | 4 ] ] [ [ [ 1 | 2 ] [ 3 | 4 ] ] point ] unit-test
+
+[ [ [ 1 | 1 ] [ 2 | 2 ] [ 3 | 3 ] ] ]
+[ [ [ 1 | 2 ] [ 2 | 3 ] [ 3 | 4 ] ] [ 1 | 0 ] list* ] unit-test
+
+[ [ 1 | 1 ] ] [ [ 1 | 2 ] [ 2 | 1 ] s* ] unit-test
+
+[ [ 4 | 5 ] ] [ [ 4 | 5 ] [ 3 | 4 ] s+ ] unit-test
index b5474b8074ffd2f25be3de5e1b95afa6f4a2febc..72ad3902a7e06a72606a7b46a16faa661d62283d 100644 (file)
@@ -42,6 +42,7 @@ public class FactorSideKickParser extends SideKickParser
 {
        private FactorInterpreter interp;
        private WordPreview wordPreview;
+       private Map previewMap;
 
        /**
         * When we parse a file, we store the <word,worddef> pairs in this
@@ -55,7 +56,7 @@ public class FactorSideKickParser extends SideKickParser
        {
                super("factor");
                interp = FactorPlugin.getInterpreter();
-               wordPreview = new WordPreview(this);
+               previewMap = new HashMap();
                worddefs = new HashMap();
        } //}}}
 
@@ -90,7 +91,10 @@ public class FactorSideKickParser extends SideKickParser
        public void activate(EditPane editPane)
        {
                super.activate(editPane);
-               editPane.getTextArea().addCaretListener(wordPreview);
+               WordPreview preview = new WordPreview(this,
+                       editPane.getTextArea());
+               previewMap.put(editPane,preview);
+               editPane.getTextArea().addCaretListener(preview);
        } //}}}
 
        //{{{ deactivate() method
@@ -103,7 +107,10 @@ public class FactorSideKickParser extends SideKickParser
        public void deactivate(EditPane editPane)
        {
                super.deactivate(editPane);
-               editPane.getTextArea().removeCaretListener(wordPreview);
+               WordPreview preview = (WordPreview)previewMap
+                       .remove(editPane);
+               if(preview != null)
+                       editPane.getTextArea().removeCaretListener(preview);
        } //}}}
 
        //{{{ parse() method
index 49b2c1e1effe7eb7e8a9b94f137ca0ec7ac8b71c..c2ae15c10e8df2222c23cfad55999826283c3e53 100644 (file)
 package factor.jedit;
 
 import factor.*;
+import java.awt.event.*;
 import java.util.*;
 import javax.swing.event.*;
+import javax.swing.Timer;
+import org.gjt.sp.jedit.syntax.*;
 import org.gjt.sp.jedit.textarea.*;
 import org.gjt.sp.jedit.*;
 import org.gjt.sp.util.Log;
 import sidekick.*;
 
-public class WordPreview implements CaretListener
+public class WordPreview implements ActionListener, CaretListener
 {
        private FactorSideKickParser parser;
+       private Timer timer;
+       private JEditTextArea textArea;
+
+       private static String[] IGNORED_RULESETS = {
+               "factor::LITERAL",
+               "factor::STACK_EFFECT",
+               "factor::COMMENT"
+       };
 
        //{{{ WordPreview constructor
-       public WordPreview(FactorSideKickParser parser)
+       public WordPreview(FactorSideKickParser parser,
+               JEditTextArea textArea)
        {
                this.parser = parser;
+               this.textArea = textArea;
+               this.timer = new Timer(0,this);
+               timer.setRepeats(false);
        } //}}}
        
        //{{{ caretUpdate() method
        public void caretUpdate(CaretEvent e)
        {
-               showPreview((JEditTextArea)e.getSource());
+               timer.stop();
+               timer.setInitialDelay(100);
+               timer.start();
        } //}}}
 
+       //{{{ public void actionPerformed() method
+       public void actionPerformed(ActionEvent evt)
+       {
+               showPreview();
+       } //}}}
+       
        //{{{ showPreview() method
-       private void showPreview(JEditTextArea textArea)
+       private void showPreview()
        {
                View view = textArea.getView();
-               String word = FactorPlugin.getWordAtCaret(textArea);
-               if(word == null)
-                       return;
+
                SideKickParsedData data = SideKickParsedData
                        .getParsedData(view);
                if(data instanceof FactorParsedData)
                {
+                       int line = textArea.getCaretLine();
+                       int caret = textArea.getCaretPosition();
+
+                       DefaultTokenHandler h = new DefaultTokenHandler();
+                       textArea.getBuffer().markTokens(line,h);
+                       Token tokens = h.getTokens();
+
+                       Token token = TextUtilities.getTokenAtOffset(tokens,
+                               caret - textArea.getLineStartOffset(line));
+
+                       String name = token.rules.getName();
+
+                       for(int i = 0; i < IGNORED_RULESETS.length; i++)
+                       {
+                               if(name.equals(IGNORED_RULESETS[i]))
+                                       return;
+                       }
+
+                       String word = FactorPlugin.getWordAtCaret(textArea);
+                       if(word == null)
+                               return;
+
                        FactorParsedData fdata = (FactorParsedData)data;
                        FactorInterpreter interp = fdata.parser
                                .getInterpreter();
index b213d867393910a384aa30e35f77712586863459..03f5883d0bbf32da25e022d9deaba9ec3ea5f3df 100644 (file)
@@ -71,7 +71,7 @@ USE: unparser
      "method" get "head" = [
         drop
     ] [
-        dup [ directory. ] simple-html-document
+        "request" get [ directory. ] simple-html-document
     ] ifte ;
 
 : serve-directory ( filename -- )
index 4538e51dc7413addfb4e294f57513b7b37188718..2e3971e5208440954dc0a50834f58a46794de66c 100644 (file)
@@ -34,20 +34,15 @@ USE: stack
 USE: vectors
 
 : 2list ( a b -- [ a b ] )
-    #! Construct a proper list of 2 elements.
     unit cons ;
 
 : 3list ( a b c -- [ a b c ] )
-    #! Construct a proper list of 3 elements.
     2list cons ;
 
 : append ( [ list1 ] [ list2 ] -- [ list1 list2 ] )
     over [ >r uncons r> append cons ] [ nip ] ifte ;
 
 : contains? ( element list -- remainder )
-    #! If the proper list contains the element, push the
-    #! remainder of the list, starting from the cell whose car
-    #! is elem. Otherwise push f.
     dup [
         2dup car = [ nip ] [ cdr contains? ] ifte
     ] [
@@ -66,7 +61,6 @@ USE: vectors
     dup cdr cons? [ cdr last* ] when ;
 
 : last ( list -- last )
-    #! Pushes last element of a list.
     last* car ;
 
 : list? ( list -- boolean )
@@ -158,7 +152,6 @@ DEFER: tree-contains?
     inline interpret-only
 
 : reverse ( list -- list )
-    #! Push a new list that is the reverse of a proper list.
     [ ] swap [ swons ] each ;
 
 : map ( list quot -- list )
@@ -185,9 +178,14 @@ DEFER: tree-contains?
     [ dupd = not ] subset nip ;
 
 : length ( list -- length )
-    #! Pushes the length of the given proper list.
     0 swap [ drop succ ] each ;
 
+: prune ( list -- list )
+    #! Remove duplicate elements.
+    dup [
+        uncons prune 2dup contains? [ nip ] [ cons ] ifte
+    ] when ;
+
 : all? ( list pred -- ? )
     #! Push if the predicate returns true for each element of
     #! the list.
index 6fdfb074931c471606528faeaba4520713a31e15..ba6a02ff15416d8b7e492ae147bb8b836d19d465 100644 (file)
@@ -61,3 +61,5 @@ USE: test
 [ [ 0 1 2 3 ] ] [ 4   count ] unit-test
 
 [ [ 1 2 3 ] ] [ [ 1 4 2 5 3 6 ] [ 4 < ] subset ] unit-test
+
+[ [ 43 "a" [ ] ] ] [ [ "a" 43 43 43 [ ] 43 "a" [ ] ] prune ] unit-test