ExternalFactor VocabularyLookup

cvs
Slava Pestov 2004-11-19 04:23:12 +00:00
parent d9f823856a
commit 84d1667fdf
5 changed files with 77 additions and 36 deletions

View File

@ -36,7 +36,7 @@
- NPE in ErrorHighlight - NPE in ErrorHighlight
- some way to not have previous definitions from a source file - some way to not have previous definitions from a source file
clutter the namespace clutter the namespace
- ExternalFactor VocabularyLookup - finish ExternalFactor VocabularyLookup
- fedit broken with listener - fedit broken with listener
- maple-like: press enter at old commands to evaluate there - maple-like: press enter at old commands to evaluate there
- completion in the listener - completion in the listener
@ -44,6 +44,7 @@
+ kernel: + kernel:
- dissolve library/platform/native/
- profiler is inaccurate: wrong word on cs - profiler is inaccurate: wrong word on cs
- better i/o scheduler - better i/o scheduler
- >lower, >upper for strings - >lower, >upper for strings

View File

@ -27,9 +27,8 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package factor.jedit; package factor;
import factor.*;
import java.io.*; import java.io.*;
import java.net.Socket; import java.net.Socket;
import java.util.*; import java.util.*;
@ -91,6 +90,8 @@ public class ExternalFactor extends DefaultVocabularyLookup
*/ */
public synchronized String eval(String cmd) throws IOException public synchronized String eval(String cmd) throws IOException
{ {
/* Log.log(Log.DEBUG,ExternalFactor.class,"SEND: " + cmd); */
waitForAck(); waitForAck();
sendEval(cmd); sendEval(cmd);
@ -99,7 +100,9 @@ public class ExternalFactor extends DefaultVocabularyLookup
byte[] response = new byte[responseLength]; byte[] response = new byte[responseLength];
in.readFully(response); in.readFully(response);
return new String(response,"ASCII"); String responseStr = new String(response,"ASCII");
/* Log.log(Log.DEBUG,ExternalFactor.class,"RECV: " + responseStr); */
return responseStr;
} //}}} } //}}}
//{{{ openStream() method //{{{ openStream() method
@ -112,6 +115,35 @@ public class ExternalFactor extends DefaultVocabularyLookup
return new FactorStream(client); return new FactorStream(client);
} //}}} } //}}}
//{{{ searchVocabulary() method
/**
* Search through the given vocabulary list for the given word.
*/
public FactorWord searchVocabulary(Cons vocabulary, String name)
{
FactorWord w = super.searchVocabulary(vocabulary,name);
if(w != null)
return w;
try
{
Cons result = parseObject(eval(FactorReader.unparseObject(name)
+ " "
+ FactorReader.unparseObject(vocabulary)
+ " jedit-lookup ."));
if(result.car == null)
return null;
result = (Cons)result.car;
return new FactorWord((String)result.car,(String)result.next().car);
}
catch(Exception e)
{
Log.log(Log.ERROR,this,e);
return null;
}
} //}}}
//{{{ close() method //{{{ close() method
/** /**
* Close communication session. Factor will then exit. * Close communication session. Factor will then exit.

View File

@ -27,10 +27,8 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package factor.jedit; package factor;
import factor.Cons;
import factor.FactorReader;
import javax.swing.text.AttributeSet; import javax.swing.text.AttributeSet;
import java.io.*; import java.io.*;
import java.net.Socket; import java.net.Socket;
@ -132,30 +130,16 @@ public class FactorStream
//{{{ WritePacket class //{{{ WritePacket class
public static class WritePacket extends Packet public static class WritePacket extends Packet
{ {
public WritePacket(String input) public WritePacket(String text)
throws Exception throws Exception
{ {
FactorReader parser = new FactorReader( this.text = text;
"parseObject()",
new BufferedReader(new StringReader(input)),
true,FactorPlugin.getExternalInstance());
Cons pair = parser.parse();
this.write = (String)pair.car;
this.attrs = new ListenerAttributeSet((Cons)pair.next().car);
} }
public String getText() public String getText()
{ {
return write; return text;
} }
public AttributeSet getAttributes() private String text;
{
return attrs;
}
private String write;
private AttributeSet attrs;
} //}}} } //}}}
} }

View File

@ -32,7 +32,7 @@ package factor.jedit;
import console.*; import console.*;
import factor.*; import factor.*;
import javax.swing.text.AttributeSet; import javax.swing.text.AttributeSet;
import java.io.IOException; import java.io.*;
import java.util.Iterator; import java.util.Iterator;
import java.util.HashMap; import java.util.HashMap;
import org.gjt.sp.jedit.jEdit; import org.gjt.sp.jedit.jEdit;
@ -200,6 +200,19 @@ public class FactorShell extends Shell
stream = null; stream = null;
} }
private void handleWritePacket(FactorStream.WritePacket w, Output output)
throws Exception
{
Cons pair = FactorPlugin.getExternalInstance()
.parseObject(w.getText());
String write = (String)pair.car;
AttributeSet attrs = new ListenerAttributeSet(
(Cons)pair.next().car);
output.writeAttrs(attrs,write);
}
void packetLoop(Output output) throws Exception void packetLoop(Output output) throws Exception
{ {
if(waitingForInput) if(waitingForInput)
@ -216,11 +229,7 @@ public class FactorShell extends Shell
break; break;
} }
else if(p instanceof FactorStream.WritePacket) else if(p instanceof FactorStream.WritePacket)
{ handleWritePacket((FactorStream.WritePacket)p,output);
FactorStream.WritePacket w
= (FactorStream.WritePacket)p;
output.writeAttrs(w.getAttributes(),w.getText());
}
} }
} }

View File

@ -26,15 +26,17 @@
! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
IN: jedit IN: jedit
USE: stdio
USE: stack
USE: strings
USE: combinators USE: combinators
USE: parser USE: lists
USE: namespaces USE: namespaces
USE: parser
USE: presentation USE: presentation
USE: streams
USE: prettyprint USE: prettyprint
USE: stack
USE: stdio
USE: streams
USE: strings
USE: words
! Wire protocol for jEdit to evaluate Factor code. ! Wire protocol for jEdit to evaluate Factor code.
! Packets are of the form: ! Packets are of the form:
@ -101,3 +103,16 @@ USE: prettyprint
: stream-server ( -- ) : stream-server ( -- )
#! Execute this in the inferior Factor. #! Execute this in the inferior Factor.
"stdio" get <jedit-stream> "stdio" set ; "stdio" get <jedit-stream> "stdio" set ;
: jedit-lookup ( word vocabs -- )
#! A utility word called by the Factor plugin to get some
#! required word info.
search dup [
[
"vocabulary"
"name"
"stack-effect"
] [
dupd word-property
] map nip
] when ;