started sidekick support in jEdit plugin
parent
9f052b3c82
commit
a01fa83bf3
11
actions.xml
11
actions.xml
|
@ -21,4 +21,15 @@
|
|||
+ "\" run-file");
|
||||
</CODE>
|
||||
</ACTION>
|
||||
<ACTION NAME="factor-apropos">
|
||||
<CODE>
|
||||
if(textArea.selectionCount == 0)
|
||||
textArea.selectWord();
|
||||
factor.jedit.FactorPlugin.eval(view,
|
||||
"\""
|
||||
+ MiscUtilities.charsToEscapes(
|
||||
textArea.selectedText)
|
||||
+ "\" apropos.");
|
||||
</CODE>
|
||||
</ACTION>
|
||||
</ACTIONS>
|
||||
|
|
22
build.xml
22
build.xml
|
@ -6,7 +6,7 @@
|
|||
<available property="jedit" classname="org.gjt.sp.jedit.jEdit" />
|
||||
</target>
|
||||
|
||||
<target name="compile">
|
||||
<target name="compile" depends="init">
|
||||
<javac
|
||||
srcdir="."
|
||||
destdir="."
|
||||
|
@ -19,18 +19,24 @@
|
|||
<exclude name="factor/jedit/*.java"/>
|
||||
</javac>
|
||||
</target>
|
||||
<target name="compile-jedit" if="jedit">
|
||||
|
||||
<path id="jedit-classpath">
|
||||
<pathelement location="${user.home}/.jedit/jars/ErrorList.jar" />
|
||||
<pathelement location="${user.home}/.jedit/jars/SideKick.jar" />
|
||||
</path>
|
||||
|
||||
<target name="compile-jedit" depends="init" if="jedit">
|
||||
<javac
|
||||
srcdir="."
|
||||
destdir="."
|
||||
deprecation="on"
|
||||
includeJavaRuntime="yes"
|
||||
classpathref="jedit-classpath"
|
||||
debug="true"
|
||||
deprecation="on"
|
||||
destdir="."
|
||||
optimize="true"
|
||||
>
|
||||
<include name="factor/jedit/*.java"/>
|
||||
srcdir=".">
|
||||
<include name="factor/jedit/*.java"/>
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
<target name="dist" depends="compile,compile-jedit">
|
||||
<jar
|
||||
jarfile="Factor.jar"
|
||||
|
|
|
@ -7,6 +7,6 @@
|
|||
<DOCKABLES>
|
||||
<DOCKABLE NAME="factor">
|
||||
new factor.listener.FactorListenerPanel(
|
||||
factor.jedit.FactorPlugin.getInterpreter(view));
|
||||
factor.jedit.FactorPlugin.getInterpreter());
|
||||
</DOCKABLE>
|
||||
</DOCKABLES>
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -93,6 +93,12 @@ public class FactorScanner
|
|||
return lineNo;
|
||||
} //}}}
|
||||
|
||||
//{{{ getColumnNumber() method
|
||||
public int getColumnNumber()
|
||||
{
|
||||
return position;
|
||||
} //}}}
|
||||
|
||||
//{{{ getFileName() method
|
||||
public String getFileName()
|
||||
{
|
||||
|
|
|
@ -78,6 +78,7 @@ public class FactorWord implements FactorExternalizable, FactorObject
|
|||
*/
|
||||
public String file;
|
||||
public int line;
|
||||
public int col;
|
||||
|
||||
private FactorNamespace namespace;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
} //}}}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 <code>SideKickParsedData</code> 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();
|
||||
}
|
||||
} //}}}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0"?>
|
||||
|
||||
<!DOCTYPE SERVICES SYSTEM "services.dtd">
|
||||
|
||||
<SERVICES>
|
||||
<SERVICE CLASS="sidekick.SideKickParser" NAME="factor">
|
||||
new factor.jedit.FactorSideKickParser();
|
||||
</SERVICE>
|
||||
</SERVICES>
|
Loading…
Reference in New Issue