[e-cvs] cvs commit: e/src/jsrc/org/quasiliteral/term Term.java TermBuilder.java TermLexer.java
markm@eros.cs.jhu.edu
markm@eros.cs.jhu.edu
Thu, 6 Dec 2001 04:26:41 -0500
markm 01/12/06 04:26:41
Modified: src/jsrc/org/quasiliteral/astro ASTBuilder.java
AstroAST.java AstroBuilder.java
AstroLexerSharedInputState.java AstroToken.java
src/jsrc/org/quasiliteral/quasiterm QuasiBuilder.java
QuasiBuilderAdaptor.java
src/jsrc/org/quasiliteral/term Term.java TermBuilder.java
TermLexer.java
Log:
progress, but doesn't yet work again
Revision Changes Path
1.3 +8 -0 e/src/jsrc/org/quasiliteral/astro/ASTBuilder.java
Index: ASTBuilder.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/quasiliteral/astro/ASTBuilder.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ASTBuilder.java 2001/12/06 06:25:08 1.2
+++ ASTBuilder.java 2001/12/06 09:26:41 1.3
@@ -154,4 +154,12 @@
public AstroArg arg(Astro node) {
return (AstroAST)node;
}
+
+ /**
+ *
+ */
+ public Object unpack(Astro litString) {
+ throw new RuntimeException
+ ("XXX unpack operator, '^', not yet implemented");
+ }
}
1.2 +18 -2 e/src/jsrc/org/quasiliteral/astro/AstroAST.java
Index: AstroAST.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/quasiliteral/astro/AstroAST.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AstroAST.java 2001/12/06 06:25:08 1.1
+++ AstroAST.java 2001/12/06 09:26:41 1.2
@@ -6,6 +6,7 @@
import antlr.collections.AST;
import org.erights.e.elib.tables.Twine;
import org.erights.e.elib.tables.ConstList;
+import org.erights.e.elib.prim.E;
/**
* AST node implementation which stores tokens explicitly.
@@ -260,10 +261,25 @@
}
public Astro withoutArgs() {
- throw new RuntimeException("XXX not yet implemented");
+ if (null == getFirstChild()) {
+ return this;
+ } else {
+ return new AstroAST(myOptToken);
+ }
}
public Astro withArgs(ConstList args) {
- throw new RuntimeException("XXX not yet implemented");
+ E.require(null == getFirstChild(),
+ "Must be a leaf: ", this);
+ int len = args.size();
+ if (0 == len) {
+ return this;
+ } else {
+ AstroAST result = new AstroAST(myOptToken);
+ for (int i = 0; i < len; i++) {
+ result.addChild((AstroAST)args.get(i));
+ }
+ return result;
+ }
}
}
1.3 +6 -0 e/src/jsrc/org/quasiliteral/astro/AstroBuilder.java
Index: AstroBuilder.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/quasiliteral/astro/AstroBuilder.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AstroBuilder.java 2001/12/06 06:25:08 1.2
+++ AstroBuilder.java 2001/12/06 09:26:41 1.3
@@ -114,4 +114,10 @@
* representing the singleton list consisting of just node.
*/
AstroArg arg(Astro node);
+
+ /**
+ * Turns the string into a list of arguments representing each character
+ * as a character literal.
+ */
+ Object unpack(Astro litString);
}
1.6 +1 -1 e/src/jsrc/org/quasiliteral/astro/AstroLexerSharedInputState.java
Index: AstroLexerSharedInputState.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/quasiliteral/astro/AstroLexerSharedInputState.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- AstroLexerSharedInputState.java 2001/12/06 06:25:08 1.5
+++ AstroLexerSharedInputState.java 2001/12/06 09:26:41 1.6
@@ -11,8 +11,8 @@
*
* <p>This file is in the public domain.</p>
*
- * @author Mark Miller
* @author based on Dan Bornstein's ExtentLexerSharedInputState
+ * @author Mark Miller
*/
public class AstroLexerSharedInputState extends LexerSharedInputState {
1.11 +15 -5 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.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- AstroToken.java 2001/12/06 06:25:08 1.10
+++ AstroToken.java 2001/12/06 09:26:41 1.11
@@ -95,8 +95,6 @@
* to have no data.
* <p>
* XXX This should probably be made into a sugar-instance-method of Token.
- *
- * @return :(Leaf | Node)
*/
static public Astro build(Token self, AstroBuilder builder) {
if (self instanceof AstroToken) {
@@ -265,20 +263,32 @@
*
*/
public ConstList getArgs() {
- throw new RuntimeException("XXX not yet implemented");
+ if (getTag().isTagForData(myOptData)) {
+ return ConstList.EmptyList;
+ } else {
+ AstroTag dataTag =
+ getTag().getOptSchema().getTypeTag(myOptData.getClass());
+ return ConstList.EmptyList.with(new AstroToken(dataTag,
+ myOptData,
+ getSource()));
+ }
}
/**
*
*/
public Astro withoutArgs() {
- throw new RuntimeException("XXX not yet implemented");
+ if (getTag().isTagForData(myOptData)) {
+ return this;
+ } else {
+ return new AstroToken(getTag(), null, getSource());
+ }
}
/**
*
*/
public Astro withArgs(ConstList args) {
- throw new RuntimeException("XXX not yet implemented");
+ return new AstroAST(this).withArgs(args);
}
}
1.2 +27 -23 e/src/jsrc/org/quasiliteral/quasiterm/QuasiBuilder.java
Index: QuasiBuilder.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/quasiliteral/quasiterm/QuasiBuilder.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- QuasiBuilder.java 2001/12/06 06:25:09 1.1
+++ QuasiBuilder.java 2001/12/06 09:26:41 1.2
@@ -18,60 +18,64 @@
* QuasiBuilder. At such a time, the org.quasiliteral.term package can
* probably stop depending on the org.quasiliteral.quasiterm package, giving
* us a happy layering rather than a sad cycle.
- * <p>
- * The pretend parameterized types from AstroBuilder are: <pre>
- * Leaf -- Leaves of the tree, representing tokens of the grammar.
- * Node -- Lnternal nodes of the tree, looks like application of a Leaf
- * as an functor to Args.
- * Arg -- An individual argument in a list of arguments. Typically the
- * same as Node, but not always. See QuasiTermBuilder.
- * Args -- Represents a list of Arg.
- * </pre>
- * QuasiBuilder adds to this list:<pre>
*
- * </pre>
- *
* @author <a href="mailto:markm@caplet.com">Mark Miller</a>
*/
public interface QuasiBuilder extends AstroBuilder {
/**
- *
+ * A kludge because of the current (pre-Antlr) lack of grammar
+ * inheritance.
+ * <p>
+ * If this is false, then the only production which work are the ones
+ * inherited from AstroBuilder, and this is really an AstroBuilder in
+ * QuasiBuilder clothing. This flag is also, by default, used to tell
+ * the lexer whether to collapse double quasi characters -- '@', '$', and
+ * '`'.
*/
boolean doesQuasis();
/**
- *
+ * Upgrades the functorHole to a TermHole.
+ * <p>
+ * If optIdent is provided, then it will only match terms with a matching
+ * tag.
*/
Astro termHole(Astro optIdent, Astro functorHole);
/**
- *
+ * Matched anything matched by either leftArg or rightArg.
+ * <p>
+ * Adds a "?" to the rank of both arguments.
*/
AstroArg alt(AstroArg leftArg, AstroArg rightArg);
/**
- *
+ * Matches a consecutive sequence of Terms matched by optTerm.
+ * <p>
+ * Adds quant to the rank of optTerm.
*/
AstroArg seq(Astro optTerm, String quant);
/**
+ * Treat the 'args' list as a repeating sequence.
+ * <p>
+ * Matches a consecutive sequence of subsequences matched by 'args'.
+ * Adds quant to the rank of each arg.
*
+ * @param args is a list of AstroArg.
*/
AstroArg argGroup(Object args, String quant);
/**
- *
+ * On substitution, "evaluates" to 'args[litInt]'.
+ * <p>
+ * On matching, matches if 'args[litInt] <=> specimen'
*/
- Object unpack(Astro litString);
-
- /**
- *
- */
Astro dollarHole(Astro litInt);
/**
- *
+ * Matches the specimen by placing it in 'bindings[litInt]'.
*/
Astro atHole(Astro litInt);
}
1.2 +4 -4 e/src/jsrc/org/quasiliteral/quasiterm/QuasiBuilderAdaptor.java
Index: QuasiBuilderAdaptor.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/quasiliteral/quasiterm/QuasiBuilderAdaptor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- QuasiBuilderAdaptor.java 2001/12/06 06:25:09 1.1
+++ QuasiBuilderAdaptor.java 2001/12/06 09:26:41 1.2
@@ -87,6 +87,10 @@
return myBuilder.arg(node);
}
+ public Object unpack(Astro litString) {
+ return myBuilder.unpack(litString);
+ }
+
public boolean doesQuasis() {
return false;
}
@@ -104,10 +108,6 @@
}
public AstroArg argGroup(Object args, String quant) {
- throw new RuntimeException("not quasi-ing");
- }
-
- public Object unpack(Astro litString) {
throw new RuntimeException("not quasi-ing");
}
1.12 +5 -3 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.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- Term.java 2001/12/06 06:25:09 1.11
+++ Term.java 2001/12/06 09:26:41 1.12
@@ -141,7 +141,7 @@
*
*/
public short getOptTagCode() {
- throw new RuntimeException("XXX not yet implemented");
+ return myTag.getOptTagCode();
}
/**
@@ -181,14 +181,16 @@
*
*/
public Astro withoutArgs() {
- throw new RuntimeException("XXX not yet implemented");
+ return new Term(myTag, myOptData, mySource, ConstList.EmptyList);
}
/**
*
*/
public Astro withArgs(ConstList args) {
- throw new RuntimeException("XXX not yet implemented");
+ E.require(myArgs.size() == 0,
+ "To use as functor, must not have args: ", this);
+ return new Term(myTag, myOptData, mySource, args);
}
/**
1.12 +8 -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.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- TermBuilder.java 2001/12/06 06:25:09 1.11
+++ TermBuilder.java 2001/12/06 09:26:41 1.12
@@ -171,4 +171,12 @@
public AstroArg arg(Astro node) {
return (Term)node;
}
+
+ /**
+ *
+ */
+ public Object unpack(Astro litString) {
+ throw new RuntimeException
+ ("XXX unpack operator, '^', not yet implemented");
+ }
}
1.11 +0 -1 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.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- TermLexer.java 2001/12/06 06:25:09 1.10
+++ TermLexer.java 2001/12/06 09:26:41 1.11
@@ -281,7 +281,6 @@
Astro t;
do {
t = lex.nextToken();
- //XXX should print t as a Functor.
stdout.println(t);
if (t.getOptTagCode() == TermParser.EOL) {
stdout.print("stack: ",