[e-cvs] cvs commit: e/src/jsrc/org/quasiliteral/term Functor.java SimpleTermBuilder.java Term.java Term.updoc TermBuilder.java TermLexer.java

markm@eros.cs.jhu.edu markm@eros.cs.jhu.edu
Wed, 21 Nov 2001 05:46:01 -0500


markm       01/11/21 05:46:00

  Modified:    src/jsrc/org/quasiliteral/astro AstroToken.java
               src/jsrc/org/quasiliteral/quasiterm ArgHole.java AtHole.java
                        BaseHole.java DollarHole.java QuasiFunctor.java
                        QuasiNode.java QuasiTerm.java QuasiTermBuilder.java
               src/jsrc/org/quasiliteral/term Functor.java
                        SimpleTermBuilder.java Term.java Term.updoc
                        TermBuilder.java TermLexer.java
  Log:
  Another major term-tree reform.  Doesn't work yet.

Revision  Changes    Path
1.5       +2 -2      e/src/jsrc/org/quasiliteral/astro/AstroToken.java

Index: AstroToken.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/quasiliteral/astro/AstroToken.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- AstroToken.java	2001/11/10 19:40:53	1.4
+++ AstroToken.java	2001/11/21 10:45:59	1.5
@@ -71,8 +71,8 @@
      *
      */
     public Functor asFunctor(ConstList typeNames) {
-        String name = (String)typeNames.get(getType());
-        return new Functor(name, mySource, myValue);
+        String tag = (String)typeNames.get(getType());
+        return new Functor(tag, mySource, myValue);
     }
 
     /**



1.2       +4 -6      e/src/jsrc/org/quasiliteral/quasiterm/ArgHole.java

Index: ArgHole.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/quasiliteral/quasiterm/ArgHole.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ArgHole.java	2001/11/20 12:32:06	1.1
+++ ArgHole.java	2001/11/21 10:46:00	1.2
@@ -1,11 +1,10 @@
 package org.quasiliteral.quasiterm;
 
-import org.quasiliteral.term.TermBuilder;
-import org.quasiliteral.term.TermParser;
-import org.quasiliteral.astro.AstroToken;
+import org.erights.e.elib.prim.StaticMaker;
 import org.erights.e.elib.tables.FlexList;
 import org.erights.e.elib.tables.Twine;
-import org.erights.e.elib.prim.StaticMaker;
+import org.quasiliteral.astro.AstroToken;
+import org.quasiliteral.term.TermBuilder;
 
 /**
  * Represents a subsequence of Terms
@@ -81,8 +80,7 @@
      */
     public boolean matchBind(Object[] args,
                              Object specimen,
-                             FlexList bindings)
-    {
+                             FlexList bindings) {
         throw new RuntimeException("XXX not yet implemented");
     }
 }



1.2       +29 -30    e/src/jsrc/org/quasiliteral/quasiterm/AtHole.java

Index: AtHole.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/quasiliteral/quasiterm/AtHole.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AtHole.java	2001/11/20 12:32:06	1.1
+++ AtHole.java	2001/11/21 10:46:00	1.2
@@ -1,26 +1,14 @@
 package org.quasiliteral.quasiterm;
 
-import antlr.Token;
-import org.erights.e.develop.format.StringHelper;
-import org.erights.e.elib.base.SourceSpan;
-import org.erights.e.elib.base.EComparable;
-import org.erights.e.elib.prim.E;
 import org.erights.e.elib.prim.StaticMaker;
-import org.erights.e.elib.serial.PassByConstruction;
-import org.erights.e.elib.serial.Persistent;
-import org.erights.e.elib.tables.ConstList;
-import org.erights.e.elib.tables.ConstMap;
-import org.erights.e.elib.tables.Selfless;
-import org.erights.e.elib.tables.Twine;
 import org.erights.e.elib.tables.FlexList;
-import org.erights.e.elib.quasi.ValueMaker;
-import org.erights.e.elib.quasi.MatchMaker;
+import org.erights.e.elib.tables.Twine;
 import org.erights.e.elib.util.OneArgFunc;
+import org.erights.e.elib.base.Ejector;
 import org.quasiliteral.astro.AstroToken;
-import org.quasiliteral.term.TermLexer;
-import org.quasiliteral.term.TermParser;
 import org.quasiliteral.term.TermBuilder;
-import org.quasiliteral.term.Functor;
+import org.quasiliteral.term.TermParser;
+import org.quasiliteral.term.Converter;
 
 import java.math.BigInteger;
 
@@ -42,22 +30,19 @@
     /**
      * @param index Which at-hole is this?
      */
-    public AtHole(Twine source, BigInteger index, OneArgFunc converter) {
+    public AtHole(Twine source, BigInteger index, Converter converter) {
         super(source, index, converter);
     }
 
     /**
-     * XXX This method is confused since we added converters.
      *
-     * @return Actually, when using the QuasiTermBuilder, this will return
-     *         a LitHole wrapping an equivalent AtHole.  This is the
-     *         best we can do, as AtHole is actually an internal type.
      */
     public Object qbuild(TermBuilder builder) {
         AstroToken token = new AstroToken(TermParser.LiteralInteger,
                                           mySource,
                                           myIndex);
-        return builder.atHole(token);
+        Object litHole = builder.atHole(token);
+        return myConverter.qbuild(builder, litHole);
     }
 
     /**
@@ -91,13 +76,27 @@
                              Object specimen,
                              FlexList bindings)
     {
-        specimen = myConverter.run(specimen);
-        Object old = bindings.get(myIndex.intValue());
-        if (null == old) {
-            bindings.put(myIndex.intValue(), specimen);
-            return true;
-        } else {
-            return DollarHole.equiv(myConverter.run(old), specimen);
+        Ejector ejector = new Ejector();
+        try {
+            specimen = convert(specimen, ejector);
+            Object old = bindings.get(myIndex.intValue());
+            if (null == old) {
+                bindings.put(myIndex.intValue(), specimen);
+                return true;
+            } else {
+                old = convert(old, ejector);
+                return Converter.equiv(old, specimen);
+            }
+        } catch (Throwable t) {
+            //If t's leaf isn't out own Ejection, then t will be rethrown
+            ejector.result(t);
+            //If we arrive here, then a convert failed.  We ignore the reason
+            //why (the value returned by result/1) and simply indicate
+            //failure.
+            return false;
+
+        } finally {
+            ejector.disable();
         }
     }
 
@@ -111,7 +110,7 @@
     /**
      *
      */
-    public BaseHole promote(OneArgFunc newConverter) {
+    public BaseHole promote(Converter newConverter) {
         return new AtHole(mySource, myIndex, newConverter);
     }
 }



1.2       +20 -41    e/src/jsrc/org/quasiliteral/quasiterm/BaseHole.java

Index: BaseHole.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/quasiliteral/quasiterm/BaseHole.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BaseHole.java	2001/11/20 12:32:06	1.1
+++ BaseHole.java	2001/11/21 10:46:00	1.2
@@ -1,26 +1,11 @@
 package org.quasiliteral.quasiterm;
 
-import antlr.Token;
-import org.erights.e.develop.format.StringHelper;
-import org.erights.e.elib.base.SourceSpan;
 import org.erights.e.elib.base.EComparable;
-import org.erights.e.elib.prim.E;
-import org.erights.e.elib.prim.StaticMaker;
-import org.erights.e.elib.serial.PassByConstruction;
-import org.erights.e.elib.serial.Persistent;
-import org.erights.e.elib.tables.ConstList;
-import org.erights.e.elib.tables.ConstMap;
-import org.erights.e.elib.tables.Selfless;
+import org.erights.e.elib.base.Ejector;
 import org.erights.e.elib.tables.Twine;
-import org.erights.e.elib.tables.FlexList;
-import org.erights.e.elib.quasi.ValueMaker;
-import org.erights.e.elib.quasi.MatchMaker;
 import org.erights.e.elib.util.OneArgFunc;
-import org.quasiliteral.astro.AstroToken;
-import org.quasiliteral.term.TermLexer;
-import org.quasiliteral.term.TermParser;
-import org.quasiliteral.term.TermBuilder;
-import org.quasiliteral.term.Functor;
+import org.erights.e.elib.prim.E;
+import org.quasiliteral.term.Converter;
 
 import java.math.BigInteger;
 
@@ -47,40 +32,20 @@
     /**
      * @serial Converts various data types into this hole's target data type.
      */
-    /*package*/ final OneArgFunc myConverter;
+    /*package*/ final Converter myConverter;
 
     /**
      * @param index Which hole is this?
      */
     /*package*/ BaseHole(Twine source,
                          BigInteger index,
-                         OneArgFunc converter)
-    {
+                         Converter converter) {
         mySource = source;
         myIndex = index;
         myConverter = converter;
     }
 
     /**
-     * Tests if x <=> y.
-     * <p>
-     * Assumes they've already been converted
-     */
-    static public boolean equiv(Object x, Object y) {
-        if (! (x instanceof EComparable)) {
-            //XXX Bug: is this right, or should we E.as() first, or should
-            //we forget EComparable and just E.call(.., "compareTo", ...)?
-            return false;
-        }
-        if (! (y instanceof EComparable)) {
-            return false;
-        }
-        //XXX BUG: If mine and spec are types that don't compare, this will
-        //throw rather than returning false.  It's unclear where to fix this.
-        return 0.0 == ((EComparable)x).compareTo((EComparable)y);
-    }
-
-    /**
      *
      */
     public Twine getSource() {
@@ -95,8 +60,22 @@
     }
 
     /**
+     *
+     */
+    public Object convert(Object specimen, Ejector optEjector) {
+        return myConverter.coerce(specimen, optEjector);
+    }
+
+    /**
+     * optEjector defaults to null
+     */
+    public Object convert(Object specimen) {
+        return myConverter.coerce(specimen, null);
+    }
+
+    /**
      * A BaseHole just like this one but using 'newConverter' instead of
      * 'myConverter'
      */
-    public abstract BaseHole promote(OneArgFunc newConverter);
+    public abstract BaseHole promote(Converter newConverter);
 }



1.3       +26 -26    e/src/jsrc/org/quasiliteral/quasiterm/DollarHole.java

Index: DollarHole.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/quasiliteral/quasiterm/DollarHole.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DollarHole.java	2001/11/20 12:32:06	1.2
+++ DollarHole.java	2001/11/21 10:46:00	1.3
@@ -1,26 +1,14 @@
 package org.quasiliteral.quasiterm;
 
-import antlr.Token;
-import org.erights.e.develop.format.StringHelper;
-import org.erights.e.elib.base.SourceSpan;
-import org.erights.e.elib.base.EComparable;
-import org.erights.e.elib.prim.E;
 import org.erights.e.elib.prim.StaticMaker;
-import org.erights.e.elib.serial.PassByConstruction;
-import org.erights.e.elib.serial.Persistent;
-import org.erights.e.elib.tables.ConstList;
-import org.erights.e.elib.tables.ConstMap;
-import org.erights.e.elib.tables.Selfless;
-import org.erights.e.elib.tables.Twine;
 import org.erights.e.elib.tables.FlexList;
-import org.erights.e.elib.quasi.ValueMaker;
-import org.erights.e.elib.quasi.MatchMaker;
+import org.erights.e.elib.tables.Twine;
 import org.erights.e.elib.util.OneArgFunc;
+import org.erights.e.elib.base.Ejector;
 import org.quasiliteral.astro.AstroToken;
-import org.quasiliteral.term.TermLexer;
-import org.quasiliteral.term.TermParser;
 import org.quasiliteral.term.TermBuilder;
-import org.quasiliteral.term.Functor;
+import org.quasiliteral.term.TermParser;
+import org.quasiliteral.term.Converter;
 
 import java.math.BigInteger;
 
@@ -40,22 +28,19 @@
     /**
      * @param index Which dollar-hole is this?
      */
-    public DollarHole(Twine source, BigInteger index, OneArgFunc converter) {
+    public DollarHole(Twine source, BigInteger index, Converter converter) {
         super(source, index, converter);
     }
 
     /**
-     * XXX This method is confused since we added converters.
      *
-     * @return Actually, when using the QuasiTermBuilder, this will return
-     *         a LitHole wrapping an equivalent DollarHole.  This is the
-     *         best we can do, as DollarHole is actually an internal type.
      */
     public Object qbuild(TermBuilder builder) {
         AstroToken token = new AstroToken(TermParser.LiteralInteger,
                                           mySource,
                                           myIndex);
-        return builder.dollarHole(token);
+        Object litHole = builder.dollarHole(token);
+        return myConverter.qbuild(builder, litHole);
     }
 
     /**
@@ -73,7 +58,7 @@
      * "Evaluates" to convert(args[index])
      */
     public Object substitute(Object[] args) {
-        return myConverter.run(args[myIndex.intValue()]);
+        return convert(args[myIndex.intValue()]);
     }
 
     /**
@@ -83,8 +68,23 @@
                              Object specimen,
                              FlexList bindings)
     {
-        return equiv(myConverter.run(specimen),
-                     myConverter.run(args[myIndex.intValue()]));
+        Ejector ejector = new Ejector();
+        try {
+            specimen = convert(specimen, ejector);
+            Object arg = convert(args[myIndex.intValue()], ejector);
+            return Converter.equiv(specimen, arg);
+
+        } catch (Throwable t) {
+            //If t's leaf isn't out own Ejection, then t will be rethrown
+            ejector.result(t);
+            //If we arrive here, then a convert failed.  We ignore the reason
+            //why (the value returned by result/1) and simply indicate
+            //failure.
+            return false;
+
+        } finally {
+            ejector.disable();
+        }
     }
 
     /**
@@ -97,7 +97,7 @@
     /**
      *
      */
-    public BaseHole promote(OneArgFunc newConverter) {
+    public BaseHole promote(Converter newConverter) {
         return new DollarHole(mySource, myIndex, newConverter);
     }
 }



1.3       +30 -42    e/src/jsrc/org/quasiliteral/quasiterm/QuasiFunctor.java

Index: QuasiFunctor.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/quasiliteral/quasiterm/QuasiFunctor.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- QuasiFunctor.java	2001/11/20 12:32:06	1.2
+++ QuasiFunctor.java	2001/11/21 10:46:00	1.3
@@ -1,24 +1,16 @@
 package org.quasiliteral.quasiterm;
 
-import antlr.Token;
 import org.erights.e.develop.format.StringHelper;
-import org.erights.e.elib.base.SourceSpan;
 import org.erights.e.elib.prim.E;
 import org.erights.e.elib.prim.StaticMaker;
-import org.erights.e.elib.serial.PassByConstruction;
-import org.erights.e.elib.serial.Persistent;
-import org.erights.e.elib.tables.ConstList;
-import org.erights.e.elib.tables.ConstMap;
-import org.erights.e.elib.tables.Selfless;
-import org.erights.e.elib.tables.Twine;
 import org.erights.e.elib.tables.FlexList;
-import org.erights.e.elib.quasi.ValueMaker;
-import org.erights.e.elib.quasi.MatchMaker;
+import org.erights.e.elib.tables.Twine;
 import org.quasiliteral.astro.AstroToken;
+import org.quasiliteral.term.Functor;
+import org.quasiliteral.term.TermBuilder;
 import org.quasiliteral.term.TermLexer;
 import org.quasiliteral.term.TermParser;
-import org.quasiliteral.term.TermBuilder;
-import org.quasiliteral.term.Functor;
+import org.quasiliteral.term.Converter;
 
 import java.math.BigInteger;
 
@@ -39,7 +31,7 @@
     /**
      * @serial The name of an Antlr token type int in a particular grammar.
      */
-    private final String myName;
+    private final String myTag;
 
     /**
      * @serial The source text corresponding to the original source of the
@@ -55,7 +47,6 @@
      *       a Character       TermParser.LiteralChar
      *       a BigInteger      TermParser.LiteralInteger
      *       a Double          TermParser.LiteralFloat64
-     *       a String          TermParser.LiteralString
      *       a Twine           TermParser.LiteralString
      * </pre>
      */
@@ -70,7 +61,7 @@
     private Object myValue;
 
     /**
-     * @param name The name of an Antlr token type int in a particular
+     * @param tag The name of an Antlr token type int in a particular
      *             grammar.  Must be an identifier.  Printed only if not
      *             implied by value.  When matching, must match exactly.
      * @param source The source text corresponding to the original source of
@@ -85,11 +76,11 @@
      *                 If non-null, is always part of the normal printed
      *                 form.  When matching, null means don't-care.
      */
-    public QuasiFunctor(String name, Twine source, Object value) {
-        if (!TermLexer.isIdentifier(name)) {
-            throw new RuntimeException("Must be an identifier: " + name);
+    public QuasiFunctor(String tag, Twine source, Object value) {
+        if (!TermLexer.isIdentifier(tag)) {
+            throw new RuntimeException("Must be an identifier: " + tag);
         }
-        myName = name;
+        myTag = tag;
         mySource = source;
         if (null == value) {
             myValueType = -1;
@@ -120,7 +111,7 @@
      *
      */
     public QuasiFunctor(Functor functor) {
-        this(functor.getName(), functor.getSource(), functor.getValue());
+        this(functor.getTag(), functor.getSource(), functor.getValue());
     }
 
     /**
@@ -130,7 +121,7 @@
         if (null == myValue) {
             return builder.functor(new AstroToken(TermParser.ID,
                                                   mySource,
-                                                  myName),
+                                                  myTag),
                                    null);
         } else if (isJustLiteral()) {
             return builder.functor(null,
@@ -139,11 +130,11 @@
                                                   myValue));
         } else {
             return builder.functor(new AstroToken(TermParser.ID,
-                                                   Twine.fromString(""),
-                                                   myName),
-                                    new AstroToken(myValueType,
-                                                   mySource,
-                                                   myValue));
+                                                  Twine.fromString(""),
+                                                  myTag),
+                                   new AstroToken(myValueType,
+                                                  mySource,
+                                                  myValue));
         }
     }
 
@@ -152,7 +143,7 @@
      */
     public Object[] getCanonicalState() {
         Object[] result = {
-            QuasiFunctorMaker, "new", myName, mySource, myValue
+            QuasiFunctorMaker, "new", myTag, mySource, myValue
         };
         return result;
     }
@@ -160,8 +151,8 @@
     /**
      *
      */
-    public String getName() {
-        return myName;
+    public String getTag() {
+        return myTag;
     }
 
     /**
@@ -183,7 +174,7 @@
      * the equivalent Functor.
      */
     public Object substitute(Object[] args) {
-        return new Functor(myName, mySource, myValue);
+        return new Functor(myTag, mySource, myValue);
     }
 
     /**
@@ -192,7 +183,7 @@
      * corresponding at-holes, and return true.  Otherwise, return false.
      * <p>
      * Since QuasiFunctors currently contain no holes, this just determines
-     * if the specimen matches.  For purposes of the match, the names must be
+     * if the specimen matches.  For purposes of the match, the tags must be
      * the same, the sources are ignored, and the values, if non-null, must be
      * &lt;=&gt; (the same magnitude).  This has the peculiar consequence that a
      * literal NaN can't be matched, since it isn't &lt;=&gt; to anything.  Further,
@@ -204,13 +195,12 @@
      */
     public boolean matchBind(Object[] args,
                              Object specimen,
-                             FlexList bindings)
-    {
-        if (! (specimen instanceof Functor)) {
+                             FlexList bindings) {
+        if (!(specimen instanceof Functor)) {
             return false;
         }
         Functor spec = (Functor)specimen;
-        if (! myName.equals(spec.getName())) {
+        if (!myTag.equals(spec.getTag())) {
             return false;
         }
         if (null == myValue) {
@@ -219,17 +209,15 @@
         if (myValueType != spec.getValueType()) {
             return false;
         }
-        double comp =
-          E.asFloat64(E.call(myValue, "compareTo", spec.getValue()));
-        return 0.0 == comp;
+        return Converter.equiv(myValue, spec.getValue());
     }
 
     /**
-     * Is myName the name implied by the type of myValue?
+     * Is myTag the tag implied by the type of myValue?
      */
     public boolean isJustLiteral() {
         return -1 != myValueType &&
-          TermParser.getTokenNames().get(myValueType).equals(myName);
+          TermParser.getTokenNames().get(myValueType).equals(myTag);
     }
 
     /**
@@ -237,7 +225,7 @@
      */
     public String toString(boolean quasiFlag) {
         if (null == myValue) {
-            return myName;
+            return myTag;
         }
         String valueStr = E.toQuote(myValue).bare();
         if (quasiFlag) {
@@ -248,6 +236,6 @@
         if (isJustLiteral()) {
             return valueStr;
         }
-        return myName + ":" + valueStr;
+        return myTag + ":" + valueStr;
     }
 }



1.3       +3 -15     e/src/jsrc/org/quasiliteral/quasiterm/QuasiNode.java

Index: QuasiNode.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/quasiliteral/quasiterm/QuasiNode.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- QuasiNode.java	2001/11/20 12:32:06	1.2
+++ QuasiNode.java	2001/11/21 10:46:00	1.3
@@ -1,26 +1,14 @@
 package org.quasiliteral.quasiterm;
 
-import antlr.Token;
-import org.erights.e.develop.format.StringHelper;
-import org.erights.e.elib.base.SourceSpan;
-import org.erights.e.elib.prim.E;
-import org.erights.e.elib.prim.StaticMaker;
+import org.erights.e.elib.quasi.MatchMaker;
+import org.erights.e.elib.quasi.ValueMaker;
 import org.erights.e.elib.serial.PassByConstruction;
 import org.erights.e.elib.serial.Persistent;
 import org.erights.e.elib.tables.ConstList;
-import org.erights.e.elib.tables.ConstMap;
+import org.erights.e.elib.tables.FlexList;
 import org.erights.e.elib.tables.Selfless;
 import org.erights.e.elib.tables.Twine;
-import org.erights.e.elib.tables.FlexList;
-import org.erights.e.elib.quasi.ValueMaker;
-import org.erights.e.elib.quasi.MatchMaker;
-import org.quasiliteral.astro.AstroToken;
-import org.quasiliteral.term.TermLexer;
-import org.quasiliteral.term.TermParser;
 import org.quasiliteral.term.TermBuilder;
-import org.quasiliteral.term.Functor;
-
-import java.math.BigInteger;
 
 /**
  * A node in a quasiliteral Term/Functor tree.



1.3       +10 -24    e/src/jsrc/org/quasiliteral/quasiterm/QuasiTerm.java

Index: QuasiTerm.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/quasiliteral/quasiterm/QuasiTerm.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- QuasiTerm.java	2001/11/20 12:32:06	1.2
+++ QuasiTerm.java	2001/11/21 10:46:00	1.3
@@ -1,27 +1,14 @@
 package org.quasiliteral.quasiterm;
 
-import org.erights.e.elib.tables.Selfless;
-import org.erights.e.elib.tables.ConstList;
-import org.erights.e.elib.tables.FlexList;
-import org.erights.e.elib.tables.Twine;
-import org.erights.e.elib.tables.ConstMap;
-import org.erights.e.elib.serial.PassByConstruction;
-import org.erights.e.elib.serial.Persistent;
+import org.erights.e.develop.exception.ExceptionMgr;
+import org.erights.e.develop.format.StringHelper;
 import org.erights.e.elib.eio.TextWriter;
 import org.erights.e.elib.prim.StaticMaker;
-import org.erights.e.elib.quasi.ValueMaker;
-import org.erights.e.elib.quasi.MatchMaker;
-import org.erights.e.develop.format.StringHelper;
-import org.erights.e.develop.exception.ExceptionMgr;
-import org.quasiliteral.astro.Astro;
+import org.erights.e.elib.tables.ConstList;
+import org.erights.e.elib.tables.FlexList;
 import org.quasiliteral.term.Functor;
-import org.quasiliteral.term.TermBuilder;
 import org.quasiliteral.term.Term;
-import antlr.collections.AST;
-import antlr.Grammar;
-import antlr.Token;
-import antlr.CommonToken;
-import antlr.CommonAST;
+import org.quasiliteral.term.TermBuilder;
 
 import java.io.IOException;
 import java.io.StringWriter;
@@ -142,13 +129,12 @@
      */
     public boolean matchBind(Object[] args,
                              Object specimen,
-                             FlexList bindings)
-    {
-        if (! (specimen instanceof Term)) {
+                             FlexList bindings) {
+        if (!(specimen instanceof Term)) {
             return false;
         }
         Term term = (Term)specimen;
-        if (! myFunctor.matchBind(args, term.getFunctor(), bindings)) {
+        if (!myFunctor.matchBind(args, term.getFunctor(), bindings)) {
             return false;
         }
         int len = myArgs.size();
@@ -158,7 +144,7 @@
             if (thing instanceof QuasiTerm) {
                 Term spec = (Term)terms.get(0);
                 terms = terms.run(0, terms.size());
-                if (! ((QuasiTerm)thing).matchBind(args, spec, bindings)) {
+                if (!((QuasiTerm)thing).matchBind(args, spec, bindings)) {
                     return false;
                 }
             } else {
@@ -211,7 +197,7 @@
      *
      */
     public void prettyPrintOn(TextWriter out, boolean quasiFlag)
-    throws IOException {
+      throws IOException {
         String functorStr = myFunctor.toString(quasiFlag);
         out.print(functorStr);
         int h = getHeight();



1.3       +35 -26    e/src/jsrc/org/quasiliteral/quasiterm/QuasiTermBuilder.java

Index: QuasiTermBuilder.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/quasiliteral/quasiterm/QuasiTermBuilder.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- QuasiTermBuilder.java	2001/11/20 12:32:06	1.2
+++ QuasiTermBuilder.java	2001/11/21 10:46:00	1.3
@@ -1,17 +1,19 @@
 package org.quasiliteral.quasiterm;
 
-import org.erights.e.elib.tables.ConstList;
-import org.erights.e.elib.tables.Twine;
+import org.erights.e.elib.prim.E;
+import org.erights.e.elib.quasi.MatchMaker;
 import org.erights.e.elib.quasi.QuasiExprParser;
 import org.erights.e.elib.quasi.QuasiPatternParser;
 import org.erights.e.elib.quasi.ValueMaker;
-import org.erights.e.elib.quasi.MatchMaker;
-import org.erights.e.elib.prim.E;
+import org.erights.e.elib.tables.ConstList;
+import org.erights.e.elib.tables.Twine;
 import org.quasiliteral.astro.AstroToken;
 import org.quasiliteral.term.TermBuilder;
-import org.quasiliteral.term.Term;
-import org.quasiliteral.term.Functor;
 import org.quasiliteral.term.TermParser;
+import org.quasiliteral.term.ToFunctor;
+import org.quasiliteral.term.ToLiteral;
+import org.quasiliteral.term.ToTerm;
+import org.quasiliteral.term.ToTermList;
 
 import java.math.BigInteger;
 
@@ -44,7 +46,8 @@
     /**
      *
      */
-    private QuasiTermBuilder() {}
+    private QuasiTermBuilder() {
+    }
 
     /**
      * XXX not yet implemented
@@ -66,8 +69,7 @@
      */
     public MatchMaker matchMaker(Twine template,
                                  int[] dlrHoles,
-                                 int[] atHoles)
-    {
+                                 int[] atHoles) {
         throw new RuntimeException
           ("XXX new quasi matchMaker API not yet implemented");
     }
@@ -82,7 +84,9 @@
     /**
      * @return true
      */
-    public boolean doesQuasis() { return true; }
+    public boolean doesQuasis() {
+        return true;
+    }
 
     /**
      * @return :[(QuasiTerm | PTermHole | ArgHole)*]
@@ -125,7 +129,7 @@
     public Object functor(Object optIdent, Object optLit) {
         AstroToken optIdTok = (AstroToken)optIdent;
 
-        String name = null;
+        String tag = null;
         Twine source = null;
         Object value = null;
 
@@ -134,26 +138,26 @@
             E.require(null != optLit, "can't default entire functor");
             AstroToken litTok = (AstroToken)optLit;
             ConstList typeNames = TermParser.getTokenNames();
-            name = (String)typeNames.get(litTok.getType());
+            tag = (String)typeNames.get(litTok.getType());
             source = litTok.getSource();
             value = litTok.getValue();
 
         } else {
-            //Has an explicit name (a tagging identifier)
+            //Has an explicit tag (a tagging identifier)
             if (TermParser.ID != optIdTok.getType()) {
                 throw new RuntimeException("Must be ID: " + optIdTok);
             }
-            name = (String)optIdTok.getValue();
-            if (null == name) {
+            tag = (String)optIdTok.getValue();
+            if (null == tag) {
                 throw new RuntimeException("Must have value: " + optIdTok);
             }
             source = (Twine)optIdTok.getSource();
 
             if (null == optLit) {
-                //Just a name, all done
+                //Just a tag, all done
 
             } else if (optLit instanceof AstroToken) {
-                //A name and a literal
+                //A tag and a literal
                 AstroToken litTok = (AstroToken)optLit;
                 source = (Twine)source
                   .add(":")
@@ -161,7 +165,7 @@
                 value = litTok.getValue();
 
             } else if (optLit instanceof BaseHole) {
-                //A name and a literal-hole
+                //A tag and a literal-hole
                 BaseHole litHole = (BaseHole)optLit;
                 source = (Twine)source
                   .add(":")
@@ -169,7 +173,7 @@
                 value = litHole;
             }
         }
-        return new QuasiFunctor(name, source, value);
+        return new QuasiFunctor(tag, source, value);
     }
 
     /**
@@ -178,20 +182,23 @@
     public Object argHole(Object optTerm, Object quant) {
         AstroToken qtoken = (AstroToken)quant;
         char q = (char)qtoken.getType();
-        E.require("?+*".indexOf(q) >= 0,
-                  "Must be a '?', '+', or '*': " + q);
-        //XXX Should cache the three Characters.
-        return new ArgHole((QuasiNode)optTerm, new Character(q));
+        return new ArgHole((QuasiNode)optTerm, ToTermList.box(q));
     }
 
     /**
      *
      */
     public Object termHole(Object optIdent, Object fnctrHole) {
-        ToTerm converter = ToTerm.ANY_TERM;
+        String optTag = null;
         if (null != optIdent) {
-            throw new RuntimeException("XXX not yet implemented");
+            AstroToken optIdTok = (AstroToken)optIdent;
+            E.require(TermParser.ID == optIdTok.getType(),
+                      "Must be ID: " + optIdTok);
+            optTag = (String)optIdTok.getValue();
+            E.require(null != optTag,
+                      "Must have value: " + optIdTok);
         }
+        ToTerm converter = ToTerm.make(optTag);
         return ((BaseHole)fnctrHole).promote(converter);
     }
 
@@ -225,5 +232,7 @@
     /**
      *
      */
-    public String toString() { return "<QuasiTermBuilder>"; }
+    public String toString() {
+        return "<QuasiTermBuilder>";
+    }
 }



1.9       +91 -77    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.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Functor.java	2001/11/20 12:32:07	1.8
+++ Functor.java	2001/11/21 10:46:00	1.9
@@ -2,8 +2,8 @@
 
 import antlr.Token;
 import org.erights.e.develop.format.StringHelper;
-import org.erights.e.elib.base.SourceSpan;
 import org.erights.e.elib.base.EComparable;
+import org.erights.e.elib.base.SourceSpan;
 import org.erights.e.elib.prim.E;
 import org.erights.e.elib.prim.StaticMaker;
 import org.erights.e.elib.serial.PassByConstruction;
@@ -50,7 +50,7 @@
     /**
      * @serial The name of an Antlr token type int in a particular grammar.
      */
-    private final String myName;
+    private final String myTag;
 
     /**
      * @serial The source text corresponding to the original source of the
@@ -66,20 +66,19 @@
      *       a Character       TermParser.LiteralChar
      *       a BigInteger      TermParser.LiteralInteger
      *       a Double          TermParser.LiteralFloat64
-     *       a String          TermParser.LiteralString
      *       a Twine           TermParser.LiteralString
      * </pre>
      */
-    private int myValueType;
+    private final int myValueType;
 
     /**
      * @serial null, {@link Character}, {@link BigInteger}, {@link Double},
-     * {@link String}, or {@link Twine} calculated from lexing the token
+     * or {@link Twine} calculated from lexing the token
      */
-    private Object myValue;
+    private final Object myValue;
 
     /**
-     * @param name The name of an Antlr token type int in a particular
+     * @param tag The name of an Antlr token type int in a particular
      *             grammar.  Must be an identifier.  Printed only if not
      *             implied by value.
      * @param source The source text corresponding to the original source of
@@ -89,62 +88,64 @@
      *               it corresponds to. This is not part of the normal
      *               printed form.
      * @param value null, {@link Character},
-     *                 {@link BigInteger}, {@link Double},
-     *                 {@link String}, or {@link Twine}
+     *                 {@link BigInteger} or other integral {@link Number},
+     *                 {@link Double} or {@link Float}, or
+     *                 {@link Twine} or {@link String}
      *                 If non-null, is always part of the normal printed
      *                 form.
      */
-    public Functor(String name, Twine source, Object value) {
-        if (!TermLexer.isIdentifier(name)) {
-            throw new RuntimeException("Must be an identifier: " + name);
+    public Functor(String tag, Twine source, Object value) {
+        if (!TermLexer.isIdentifier(tag)) {
+            throw new RuntimeException("Must be an identifier: " + tag);
         }
-        myName = name;
+        myTag = tag;
         mySource = source;
-        myValueType = literalType(value);
-        myValue = value;
-    }
-
-    /**
-     * returns the literal type code according to the type of 'value'.
-     * <p>
-     * <pre>
-     *   If value is         return is
-     *       null              -1
-     *       a Character       TermParser.LiteralChar
-     *       a BigInteger      TermParser.LiteralInteger
-     *       a Double          TermParser.LiteralFloat64
-     *       a String          TermParser.LiteralString
-     *       a Twine           TermParser.LiteralString
-     *       anything else     throw a complaint
-     * </pre>
-     */
-    static public int literalType(Object value) {
-        if (null == value) {
-            return -1;
-        } else if (value instanceof Character) {
-            return TermParser.LiteralChar;
-        } else if (value instanceof Number) {
-            if (value instanceof BigInteger) {
-                return TermParser.LiteralInteger;
-            } else if (value instanceof Double) {
-                return TermParser.LiteralFloat64;
-            } else {
-                throw new RuntimeException
-                  ("XXX Functor value coercion not yet implemented");
+        myValueType = Converter.literalType(value);
+        switch (myValueType) {
+            case -1: {
+                myValue = null;
+                break;
             }
-        } else if (value instanceof String) {
-            return TermParser.LiteralString;
-            //XXX consider coercing value to Twine
-        } else if (value instanceof Twine) {
-            return TermParser.LiteralString;
-        } else {
-            throw new RuntimeException(value.getClass().getName() +
-                                       " not a literal type");
+            case TermParser.LiteralChar: {
+                myValue = (Character)value;
+                break;
+            }
+            case TermParser.LiteralInteger: {
+                if (value instanceof BigInteger) {
+                    myValue = value;
+                } else {
+                    myValue = BigInteger.valueOf(((Number)value).longValue());
+                }
+                break;
+            }
+            case TermParser.LiteralFloat64: {
+                if (value instanceof Double) {
+                    myValue = value;
+                } else {
+                    myValue = new Double(((Float)value).doubleValue());
+                }
+                break;
+            }
+            case TermParser.LiteralString: {
+                if (value instanceof Twine) {
+                    myValue = value;
+                } else {
+                    myValue = Twine.fromString((String)value);
+                }
+                break;
+            }
+            default: {
+                throw new RuntimeException("Unrecognized value type: " +
+                                           value.getClass());
+            }
         }
     }
 
     /**
-     * If token is an AstroToken, this just does token.asFunctor(typeNames)
+     * Convert from an Antlr {@link Token}.
+     * <p>
+     * If token is an AstroToken, this just does token.asFunctor(typeNames),
+     * in which case equivalence should be preserved.
      */
     static public Functor fromToken(Token token,
                                     String url,
@@ -166,63 +167,76 @@
     }
 
     /**
-     *
+     * Converts to an equivalent {@link AstroToken}, for use with Antlr.
+     * <p>
+     * This should be compatible with Antlr code that just assumes a Token.
      */
     public AstroToken asToken(ConstMap typeNums) {
-        int tokenTypeInt = E.asInt(typeNums.get(myName));
+        int tokenTypeInt = E.asInt(typeNums.get(myTag));
         return new AstroToken(tokenTypeInt, mySource, myValue);
     }
 
     /**
-     *
+     * Call the builder's productions in order to represent this Functor.
+     * <p>
+     * This is a kind of visitor pattern.  If the builder provided is the
+     * SimpleTermBuilder, this should make a semantically equivalent copy
+     * of this Functor.
      */
     public Object build(TermBuilder builder) {
         if (null == myValue) {
             return builder.functor(new AstroToken(TermParser.ID,
                                                   mySource,
-                                                  myName),
+                                                  myTag),
                                    null);
-        } else if (isJustLiteral()) {
+        } else if (isLiteral()) {
             return builder.functor(null,
                                    new AstroToken(myValueType,
                                                   mySource,
                                                   myValue));
         } else {
             return builder.functor(new AstroToken(TermParser.ID,
-                                                   Twine.fromString(""),
-                                                   myName),
-                                    new AstroToken(myValueType,
-                                                   mySource,
-                                                   myValue));
+                                                  Twine.fromString(""),
+                                                  myTag),
+                                   new AstroToken(myValueType,
+                                                  mySource,
+                                                  myValue));
         }
     }
 
     /**
-     * 'FunctorMaker new(myTokenType, mySource, myOptValue)'
+     * 'FunctorMaker new(myTag, mySource, myValue)'
      */
     public Object[] getCanonicalState() {
         Object[] result = {
-            FunctorMaker, "new", myName, mySource, myValue
+            FunctorMaker, "new", myTag, mySource, myValue
         };
         return result;
     }
 
     /**
-     *
+     * An identifier typically representing a type of AST node.
      */
-    public String getName() {
-        return myName;
+    public String getTag() {
+        return myTag;
     }
 
     /**
-     *
+     * Presumably, some of the source text that produced this Functor.
+     * <p>
+     * Only the source-position-tracking info is really significant here.
+     * If absent, the absence is indicated with an empty string rather than
+     * null.
      */
     public Twine getSource() {
         return mySource;
     }
 
     /**
-     *
+     * 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.
      */
     public Object getValue() {
         return myValue;
@@ -249,7 +263,7 @@
      */
     public double compareTo(EComparable other) {
         Functor ofunctor = (Functor)E.as(other, Functor.class);
-        double result = myName.compareTo(ofunctor.myName);
+        double result = myTag.compareTo(ofunctor.myTag);
         if (0.0 != result) {
             return result;
         }
@@ -268,11 +282,11 @@
     }
 
     /**
-     * Is myName the name implied by the type of myValue?
+     * Is myTag the tag implied by the type of myValue?
      */
-    public boolean isJustLiteral() {
+    public boolean isLiteral() {
         return -1 != myValueType &&
-          TermParser.getTokenNames().get(myValueType).equals(myName);
+          TermParser.getTokenNames().get(myValueType).equals(myTag);
     }
 
     /**
@@ -280,7 +294,7 @@
      */
     public String toString(boolean quasiFlag) {
         if (null == myValue) {
-            return myName;
+            return myTag;
         }
         String valueStr = E.toQuote(myValue).bare();
         if (quasiFlag) {
@@ -288,9 +302,9 @@
             valueStr = StringHelper.replaceAll(valueStr, "@", "@@");
             valueStr = StringHelper.replaceAll(valueStr, "`", "``");
         }
-        if (isJustLiteral()) {
+        if (isLiteral()) {
             return valueStr;
         }
-        return myName + ":" + valueStr;
+        return myTag + ":" + valueStr;
     }
 }



1.7       +17 -15    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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- SimpleTermBuilder.java	2001/11/20 12:32:07	1.6
+++ SimpleTermBuilder.java	2001/11/21 10:46:00	1.7
@@ -1,8 +1,8 @@
 package org.quasiliteral.term;
 
+import org.erights.e.elib.prim.E;
 import org.erights.e.elib.tables.ConstList;
 import org.erights.e.elib.tables.Twine;
-import org.erights.e.elib.prim.E;
 import org.quasiliteral.astro.AstroToken;
 
 /**
@@ -32,7 +32,9 @@
     /**
      * @return false
      */
-    public boolean doesQuasis() { return false; }
+    public boolean doesQuasis() {
+        return false;
+    }
 
     /**
      * @return :[Term*]
@@ -76,7 +78,7 @@
         AstroToken optIdTok = (AstroToken)optIdent;
         AstroToken optLitTok = (AstroToken)optLit;
 
-        String name = null;
+        String tag = null;
         Twine source = null;
         Object value = null;
 
@@ -84,23 +86,21 @@
             //Just a literal
             E.require(null != optLitTok, "can't default entire functor");
             ConstList typeNames = TermParser.getTokenNames();
-            name = (String)typeNames.get(optLitTok.getType());
+            tag = (String)typeNames.get(optLitTok.getType());
             source = optLitTok.getSource();
             value = optLitTok.getValue();
 
         } else {
-            //Has an explicit name (a tagging identifier)
-            if (TermParser.ID != optIdTok.getType()) {
-                throw new RuntimeException("Must be ID: " + optIdTok);
-            }
-            name = (String)optIdTok.getValue();
-            if (null == name) {
-                throw new RuntimeException("Must have value: " + optIdTok);
-            }
+            //Has an explicit tag (a tagging identifier)
+            E.require(TermParser.ID == optIdTok.getType(),
+                      "Must be ID: " + optIdTok);
+            tag = (String)optIdTok.getValue();
+            E.require(null != tag,
+                      "Must have value: " + optIdTok);
             source = (Twine)optIdTok.getSource();
 
             if (null == optLitTok) {
-                //Just a name, all done
+                //Just a tag, all done
             } else {
                 //Has both
                 source = (Twine)source
@@ -109,7 +109,7 @@
                 value = optLitTok.getValue();
             }
         }
-        return new Functor(name, source, value);
+        return new Functor(tag, source, value);
     }
 
     /**
@@ -150,5 +150,7 @@
     /**
      *
      */
-    public String toString() { return "<SimpleTermBuilder>"; }
+    public String toString() {
+        return "<SimpleTermBuilder>";
+    }
 }



1.5       +15 -20    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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Term.java	2001/11/20 12:32:07	1.4
+++ Term.java	2001/11/21 10:46:00	1.5
@@ -1,23 +1,20 @@
 package org.quasiliteral.term;
 
-import org.erights.e.elib.tables.Selfless;
-import org.erights.e.elib.tables.ConstList;
-import org.erights.e.elib.tables.FlexList;
-import org.erights.e.elib.tables.Twine;
-import org.erights.e.elib.tables.ConstMap;
-import org.erights.e.elib.serial.PassByConstruction;
-import org.erights.e.elib.serial.Persistent;
+import antlr.CommonToken;
+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.StaticMaker;
 import org.erights.e.elib.prim.E;
-import org.erights.e.elib.base.EComparable;
-import org.erights.e.develop.format.StringHelper;
+import org.erights.e.elib.prim.StaticMaker;
+import org.erights.e.elib.serial.PassByConstruction;
+import org.erights.e.elib.serial.Persistent;
+import org.erights.e.elib.tables.ConstList;
+import org.erights.e.elib.tables.ConstMap;
+import org.erights.e.elib.tables.FlexList;
+import org.erights.e.elib.tables.Selfless;
 import org.quasiliteral.astro.Astro;
-import antlr.collections.AST;
-import antlr.Grammar;
-import antlr.Token;
-import antlr.CommonToken;
-import antlr.CommonAST;
 
 import java.io.IOException;
 
@@ -79,8 +76,7 @@
      */
     static public Term fromAST(AST ast,
                                String url,
-                               ConstList typeNames)
-    {
+                               ConstList typeNames) {
         Token token;
         if (ast instanceof Astro) {
             token = ((Astro)ast).getToken();
@@ -90,8 +86,7 @@
         FlexList args = FlexList.fromType(Term.class);
         for (AST arg = ast.getFirstChild();
              null != arg;
-             arg = arg.getNextSibling())
-        {
+             arg = arg.getNextSibling()) {
             args.push(Term.fromAST(arg, url, typeNames));
         }
         return new Term(Functor.fromToken(token, url, typeNames),
@@ -191,7 +186,7 @@
      *
      */
     public void prettyPrintOn(TextWriter out, boolean quasiFlag)
-    throws IOException {
+      throws IOException {
         String functorStr = myFunctor.toString(quasiFlag);
         out.print(functorStr);
         int h = getHeight();



1.9       +2 -2      e/src/jsrc/org/quasiliteral/term/Term.updoc

Index: Term.updoc
===================================================================
RCS file: /cvs/e/src/jsrc/org/quasiliteral/term/Term.updoc,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Term.updoc	2001/11/20 12:32:07	1.8
+++ Term.updoc	2001/11/21 10:46:00	1.9
@@ -2,9 +2,9 @@
     # value: term`"foo"`
     
     ? def t2 := term`$t1(4)`
-    # problem: XXX not yet implemented
+    # value: term`# problem: <NullPointerException>
     #
-    #   <QuasiTermBuilder> valueMaker("${0}(4)")
+    #   ....(org.erights.e.develop.exception.NestedException: ...)
     #   <interactive interp> evalPrint(e`def t2 :any := term__quasiParser valueMaker("${0}(4)") substitute(ListMaker run(t1))`)
     
     ? def t3 := term`$t1(bar, $t2)`



1.6       +6 -6      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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- TermBuilder.java	2001/11/20 12:32:07	1.5
+++ TermBuilder.java	2001/11/21 10:46:00	1.6
@@ -1,7 +1,7 @@
 package org.quasiliteral.term;
 
-import org.quasiliteral.astro.AstroToken;
 
+
 /**
  * Used by the actions of term.y / TermParser.
  * <p>
@@ -13,7 +13,7 @@
  * The arguments and return types are all 'Object' below, because the actual
  * types are to be determined by the subclasses.  However, these choices
  * need to be consistent.  We express the required consistency using pretend
- * parameterized types encoded in the javadoc comments.  The types names are
+ * parameterized types encoded in the javadoc comments.  The types tags are
  * based on the productions in term.y.  Concrete subclasses should say what
  * concrete types they use for these parameterized types.
  * <p>
@@ -84,11 +84,11 @@
     Object term(Object fnctr, Object args);
 
     /**
-     * Returns a representation of the functor whose type name is optIdent's
+     * Returns a representation of the functor whose type tag is optIdent's
      * value, and whose value is optLit's value.
      * <p>
      * At least one of optIdent and optLit must not be null.  If optIdent is
-     * null and optLit is literal, optIdent defaults to the name of the
+     * null and optLit is literal, optIdent defaults to the tag of the
      * name of optLit's literal type.  If optLit is null, then, in a pattern,
      * it means "don't-care".  In a non-pattern usage, null just means
      * "no-data".
@@ -113,7 +113,7 @@
      * <p>
      * This should extract the maximal list of matching terms from the
      * specimen, within the constraints of the quantity indicator and
-     * the term-hole's optional type name.
+     * the term-hole's optional type tag.
      *
      * @param optTerm :(PTermHole | null)
      * @param quant :AstroToken('?', '+', or '*')
@@ -125,7 +125,7 @@
      * Promotes a functor-hole to a term-hole.
      * <p>
      * If the optIdent is provided, then it constrains the hole to only match
-     * Terms whose functor has that name.
+     * Terms whose functor has that tag.
      *
      * @param optIdent :(AstroToken(ID) | null)
      * @param fnctrHole :PFunctorHole



1.6       +163 -123  e/src/jsrc/org/quasiliteral/term/TermLexer.java

Index: TermLexer.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/quasiliteral/term/TermLexer.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- TermLexer.java	2001/11/19 19:15:35	1.5
+++ TermLexer.java	2001/11/21 10:46:00	1.6
@@ -2,16 +2,14 @@
 
 import org.erights.e.develop.exception.PrintStreamWriter;
 import org.erights.e.develop.exception.ThrowableSugar;
-import org.erights.e.develop.exception.ExceptionMgr;
-import org.erights.e.elib.eio.TextWriter;
-import org.erights.e.elib.tables.Twine;
-import org.erights.e.elang.syntax.LineFeeder;
+import org.erights.e.elang.syntax.FileFeeder;
 import org.erights.e.elang.syntax.Indenter;
-import org.erights.e.elang.syntax.TwineFeeder;
+import org.erights.e.elang.syntax.LineFeeder;
 import org.erights.e.elang.syntax.SyntaxException;
-import org.erights.e.elang.syntax.FileFeeder;
+import org.erights.e.elang.syntax.TwineFeeder;
+import org.erights.e.elib.eio.TextWriter;
+import org.erights.e.elib.tables.Twine;
 import org.quasiliteral.astro.AstroToken;
-import org.quasiliteral.term.TermParser;
 
 import java.io.BufferedReader;
 import java.io.FileReader;
@@ -83,7 +81,7 @@
      * @param quasiFlag Should doubled @ and $ be collapsed to singles?
      */
     public TermLexer(LineFeeder input, boolean quasiFlag)
-    throws IOException {
+      throws IOException {
 
         myInput = input;
         myPos = -1;
@@ -226,13 +224,13 @@
      *
      */
     /*package*/ void syntaxError(String msg)
-    throws SyntaxException {
+      throws SyntaxException {
         int start = myOptStartPos;
         if (-1 == start) {
-            start = myPos -1;
+            start = myPos - 1;
         }
-        start = Math.max(Math.min(start, myPos -1), 0);
-        int bound = Math.max(myPos, start +1);
+        start = Math.max(Math.min(start, myPos - 1), 0);
+        int bound = Math.max(myPos, start + 1);
         SyntaxException sex = new SyntaxException(msg,
                                                   myLTwine,
                                                   start,
@@ -275,7 +273,7 @@
      */
     private boolean isWhite(int start, int bound) {
         for (int i = start; i < bound; i++) {
-            if (! Character.isWhitespace(myLData[i])) {
+            if (!Character.isWhitespace(myLData[i])) {
                 return false;
             }
         }
@@ -289,45 +287,64 @@
         skipWhiteSpace();
         startToken();
 
-        switch(myChar) {
+        switch (myChar) {
             case ',':
             case ':':
             case '$':
             case '@':
             case '?':
             case '+':
-            case '*': {
-                char c = (char)myChar;
-                nextChar();
-                return new AstroToken(c, endToken());
-            } case EOFCHAR: {
-                return new AstroToken(TermParser.EOFTOK, Twine.fromString(""));
-            } case '(': {
-                return openBracket(')');
-            } case ')': {
-                return closeBracket();
-            } case '{': {
-                return openBracket('}');
-            } case '}': {
-                return closeBracket();
-            } case '#': {
-                // Skip comment to end of line (as in "//" case above).
-                skipLine();
-                stopToken();
-                return getNextToken();
-            } case '\\': {
-                nextChar();
-                if (myChar == 'u' || myChar == 'U') {
-                    syntaxError("\\u... not yet implemented");
+            case '*':
+                {
+                    char c = (char)myChar;
+                    nextChar();
+                    return new AstroToken(c, endToken());
+                }
+            case EOFCHAR:
+                {
+                    return new AstroToken(TermParser.EOFTOK, Twine.fromString(""));
+                }
+            case '(':
+                {
+                    return openBracket(')');
+                }
+            case ')':
+                {
+                    return closeBracket();
+                }
+            case '{':
+                {
+                    return openBracket('}');
+                }
+            case '}':
+                {
+                    return closeBracket();
+                }
+            case '#':
+                {
+                    // Skip comment to end of line (as in "//" case above).
+                    skipLine();
+                    stopToken();
+                    return getNextToken();
+                }
+            case '\\':
+                {
+                    nextChar();
+                    if (myChar == 'u' || myChar == 'U') {
+                        syntaxError("\\u... not yet implemented");
+                        return null; //keep compiler happy
+                    }
+                    syntaxError("unrecognized escape");
                     return null; //keep compiler happy
                 }
-                syntaxError("unrecognized escape");
-                return null; //keep compiler happy
-            } case '\'': {
-                return charLiteral();
-            } case '"': {
-                return stringLiteral();
-            }
+            case '\'':
+                {
+                    return charLiteral();
+                }
+            case '"':
+                {
+                    return stringLiteral();
+                }
             case '0':
             case '1':
             case '2':
@@ -337,18 +354,21 @@
             case '6':
             case '7':
             case '8':
-            case '9': {
-                return numberLiteral();
+            case '9':
+                {
+                    return numberLiteral();
 
-            } default: {
-                if (isIdentifierStart((char)myChar)) {
-                    return identifier();
-                } else {
-                    syntaxError("unrecognized character: '" + (char)myChar +
-                                "' code: " + (int)myChar);
-                    return null; //keep compiler happy
                 }
-            }
+            default:
+                {
+                    if (isIdentifierStart((char)myChar)) {
+                        return identifier();
+                    } else {
+                        syntaxError("unrecognized character: '" + (char)myChar +
+                                    "' code: " + (int)myChar);
+                        return null; //keep compiler happy
+                    }
+                }
         }
     }
 
@@ -366,7 +386,7 @@
      *
      */
     private AstroToken openBracket(int tokenType, Twine openner, char closer)
-    throws IOException {
+      throws IOException {
         if (isWhite(myPos, myLData.length)) {
             myIndenter.nest(openner, closer);
         } else {
@@ -394,64 +414,80 @@
      */
     private char charConstant() throws IOException, SyntaxException {
         switch (myChar) {
-            case '\\': {
-                nextChar();
-                switch(myChar) {
-                    case 'b': return '\b';
-                    case 't': return '\t';
-                    case 'n': return '\n';
-                    case 'f': return '\f';
-                    case 'r': return '\r';
-                    case '"': return '"';
-                    case '\'': return '\'';
-                    case '\\': return '\\';
-                    case '\n': {
-                        //XXX need to move into stringLiteral only
-                        //XXX bug: must be accepted at end of string
-                        nextChar();
-                        return charConstant();
-                    }
-                    case EOFCHAR: {
-                        syntaxError("End of file in middle of literal");
-                    }
-                    case 'u': {
-                        syntaxError
-                          ("XXX escaped uchar codes not yet implemented");
-                    }
-                    default: {
-                        if (Character.isDigit((char)myChar)) {
-                            syntaxError
-                              ("XXX escaped char codes not yet implemented");
-                        } else {
-                            syntaxError("Unrecognized escaped character");
-                        }
+            case '\\':
+                {
+                    nextChar();
+                    switch (myChar) {
+                        case 'b':
+                            return '\b';
+                        case 't':
+                            return '\t';
+                        case 'n':
+                            return '\n';
+                        case 'f':
+                            return '\f';
+                        case 'r':
+                            return '\r';
+                        case '"':
+                            return '"';
+                        case '\'':
+                            return '\'';
+                        case '\\':
+                            return '\\';
+                        case '\n':
+                            {
+                                //XXX need to move into stringLiteral only
+                                //XXX bug: must be accepted at end of string
+                                nextChar();
+                                return charConstant();
+                            }
+                        case EOFCHAR:
+                            {
+                                syntaxError("End of file in middle of literal");
+                            }
+                        case 'u':
+                            {
+                                syntaxError
+                                  ("XXX escaped uchar codes not yet implemented");
+                            }
+                        default:
+                            {
+                                if (Character.isDigit((char)myChar)) {
+                                    syntaxError
+                                      ("XXX escaped char codes not yet implemented");
+                                } else {
+                                    syntaxError("Unrecognized escaped character");
+                                }
+                            }
                     }
                 }
-            }
             case '$':
             case '@':
-            case '`': {
-                char c = (char)myChar;
-                if (myQuasiFlag) {
-                    nextChar();
-                    if (c == myChar) {
-                        //collapse double to single
-                        return c;
+            case '`':
+                {
+                    char c = (char)myChar;
+                    if (myQuasiFlag) {
+                        nextChar();
+                        if (c == myChar) {
+                            //collapse double to single
+                            return c;
+                        } else {
+                            //require double
+                            syntaxError("Expected: " + c + c);
+                        }
                     } else {
-                        //require double
-                        syntaxError("Expected: " + c + c);
+                        //treat as a normal character
+                        return c;
                     }
-                } else {
-                    //treat as a normal character
-                    return c;
                 }
-            }
-            case EOFCHAR: {
-                syntaxError("End of file in middle of literal");
-            }
-            default: {
-                return (char)myChar;
-            }
+            case EOFCHAR:
+                {
+                    syntaxError("End of file in middle of literal");
+                }
+            default:
+                {
+                    return (char)myChar;
+                }
         }
     }
 
@@ -467,8 +503,8 @@
         }
         nextChar();
         return new AstroToken(TermParser.LiteralChar,
-                             endToken(),
-                             new Character(value));
+                              endToken(),
+                              new Character(value));
     }
 
     /**
@@ -518,11 +554,11 @@
         if (len <= 0) {
             return false;
         }
-        if (! isIdentifierStart(str.charAt(0))) {
+        if (!isIdentifierStart(str.charAt(0))) {
             return false;
         }
         for (int i = 1; i < len; i++) {
-            if (! isIdentifierPart(str.charAt(i))) {
+            if (!isIdentifierPart(str.charAt(i))) {
                 return false;
             }
         }
@@ -533,7 +569,7 @@
      *
      */
     private AstroToken numberLiteral()
-    throws IOException, SyntaxException {
+      throws IOException, SyntaxException {
         // Now handles floating point numbers as well as integers
         boolean floating = false;
         int radix = 10;
@@ -546,15 +582,18 @@
             }
         }
         if (radix == 16) {
-            while (eatDigit(16)) {}
+            while (eatDigit(16)) {
+            }
         } else {
             //even if radix == 8, we may instead have a floating point literal
-            while (eatDigit(10)) {}
+            while (eatDigit(10)) {
+            }
             // If we have a decimal point go for the fractional part
-            if (myChar == '.' && ! peekChar('.')) {
+            if (myChar == '.' && !peekChar('.')) {
                 nextChar();
                 floating = true;
-                while (eatDigit(10)) {}
+                while (eatDigit(10)) {
+                }
             }
 
             if ((myChar == 'E') || (myChar == 'e')) {
@@ -562,8 +601,9 @@
                 floating = true;
                 if (myChar == '-') {
                     nextChar();
+                }
+                while (eatDigit(10)) {
                 }
-                while (eatDigit(10)) {}
             }
         }
         Twine tok = endToken();
@@ -590,10 +630,10 @@
         if (myChar == EOFCHAR || myChar == '\n') {
             throw new Error("internal: can't peek here");
         }
-        int last = myLData.length -1;
+        int last = myLData.length - 1;
 
         if (myPos < last) {
-            return myLData[myPos +1];
+            return myLData[myPos + 1];
         } else {
             throw new Error("internal: (XXX bug) peek past end");
         }
@@ -606,10 +646,10 @@
         if (myChar == EOFCHAR || myChar == '\n') {
             throw new Error("internal: can't peek here");
         }
-        int last = myLData.length -1;
+        int last = myLData.length - 1;
 
         if (myPos < last) {
-            return c == myLData[myPos +1];
+            return c == myLData[myPos + 1];
         } else {
             return false;
         }
@@ -620,7 +660,7 @@
      */
     private void skipLine() throws IOException {
         if (null != myLTwine) {
-            myPos = myLData.length -1;
+            myPos = myLData.length - 1;
             myChar = myLData[myPos];
         }
         nextChar();
@@ -696,7 +736,7 @@
      * to stdout.
      */
     static public void main(String[] args)
-    throws IOException, SyntaxException {
+      throws IOException, SyntaxException {
 
         TextWriter stdout = new TextWriter(PrintStreamWriter.out(), true);
         String url;
@@ -709,7 +749,7 @@
             ins = new BufferedReader(new FileReader(args[0]));
         } else {
             throw new RuntimeException
-                ("usage: java org.quasiliteral.term.TermLexer file");
+              ("usage: java org.quasiliteral.term.TermLexer file");
         }
         LineFeeder lr = new FileFeeder(url, ins, stdout);
         TermLexer lex = new TermLexer(lr, false);