added support for new OOP features to Java parser

cvs
Slava Pestov 2004-12-06 00:42:55 +00:00
parent 088eb786c8
commit bd0b1c4f0d
18 changed files with 363 additions and 43 deletions

View File

@ -321,6 +321,3 @@ SYMBOL: event
] with-screen ;
factoroids
! Currently the plugin doesn't handle GENERIC: and M:, so we
! disable the parser. too many errors :sidekick.parser=factor:

View File

@ -113,6 +113,16 @@ public class DefaultVocabularyLookup implements VocabularyLookup
FactorWord pushWord = define("syntax","\\");
pushWord.parsing = new PushWord(pushWord);
/* OOP */
FactorWord generic = define("generic","GENERIC:");
generic.parsing = new Generic(generic);
FactorWord traits = define("generic","TRAITS:");
traits.parsing = new Traits(traits);
FactorWord beginMethod = define("generic","M:");
beginMethod.parsing = new BeginMethod(beginMethod);
FactorWord endMethod = define("generic",";M");
endMethod.parsing = new EndMethod(beginMethod,endMethod);
} //}}}
//{{{ getVocabulary() method

View File

@ -29,9 +29,6 @@
package factor;
import java.lang.reflect.*;
import java.util.*;
/**
* : name ... ;
*/

View File

@ -0,0 +1,45 @@
/* :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;
/**
* GENERIC: name
*/
public class FactorGenericDefinition extends FactorWordDefinition
{
//{{{ FactorGenericDefinition constructor
/**
* A new definition.
*/
public FactorGenericDefinition(FactorWord word)
{
super(word);
} //}}}
}

View File

@ -0,0 +1,52 @@
/* :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;
/**
* M: type generic ... ;M
*/
public class FactorMethodDefinition extends FactorWordDefinition
{
private FactorWord type;
private Cons def;
public FactorMethodDefinition(FactorWord type,
FactorWord generic, Cons def)
{
super(generic);
this.type = type;
this.def = def;
}
public Cons toList()
{
return def;
}
}

View File

@ -47,10 +47,4 @@ public class FactorSymbolDefinition extends FactorWordDefinition
super(word);
this.symbol = symbol;
} //}}}
//{{{ toList() method
public Cons toList()
{
return new Cons(symbol,null);
} //}}}
}

View File

@ -0,0 +1,41 @@
/* :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;
/**
* TRAITS: type
*/
public class FactorTraitsDefinition extends FactorSymbolDefinition
{
public FactorTraitsDefinition(FactorWord word)
{
super(word,word);
}
}

View File

@ -51,7 +51,7 @@ public abstract class FactorWordDefinition
//{{{ toList() method
public Cons toList()
{
return new Cons(new FactorWord(null,getClass().getName()),null);
return null;
} //}}}
//{{{ toString() method

View File

@ -13,6 +13,8 @@ plugin.factor.jedit.FactorPlugin.depend.3=plugin console.ConsolePlugin 4.0.2
#! Menu
plugin.factor.jedit.FactorPlugin.menu=factor-listener \
sidekick-tree \
sidekick-complete \
- \
factor-run-file \
factor-eval-selection \

View File

@ -210,14 +210,14 @@ public class FactorShell extends Shell
}
else
{
try
/* try
{
packetLoop(output);
}
catch(Exception e)
{
Log.log(Log.ERROR,this,e);
}
} */
}
}

View File

@ -51,19 +51,6 @@ public class FactorWordRenderer extends DefaultListCellRenderer
else if(def instanceof FactorSymbolDefinition)
{
prop = "factor.completion.symbol";
}
else
{
Cons d = def.toList();
if(d != null && d.car instanceof FactorDocComment)
{
FactorDocComment comment = (FactorDocComment)
d.car;
if(comment.isStackComment())
{
stackEffect = comment.toString();
}
}
} */
String in;

View File

@ -0,0 +1,54 @@
/* :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.parser;
import factor.*;
public class BeginMethod extends FactorParsingDefinition
{
public BeginMethod(FactorWord word)
{
super(word);
}
public void eval(FactorReader reader)
throws Exception
{
FactorWord type = reader.nextWord(true);
if(type == null)
return;
FactorWord generic = reader.nextWord(true);
if(generic == null)
return;
reader.pushExclusiveState(word,generic);
}
}

View File

@ -33,14 +33,10 @@ import factor.*;
public class Def extends FactorParsingDefinition
{
//{{{ Def constructor
/**
* A new definition.
*/
public Def(FactorWord word)
{
super(word);
} //}}}
}
public void eval(FactorReader reader)
throws Exception

View File

@ -0,0 +1,57 @@
/* :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.parser;
import factor.*;
public class EndMethod extends FactorParsingDefinition
{
public FactorWord start;
public EndMethod(FactorWord start, FactorWord end)
{
super(end);
this.start = start;
}
public void eval(FactorReader reader)
throws Exception
{
FactorReader.ParseState state = reader.popState(start,word);
FactorWord w = state.defining;
/* Only ever null with restartable scanner;
error already logged, so give up */
if(w == null)
return;
w.def = new FactorMethodDefinition(null,w,state.first);
reader.append(w.def);
}
}

View File

@ -0,0 +1,48 @@
/* :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.parser;
import factor.*;
public class Generic extends FactorParsingDefinition
{
public Generic(FactorWord word)
{
super(word);
}
public void eval(FactorReader reader)
throws Exception
{
FactorWord w = reader.nextWord(true);
w.def = new FactorGenericDefinition(w);
reader.append(w.def);
}
}

View File

@ -35,15 +35,11 @@ public class Ine extends FactorParsingDefinition
{
public FactorWord start;
//{{{ Ine constructor
/**
* A new definition.
*/
public Ine(FactorWord start, FactorWord end)
{
super(end);
this.start = start;
} //}}}
}
public void eval(FactorReader reader)
throws Exception

View File

@ -33,14 +33,10 @@ import factor.*;
public class Symbol extends FactorParsingDefinition
{
//{{{ Symbol constructor
/**
* A new definition.
*/
public Symbol(FactorWord word)
{
super(word);
} //}}}
}
public void eval(FactorReader reader)
throws Exception

48
factor/parser/Traits.java Normal file
View File

@ -0,0 +1,48 @@
/* :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.parser;
import factor.*;
public class Traits extends FactorParsingDefinition
{
public Traits(FactorWord word)
{
super(word);
}
public void eval(FactorReader reader)
throws Exception
{
FactorWord w = reader.nextWord(true);
w.def = new FactorTraitsDefinition(w);
reader.append(w.def);
}
}