+ listener/plugin:\r
\r
- faster completion\r
-- word added >1 if external instance dies\r
- sidekick: still parsing too much\r
- errors don't always disappear\r
-- console: wrong history\r
-- listener: if too many things popped off the stack, complain\r
- NPE in ErrorHighlight\r
-- some way to not have previous definitions from a source file\r
- clutter the namespace\r
- maple-like: press enter at old commands to evaluate there\r
- completion in the listener\r
- special completion for USE:/IN:\r
}
} //}}}
+ //{{{ forget() method
+ public void forget(FactorWord word)
+ {
+ Map vocab = (Map)vocabularies.get(word.vocabulary);
+ if(vocab != null)
+ vocab.remove(word.name);
+ } //}}}
+
//{{{ getVocabularies() method
public Cons getVocabularies()
{
public synchronized FactorWord searchVocabulary(Cons vocabulary, String name)
{
FactorWord w = super.searchVocabulary(vocabulary,name);
+
if(w != null)
return w;
+ if(closed)
+ return define("#<unknown>",name);
+
try
{
- if(!closed)
- {
- Cons result = parseObject(eval(FactorReader.unparseObject(name)
- + " "
- + FactorReader.unparseObject(vocabulary)
- + " jedit-lookup ."));
- if(result.car == null)
- return null;
-
- result = (Cons)result.car;
- w = new FactorWord(
- (String)result.car,
- (String)result.next().car);
- w.stackEffect = (String)result.next().next().car;
- return w;
- }
+ Cons result = parseObject(eval(FactorReader.unparseObject(name)
+ + " "
+ + FactorReader.unparseObject(vocabulary)
+ + " jedit-lookup ."));
+ if(result.car == null)
+ return null;
+
+ result = (Cons)result.car;
+ w = new FactorWord(
+ (String)result.car,
+ (String)result.next().car);
+ w.stackEffect = (String)result.next().next().car;
+ return w;
}
catch(Exception e)
{
Log.log(Log.ERROR,this,e);
+ return null;
}
-
- return new FactorWord("unknown",name);
} //}}}
//{{{ getCompletions() method
{
public FactorWord define(String in, String word)
throws Exception;
+
public FactorWord searchVocabulary(Cons use, String word)
throws Exception;
+ public void forget(FactorWord word);
+
/**
* @param vocab The vocabulary name
* @param word A substring of the word name to complete
public FactorSideKickParser parser;
public String in;
public Cons use;
-
+
FactorParsedData(FactorSideKickParser parser, String fileName)
{
super(fileName);
public class FactorSideKickParser extends SideKickParser
{
- private Map previewMap;
-
/**
- * When we parse a file, we store the <word,worddef> pairs in this
- * map, so that completion popups show the latest stack effects,
- * and not whatever they were the last time the source was run-file'd.
+ * We store the file's parse tree in this property.
*/
- private Map worddefs;
+ public static String PARSED_PROPERTY = "factor-parsed";
+
+ private Map previewMap;
//{{{ FactorSideKickParser constructor
public FactorSideKickParser()
public SideKickParsedData parse(Buffer buffer,
DefaultErrorSource errorSource)
{
+ Cons parsed = (Cons)buffer.getProperty(PARSED_PROPERTY);
+ removeWordDefinitions(parsed);
+
FactorParsedData d = new FactorParsedData(
this,buffer.getPath());
errorSource);
FactorReader r = new FactorReader(scanner,
false,FactorPlugin.getExternalInstance());
-
- Cons parsed = r.parse();
-
+
+ parsed = r.parse();
+
d.in = r.getIn();
d.use = r.getUse();
+ buffer.setProperty(PARSED_PROPERTY,parsed);
+
addWordDefNodes(d,parsed,buffer);
}
catch(FactorParseException pe)
return d;
} //}}}
+ //{{{ removeWordDefinitions() method
+ private void removeWordDefinitions(Cons parsed)
+ {
+ while(parsed != null)
+ {
+ Object obj = parsed.car;
+ if(obj instanceof FactorWordDefinition)
+ {
+ FactorPlugin.getExternalInstance().forget(
+ ((FactorWordDefinition)obj).word);
+ }
+ parsed = parsed.next();
+ }
+ } //}}}
+
//{{{ addWordDefNodes() method
- private void addWordDefNodes(SideKickParsedData d, Cons parsed,
- Buffer buffer)
+ private void addWordDefNodes(FactorParsedData d, Cons parsed, Buffer buffer)
{
FactorAsset last = null;
int startLine = Math.min(
buffer.getLineCount() - 1,
word.line - 1);
- int startLineLength = buffer.getLineLength(
- startLine);
- int startCol = Math.min(word.col,
- startLineLength);
+ int startLineLength = buffer.getLineLength(startLine);
+ int startCol = Math.min(word.col,startLineLength);
int start = buffer.getLineStartOffset(startLine)
+ startCol;
! A simple single-dispatch generic word system.
+! "if I say I'd rather eat cheese than shit... doesn't mean
+! those are the only two things I can eat." - Tac
+
: predicate-word ( word -- word )
word-name "?" cat2 "in" get create ;
USE: math
USE: math-internals
-: >rect ( x -- xr xi ) dup real swap imaginary ;
+: >rect ( x -- xr xi ) dup real swap imaginary ; inline
: conjugate ( z -- z* )
>rect neg rect> ;
: 2>rect ( x y -- xr yr xi yi )
[ swap real swap real ] 2keep
- swap imaginary swap imaginary ;
+ swap imaginary swap imaginary ; inline
M: complex number= ( x y -- ? )
2>rect number= [ number= ] [ 2drop f ] ifte ;
: (read-multiline) ( quot depth -- quot ? )
#! Flag indicates EOF.
>r read dup [
- (parse) depth r> dup >r = [
+ (parse) depth r> dup >r <= [
( we're done ) r> drop t
] [
( more input needed ) r> cont-prompt get prompt.