diff --git a/actions.xml b/actions.xml
index a75b0cc602..1318361fdc 100644
--- a/actions.xml
+++ b/actions.xml
@@ -21,4 +21,15 @@
+ "\" run-file");
+
+
+ if(textArea.selectionCount == 0)
+ textArea.selectWord();
+ factor.jedit.FactorPlugin.eval(view,
+ "\""
+ + MiscUtilities.charsToEscapes(
+ textArea.selectedText)
+ + "\" apropos.");
+
+
diff --git a/build.xml b/build.xml
index 84489b8cf5..2d1ad52c37 100644
--- a/build.xml
+++ b/build.xml
@@ -6,7 +6,7 @@
-
+
-
+
+
+
+
+
+
+
-
+ srcdir=".">
+
+
new factor.listener.FactorListenerPanel(
- factor.jedit.FactorPlugin.getInterpreter(view));
+ factor.jedit.FactorPlugin.getInterpreter());
diff --git a/factor/FactorParseException.java b/factor/FactorParseException.java
index 6c19b7b0a8..3d3aed754e 100644
--- a/factor/FactorParseException.java
+++ b/factor/FactorParseException.java
@@ -31,12 +31,20 @@ package factor;
public class FactorParseException extends FactorException
{
+ private String filename;
+ private int lineno;
+ private int position;
+ private String msg;
+
public FactorParseException(
String filename,
int lineno,
String str)
{
super(filename + ":" + lineno + ": " + str);
+ this.filename = filename;
+ this.lineno = lineno;
+ this.msg = str;
}
public FactorParseException(
@@ -48,6 +56,30 @@ public class FactorParseException extends FactorException
{
super(filename + ":" + lineno + ": " + str
+ "\n" + getDetailMessage(line,position));
+ this.filename = filename;
+ this.lineno = lineno;
+ this.position = position;
+ this.msg = str;
+ }
+
+ public String getFileName()
+ {
+ return filename;
+ }
+
+ public int getLineNumber()
+ {
+ return lineno;
+ }
+
+ public int getPosition()
+ {
+ return position;
+ }
+
+ public String getMessage()
+ {
+ return msg;
}
private static String getDetailMessage(String line, int position)
diff --git a/factor/FactorScanner.java b/factor/FactorScanner.java
index a96a4b5312..480ed88690 100644
--- a/factor/FactorScanner.java
+++ b/factor/FactorScanner.java
@@ -93,6 +93,12 @@ public class FactorScanner
return lineNo;
} //}}}
+ //{{{ getColumnNumber() method
+ public int getColumnNumber()
+ {
+ return position;
+ } //}}}
+
//{{{ getFileName() method
public String getFileName()
{
diff --git a/factor/FactorWord.java b/factor/FactorWord.java
index 2c814e2c43..326e3fc94f 100644
--- a/factor/FactorWord.java
+++ b/factor/FactorWord.java
@@ -78,6 +78,7 @@ public class FactorWord implements FactorExternalizable, FactorObject
*/
public String file;
public int line;
+ public int col;
private FactorNamespace namespace;
diff --git a/factor/FactorWordDefinition.java b/factor/FactorWordDefinition.java
index d780eb596e..2020f032ed 100644
--- a/factor/FactorWordDefinition.java
+++ b/factor/FactorWordDefinition.java
@@ -39,8 +39,7 @@ import org.objectweb.asm.*;
*/
public abstract class FactorWordDefinition implements Constants
{
- protected FactorWord word;
-
+ public FactorWord word;
public boolean compileFailed;
//{{{ FactorWordDefinition constructor
@@ -55,12 +54,6 @@ public abstract class FactorWordDefinition implements Constants
public abstract void eval(FactorInterpreter interp)
throws Exception;
- //{{{ getWord() method
- public FactorWord getWord(FactorInterpreter interp)
- {
- return word;
- } //}}}
-
//{{{ fromList() method
public void fromList(Cons cons, FactorInterpreter interp)
throws FactorRuntimeException
diff --git a/factor/jedit/FactorAsset.java b/factor/jedit/FactorAsset.java
new file mode 100644
index 0000000000..d594b90979
--- /dev/null
+++ b/factor/jedit/FactorAsset.java
@@ -0,0 +1,59 @@
+/* :folding=explicit:collapseFolds=1: */
+
+/*
+ * $Id$
+ *
+ * Copyright (C) 2004 Slava Pestov.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * DEVELOPERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package factor.jedit;
+
+import javax.swing.Icon;
+import javax.swing.text.Position;
+import org.gjt.sp.jedit.Buffer;
+import sidekick.*;
+
+public class FactorAsset extends Asset
+{
+ public FactorAsset(String name, Position start)
+ {
+ super(name);
+ this.start = start;
+ }
+
+ public Icon getIcon()
+ {
+ return null;
+ }
+
+ public String getShortString()
+ {
+ return name;
+ }
+
+ public String getLongString()
+ {
+ return name;
+ }
+}
diff --git a/factor/jedit/FactorPlugin.java b/factor/jedit/FactorPlugin.java
index 304dfe7da4..f05085b467 100644
--- a/factor/jedit/FactorPlugin.java
+++ b/factor/jedit/FactorPlugin.java
@@ -33,13 +33,12 @@ import factor.listener.FactorListenerPanel;
import factor.FactorInterpreter;
import org.gjt.sp.jedit.gui.*;
import org.gjt.sp.jedit.*;
-import java.util.WeakHashMap;
public class FactorPlugin extends EditPlugin
{
private static final String DOCKABLE_NAME = "factor";
- private static WeakHashMap views = new WeakHashMap();
+ private static FactorInterpreter interp;
//{{{ start() method
public void start()
@@ -48,16 +47,17 @@ public class FactorPlugin extends EditPlugin
} //}}}
//{{{ getInterpreter() method
- public static FactorInterpreter getInterpreter(View view)
+ /**
+ * This can be called from the SideKick thread and must be thread safe.
+ */
+ public static synchronized FactorInterpreter getInterpreter()
{
- FactorInterpreter interp = (FactorInterpreter)
- views.get(view);
if(interp == null)
{
interp = FactorListenerPanel.newInterpreter(
new String[] { "-jedit" });
- views.put(view,interp);
}
+
return interp;
} //}}}
diff --git a/factor/jedit/FactorPlugin.props b/factor/jedit/FactorPlugin.props
index cd17135389..a625e417bd 100644
--- a/factor/jedit/FactorPlugin.props
+++ b/factor/jedit/FactorPlugin.props
@@ -8,14 +8,21 @@ plugin.factor.jedit.FactorPlugin.author=Slava Pestov
plugin.factor.jedit.FactorPlugin.docs=index.html
plugin.factor.jedit.FactorPlugin.depend.0=jedit 04.02.15.00
+plugin.factor.jedit.FactorPlugin.depend.1=plugin errorlist.ErrorListPlugin 1.3.2
+plugin.factor.jedit.FactorPlugin.depend.2=plugin sidekick.SideKickPlugin 0.3
plugin.factor.jedit.FactorPlugin.menu=factor \
- \
factor-run-file \
- factor-eval-selection
+ factor-eval-selection \
+ factor-apropos
factor.label=Factor Listener
factor-run-file.label=Run Current File
factor-eval-selection.label=Evaluate Selection
+factor-apropos.label=Apropos
factor.title=Factor
+
+sidekick.parser.factor.label=Factor
+mode.factor.sidekick.parser=factor
diff --git a/factor/jedit/FactorSideKickParser.java b/factor/jedit/FactorSideKickParser.java
new file mode 100644
index 0000000000..de350f5cf3
--- /dev/null
+++ b/factor/jedit/FactorSideKickParser.java
@@ -0,0 +1,141 @@
+/* :folding=explicit:collapseFolds=1: */
+
+/*
+ * $Id$
+ *
+ * Copyright (C) 2004 Slava Pestov.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * DEVELOPERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package factor.jedit;
+
+import errorlist.*;
+import factor.*;
+import java.io.*;
+import javax.swing.tree.DefaultMutableTreeNode;
+import org.gjt.sp.jedit.Buffer;
+import org.gjt.sp.util.Log;
+import sidekick.*;
+
+public class FactorSideKickParser extends SideKickParser
+{
+ //{{{ FactorSideKickParser constructor
+ public FactorSideKickParser()
+ {
+ super("factor");
+ } //}}}
+
+ //{{{ parse() method
+ /**
+ * Parses the given text and returns a tree model.
+ *
+ * @param buffer The buffer to parse.
+ * @param errorSource An error source to add errors to.
+ *
+ * @return A new instance of the SideKickParsedData
class.
+ */
+ public SideKickParsedData parse(Buffer buffer,
+ DefaultErrorSource errorSource)
+ {
+ SideKickParsedData d = new SideKickParsedData(buffer.getPath());
+
+ FactorInterpreter interp = FactorPlugin.getInterpreter();
+
+ String text;
+
+ try
+ {
+ buffer.readLock();
+
+ text = buffer.getText(0,buffer.getLength());
+
+ /* of course wrapping a string reader in a buffered
+ reader is dumb, but the FactorReader uses readLine() */
+ FactorReader r = new FactorReader(buffer.getPath(),
+ new BufferedReader(new StringReader(text)),
+ interp);
+ Cons parsed = r.parse();
+
+ addWordDefNodes(d,parsed,buffer);
+ }
+ catch(FactorParseException pe)
+ {
+ errorSource.addError(ErrorSource.ERROR,pe.getFileName(),
+ /* Factor line #'s are 1-indexed */
+ pe.getLineNumber() - 1,0,0,pe.getMessage());
+ }
+ catch(Exception e)
+ {
+ errorSource.addError(ErrorSource.ERROR,
+ buffer.getPath(),
+ 0,0,0,e.toString());
+ Log.log(Log.DEBUG,this,e);
+ }
+ finally
+ {
+ buffer.readUnlock();
+ }
+
+ return d;
+ } //}}}
+
+ //{{{ addWordDefNodes() method
+ private void addWordDefNodes(SideKickParsedData d, Cons parsed,
+ Buffer buffer)
+ {
+ FactorAsset last = null;
+
+ while(parsed != null)
+ {
+ if(parsed.car instanceof FactorWordDefinition)
+ {
+ FactorWordDefinition def
+ = (FactorWordDefinition)
+ parsed.car;
+
+ FactorWord word = def.word;
+
+ /* word lines are indexed from 1 */
+ int startLine = Math.min(
+ buffer.getLineCount() - 1,
+ word.line - 1);
+ int startLineLength = buffer.getLineLength(
+ startLine);
+ int startCol = Math.min(word.col,
+ startLineLength);
+
+ int start = buffer.getLineStartOffset(startLine)
+ + startCol;
+
+ if(last != null)
+ last.end = buffer.createPosition(start - 1);
+
+ last = new FactorAsset(word.name,
+ buffer.createPosition(start));
+ d.root.add(new DefaultMutableTreeNode(last));
+ }
+
+ parsed = parsed.next();
+ }
+ } //}}}
+}
diff --git a/factor/parser/Def.java b/factor/parser/Def.java
index d7b0e3d0db..c17b2140ec 100644
--- a/factor/parser/Def.java
+++ b/factor/parser/Def.java
@@ -46,10 +46,18 @@ public class Def extends FactorParsingDefinition
public void eval(FactorInterpreter interp, FactorReader reader)
throws Exception
{
+ FactorScanner scanner = reader.getScanner();
+
+ // remember the position before the word name
+ int line = scanner.getLineNumber();
+ int col = scanner.getColumnNumber();
+
// Read the word name
FactorWord newWord = reader.nextWord(true);
- newWord.line = reader.getScanner().getLineNumber();
- newWord.file = reader.getScanner().getFileName();
+
+ newWord.line = line;
+ newWord.col = col;
+ newWord.file = scanner.getFileName();
reader.pushExclusiveState(word,newWord);
}
}
diff --git a/services.xml b/services.xml
new file mode 100644
index 0000000000..a5b455a981
--- /dev/null
+++ b/services.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+ new factor.jedit.FactorSideKickParser();
+
+