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

View File

@ -27,9 +27,8 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package factor.jedit;
package factor;
import factor.*;
import java.io.*;
import java.net.Socket;
import java.util.*;
@ -91,6 +90,8 @@ public class ExternalFactor extends DefaultVocabularyLookup
*/
public synchronized String eval(String cmd) throws IOException
{
/* Log.log(Log.DEBUG,ExternalFactor.class,"SEND: " + cmd); */
waitForAck();
sendEval(cmd);
@ -99,7 +100,9 @@ public class ExternalFactor extends DefaultVocabularyLookup
byte[] response = new byte[responseLength];
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
@ -112,6 +115,35 @@ public class ExternalFactor extends DefaultVocabularyLookup
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 communication session. Factor will then exit.

View File

@ -27,10 +27,8 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package factor.jedit;
package factor;
import factor.Cons;
import factor.FactorReader;
import javax.swing.text.AttributeSet;
import java.io.*;
import java.net.Socket;
@ -132,30 +130,16 @@ public class FactorStream
//{{{ WritePacket class
public static class WritePacket extends Packet
{
public WritePacket(String input)
public WritePacket(String text)
throws Exception
{
FactorReader parser = new FactorReader(
"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);
this.text = text;
}
public String getText()
{
return write;
return text;
}
public AttributeSet getAttributes()
{
return attrs;
}
private String write;
private AttributeSet attrs;
private String text;
} //}}}
}

View File

@ -32,7 +32,7 @@ package factor.jedit;
import console.*;
import factor.*;
import javax.swing.text.AttributeSet;
import java.io.IOException;
import java.io.*;
import java.util.Iterator;
import java.util.HashMap;
import org.gjt.sp.jedit.jEdit;
@ -200,6 +200,19 @@ public class FactorShell extends Shell
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
{
if(waitingForInput)
@ -216,11 +229,7 @@ public class FactorShell extends Shell
break;
}
else if(p instanceof FactorStream.WritePacket)
{
FactorStream.WritePacket w
= (FactorStream.WritePacket)p;
output.writeAttrs(w.getAttributes(),w.getText());
}
handleWritePacket((FactorStream.WritePacket)p,output);
}
}

View File

@ -26,15 +26,17 @@
! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
IN: jedit
USE: stdio
USE: stack
USE: strings
USE: combinators
USE: parser
USE: lists
USE: namespaces
USE: parser
USE: presentation
USE: streams
USE: prettyprint
USE: stack
USE: stdio
USE: streams
USE: strings
USE: words
! Wire protocol for jEdit to evaluate Factor code.
! Packets are of the form:
@ -101,3 +103,16 @@ USE: prettyprint
: stream-server ( -- )
#! Execute this in the inferior Factor.
"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 ;