[e-cvs] cvs commit: e/src/jsrc/org/quasiliteral/term QuasiBuilder.java QuasiBuilderAdaptor.java Term.java Term.updoc TermBuilder.java TermParser.java term.y
markm@eros.cs.jhu.edu
markm@eros.cs.jhu.edu
Wed, 19 Dec 2001 05:18:08 -0500
markm 01/12/19 05:18:08
Modified: src/jsrc/org/erights/e/develop/format StringHelper.java
src/jsrc/org/erights/e/elang/evm CdrPattern.java
EMethodNode.java ListPattern.java
src/jsrc/org/erights/e/elang/interp Help.java
ScopeSetup.java
src/jsrc/org/erights/e/elang/scope OuterScope.java
Scope.java
src/jsrc/org/erights/e/elib/base ClassDesc.java
MessageDesc.java ParamDesc.java
src/jsrc/org/erights/e/elib/prim ConstructorNode.java
InstanceMethodNode.java JavaMemberNode.java
StaticMethodNode.java SugarMethodNode.java
src/jsrc/org/quasiliteral/quasiterm QAstroArg.java
QBuilder.java QTerm.java
src/jsrc/org/quasiliteral/term QuasiBuilder.java
QuasiBuilderAdaptor.java Term.java Term.updoc
TermBuilder.java TermParser.java term.y
Log:
quasiliteral terms with no holes or ranking operators seem to work
Revision Changes Path
1.4 +15 -0 e/src/jsrc/org/erights/e/develop/format/StringHelper.java
Index: StringHelper.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/develop/format/StringHelper.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- StringHelper.java 2001/11/10 19:40:39 1.3
+++ StringHelper.java 2001/12/19 10:18:06 1.4
@@ -145,4 +145,19 @@
buf.append('\"');
return buf.toString();
}
+
+ /**
+ * Return name prefixed by "a " or "an " according to a simple (and
+ * therefore inadequate) heuristic, but good enough for cheezy uses.
+ * <p>
+ * Note that this routine is not expected to internationalize well.
+ */
+ static public String aan(String name) {
+ char c = Character.toLowerCase(name.charAt(0));
+ if (name.length() >= 1 && "aeiouh".indexOf(c) != -1) {
+ return "an " + name;
+ } else {
+ return "a " + name;
+ }
+ }
}
1.19 +1 -2 e/src/jsrc/org/erights/e/elang/evm/CdrPattern.java
Index: CdrPattern.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/elang/evm/CdrPattern.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- CdrPattern.java 2001/12/18 21:59:30 1.18
+++ CdrPattern.java 2001/12/19 10:18:06 1.19
@@ -21,14 +21,13 @@
import org.erights.e.elang.scope.EvalContext;
import org.erights.e.elang.visitors.ETreeVisitor;
+import org.erights.e.elib.base.ClassDesc;
import org.erights.e.elib.eio.TextWriter;
import org.erights.e.elib.prim.Thrower;
import org.erights.e.elib.ref.Ref;
-import org.erights.e.elib.tables.ConstList;
import org.erights.e.elib.tables.EList;
import org.erights.e.elib.tables.FlexList;
import org.erights.e.elib.util.OneArgFunc;
-import org.erights.e.elib.base.ClassDesc;
import java.io.IOException;
1.29 +1 -1 e/src/jsrc/org/erights/e/elang/evm/EMethodNode.java
Index: EMethodNode.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/elang/evm/EMethodNode.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- EMethodNode.java 2001/12/18 21:59:30 1.28
+++ EMethodNode.java 2001/12/19 10:18:06 1.29
@@ -20,8 +20,8 @@
*/
import org.erights.e.develop.exception.ExceptionMgr;
-import org.erights.e.elib.base.MethodNode;
import org.erights.e.elib.base.MessageDesc;
+import org.erights.e.elib.base.MethodNode;
import org.erights.e.elib.tables.FlexMap;
1.17 +1 -2 e/src/jsrc/org/erights/e/elang/evm/ListPattern.java
Index: ListPattern.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/elang/evm/ListPattern.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- ListPattern.java 2001/12/18 21:59:30 1.16
+++ ListPattern.java 2001/12/19 10:18:06 1.17
@@ -21,14 +21,13 @@
import org.erights.e.elang.scope.EvalContext;
import org.erights.e.elang.visitors.ETreeVisitor;
+import org.erights.e.elib.base.ClassDesc;
import org.erights.e.elib.eio.TextWriter;
import org.erights.e.elib.prim.Thrower;
import org.erights.e.elib.ref.Ref;
-import org.erights.e.elib.tables.ConstList;
import org.erights.e.elib.tables.EList;
import org.erights.e.elib.tables.FlexList;
import org.erights.e.elib.util.OneArgFunc;
-import org.erights.e.elib.base.ClassDesc;
import java.io.IOException;
1.22 +1 -15 e/src/jsrc/org/erights/e/elang/interp/Help.java
Index: Help.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/elang/interp/Help.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- Help.java 2001/12/18 21:59:30 1.21
+++ Help.java 2001/12/19 10:18:06 1.22
@@ -46,20 +46,6 @@
}
/**
- * Return name prefixed by "a " or "an " according to a simple (and
- * therefore inadequate) heuristic. But good enough for cheezy uses.
- * Note that this routine is not expected to internationalize well.
- */
- static public String aan(String name) {
- char c = Character.toLowerCase(name.charAt(0));
- if (name.length() >= 1 && "aeiouh".indexOf(c) != -1) {
- return "an " + name;
- } else {
- return "a " + name;
- }
- }
-
- /**
*
*/
public UnQuote run(Object subject) throws IOException {
@@ -78,7 +64,7 @@
if (null == subject) {
out.println("a null");
} else {
- out.println(aan(subject.getClass().getName()));
+ out.println(StringHelper.aan(subject.getClass().getName()));
}
if (Ref.isNear(subject)) {
TypeDesc type
1.82 +2 -2 e/src/jsrc/org/erights/e/elang/interp/ScopeSetup.java
Index: ScopeSetup.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/elang/interp/ScopeSetup.java,v
retrieving revision 1.81
retrieving revision 1.82
diff -u -r1.81 -r1.82
--- ScopeSetup.java 2001/12/14 00:06:00 1.81
+++ ScopeSetup.java 2001/12/19 10:18:07 1.82
@@ -55,6 +55,7 @@
import org.erights.e.elib.tables.Twine;
import org.erights.e.elib.util.ClassCache;
import org.erights.e.meta.java.io.FileGetter;
+import org.quasiliteral.quasiterm.QBuilder;
import org.quasiliteral.text.SimpleQuasiParser;
/**
@@ -182,8 +183,7 @@
um.comp("epatt__quasiParser", univ,
"<import:org.erights.e.elang.syntax.epatt__quasiParser>");
um.comp("sml__quasiParser", XMLQuasiParser.XMLQuasiParserMaker);
- um.comp("term__quasiParser", univ,
- "<import:org.quasiliteral.quasiterm.term__quasiParser>");
+ um.comp("term__quasiParser", QBuilder.term__quasiParser);
um.init("universalScope", univ); // not uconstant
OuterScope realUniv = um.scope();
1.11 +0 -1 e/src/jsrc/org/erights/e/elang/scope/OuterScope.java
Index: OuterScope.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/elang/scope/OuterScope.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- OuterScope.java 2001/12/19 03:25:38 1.10
+++ OuterScope.java 2001/12/19 10:18:07 1.11
@@ -23,7 +23,6 @@
import org.erights.e.elang.evm.OuterNounExpr;
import org.erights.e.elib.eio.TextWriter;
import org.erights.e.elib.slot.Slot;
-import org.erights.e.elib.tables.ConstMap;
import org.erights.e.elib.util.AlreadyDefinedException;
import java.io.IOException;
1.56 +1 -2 e/src/jsrc/org/erights/e/elang/scope/Scope.java
Index: Scope.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/elang/scope/Scope.java,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -r1.55 -r1.56
--- Scope.java 2001/12/19 03:25:38 1.55
+++ Scope.java 2001/12/19 10:18:07 1.56
@@ -22,7 +22,6 @@
import org.erights.e.develop.format.StringHelper;
import org.erights.e.elang.evm.ENode;
import org.erights.e.elang.evm.NounExpr;
-import org.erights.e.elang.interp.Help;
import org.erights.e.elang.interp.ScopeSetup;
import org.erights.e.elib.base.ClassDesc;
import org.erights.e.elib.eio.EPrintable;
@@ -176,7 +175,7 @@
out.print("null");
} else {
String sig = ClassDesc.typeSig(optValue.getClass());
- out.print(Help.aan(sig));
+ out.print(StringHelper.aan(sig));
}
} catch (Exception ex) {
out.print("*** ", ex);
1.38 +2 -2 e/src/jsrc/org/erights/e/elib/base/ClassDesc.java
Index: ClassDesc.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/elib/base/ClassDesc.java,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- ClassDesc.java 2001/12/19 03:25:38 1.37
+++ ClassDesc.java 2001/12/19 10:18:07 1.38
@@ -22,6 +22,7 @@
*/
import org.erights.e.develop.exception.ExceptionMgr;
+import org.erights.e.develop.format.StringHelper;
import org.erights.e.elib.prim.ScriptMaker;
import org.erights.e.elib.prim.Thrower;
import org.erights.e.elib.ref.Ref;
@@ -39,7 +40,6 @@
import org.erights.e.elib.util.OneArgFunc;
import org.erights.e.meta.java.lang.ArrayGuardSugar;
import org.erights.e.meta.java.lang.InterfaceGuardSugar;
-import org.erights.e.elang.interp.Help;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
@@ -430,7 +430,7 @@
throw Thrower.toEject(optEjector,
new ClassCastException(specTypeName +
" doesn't coerce to " +
- Help.aan(getName())));
+ StringHelper.aan(getName())));
}
/**
1.15 +1 -1 e/src/jsrc/org/erights/e/elib/base/MessageDesc.java
Index: MessageDesc.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/elib/base/MessageDesc.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- MessageDesc.java 2001/12/18 21:59:30 1.14
+++ MessageDesc.java 2001/12/19 10:18:07 1.15
@@ -22,8 +22,8 @@
*/
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.prim.StaticMaker;
import org.erights.e.elib.serial.Persistent;
import org.erights.e.elib.slot.ValueGuard;
import org.erights.e.elib.slot.VoidMaker;
1.15 +1 -1 e/src/jsrc/org/erights/e/elib/base/ParamDesc.java
Index: ParamDesc.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/elib/base/ParamDesc.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- ParamDesc.java 2001/12/18 21:59:30 1.14
+++ ParamDesc.java 2001/12/19 10:18:07 1.15
@@ -22,8 +22,8 @@
*/
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.prim.StaticMaker;
import org.erights.e.elib.serial.Persistent;
import org.erights.e.elib.slot.SimpleSlotMaker;
import org.erights.e.elib.slot.SlotGuard;
1.20 +1 -1 e/src/jsrc/org/erights/e/elib/prim/ConstructorNode.java
Index: ConstructorNode.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/elib/prim/ConstructorNode.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- ConstructorNode.java 2001/12/19 03:25:38 1.19
+++ ConstructorNode.java 2001/12/19 10:18:07 1.20
@@ -24,8 +24,8 @@
import org.erights.e.elib.util.AlreadyDefinedException;
import java.lang.reflect.Constructor;
-import java.lang.reflect.Modifier;
import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Modifier;
/**
* Turns a java constructor into a "new" method on the corresponding
1.19 +1 -1 e/src/jsrc/org/erights/e/elib/prim/InstanceMethodNode.java
Index: InstanceMethodNode.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/elib/prim/InstanceMethodNode.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- InstanceMethodNode.java 2001/12/19 03:25:38 1.18
+++ InstanceMethodNode.java 2001/12/19 10:18:07 1.19
@@ -24,9 +24,9 @@
import org.erights.e.elib.util.AlreadyDefinedException;
import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
-import java.lang.reflect.InvocationTargetException;
/**
* How a java instance method is installed in a VTable
1.35 +1 -1 e/src/jsrc/org/erights/e/elib/prim/JavaMemberNode.java
Index: JavaMemberNode.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/elib/prim/JavaMemberNode.java,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- JavaMemberNode.java 2001/12/19 03:25:38 1.34
+++ JavaMemberNode.java 2001/12/19 10:18:07 1.35
@@ -31,8 +31,8 @@
import org.erights.e.elib.util.OneArgFunc;
import java.io.IOException;
-import java.lang.reflect.Member;
import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Member;
import java.math.BigInteger;
1.23 +1 -1 e/src/jsrc/org/erights/e/elib/prim/StaticMethodNode.java
Index: StaticMethodNode.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/elib/prim/StaticMethodNode.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- StaticMethodNode.java 2001/12/19 03:25:38 1.22
+++ StaticMethodNode.java 2001/12/19 10:18:07 1.23
@@ -24,9 +24,9 @@
import org.erights.e.elib.util.AlreadyDefinedException;
import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
-import java.lang.reflect.InvocationTargetException;
/**
* How a java static is made to appear as an instance method of an
1.21 +1 -1 e/src/jsrc/org/erights/e/elib/prim/SugarMethodNode.java
Index: SugarMethodNode.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/elib/prim/SugarMethodNode.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- SugarMethodNode.java 2001/12/19 03:25:38 1.20
+++ SugarMethodNode.java 2001/12/19 10:18:07 1.21
@@ -28,9 +28,9 @@
import java.io.IOException;
import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
-import java.lang.reflect.InvocationTargetException;
/**
1.2 +104 -5 e/src/jsrc/org/quasiliteral/quasiterm/QAstroArg.java
Index: QAstroArg.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/quasiliteral/quasiterm/QAstroArg.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- QAstroArg.java 2001/12/18 21:59:31 1.1
+++ QAstroArg.java 2001/12/19 10:18:08 1.2
@@ -1,16 +1,22 @@
package org.quasiliteral.quasiterm;
+import org.erights.e.develop.assertion.T;
+import org.erights.e.develop.exception.ExceptionMgr;
import org.erights.e.elib.eio.TextWriter;
import org.erights.e.elib.serial.PassByConstruction;
import org.erights.e.elib.serial.Persistent;
-import org.erights.e.elib.tables.Selfless;
-import org.erights.e.elib.tables.Twine;
import org.erights.e.elib.tables.ConstList;
import org.erights.e.elib.tables.FlexList;
+import org.erights.e.elib.tables.Selfless;
+import org.erights.e.elib.tables.Twine;
+import org.quasiliteral.astro.AstroArg;
+import org.quasiliteral.astro.AstroBuilder;
import org.quasiliteral.base.MatchMaker;
import org.quasiliteral.base.ValueMaker;
+import org.quasiliteral.term.QuasiBuilder;
import java.io.IOException;
+import java.io.StringWriter;
//This file is hereby placed in the public domain
@@ -20,23 +26,57 @@
*/
public abstract class QAstroArg
implements Selfless, PassByConstruction, Persistent,
- ValueMaker, MatchMaker {
+ AstroArg, ValueMaker, MatchMaker {
+
+ /**
+ * @serial Builds Terms using the Schema derived from myTag.
+ */
+ /*package*/
+ final AstroBuilder myBuilder;
/**
* @serial What source text was originally lexed or parsed to produce
* this node?
*/
- protected final Twine mySource;
+ /*package*/
+ final Twine mySource;
/**
*
+ * @param builder For building the result of a substitute.
* @param source The source text this node was extracted from. To
* provide no info, use "" rather than null.
*/
- public QAstroArg(Twine source) {
+ public QAstroArg(AstroBuilder builder, Twine source) {
+ myBuilder = builder;
mySource = source;
}
+ /**
+ * @return :Astro
+ */
+ public Object substitute(Object[] args) {
+ ConstList list = substSlice(args, "");
+ T.require(list.size() == 1,
+ "Must be singleton: ", list);
+ return list.get(0);
+ }
+
+ /**
+ * @param args Each arg[i] is of a type matched to the corresponding
+ * dollar-hole. For example, if dollar-hole 3 (ie "${3}")
+ * has rank "?*+", then args[3] must be a list of lists of
+ * lists of terms, for which the outer list may only be zero
+ * or one long, the middle lists may be any length, and the
+ * inner lists must all have at least one element.
+ * @param rank :String(('?'|'+'|'*')*)
+ * @return :(ConstList of(Astro))
+ */
+ public abstract ConstList substSlice(Object[] args, String rank);
+
+ /**
+ *
+ */
public ConstList matchBind(Object[] args, Object specimen) {
FlexList bindings = FlexList.make();
if (matchBind(args, specimen, bindings)) {
@@ -47,6 +87,39 @@
}
/**
+ *
+ * @param args See the doc on 'args' in {@link #substitute(Object[],
+ * String)}
+ * @param specimen :Astro
+ * @param bindings Like 'args', but by extraction from specimen
+ * @return Do we have a match?
+ */
+ public boolean matchBind(Object[] args,
+ Object specimen,
+ FlexList bindings) {
+ return 1 == matchBindSlice(args,
+ ConstList.EmptyList.with(specimen),
+ bindings,
+ "");
+ }
+
+ /**
+ *
+ * @param args See the doc on 'args' in {@link #substitute(Object[],
+ * String)}
+ * @param specimenList :(ConstList of(Astro))
+ * @param bindings Like 'args', but by extraction from specimen
+ * @param rank :String(('?'|'+'|'*')*)
+ * @return How many elements of specimen are matched? Zero indicates a
+ * successful match of no elements, so -1 is used to instead
+ * indicate a failed match.
+ */
+ public abstract int matchBindSlice(Object[] args,
+ ConstList specimenList,
+ FlexList bindings,
+ String rank);
+
+ /**
* What source text was originally lexed or parsed to produce this node,
* or a representative token of this node?
*/
@@ -57,10 +130,36 @@
/**
*
*/
+ public abstract AstroArg qbuild(QuasiBuilder qbuilder);
+
+ /**
+ * What's the longest distance to the bottom?
+ * <p>
+ * A leaf node is height 1. All other nodes are one more than the height
+ * of their highest child. This is used for pretty printing.
+ */
+ public abstract int getHeight();
+
+ /**
+ *
+ */
public void printOn(TextWriter out) throws IOException {
out.print("term`");
prettyPrintOn(out.indent(" "));
out.print("`");
+ }
+
+ /**
+ *
+ */
+ public String asText() {
+ StringWriter strWriter = new StringWriter();
+ try {
+ prettyPrintOn(new TextWriter(strWriter));
+ } catch (Throwable th) {
+ throw ExceptionMgr.asSafe(th);
+ }
+ return strWriter.getBuffer().toString();
}
/**
1.2 +116 -13 e/src/jsrc/org/quasiliteral/quasiterm/QBuilder.java
Index: QBuilder.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/quasiliteral/quasiterm/QBuilder.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- QBuilder.java 2001/12/18 21:59:31 1.1
+++ QBuilder.java 2001/12/19 10:18:08 1.2
@@ -1,12 +1,20 @@
package org.quasiliteral.quasiterm;
-import org.quasiliteral.astro.BaseBuilder;
+import org.erights.e.elib.tables.EList;
+import org.erights.e.elib.tables.FlexList;
+import org.erights.e.elib.tables.Twine;
import org.quasiliteral.astro.Astro;
-import org.quasiliteral.astro.AstroTag;
import org.quasiliteral.astro.AstroArg;
-import org.quasiliteral.astro.AstroSchema;
+import org.quasiliteral.astro.AstroBuilder;
+import org.quasiliteral.astro.AstroTag;
+import org.quasiliteral.astro.BaseBuilder;
+import org.quasiliteral.base.MatchMaker;
+import org.quasiliteral.base.QuasiExprParser;
+import org.quasiliteral.base.QuasiPatternParser;
+import org.quasiliteral.base.ValueMaker;
import org.quasiliteral.term.QuasiBuilder;
-import org.erights.e.elib.tables.Twine;
+import org.quasiliteral.term.TermBuilder;
+import org.quasiliteral.term.TermParser;
//This file is hereby placed in the public domain
@@ -14,57 +22,152 @@
*
* @author <a href="mailto:markm@caplet.com">Mark Miller</a>
*/
-public class QBuilder extends BaseBuilder implements QuasiBuilder {
+public class QBuilder extends BaseBuilder
+ implements QuasiBuilder, QuasiExprParser, QuasiPatternParser {
+
+ /**
+ *
+ */
+ static public QBuilder term__quasiParser =
+ new QBuilder(TermBuilder.FOR_TERMS);
+
+ /**
+ *
+ */
+ private final AstroBuilder myBuilder;
+
+ /**
+ *
+ */
+ public QBuilder(AstroBuilder builder) {
+ super(builder.getSchema());
+ myBuilder = builder;
+ }
+
+ /**
+ *
+ */
+ public ValueMaker valueMaker(Twine template, int[] dlrHoles) {
+ throw new RuntimeException
+ ("XXX new quasi valueMaker API not yet implemented");
+ }
/**
*
*/
- public QBuilder(AstroSchema schema) {
- super(schema);
+ public ValueMaker valueMaker(Twine template) {
+ return (QAstro)TermParser.run(template, this);
}
+ /**
+ *
+ */
+ public MatchMaker matchMaker(Twine template,
+ int[] dlrHoles,
+ int[] atHoles) {
+ throw new RuntimeException
+ ("XXX new quasi matchMaker API not yet implemented");
+ }
+
+ /**
+ *
+ */
+ public MatchMaker matchMaker(Twine template) {
+ return (QAstro)TermParser.run(template, this);
+ }
+
+ /**
+ *
+ */
protected Astro leafInternal(AstroTag tag,
Object optData,
Twine source) {
- throw new RuntimeException("XXX not yet implemented");
+ return new QFunctor(myBuilder, tag, optData, source);
+ }
+
+ /**
+ * For QTerms, this is non-atomic
+ */
+ public Astro composite(AstroTag tag, Object data, Twine source) {
+ return term(leafTag(tag, source),
+ list(leafData(data, source)));
}
+ /**
+ *
+ */
public Astro term(Astro leaf, Object args) {
- throw new RuntimeException("XXX not yet implemented");
+ return new QTerm(myBuilder, (QAstro)leaf, ((EList)args).snapshot());
}
+ /**
+ *
+ */
public boolean doesQuasis() {
- throw new RuntimeException("XXX not yet implemented");
+ return true;
}
+ /**
+ *
+ */
public Object list() {
- throw new RuntimeException("XXX not yet implemented");
+ return FlexList.fromType(QAstroArg.class);
+ }
+
+ /**
+ *
+ */
+ public Object with(Object list, AstroArg next) {
+ FlexList result = (FlexList)list;
+ result.push(next);
+ return result;
}
+ /**
+ *
+ */
public Astro termHole(Astro optIdent, Astro functorHole) {
throw new RuntimeException("XXX not yet implemented");
}
- public Object with(Object list, AstroArg next) {
+ /**
+ *
+ */
+ public AstroArg alt(AstroArg leftArg, AstroArg rightArg) {
throw new RuntimeException("XXX not yet implemented");
}
- public AstroArg alt(AstroArg leftArg, AstroArg rightArg) {
+ /**
+ *
+ */
+ public AstroArg bag(AstroArg leftArg, AstroArg rightArg) {
throw new RuntimeException("XXX not yet implemented");
}
+ /**
+ *
+ */
public AstroArg seq(Astro optTerm, String quant) {
throw new RuntimeException("XXX not yet implemented");
}
+ /**
+ *
+ */
public AstroArg group(Object args, String quant) {
throw new RuntimeException("XXX not yet implemented");
}
+ /**
+ *
+ */
public Astro dollarHole(Astro litInt) {
throw new RuntimeException("XXX not yet implemented");
}
+ /**
+ *
+ */
public Astro atHole(Astro litInt) {
throw new RuntimeException("XXX not yet implemented");
}
1.2 +119 -117 e/src/jsrc/org/quasiliteral/quasiterm/QTerm.java
Index: QTerm.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/quasiliteral/quasiterm/QTerm.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- QTerm.java 2001/12/18 21:59:31 1.1
+++ QTerm.java 2001/12/19 10:18:08 1.2
@@ -3,54 +3,43 @@
import org.erights.e.develop.assertion.T;
import org.erights.e.develop.format.StringHelper;
import org.erights.e.elib.eio.TextWriter;
-import org.erights.e.elib.prim.E;
import org.erights.e.elib.prim.StaticMaker;
import org.erights.e.elib.tables.ConstList;
-import org.erights.e.elib.tables.Twine;
import org.erights.e.elib.tables.FlexList;
import org.quasiliteral.astro.Astro;
+import org.quasiliteral.astro.AstroArg;
import org.quasiliteral.astro.AstroBuilder;
import org.quasiliteral.astro.AstroTag;
+import org.quasiliteral.term.QuasiBuilder;
import java.io.IOException;
//This file is hereby placed in the public domain
/**
- * A quasi-literal Term, that matches or generates an actual {@link Term}.
+ * A quasi-literal Term, that matches or generates an actual {@link Astro}.
*
* @author <a href="mailto:markm@caplet.com">Mark S Miller</a>
*/
-public class QTerm extends QAstroArg
- implements Astro {
+public class QTerm extends QAstro {
/**
*
*/
- static public final StaticMaker TermMaker =
+ static public final StaticMaker QTermMaker =
StaticMaker.make(QTerm.class);
/**
- * @serial Represents the token-type of the functor of this term.
+ * @serial The functor info
*/
- private final AstroTag myTag;
+ private final QAstro myQFunctor;
/**
- * @serial If the functor represents a literal-data token, then this is
- * the data, and myTag must represent the cononical corresponding
- * token-type for this kind of data in this schema.
+ * @serial :(ConstList of(QAstroArg))
*/
- private final Object myOptData;
+ private final ConstList myQArgs;
/**
- * A term is a functor (the above three instance variables) as
- * parameterized by a list of argument Terms. These are the arguments. A
- * term of zero arguments is often refered to as a "functor", so there's
- * no information beyond the functor-part.
- */
- private final ConstList myArgs;
-
- /**
* Just used to decide how to pretty print.
* <p>
* Initialized lazily. 0 if uninitialized, so does not need to be
@@ -59,40 +48,31 @@
private transient int myHeight = 0;
/**
- * Makes a Term that represents a node in an abstract syntax tree, ie,
- * a Term tree.
+ * Makes a QTerm that matches or generates a Astro.
* <p>
- * The invariants of a Term are not checked here, but rather are
- * enforced by the callers in this class and in TermBuilder.
+ * The invariants of a QTerm are not checked here, but rather are
+ * enforced by the callers in this class and in QTermBuilder.
*
- * @param tag Identifies a token type in a particular grammar or set
- * of related grammars, used as the functor (or "label") of
- * this Term
- * @param optData Either {@link Character},
- * {@link BigInteger}, {@link Double},
- * or {@link Twine} or null. If not null, then the tag
- * must represent the canonical literal type for this
- * kind of data in this schema.
- * @param args This Term's argument list -- a list of Terms
+ * @param builder Used to build the results of a substitute
+ * @param qFunctor Matches of generates functor information
+ * @param qArgs This QTerm's argument list -- a list of QAstroArg
*/
/*package*/
- QTerm(AstroTag tag,
- Object optData,
- Twine source,
- ConstList args) {
+ QTerm(AstroBuilder builder,
+ QAstro qFunctor,
+ ConstList qArgs) {
- super(source);
- myTag = tag;
- myOptData = optData;
- myArgs = args;
+ super(builder, qFunctor.getSource());
+ myQFunctor = qFunctor;
+ myQArgs = qArgs;
}
/**
- * Uses 'TermMaker new(myTag, myOptData, mySource, myArgs)'
+ * Uses 'QTermMaker new(myBuilder, myQFunctor, myQArgs)'
*/
public Object[] getCanonicalState() {
Object[] result = {
- TermMaker, "new", myTag, myOptData, mySource, myArgs
+ QTermMaker, "new", myBuilder, myQFunctor, myQArgs
};
return result;
}
@@ -101,34 +81,35 @@
*
*/
public Astro build(AstroBuilder builder) {
- Astro func;
- if (null == myOptData) {
- func = builder.leafTag(myTag, mySource);
- } else {
- //Assumes tag adds no more info.
- func = builder.leafData(myOptData, mySource);
- }
- Object args = builder.list();
- int len = myArgs.size();
+ throw new RuntimeException("Can't build. Try qbuild instead");
+ }
+
+ /**
+ *
+ */
+ public AstroArg qbuild(QuasiBuilder qbuilder) {
+ Astro func = (Astro)myQFunctor.qbuild(qbuilder);
+ Object args = qbuilder.list();
+ int len = myQArgs.size();
for (int i = 0; i < len; i++) {
- Astro arg = ((QTerm)myArgs.get(i)).build(builder);
- args = builder.with(args, arg);
+ AstroArg arg = ((QAstroArg)myQArgs.get(i)).qbuild(qbuilder);
+ args = qbuilder.with(args, arg);
}
- return builder.term(func, args);
+ return qbuilder.term(func, args);
}
/**
* Represents the token-type of the functor of this term.
*/
public AstroTag getTag() {
- return myTag;
+ return myQFunctor.getTag();
}
/**
*
*/
public short getOptTagCode() {
- return myTag.getOptTagCode();
+ return myQFunctor.getOptTagCode();
}
/**
@@ -137,83 +118,110 @@
* kind of data in this schema.
*/
public Object getOptData() {
- return myOptData;
+ return myQFunctor.getOptData();
}
- public String getOptString() {
- return ((Twine)getOptData()).bare();
- }
-
/**
*
*/
- public Object getOptArgData() {
- return ((QTerm)myArgs.get(0)).getOptData();
- }
-
- public Object getOptArgData(short tagCode) {
- //This is too much reporting work when the error doesn't happen.
- //Should consider putting into a thunk instead.
- AstroTag optTag = myTag.getSchema().getOptTagForCode(tagCode);
- T.require(tagCode == myTag.getOptTagCode(),
- "Tag mismatch: ", myTag, " vs ",
- (null == optTag ?
- (Object)new Integer(tagCode) :
- (Object)optTag));
- return ((QTerm)myArgs.get(0)).getOptData();
- }
-
- public String getOptArgString(short tagCode) {
- return ((Twine)getOptArgData(tagCode)).bare();
+ public String getOptString() {
+ return myQFunctor.getOptString();
}
/**
- * A term is a functor (the above three instance variables) as
- * parameterized by a list of argument Terms. These are the arguments.
- * A term of zero arguments is often refered to as a "functor", so there's
- * no information beyond the functor-part.
+ * @return :(ConstList of(QAstroArg))
*/
public ConstList getArgs() {
- return myArgs;
+ return myQArgs;
}
/**
- *
+ * Returns a QTerm like with one, but without args.
+ * <p>
+ * Unlike myQFunctor, this will only match a Term of zero-arity.
*/
public Astro withoutArgs() {
- return new QTerm(myTag, myOptData, mySource, ConstList.EmptyList);
+ return new QTerm(myBuilder, myQFunctor, ConstList.EmptyList);
}
/**
*
*/
- public Astro withArgs(ConstList args) {
- T.require(myArgs.size() == 0,
- "To use as functor, must not have args: ", this);
- return new QTerm(myTag, myOptData, mySource, args);
+ public Astro withArgs(ConstList qArgs) {
+ T.require(myQArgs.size() == 0,
+ "To use as quasi-functor, must not have quasi-args: ",
+ this);
+ return new QTerm(myBuilder, myQFunctor, qArgs);
}
- public Object substitute(Object[] args) {
- throw new RuntimeException("XXX not yet implemented");
+ /**
+ * @return A single list of a single Astro, whose functor is based on
+ * literal functor info of this qterm, and whose args are the
+ * concatentation of the substSlice of the qargs of this qterm.
+ */
+ public ConstList substSlice(Object[] args, String rank) {
+ Astro tFunctor = (Astro)myQFunctor.substSlice(args, rank).get(0);
+ Object tArgs = myBuilder.list();
+ for (int i = 0, ilen = myQArgs.size(); i < ilen; i++) {
+ QAstroArg qArg = (QAstroArg)myQArgs.get(i);
+ ConstList tSlice = qArg.substSlice(args, rank);
+ for (int j = 0, jlen = tSlice.size(); j < jlen; j++) {
+ AstroArg tArg = (AstroArg)tSlice.get(j);
+ tArgs = myBuilder.with(tArgs, tArg);
+ }
+ }
+ Astro tTerm = myBuilder.term(tFunctor, tArgs);
+ return ConstList.EmptyList.with(tTerm);
}
- public boolean matchBind(Object[] args,
- Object specimen,
- FlexList bindings) {
- throw new RuntimeException("XXX not yet implemented");
+ /**
+ * Attempts to match against the Astro specimenList[0].
+ * <p>
+ * Matches the arg list by a naive greedy algorithm.
+ *
+ * @return -1 or 1, depending on whether specimenList[0] matches this
+ * qterm.
+ */
+ public int matchBindSlice(Object[] args,
+ ConstList specimenList,
+ FlexList bindings,
+ String rank) {
+ int matches = myQFunctor.matchBindSlice(args,
+ specimenList,
+ bindings,
+ rank);
+ if (matches <= 0) {
+ return -1;
+ }
+ T.requireSI(1 == matches,
+ "Functor may only match 0 or 1 specimen: ", matches);
+ ConstList tArgs = ((Astro)specimenList.get(0)).getArgs();
+ for (int i = 0, len = myQArgs.size(); i < len; i++) {
+ QAstroArg qArg = (QAstroArg)myQArgs.get(i);
+ int num = qArg.matchBindSlice(args,
+ tArgs,
+ bindings,
+ rank);
+ if (num <= -1) {
+ return -1;
+ }
+ tArgs = tArgs.run(num, tArgs.size());
+ }
+ if (tArgs.size() == 0) {
+ return 1;
+ } else {
+ return -1;
+ }
}
/**
- * What's the longest distance to the bottom?
- * <p>
- * A leaf node is height 1. All other nodes are one more than the height
- * of their highest child. This is used for pretty printing.
+ *
*/
public int getHeight() {
if (myHeight <= 0) {
myHeight = 1;
- for (int i = 0; i < myArgs.size(); i++) {
- int h = ((QTerm)myArgs.get(i)).getHeight();
+ for (int i = 0; i < myQArgs.size(); i++) {
+ int h = ((QAstroArg)myQArgs.get(i)).getHeight();
myHeight = Math.max(myHeight, h + 1);
}
}
@@ -225,17 +233,11 @@
*/
public void prettyPrintOn(TextWriter out)
throws IOException {
- String label = myTag.getTagName();
- if (null != myOptData) {
- label = E.toQuote(myOptData).bare();
- label = StringHelper.replaceAll(label, "$", "$$");
- label = StringHelper.replaceAll(label, "@", "@@");
- label = StringHelper.replaceAll(label, "`", "``");
- }
+ String label = myQFunctor.asText();
out.print(label);
int h = getHeight();
if (h <= 1) {
- if (myArgs.size() != 0) {
+ if (myQArgs.size() != 0) {
throw new RuntimeException("internal: bad height " + h);
}
//If it's a leaf, don't show parens either
@@ -244,10 +246,10 @@
if (h == 2) {
//If it only contains leaves, do it on one line
out.print("(");
- ((QAstroArg)myArgs.get(0)).prettyPrintOn(out);
- for (int i = 1; i < myArgs.size(); i++) {
+ ((QAstroArg)myQArgs.get(0)).prettyPrintOn(out);
+ for (int i = 1; i < myQArgs.size(); i++) {
out.print(", ");
- ((QAstroArg)myArgs.get(i)).prettyPrintOn(out);
+ ((QAstroArg)myQArgs.get(i)).prettyPrintOn(out);
}
out.print(")");
return;
@@ -258,10 +260,10 @@
String spaces = StringHelper.multiply(" ", reps);
TextWriter sub = out.indent(spaces);
- ((QAstroArg)myArgs.get(0)).prettyPrintOn(sub);
- for (int i = 1; i < myArgs.size(); i++) {
+ ((QAstroArg)myQArgs.get(0)).prettyPrintOn(sub);
+ for (int i = 1; i < myQArgs.size(); i++) {
sub.println(",");
- ((QAstroArg)myArgs.get(i)).prettyPrintOn(sub);
+ ((QAstroArg)myQArgs.get(i)).prettyPrintOn(sub);
}
sub.print(")");
}
1.2 +22 -0 e/src/jsrc/org/quasiliteral/term/QuasiBuilder.java
Index: QuasiBuilder.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/quasiliteral/term/QuasiBuilder.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- QuasiBuilder.java 2001/12/18 21:59:31 1.1
+++ QuasiBuilder.java 2001/12/19 10:18:08 1.2
@@ -51,6 +51,28 @@
AstroArg alt(AstroArg leftArg, AstroArg rightArg);
/**
+ * Matched any sequence in which both leftArg and rightArg are matched
+ * exactly once.
+ * <p>
+ * Does not affect the rank of the arguments, since they are still
+ * exactly-once.
+ * <p>
+ * If 'leftArg' is itself a bag (the result of a call to bag), then the
+ * new effective bag is rightArg + the members of leftArg. This matches
+ * and sequence in which each member of the sequence matches a unique
+ * member of the bag, and all the members of the bag are matched.
+ * <p>
+ * This is inspired by the '&' of <a href=
+ * "http://www.thaiopensource.com/relaxng/nonxml/syntax.html"
+ * >RELAX-NG's Non-XML Syntax</a>, which expands to <a href=
+ * "http://www.thaiopensource.com/relaxng/design.html#section:12"
+ * >RELAX-NG's "interleave" tag</a>, though we don't yet know how closely
+ * the semantics of the two can correspond. (If 'bag' can correspond
+ * perfectly to RELAX-NG's interleave tag, then we will so specify.)
+ */
+ AstroArg bag(AstroArg leftArg, AstroArg rightArg);
+
+ /**
* Matches a consecutive sequence of Terms matched by optTerm.
* <p>
* Adds quant to the rank of optTerm.
1.2 +4 -0 e/src/jsrc/org/quasiliteral/term/QuasiBuilderAdaptor.java
Index: QuasiBuilderAdaptor.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/quasiliteral/term/QuasiBuilderAdaptor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- QuasiBuilderAdaptor.java 2001/12/18 21:59:31 1.1
+++ QuasiBuilderAdaptor.java 2001/12/19 10:18:08 1.2
@@ -129,6 +129,10 @@
throw new RuntimeException("not quasi-ing");
}
+ public AstroArg bag(AstroArg leftArg, AstroArg rightArg) {
+ throw new RuntimeException("not quasi-ing");
+ }
+
public AstroArg seq(Astro optTerm, String quant) {
throw new RuntimeException("not quasi-ing");
}
1.19 +21 -0 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.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- Term.java 2001/12/18 05:24:44 1.18
+++ Term.java 2001/12/19 10:18:08 1.19
@@ -1,6 +1,7 @@
package org.quasiliteral.term;
import org.erights.e.develop.assertion.T;
+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.E;
@@ -15,6 +16,7 @@
import org.quasiliteral.astro.AstroTag;
import java.io.IOException;
+import java.io.StringWriter;
//This file is hereby placed in the public domain
@@ -174,6 +176,9 @@
return ((Term)myArgs.get(0)).getOptData();
}
+ /**
+ *
+ */
public Object getOptArgData(short tagCode) {
//This is too much reporting work when the error doesn't happen.
//Should consider putting into a thunk instead.
@@ -186,6 +191,9 @@
return ((Term)myArgs.get(0)).getOptData();
}
+ /**
+ *
+ */
public String getOptArgString(short tagCode) {
return ((Twine)getOptArgData(tagCode)).bare();
}
@@ -287,6 +295,19 @@
out.print("term`");
prettyPrintOn(out.indent(" "), true);
out.print("`");
+ }
+
+ /**
+ *
+ */
+ public String asText() {
+ StringWriter strWriter = new StringWriter();
+ try {
+ prettyPrintOn(new TextWriter(strWriter), false);
+ } catch (Throwable th) {
+ throw ExceptionMgr.asSafe(th);
+ }
+ return strWriter.getBuffer().toString();
}
/**
1.16 +9 -1 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.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- Term.updoc 2001/12/13 05:01:31 1.15
+++ Term.updoc 2001/12/19 10:18:08 1.16
@@ -237,8 +237,16 @@
? def t1 := term`"foo"`
# value: term`"foo"`
+ ? def t2 := term`bar(3, "x", zip(zap, 'x', 2.3))`
+ # value: term`bar(3,
+ # "x",
+ # zip(zap, 'x', 2.3))`
+
? def t2 := term`$t1(4)`
- # value: term`"foo"(4)`
+ # problem: XXX not yet implemented
+ #
+ # org.quasiliteral.quasiterm.QBuilder@12033fc valueMaker("${0}(4)")
+ # <interactive interp> evalPrint(e`def t2 :any := term__quasiParser valueMaker("${0}(4)") substitute(ListMaker run(t1))`)
? def t3 := term`$t1(bar, $t2)`
# value: term`"foo"(bar,
1.19 +3 -0 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.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- TermBuilder.java 2001/12/18 05:24:44 1.18
+++ TermBuilder.java 2001/12/19 10:18:08 1.19
@@ -67,6 +67,9 @@
ConstList.EmptyList);
}
+ /**
+ * For Terms, this is non-atomic
+ */
public Astro composite(AstroTag tag, Object data, Twine source) {
return term(leafTag(tag, source),
list(leafData(data, source)));
1.17 +100 -89 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.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- TermParser.java 2001/12/18 21:59:31 1.16
+++ TermParser.java 2001/12/19 10:18:08 1.17
@@ -11,7 +11,6 @@
//#line 7 "term.y"
package org.quasiliteral.term;
-
import org.erights.e.develop.exception.ThrowableSugar;
import org.erights.e.elib.tables.ConstList;
import org.erights.e.elib.tables.Twine;
@@ -23,9 +22,11 @@
import org.quasiliteral.term.QuasiBuilder;
import org.quasiliteral.term.QuasiBuilderAdaptor;
import org.quasiliteral.syntax.SyntaxException;
+import org.quasiliteral.syntax.LineFeeder;
+import org.quasiliteral.syntax.TwineFeeder;
import java.io.IOException;
-//#line 27 "TermParser.java"
+//#line 28 "TermParser.java"
@@ -165,58 +166,58 @@
public final static short YYERRCODE=256;
final static short yylhs[] = { -1,
0, 1, 1, 1, 1, 1, 3, 3, 5, 5,
- 6, 6, 7, 7, 7, 7, 7, 7, 8, 8,
- 8, 2, 2, 2, 2, 2, 4, 4,
+ 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,
+ 9, 9, 9, 2, 2, 2, 2, 2, 4, 4,
};
final static short yylen[] = { 2,
1, 1, 4, 4, 1, 2, 0, 1, 1, 3,
- 1, 3, 1, 2, 1, 1, 4, 2, 1, 1,
- 1, 1, 1, 1, 1, 1, 4, 4,
+ 1, 3, 1, 3, 1, 2, 1, 1, 4, 2,
+ 1, 1, 1, 1, 1, 1, 1, 1, 4, 4,
};
final static short yydefred[] = { 0,
- 0, 23, 24, 25, 26, 0, 0, 0, 1, 0,
- 0, 6, 0, 0, 0, 0, 0, 0, 0, 16,
- 0, 19, 20, 21, 0, 0, 0, 0, 11, 15,
- 0, 27, 28, 0, 18, 14, 3, 0, 0, 4,
- 0, 0, 12, 17,
+ 0, 25, 26, 27, 28, 0, 0, 0, 1, 0,
+ 0, 6, 0, 0, 0, 0, 0, 0, 0, 18,
+ 0, 21, 22, 23, 0, 0, 0, 0, 0, 13,
+ 17, 0, 29, 30, 0, 20, 16, 3, 0, 0,
+ 0, 4, 0, 0, 0, 14, 19,
};
final static short yydgoto[] = { 8,
- 25, 10, 26, 11, 27, 28, 29, 30,
+ 25, 10, 26, 11, 27, 28, 29, 30, 31,
};
final static short yysindex[] = { -31,
- -34, 0, 0, 0, 0, -114, -110, 0, 0, -17,
- -16, 0, -233, -230, -36, -36, -94, -93, -36, 0,
- -227, 0, 0, 0, -27, -6, -7, -86, 0, 0,
- -2, 0, 0, -24, 0, 0, 0, -36, -36, 0,
- -27, -86, 0, 0,
+ -34, 0, 0, 0, 0, -106, -99, 0, 0, -9,
+ -6, 0, -224, -223, -36, -36, -88, -87, -36, 0,
+ -214, 0, 0, 0, -23, 7, 9, -70, 17, 0,
+ 0, 16, 0, 0, -19, 0, 0, 0, -36, -36,
+ -36, 0, -23, -70, 17, 0, 0,
};
final static short yyrindex[] = { 0,
1, 0, 0, 0, 0, 0, 0, 0, 0, 8,
- 12, 0, 0, 0, -1, -1, 0, 0, 0, 0,
- 0, 0, 0, 0, -30, 0, 5, -23, 0, 0,
+ 18, 0, 0, 0, 22, 22, 0, 0, 0, 0,
+ 0, 0, 0, 0, -29, 0, 24, -18, -30, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, -19, 0, 0,
+ 0, 0, 0, -12, -28, 0, 0,
};
final static short yygindex[] = { 0,
- 47, 0, 32, 56, 40, 22, 23, -22,
+ 66, 0, 51, 67, 50, 31, 32, 33, -22,
};
final static int YYTABLESIZE=230;
final static short yytable[] = { 6,
- 22, 6, 36, 19, 6, 24, 23, 2, 13, 20,
- 13, 5, 14, 13, 24, 23, 41, 9, 44, 38,
- 9, 10, 15, 16, 10, 17, 22, 7, 18, 7,
- 32, 33, 7, 35, 37, 22, 38, 39, 40, 7,
- 22, 22, 22, 22, 22, 8, 9, 31, 2, 2,
- 2, 2, 5, 5, 5, 5, 12, 21, 34, 42,
- 0, 43, 0, 22, 0, 0, 0, 0, 0, 0,
- 2, 0, 0, 0, 5, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 13, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 24, 6, 37, 19, 6, 24, 23, 2, 15, 20,
+ 11, 15, 12, 11, 15, 12, 13, 5, 24, 23,
+ 47, 43, 9, 14, 39, 9, 22, 7, 10, 7,
+ 15, 10, 7, 16, 17, 18, 33, 34, 24, 22,
+ 24, 24, 24, 24, 24, 2, 36, 38, 2, 2,
+ 2, 2, 39, 40, 41, 5, 42, 21, 5, 5,
+ 5, 5, 7, 24, 8, 9, 32, 12, 35, 44,
+ 2, 45, 0, 46, 0, 0, 0, 0, 0, 0,
+ 5, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 11, 15, 12, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 22, 0, 0, 0, 0, 0,
- 0, 2, 0, 0, 0, 5, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 24, 0, 0, 0, 0, 0,
+ 0, 2, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 5, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -227,21 +228,21 @@
1, 2, 3, 4, 5, 1, 2, 3, 4, 5,
};
final static short yycheck[] = { 36,
- 0, 36, 25, 40, 36, 42, 43, 0, 123, 46,
- 41, 0, 123, 44, 42, 43, 41, 41, 41, 44,
- 44, 41, 40, 40, 44, 259, 63, 64, 259, 64,
- 125, 125, 64, 261, 41, 63, 44, 124, 41, 41,
- 40, 41, 42, 43, 44, 41, 0, 16, 41, 42,
- 43, 44, 41, 42, 43, 44, 1, 94, 19, 38,
- -1, 39, -1, 63, -1, -1, -1, -1, -1, -1,
- 63, -1, -1, -1, 63, -1, -1, -1, -1, -1,
+ 0, 36, 25, 40, 36, 42, 43, 0, 38, 46,
+ 41, 41, 41, 44, 44, 44, 123, 0, 42, 43,
+ 43, 41, 41, 123, 44, 44, 63, 64, 41, 64,
+ 40, 44, 64, 40, 259, 259, 125, 125, 38, 63,
+ 40, 41, 42, 43, 44, 38, 261, 41, 41, 42,
+ 43, 44, 44, 124, 38, 38, 41, 94, 41, 42,
+ 43, 44, 41, 63, 41, 0, 16, 1, 19, 39,
+ 63, 40, -1, 41, -1, -1, -1, -1, -1, -1,
+ 63, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, 124, 124, 124, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, 124, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, 124, -1, -1, -1, -1, -1,
- -1, 124, -1, -1, -1, 124, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, 124, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, 124, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
@@ -256,7 +257,7 @@
final static String yyname[] = {
"end-of-file",null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
-null,null,null,null,null,null,"'$'",null,null,null,"'('","')'","'*'","'+'",
+null,null,null,null,null,null,"'$'",null,"'&'",null,"'('","')'","'*'","'+'",
"','",null,"'.'",null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,"'?'","'@'",null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
@@ -285,8 +286,10 @@
"argList : args",
"args : arg",
"args : args ',' arg",
-"arg : seq",
-"arg : arg '|' seq",
+"arg : bag",
+"arg : arg '|' bag",
+"bag : seq",
+"bag : bag '&' seq",
"seq : term",
"seq : term quant",
"seq : quant",
@@ -305,7 +308,7 @@
"functorHole : '@' '{' LiteralInteger '}'",
};
-//#line 138 "term.y"
+//#line 144 "term.y"
/**
@@ -321,7 +324,7 @@
/**
*
*/
-private Object myOptResult;
+private Astro myOptResult;
/**
*
@@ -343,9 +346,14 @@
/**
*
*/
-static public Object run(Twine source, QuasiBuilder builder) {
+static public Astro run(Twine source, QuasiBuilder builder) {
try {
- TermLexer lexer = TermLexer.make(source, builder.doesQuasis(), false);
+ LineFeeder lineFeeder = new TwineFeeder(source);
+ TermLexer lexer = new TermLexer(lineFeeder,
+ false,
+ builder.doesQuasis(),
+ false,
+ builder);
TermParser parser = new TermParser(lexer, builder);
return parser.parse();
} catch (IOException iox) {
@@ -353,12 +361,10 @@
}
}
-
-
/**
*
*/
-public Object parse() {
+public Astro parse() {
if (yyparse() == 0) {
return myOptResult;
} else {
@@ -446,6 +452,7 @@
TheTokens[EOL] = "EOL";
/* Single-Character Tokens */
+ TheTokens['&'] = "Ampersand";
TheTokens['|'] = "VerticalBar";
TheTokens['^'] = "Caret";
TheTokens['+'] = "Plus";
@@ -468,7 +475,7 @@
static public final AstroSchema DEFAULT_SCHEMA =
new BaseSchema("Term-Tree-Language", ConstList.fromArray(TheTokens));
-//#line 420 "TermParser.java"
+//#line 427 "TermParser.java"
//###############################################################
// method: yylexdebug : check lexer state
//###############################################################
@@ -615,86 +622,90 @@
{
//########## USER-SUPPLIED ACTIONS ##########
case 1:
-//#line 75 "term.y"
-{ myOptResult = val_peek(0); }
+//#line 76 "term.y"
+{ myOptResult = (Astro)val_peek(0); }
break;
case 3:
-//#line 80 "term.y"
+//#line 81 "term.y"
{ yyval = b.term((Astro)val_peek(3), val_peek(1)); }
break;
case 4:
-//#line 81 "term.y"
+//#line 82 "term.y"
{ yyval = b.term((Astro)val_peek(3), val_peek(1)); }
break;
case 5:
-//#line 83 "term.y"
+//#line 84 "term.y"
{ yyval = b.termHole(null, (Astro)val_peek(0)); }
break;
case 6:
-//#line 84 "term.y"
+//#line 85 "term.y"
{ yyval = b.termHole((Astro)val_peek(1), (Astro)val_peek(0)); }
break;
case 7:
-//#line 88 "term.y"
+//#line 89 "term.y"
{ yyval = b.list(); }
break;
case 9:
-//#line 93 "term.y"
+//#line 94 "term.y"
{ yyval = b.list((AstroArg)val_peek(0)); }
break;
case 10:
-//#line 94 "term.y"
+//#line 95 "term.y"
{ yyval = b.with(val_peek(2), (AstroArg)val_peek(0)); }
break;
case 12:
-//#line 99 "term.y"
+//#line 100 "term.y"
{ yyval = b.alt((AstroArg)val_peek(2), (AstroArg)val_peek(0));}
break;
case 14:
-//#line 107 "term.y"
+//#line 105 "term.y"
+{ yyval = b.bag((AstroArg)val_peek(2), (AstroArg)val_peek(0));}
+break;
+case 16:
+//#line 113 "term.y"
{ yyval = b.seq((Astro)val_peek(1), (String)val_peek(0)); }
break;
-case 15:
-//#line 108 "term.y"
+case 17:
+//#line 114 "term.y"
{ yyval = b.seq(null, (String)val_peek(0)); }
break;
-case 16:
-//#line 109 "term.y"
+case 18:
+//#line 115 "term.y"
{ yyval = b.seq(null, "."); }
break;
-case 17:
-//#line 110 "term.y"
+case 19:
+//#line 116 "term.y"
{ yyval = b.group(val_peek(2), (String)val_peek(0)); }
break;
-case 18:
-//#line 111 "term.y"
+case 20:
+//#line 117 "term.y"
{ yyval = b.unpack((Astro)val_peek(0)); }
break;
-case 19:
-//#line 115 "term.y"
+case 21:
+//#line 121 "term.y"
{ yyval = "?"; }
break;
-case 20:
-//#line 116 "term.y"
+case 22:
+//#line 122 "term.y"
{ yyval = "+"; }
break;
-case 21:
-//#line 117 "term.y"
+case 23:
+//#line 123 "term.y"
{ yyval = "*"; }
break;
-case 22:
-//#line 121 "term.y"
+case 24:
+//#line 127 "term.y"
{ yyval = untag((Astro)val_peek(0)); }
break;
-case 27:
-//#line 132 "term.y"
+case 29:
+//#line 138 "term.y"
{ yyval = b.dollarHole((Astro)val_peek(1)); }
break;
-case 28:
-//#line 133 "term.y"
+case 30:
+//#line 139 "term.y"
{ yyval = b.atHole( (Astro)val_peek(1)); }
break;
-//#line 643 "TermParser.java"
+//#line 654 "TermParser.java"
//########## END OF USER-SUPPLIED ACTIONS ##########
}//switch
//#### Now let's reduce... ####
1.16 +19 -9 e/src/jsrc/org/quasiliteral/term/term.y
Index: term.y
===================================================================
RCS file: /cvs/e/src/jsrc/org/quasiliteral/term/term.y,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- term.y 2001/12/18 21:59:31 1.15
+++ term.y 2001/12/19 10:18:08 1.16
@@ -6,7 +6,6 @@
%{
package org.quasiliteral.term;
-
import org.erights.e.develop.exception.ThrowableSugar;
import org.erights.e.elib.tables.ConstList;
import org.erights.e.elib.tables.Twine;
@@ -18,6 +17,8 @@
import org.quasiliteral.term.QuasiBuilder;
import org.quasiliteral.term.QuasiBuilderAdaptor;
import org.quasiliteral.syntax.SyntaxException;
+import org.quasiliteral.syntax.LineFeeder;
+import org.quasiliteral.syntax.TwineFeeder;
import java.io.IOException;
%}
@@ -72,7 +73,7 @@
* </pre>
*/
start:
- term { myOptResult = $1; }
+ term { myOptResult = (Astro)$1; }
;
term:
@@ -95,8 +96,13 @@
;
arg:
+ bag
+ | arg '|' bag { $$ = b.alt((AstroArg)$1, (AstroArg)$3);}
+ ;
+
+bag:
seq
- | arg '|' seq { $$ = b.alt((AstroArg)$1, (AstroArg)$3);}
+ | bag '&' seq { $$ = b.bag((AstroArg)$1, (AstroArg)$3);}
;
/**
@@ -150,7 +156,7 @@
/**
*
*/
-private Object myOptResult;
+private Astro myOptResult;
/**
*
@@ -172,9 +178,14 @@
/**
*
*/
-static public Object run(Twine source, QuasiBuilder builder) {
+static public Astro run(Twine source, QuasiBuilder builder) {
try {
- TermLexer lexer = TermLexer.make(source, builder.doesQuasis(), false);
+ LineFeeder lineFeeder = new TwineFeeder(source);
+ TermLexer lexer = new TermLexer(lineFeeder,
+ false,
+ builder.doesQuasis(),
+ false,
+ builder);
TermParser parser = new TermParser(lexer, builder);
return parser.parse();
} catch (IOException iox) {
@@ -182,12 +193,10 @@
}
}
-
-
/**
*
*/
-public Object parse() {
+public Astro parse() {
if (yyparse() == 0) {
return myOptResult;
} else {
@@ -275,6 +284,7 @@
TheTokens[EOL] = "EOL";
/* Single-Character Tokens */
+ TheTokens['&'] = "Ampersand";
TheTokens['|'] = "VerticalBar";
TheTokens['^'] = "Caret";
TheTokens['+'] = "Plus";