[e-cvs] cvs commit: e/src/jsrc/org/quasiliteral/term Converter.java Functor.java SimpleTermBuilder.java Term.java TermBuilder.java TermParser.java ToFunctor.java ToLiteral.java ToTerm.java ToTermList.java

markm@eros.cs.jhu.edu markm@eros.cs.jhu.edu
Fri, 30 Nov 2001 22:44:02 -0500


markm       01/11/30 22:44:02

  Modified:    src/jsrc/org/quasiliteral/term Converter.java Functor.java
                        SimpleTermBuilder.java Term.java TermBuilder.java
                        TermParser.java
  Removed:     src/jsrc/org/quasiliteral/term ToFunctor.java ToLiteral.java
                        ToTerm.java ToTermList.java
  Log:
  intermediate, non-working state

Revision  Changes    Path
1.3       +2 -1      e/src/jsrc/org/quasiliteral/term/Converter.java

Index: Converter.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/quasiliteral/term/Converter.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Converter.java	2001/11/21 14:21:32	1.2
+++ Converter.java	2001/12/01 03:44:02	1.3
@@ -7,6 +7,7 @@
 import org.erights.e.elib.tables.Twine;
 import org.erights.e.elib.base.ClassDesc;
 import org.erights.e.elib.prim.E;
+import org.quasiliteral.astro.TreeBuilder;
 
 /**
  * Coerces input to some type needed in a Term/Functor tree.
@@ -80,5 +81,5 @@
      * to build from that the kind of hole that would be parameterized by
      * this converter.
      */
-    public abstract Object qbuild(TermBuilder builder, Object litHole);
+    public abstract Object qbuild(TreeBuilder builder, Object litHole);
 }



1.12      +69 -82    e/src/jsrc/org/quasiliteral/term/Functor.java

Index: Functor.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/quasiliteral/term/Functor.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- Functor.java	2001/11/27 07:27:54	1.11
+++ Functor.java	2001/12/01 03:44:02	1.12
@@ -2,7 +2,6 @@
 
 import antlr.Token;
 import org.erights.e.develop.format.StringHelper;
-import org.erights.e.elib.base.EComparable;
 import org.erights.e.elib.base.SourceSpan;
 import org.erights.e.elib.base.ClassDesc;
 import org.erights.e.elib.prim.E;
@@ -17,6 +16,8 @@
 import org.erights.e.elib.ref.Ref;
 import org.quasiliteral.astro.AstroToken;
 import org.quasiliteral.astro.AstroTag;
+import org.quasiliteral.astro.AstroSchema;
+import org.quasiliteral.astro.TreeBuilder;
 
 import java.math.BigInteger;
 
@@ -44,7 +45,7 @@
  * @author Many thanks also to Dean Tribble
  */
 public class Functor
-  implements EComparable, Selfless, PassByConstruction, Persistent {
+  implements Selfless, PassByConstruction, Persistent {
 
     /**
      *
@@ -64,13 +65,12 @@
 
     /**
      * @serial null, {@link Character}, {@link BigInteger}, {@link Double},
-     * or {@link Twine} calculated from lexing the token
+     * or {@link Twine}, presumably calculated from lexing the token
      */
-    private final Object myOptValue;
+    private final Object myOptData;
 
     /**
-     * A Functor that represents a token other than literal data in a
-     * particular grammar.
+     * Makes a Functor that represents a Token of some grammar.
      *
      * @param tag Represents a token type in a particular grammar.
      * @param source The source text corresponding to the original source of
@@ -79,35 +79,21 @@
      *               information says what positions in the original source
      *               it corresponds to. This is not part of the normal
      *               printed form.
+     * @param optData null,
+     *                or a {@link Character},
+     *                or a {@link BigInteger},
+     *                or a {@link Double},
+     *                or a {@link Twine}
+     *                If non-null, the data as a literal is the printed form.
      */
-    public Functor(AstroTag tag, Twine source) {
+    public Functor(AstroTag tag, Twine source, Object optData) {
         myTag = tag;
         mySource = source;
-    }
-
-    /**
-     * A Functor that represents literal data in a particular grammar.
-     *
-     * @param tag Represents a token type in a particular grammar.
-     * @param source The source text corresponding to the original source of
-     *               the token, although it isn't necessarily the same as the
-     *               original source text.  In any case, its source span
-     *               information says what positions in the original source
-     *               it corresponds to. This is not part of the normal
-     *               printed form.
-     * @param value {@link Character},
-     *                 {@link BigInteger} or other integral {@link Number}s,
-     *                 {@link Double} or {@link Float}, or
-     *                 {@link Twine} or {@link String}
-     *                 If non-null, is always part of the normal printed
-     *                 form.
-     */
-    public Functor(AstroTag tag, Twine source, Object value) {
-        myTag = tag;
-        mySource = source;
-        myOptValue = value;
-        E.require(Ref.same(tag.getSchema().getOptLiteralDataTag(value),
-                           tag));
+        myOptData = optData;
+        if (null != optData) {
+            E.require(Ref.same(tag.getOptSchema().getOptLiteralDataTag(optData),
+                               tag));
+        }
     }
 
     /**
@@ -116,7 +102,7 @@
      * This should be compatible with Antlr code that just assumes a Token.
      */
     public Token asToken(ConstMap typeNums) {
-        return myTag.getSchema().tokenFromFunctor(this);
+        return myTag.getOptSchema().tokenFromFunctor(this);
     }
 
     /**
@@ -126,25 +112,26 @@
      * SimpleTermBuilder, this should make a semantically equivalent copy
      * of this Functor.
      */
-    public Object build(TermBuilder builder) {
-        if (null == myOptValue) {
-            return builder.functor(new AstroToken(TermParser.ID,
-                                                  mySource,
-                                                  myTag),
-                                   null);
-        } else if (isLiteral()) {
-            return builder.functor(null,
-                                   new AstroToken(myValueType,
-                                                  mySource,
-                                                  myOptValue));
-        } else {
-            return builder.functor(new AstroToken(TermParser.ID,
-                                                  EmptyTwine.THE_ONE,
-                                                  myTag),
-                                   new AstroToken(myValueType,
-                                                  mySource,
-                                                  myOptValue));
-        }
+    public Object build(TreeBuilder builder) {
+//        if (null == myOptData) {
+//            return builder.functor(new AstroToken(TermParser.ID,
+//                                                  mySource,
+//                                                  myTag),
+//                                   null);
+//        } else if (isLiteral()) {
+//            return builder.functor(null,
+//                                   new AstroToken(myValueType,
+//                                                  mySource,
+//                                                  myOptData));
+//        } else {
+//            return builder.functor(new AstroToken(TermParser.ID,
+//                                                  EmptyTwine.THE_ONE,
+//                                                  myTag),
+//                                   new AstroToken(myValueType,
+//                                                  mySource,
+//                                                  myOptData));
+//        }
+        throw new RuntimeException("XXX not yet implemented");
     }
 
     /**
@@ -152,7 +139,7 @@
      */
     public Object[] getCanonicalState() {
         Object[] result = {
-            FunctorMaker, "new", myTag, mySource, myOptValue
+            FunctorMaker, "new", myTag, mySource, myOptData
         };
         return result;
     }
@@ -165,6 +152,13 @@
     }
 
     /**
+     *
+     */
+    public AstroSchema getSchema() {
+        return myTag.getOptSchema();
+    }
+
+    /**
      * Presumably, some of the source text that produced this Functor.
      * <p>
      * Only the source-position-tracking info is really significant here.
@@ -178,27 +172,31 @@
     /**
      * null, or the actual literal data in canonical form.
      * <p>
-     * For example, if the Functor was made using an Integer, getValue() will
-     * return a corresponding BigInteger.
+     * For example, if the Functor was made using an Integer, getOptData()
+     * will return a corresponding BigInteger.
      */
-    public Object getValue() {
-        return myOptValue;
+    public Object getOptData() {
+        return myOptData;
     }
 
     /**
+     * If this token represents literal data, return that data,
+     * else throw an exception.
+     */
+    public Object getData() {
+        E.require(null != myOptData, "No data: ", this);
+        return myOptData;
+    }
+
+    /**
      *
      */
-    public double compareTo(EComparable other) {
-        Functor ofunctor = (Functor)E.as(other, Functor.class);
-        double result = myTag.compareTo(ofunctor.myTag);
+    public double compareTo(Functor other) {
+        double result = myTag.compareTo(other.myTag);
         if (0.0 != result) {
             return result;
         }
-        result = myValueType - ofunctor.myValueType;
-        if (0.0 != result) {
-            return result;
-        }
-        return E.asFloat64(E.call(myOptValue, "compareTo", ofunctor.myOptValue));
+        return E.asFloat64(E.call(myOptData, "compareTo", other.myOptData));
     }
 
     /**
@@ -209,29 +207,18 @@
     }
 
     /**
-     * Is myTag the tag implied by the type of myValue?
-     */
-    public boolean isLiteral() {
-        return -1 != myValueType &&
-          TermParser.getTokenNames().get(myValueType).equals(myTag);
-    }
-
-    /**
      *
      */
     public String toString(boolean quasiFlag) {
-        if (null == myOptValue) {
+        if (null == myOptData) {
             return myTag.getTypeName().bare();
         }
-        String valueStr = E.toQuote(myOptValue).bare();
+        String result = E.toQuote(myOptData).bare();
         if (quasiFlag) {
-            valueStr = StringHelper.replaceAll(valueStr, "$", "$$");
-            valueStr = StringHelper.replaceAll(valueStr, "@", "@@");
-            valueStr = StringHelper.replaceAll(valueStr, "`", "``");
+            result = StringHelper.replaceAll(result, "$", "$$");
+            result = StringHelper.replaceAll(result, "@", "@@");
+            result = StringHelper.replaceAll(result, "`", "``");
         }
-        if (isLiteral()) {
-            return valueStr;
-        }
-        return myTag + ":" + valueStr;
+        return result;
     }
 }



1.9       +9 -8      e/src/jsrc/org/quasiliteral/term/SimpleTermBuilder.java

Index: SimpleTermBuilder.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/quasiliteral/term/SimpleTermBuilder.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- SimpleTermBuilder.java	2001/11/27 07:27:54	1.8
+++ SimpleTermBuilder.java	2001/12/01 03:44:02	1.9
@@ -4,11 +4,12 @@
 import org.erights.e.elib.tables.ConstList;
 import org.erights.e.elib.tables.Twine;
 import org.quasiliteral.astro.AstroToken;
+import org.quasiliteral.astro.TreeBuilder;
 
 /**
  * For building a actual (not quasiliteral) Term/Functor tree directly.
  * <p>
- * The parameterization of types from TermBuilder are:<ul>
+ * The parameterization of types from TreeBuilder are:<ul>
  * <li>PLitHole, PFunctorHole, PTermHole, PArgHole -- not applicable.</li>
  * <li>PFunctor -- {@link Functor}</li>
  * <li>PTerm, PArg -- {@link Term}</li>
@@ -17,7 +18,7 @@
  *
  * @author <a href="mailto:markm@caplet.com">Mark S Miller</a>
  */
-public class SimpleTermBuilder implements TermBuilder {
+public class SimpleTermBuilder implements TreeBuilder {
 
     /**
      *
@@ -87,17 +88,17 @@
             E.require(null != optLitTok, "can't default entire functor");
             ConstList typeNames = TermParser.getTokenNames();
             tag = (String)typeNames.get(optLitTok.getType());
-            source = optLitTok.getSource();
-            value = optLitTok.getValue();
+            source = optLitTok.getOptSource();
+            value = optLitTok.getData();
 
         } else {
             //Has an explicit tag (a tagging identifier)
             E.require(TermParser.ID == optIdTok.getType(),
                       "Must be ID: " + optIdTok);
-            tag = (String)optIdTok.getValue();
+            tag = (String)optIdTok.getData();
             E.require(null != tag,
                       "Must have value: " + optIdTok);
-            source = (Twine)optIdTok.getSource();
+            source = (Twine)optIdTok.getOptSource();
 
             if (null == optLitTok) {
                 //Just a tag, all done
@@ -105,8 +106,8 @@
                 //Has both
                 source = (Twine)source
                   .add(":")
-                  .add(optLitTok.getSource());
-                value = optLitTok.getValue();
+                  .add(optLitTok.getOptSource());
+                value = optLitTok.getData();
             }
         }
         return new Functor(tag, source, value);



1.8       +6 -7      e/src/jsrc/org/quasiliteral/term/Term.java

Index: Term.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/quasiliteral/term/Term.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Term.java	2001/11/27 07:27:54	1.7
+++ Term.java	2001/12/01 03:44:02	1.8
@@ -4,7 +4,6 @@
 import antlr.Token;
 import antlr.collections.AST;
 import org.erights.e.develop.format.StringHelper;
-import org.erights.e.elib.base.EComparable;
 import org.erights.e.elib.eio.TextWriter;
 import org.erights.e.elib.prim.E;
 import org.erights.e.elib.prim.StaticMaker;
@@ -15,6 +14,7 @@
 import org.erights.e.elib.tables.FlexList;
 import org.erights.e.elib.tables.Selfless;
 import org.quasiliteral.astro.Astro;
+import org.quasiliteral.astro.TreeBuilder;
 
 import java.io.IOException;
 
@@ -38,7 +38,7 @@
  * @author Many thanks also to Dean Tribble
  */
 public class Term
-  implements EComparable, Selfless, PassByConstruction, Persistent {
+  implements Selfless, PassByConstruction, Persistent {
 
     /**
      *
@@ -115,7 +115,7 @@
      * When built using the SimpleTermBuilder, the result should be
      * a semantically equivalent copy except for source tracking.
      */
-    public Object build(TermBuilder builder) {
+    public Object build(TreeBuilder builder) {
         Object builtFunctor = myFunctor.build(builder);
         Object builtArgs = builder.argList();
         int len = myArgs.size();
@@ -151,13 +151,12 @@
     /**
      *
      */
-    public double compareTo(EComparable other) {
-        Term oterm = (Term)E.as(other, Term.class);
-        double result = myFunctor.compareTo(oterm.myFunctor);
+    public double compareTo(Term other) {
+        double result = myFunctor.compareTo(other.myFunctor);
         if (0.0 != result) {
             return result;
         }
-        return myArgs.compareTo(oterm.myArgs);
+        return myArgs.compareTo(other.myArgs);
     }
 
     /**



1.8       +5 -85     e/src/jsrc/org/quasiliteral/term/TermBuilder.java

Index: TermBuilder.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/quasiliteral/term/TermBuilder.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- TermBuilder.java	2001/11/27 07:27:54	1.7
+++ TermBuilder.java	2001/12/01 03:44:02	1.8
@@ -1,14 +1,15 @@
 package org.quasiliteral.term;
 
-import org.quasiliteral.astro.AstroToken;
 
+import org.quasiliteral.astro.AstroToken;
+import org.quasiliteral.astro.TreeBuilder;
 
 /**
  * Used by the actions of term.y / TermParser.
  * <p>
- * XXX TermBuilder, TermParser, term.y, and TermLexer are all to be replaced
+ * XXX TreeBuilder, TermParser, term.y, and TermLexer are all to be replaced
  * with Antlr-based equivalents.  We hope that the abstraction provided by
- * TermBuilder may allow it, its subclasses, and its clients to survive this
+ * TreeBuilder may allow it, its subclasses, and its clients to survive this
  * transition without great change.
  * <p>
  * The arguments and return types are all 'Object' below, because the actual
@@ -36,7 +37,7 @@
  *
  * @author <a href="mailto:markm@caplet.com">Mark S Miller</a>
  */
-public interface TermBuilder {
+public interface TermBuilder extends TreeBuilder {
 
     /**
      * If true, then this builder accepts the hole productions, and the
@@ -50,15 +51,6 @@
     boolean doesQuasis();
 
     /**
-     * The term 'functor(args...)'
-     *
-     * @param functor :PFunctor
-     * @param args :PArgs
-     * @return :PTerm
-     */
-    Object term(Object functor, Object args);
-
-    /**
      * Promotes a functor-hole to a term-hole.
      * <p>
      * If the optIdent is provided, then it constrains the hole to only match
@@ -71,32 +63,6 @@
     Object termHole(AstroToken optIdent, Object functorHole);
 
     /**
-     * The empty args list
-     *
-     * @return :PArgs
-     */
-    Object argList();
-
-    /**
-     * The args list of one element.
-     * <p>
-     * Should be equivalent to 'argList(argList(), first)'
-     *
-     * @param first :PArg
-     * @return :PArgs
-     */
-    Object argList(Object first);
-
-    /**
-     * Extend args list with an additional term, like a backwards cons.
-     *
-     * @param list :PArgs
-     * @param next :PArg
-     * @return :PArgs
-     */
-    Object argList(Object list, Object next);
-
-    /**
      * Promotes a term or term-hole to an arg, which represents a sequence of
      * terms.
      * <p>
@@ -118,52 +84,6 @@
      *
      */
     Object argGroup(Object args, String quant);
-
-    /**
-     * Returns a representation of the functor whose type tag is ident's
-     * value.
-     *
-     * @param optIdent :AstroToken(ID)
-     * @return :PFunctor
-     */
-    Object tag(AstroToken ident);
-
-    /**
-     * Returns a representation of the functor that represents this literal
-     * character (actually represented as a Character).
-     *
-     * @param lit :AstroToken(LiteralChar)
-     * @return :PFunctor
-     */
-    Object litChar(AstroToken lit);
-
-    /**
-     * Returns a representation of the functor that represents this literal
-     * (precision unlimited) integer (actually represented as a BigInteger).
-     *
-     * @param lit :AstroToken(LiteralInteger)
-     * @return :PFunctor
-     */
-    Object litInteger(AstroToken lit);
-
-    /**
-     * Returns a representation of the functor that represents this literal
-     * IEEE double precision floating point number (actually represented as a
-     * Double).
-     *
-     * @param lit :AstroToken(LiteralFloat64)
-     * @return :PFunctor
-     */
-    Object litFloat64(AstroToken lit);
-
-    /**
-     * Returns a representation of the functor that represents this literal
-     * string (actually represented as a Twine).
-     *
-     * @param lit :AstroToken(LiteralString)
-     * @return :PFunctor
-     */
-    Object litString(AstroToken lit);
 
     /**
      * A dollar-hole corresponds to an extracted expression whose value



1.8       +6 -5      e/src/jsrc/org/quasiliteral/term/TermParser.java

Index: TermParser.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/quasiliteral/term/TermParser.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- TermParser.java	2001/11/27 07:27:54	1.7
+++ TermParser.java	2001/12/01 03:44:02	1.8
@@ -15,6 +15,7 @@
 import org.erights.e.elib.tables.ConstList;
 import org.erights.e.elib.tables.Twine;
 import org.quasiliteral.astro.AstroToken;
+import org.quasiliteral.astro.TreeBuilder;
 
 import java.io.IOException;
 //#line 19 "TermParser.java"
@@ -306,7 +307,7 @@
 /**
  *
  */
-private TermBuilder b;
+private TreeBuilder b;
 
 /**
  *
@@ -316,7 +317,7 @@
 /**
  *
  */
-public TermParser(TermLexer lexer, TermBuilder builder) {
+public TermParser(TermLexer lexer, TreeBuilder builder) {
     myLexer = lexer;
     b = builder;
     myOptResult = null;
@@ -332,7 +333,7 @@
 /**
  *
  */
-static public Object run(Twine source, TermBuilder builder) {
+static public Object run(Twine source, TreeBuilder builder) {
     TermLexer lexer = TermLexer.make(source, builder.doesQuasis());
     TermParser parser = new TermParser(lexer, builder);
     return parser.parse();
@@ -349,8 +350,8 @@
     }
     return null; //keep compiler happy
 }
-    
 
+
 /**
  *
  */
@@ -447,7 +448,7 @@
   while (true) //until parsing is done, either correctly, or w/error
     {
     doaction=true;
-    if (yydebug) debug("loop"); 
+    if (yydebug) debug("loop");
     //#### NEXT ACTION (from reduction table)
     for (yyn=yydefred[yystate];yyn==0;yyn=yydefred[yystate])
       {