From bd0b1c4f0daff5879f29486b23058e9dd69f1f39 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Mon, 6 Dec 2004 00:42:55 +0000 Subject: [PATCH] added support for new OOP features to Java parser --- examples/factoroids.factor | 3 -- factor/DefaultVocabularyLookup.java | 10 +++++ factor/FactorCompoundDefinition.java | 3 -- factor/FactorGenericDefinition.java | 45 ++++++++++++++++++++++ factor/FactorMethodDefinition.java | 52 +++++++++++++++++++++++++ factor/FactorSymbolDefinition.java | 6 --- factor/FactorTraitsDefinition.java | 41 ++++++++++++++++++++ factor/FactorWordDefinition.java | 2 +- factor/jedit/FactorPlugin.props | 2 + factor/jedit/FactorShell.java | 4 +- factor/jedit/FactorWordRenderer.java | 13 ------- factor/parser/BeginMethod.java | 54 ++++++++++++++++++++++++++ factor/parser/Def.java | 6 +-- factor/parser/EndMethod.java | 57 ++++++++++++++++++++++++++++ factor/parser/Generic.java | 48 +++++++++++++++++++++++ factor/parser/Ine.java | 6 +-- factor/parser/Symbol.java | 6 +-- factor/parser/Traits.java | 48 +++++++++++++++++++++++ 18 files changed, 363 insertions(+), 43 deletions(-) create mode 100644 factor/FactorGenericDefinition.java create mode 100644 factor/FactorMethodDefinition.java create mode 100644 factor/FactorTraitsDefinition.java create mode 100644 factor/parser/BeginMethod.java create mode 100644 factor/parser/EndMethod.java create mode 100644 factor/parser/Generic.java create mode 100644 factor/parser/Traits.java diff --git a/examples/factoroids.factor b/examples/factoroids.factor index c2bdb78096..d743ebd836 100644 --- a/examples/factoroids.factor +++ b/examples/factoroids.factor @@ -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: diff --git a/factor/DefaultVocabularyLookup.java b/factor/DefaultVocabularyLookup.java index 3821b54978..988a624df9 100644 --- a/factor/DefaultVocabularyLookup.java +++ b/factor/DefaultVocabularyLookup.java @@ -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 diff --git a/factor/FactorCompoundDefinition.java b/factor/FactorCompoundDefinition.java index 8720258799..4f6174b833 100644 --- a/factor/FactorCompoundDefinition.java +++ b/factor/FactorCompoundDefinition.java @@ -29,9 +29,6 @@ package factor; -import java.lang.reflect.*; -import java.util.*; - /** * : name ... ; */ diff --git a/factor/FactorGenericDefinition.java b/factor/FactorGenericDefinition.java new file mode 100644 index 0000000000..0794778036 --- /dev/null +++ b/factor/FactorGenericDefinition.java @@ -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); + } //}}} +} diff --git a/factor/FactorMethodDefinition.java b/factor/FactorMethodDefinition.java new file mode 100644 index 0000000000..440b03416e --- /dev/null +++ b/factor/FactorMethodDefinition.java @@ -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; + } +} diff --git a/factor/FactorSymbolDefinition.java b/factor/FactorSymbolDefinition.java index d2a80dc321..db9d09f341 100644 --- a/factor/FactorSymbolDefinition.java +++ b/factor/FactorSymbolDefinition.java @@ -47,10 +47,4 @@ public class FactorSymbolDefinition extends FactorWordDefinition super(word); this.symbol = symbol; } //}}} - - //{{{ toList() method - public Cons toList() - { - return new Cons(symbol,null); - } //}}} } diff --git a/factor/FactorTraitsDefinition.java b/factor/FactorTraitsDefinition.java new file mode 100644 index 0000000000..3fdbf43bc5 --- /dev/null +++ b/factor/FactorTraitsDefinition.java @@ -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); + } +} diff --git a/factor/FactorWordDefinition.java b/factor/FactorWordDefinition.java index 1366c78014..2c4ee3f155 100644 --- a/factor/FactorWordDefinition.java +++ b/factor/FactorWordDefinition.java @@ -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 diff --git a/factor/jedit/FactorPlugin.props b/factor/jedit/FactorPlugin.props index 6da6a4908b..2a35e84023 100644 --- a/factor/jedit/FactorPlugin.props +++ b/factor/jedit/FactorPlugin.props @@ -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 \ diff --git a/factor/jedit/FactorShell.java b/factor/jedit/FactorShell.java index 6b1de96b2a..31d5bd345b 100644 --- a/factor/jedit/FactorShell.java +++ b/factor/jedit/FactorShell.java @@ -210,14 +210,14 @@ public class FactorShell extends Shell } else { - try + /* try { packetLoop(output); } catch(Exception e) { Log.log(Log.ERROR,this,e); - } + } */ } } diff --git a/factor/jedit/FactorWordRenderer.java b/factor/jedit/FactorWordRenderer.java index 2b1a68a5b8..08a6fefaf6 100644 --- a/factor/jedit/FactorWordRenderer.java +++ b/factor/jedit/FactorWordRenderer.java @@ -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; diff --git a/factor/parser/BeginMethod.java b/factor/parser/BeginMethod.java new file mode 100644 index 0000000000..9271e913b8 --- /dev/null +++ b/factor/parser/BeginMethod.java @@ -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); + } +} diff --git a/factor/parser/Def.java b/factor/parser/Def.java index b80d0b574d..e71a1be04e 100644 --- a/factor/parser/Def.java +++ b/factor/parser/Def.java @@ -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 diff --git a/factor/parser/EndMethod.java b/factor/parser/EndMethod.java new file mode 100644 index 0000000000..763db97713 --- /dev/null +++ b/factor/parser/EndMethod.java @@ -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); + } +} diff --git a/factor/parser/Generic.java b/factor/parser/Generic.java new file mode 100644 index 0000000000..6886b9675a --- /dev/null +++ b/factor/parser/Generic.java @@ -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); + } +} diff --git a/factor/parser/Ine.java b/factor/parser/Ine.java index 28dc939656..24c6500549 100644 --- a/factor/parser/Ine.java +++ b/factor/parser/Ine.java @@ -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 diff --git a/factor/parser/Symbol.java b/factor/parser/Symbol.java index 3e6198a1d8..000d290106 100644 --- a/factor/parser/Symbol.java +++ b/factor/parser/Symbol.java @@ -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 diff --git a/factor/parser/Traits.java b/factor/parser/Traits.java new file mode 100644 index 0000000000..2bb7286cd3 --- /dev/null +++ b/factor/parser/Traits.java @@ -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); + } +}