[e-cvs] cvs commit: e/src/jsrc/org/quasiliteral/term Term.java TermBuilder.java TermParser.java term.y
markm@eros.cs.jhu.edu
markm@eros.cs.jhu.edu
Mon, 10 Dec 2001 01:11:04 -0500
markm 01/12/10 01:11:03
Modified: src/jsrc/org/capml/dom Element.java Node.java Text.java
src/jsrc/org/erights/e/elang/syntax EBuilder.java
ELexer.java EParser.java PrettyFeeder.java e.y
src/jsrc/org/erights/e/elib/prim VTable.java
src/jsrc/org/quasiliteral/astro ASTBuilder.java Astro.java
AstroAST.java AstroBuilder.java AstroSchema.java
AstroTag.java AstroToken.java BaseSchema.java
src/jsrc/org/quasiliteral/quasiterm QuasiBuilderAdaptor.java
src/jsrc/org/quasiliteral/syntax BaseLexer.java
src/jsrc/org/quasiliteral/term Term.java TermBuilder.java
TermParser.java term.y
Added: src/jsrc/org/quasiliteral/astro BaseBuilder.java
Log:
Term Trees are back together yet again, this time with Functors gone.
Revision Changes Path
1.8 +3 -6 e/src/jsrc/org/capml/dom/Element.java
Index: Element.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/capml/dom/Element.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Element.java 2001/12/06 06:25:07 1.7
+++ Element.java 2001/12/10 06:11:00 1.8
@@ -150,14 +150,11 @@
}
/**
- * Currently returns a Node whose functor-leaf is the token-type for this
- * Element's tag name, and whose arguments are the converted child nodes
- * in order.
- *
- * @return :Node (see {@link AstroBuilder})
+ * Converts to a Astro (eg, Term or AST) whose functor has this tag name
+ * and whose args are my converted children in order.
*/
public Astro build(AstroBuilder builder) {
- AstroTag tag = builder.getSchema().getTagForName(myTagName);
+ AstroTag tag = builder.getSchema().obtainTagForName(myTagName);
Astro func = builder.leafTag(tag, EmptyTwine.THE_ONE);
Object args = builder.argList();
int len = myChildren.size();
1.10 +1 -3 e/src/jsrc/org/capml/dom/Node.java
Index: Node.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/capml/dom/Node.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- Node.java 2001/12/06 06:25:07 1.9
+++ Node.java 2001/12/10 06:11:00 1.10
@@ -153,9 +153,7 @@
public abstract void prettyPrintOn(TextWriter out) throws IOException;
/**
- * Used to convert from a Node tree to an AST or Term tree.
- *
- * @return :Node (see {@link AstroBuilder})
+ * Used to convert from a Node tree to an Astro (eg, AST or Term) tree.
*/
public abstract Astro build(AstroBuilder builder);
}
1.8 +3 -5 e/src/jsrc/org/capml/dom/Text.java
Index: Text.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/capml/dom/Text.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Text.java 2001/12/06 06:25:07 1.7
+++ Text.java 2001/12/10 06:11:00 1.8
@@ -151,13 +151,11 @@
}
/**
- * Returns a node consisting of this literal text (as a leaf) and zero
- * arguments.
- *
- * @return :Node (see {@link AstroBuilder})
+ * Returns an Astro (eg, AstroToken or Term) consisting of this literal
+ * text (as a leaf) and zero arguments.
*/
public Astro build(AstroBuilder builder) {
- return builder.node(builder.leafData(myData, EmptyTwine.THE_ONE),
+ return builder.node(builder.leafString(myData, EmptyTwine.THE_ONE),
builder.argList());
}
}
1.90 +27 -23 e/src/jsrc/org/erights/e/elang/syntax/EBuilder.java
Index: EBuilder.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/elang/syntax/EBuilder.java,v
retrieving revision 1.89
retrieving revision 1.90
diff -u -r1.89 -r1.90
--- EBuilder.java 2001/12/06 06:25:07 1.89
+++ EBuilder.java 2001/12/10 06:11:00 1.90
@@ -63,7 +63,7 @@
import org.erights.e.elib.tables.FlexList;
import org.erights.e.elib.tables.FlexMap;
import org.erights.e.elib.tables.Twine;
-import org.quasiliteral.astro.AstroToken;
+import org.quasiliteral.astro.Astro;
import org.quasiliteral.syntax.SyntaxException;
/**
@@ -261,8 +261,8 @@
EExpr update(Object lValue, Object verb, Object rnValue) {
String verbName;
- if (verb instanceof AstroToken) {
- verbName = (String)((AstroToken)verb).getOptTokenData();
+ if (verb instanceof Astro) {
+ verbName = ((Astro)verb).getOptArgString(EParser.ID);
} else {
verbName = (String)verb;
}
@@ -353,7 +353,7 @@
*/
/*package*/
EExpr doMeta(Object keyword, Object verb, Object args) {
- String kword = ((AstroToken)keyword).getText().intern();
+ String kword = ((Astro)keyword).getOptArgString(EParser.ID).intern();
String vrb = ((String)verb).intern();
EExpr[] exprs = exprs(args);
if ("meta" == kword) {
@@ -423,7 +423,7 @@
*/
/*package*/
EExpr doMetaSend(Object keyword, Object verb, Object args) {
- String kword = ((AstroToken)keyword).getText().intern();
+ String kword = ((Astro)keyword).getOptArgString(EParser.ID).intern();
String vrb = ((String)verb).intern();
EExpr[] exprs = exprs(args);
if ("meta" == kword) {
@@ -636,7 +636,7 @@
*/
/*package*/
Pattern atNoun(Object token) {
- String str = (String)((AstroToken)token).getOptTokenData();
+ String str = ((Astro)token).getOptArgString(EParser.ID);
str = hilbert(str);
if ("_".equals(str)) {
return ignore();
@@ -694,7 +694,7 @@
*/
/*package*/
EExpr dollarNoun(Object token) {
- String str = (String)((AstroToken)token).getOptTokenData();
+ String str = ((Astro)token).getOptArgString(EParser.DollarIdent);
str = hilbert(str);
return noun(str);
}
@@ -1017,8 +1017,11 @@
*/
/*package*/
LiteralExpr literal(Object token) {
- AstroToken tokn = (AstroToken)token;
- return new LiteralExpr(tokn.getOptTokenData());
+ Object data = ((Astro)token).getOptData();
+ if (data instanceof Twine) {
+ data = ((Twine)data).bare();
+ }
+ return new LiteralExpr(data);
}
/**
@@ -1203,7 +1206,7 @@
eScript);
} else if (isLiteralToken(optOName)) {
return object(docComment,
- ((AstroToken)optOName).getOptTokenData(),
+ ((Astro)optOName).getOptString(),
auditors,
eScript);
@@ -1270,7 +1273,7 @@
for (int i = 0; i < qList.length; i++) {
if (isQuasiPart(qList[i])) {
- buf.append(((AstroToken)qList[i]).getOptTokenData());
+ buf.append(((Astro)qList[i]).getOptArgData());
} else {
EExpr eExpr = (EExpr)qList[i];
@@ -1297,8 +1300,8 @@
*/
/*package*/
QuasiLiteralExpr quasiLiteralExpr(Object litIndex) {
- AstroToken lit = (AstroToken)litIndex;
- int index = ((Number)lit.getOptTokenData()).intValue();
+ Astro lit = (Astro)litIndex;
+ int index = ((Number)lit.getOptData()).intValue();
return new QuasiLiteralExpr(index);
}
@@ -1307,8 +1310,8 @@
*/
/*package*/
QuasiLiteralPatt quasiLiteralPatt(Object litIndex) {
- AstroToken lit = (AstroToken)litIndex;
- int index = ((Number)lit.getOptTokenData()).intValue();
+ Astro lit = (Astro)litIndex;
+ int index = ((Number)lit.getOptData()).intValue();
return new QuasiLiteralPatt(index);
}
@@ -1329,7 +1332,7 @@
for (int i = 0; i < qList.length; i++) {
if (isQuasiPart(qList[i])) {
- buf.append(((AstroToken)qList[i]).getOptTokenData());
+ buf.append(((Astro)qList[i]).getOptArgData());
} else if (qList[i] instanceof EExpr) {
EExpr eExpr = (EExpr)qList[i];
@@ -1358,8 +1361,8 @@
*/
/*package*/
QuasiPatternExpr quasiPatternExpr(Object litIndex) {
- AstroToken lit = (AstroToken)litIndex;
- int index = ((Number)lit.getOptTokenData()).intValue();
+ Astro lit = (Astro)litIndex;
+ int index = ((Number)lit.getOptData()).intValue();
return new QuasiPatternExpr(index);
}
@@ -1368,8 +1371,8 @@
*/
/*package*/
QuasiPatternPatt quasiPatternPatt(Object litIndex) {
- AstroToken lit = (AstroToken)litIndex;
- int index = ((Number)lit.getOptTokenData()).intValue();
+ Astro lit = (Astro)litIndex;
+ int index = ((Number)lit.getOptData()).intValue();
return new QuasiPatternPatt(index);
}
@@ -1571,7 +1574,7 @@
*/
/*package*/
EExpr uriExpr(Object uriToken) {
- Twine uriText = (Twine)((AstroToken)uriToken).getOptData();
+ Twine uriText = (Twine)((Astro)uriToken).getOptArgData(EParser.URI);
String protocol = URIKit.getProtcol(uriText).bare();
String body = URIKit.getBody(uriText).bare();
if (protocol.length() == 1) {
@@ -1595,7 +1598,8 @@
*/
/*package*/
EExpr uriExpr(Object uriStartToken, Object uriBodyExpr) {
- Twine uriText = (Twine)((AstroToken)uriStartToken).getOptData();
+ Twine uriText =
+ (Twine)((Astro)uriStartToken).getOptArgData(EParser.URIStart);
String protocol = URIKit.getProtcol(uriText).bare();
if (protocol.length() == 1) {
char c = Character.toLowerCase(protocol.charAt(0));
@@ -1845,7 +1849,7 @@
} else if (isLiteralToken(optOName)) {
return oType(docComment,
- ((AstroToken)optOName).getOptTokenData(),
+ ((Astro)optOName).getOptData(),
auditors,
mTypes);
1.73 +18 -16 e/src/jsrc/org/erights/e/elang/syntax/ELexer.java
Index: ELexer.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/elang/syntax/ELexer.java,v
retrieving revision 1.72
retrieving revision 1.73
diff -u -r1.72 -r1.73
--- ELexer.java 2001/12/06 06:25:07 1.72
+++ ELexer.java 2001/12/10 06:11:00 1.73
@@ -23,17 +23,16 @@
import org.erights.e.elib.eio.TextWriter;
import org.erights.e.elib.tables.EmptyTwine;
import org.erights.e.elib.tables.Twine;
-import org.quasiliteral.astro.AstroSchema;
-import org.quasiliteral.astro.AstroToken;
-import org.quasiliteral.astro.AstroTag;
-import org.quasiliteral.astro.AstroBuilder;
import org.quasiliteral.astro.ASTBuilder;
import org.quasiliteral.astro.Astro;
+import org.quasiliteral.astro.AstroBuilder;
+import org.quasiliteral.astro.AstroTag;
import org.quasiliteral.syntax.BaseLexer;
import org.quasiliteral.syntax.FileFeeder;
import org.quasiliteral.syntax.LineFeeder;
import org.quasiliteral.syntax.SyntaxException;
import org.quasiliteral.syntax.TwineFeeder;
+import org.quasiliteral.term.TermBuilder;
import java.io.BufferedReader;
import java.io.FileReader;
@@ -56,11 +55,17 @@
/**
*
*/
+ static public final AstroBuilder FOR_TERMS =
+ new TermBuilder(EParser.DEFAULT_SCHEMA);
+
+ /**
+ *
+ */
public ELexer(LineFeeder input,
boolean partialFlag,
boolean noTabsFlag)
throws IOException {
- this(input, partialFlag, noTabsFlag, FOR_ASTS);
+ this(input, partialFlag, noTabsFlag, FOR_TERMS);
}
/**
@@ -204,8 +209,7 @@
isIdentifierPart((char)myChar));
Twine name = endToken();
String key = name.bare().substring(1);
- int tt = optKeywordType(key);
- if (tt != -1) {
+ if (-1 != optKeywordType(key)) {
syntaxError(key + " is a keyword");
}
myIndenter.pop('$', name);
@@ -238,8 +242,7 @@
isIdentifierPart((char)myChar));
Twine name = endToken();
String key = name.bare().substring(1);
- int tt = optKeywordType(key);
- if (tt != -1) {
+ if (-1 != optKeywordType(key)) {
syntaxError(key + " is a keyword");
}
myIndenter.pop('@', name);
@@ -576,7 +579,7 @@
}
/**
- * If 'name' is a keyword, return it's token type code, else -1.
+ * If 'name' is a keyword, return it's token tag code, else -1.
* <p>
* Note that E keywords are case insensitive, so 'name' is first
* toLowerCase()d.
@@ -607,25 +610,24 @@
nextChar();
Twine source = endToken();
String name = source.bare().substring(0, source.size() - 1);
- int tt = optKeywordType(name);
- if (tt != -1) {
+ if (-1 != optKeywordType(name)) {
syntaxError(name + " is a keyword");
}
return composite(EParser.VerbAssign, name, source);
}
}
Twine source = endToken();
- short ttype = optKeywordType(source.bare());
- if (-1 == ttype) {
+ short tagCode = optKeywordType(source.bare());
+ if (-1 == tagCode) {
return composite(EParser.ID, source.bare(), source);
} else {
//keyword
- return leafTag(ttype, source);
+ return leafTag(tagCode, source);
}
}
/**
- * XXX In order to enable optValue to be recovered from ttype and
+ * XXX In order to enable optValue to be recovered from tagCode and
* source, we need four ttypes rather than the current two: QuasiOpen
* and QuasiClose.
*/
1.110 +15 -15 e/src/jsrc/org/erights/e/elang/syntax/EParser.java
Index: EParser.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/elang/syntax/EParser.java,v
retrieving revision 1.109
retrieving revision 1.110
diff -u -r1.109 -r1.110
--- EParser.java 2001/12/06 06:25:07 1.109
+++ EParser.java 2001/12/10 06:11:00 1.110
@@ -23,8 +23,8 @@
import org.erights.e.elib.tables.IdentityCacheTable;
import org.erights.e.elib.tables.IntTable;
import org.erights.e.elib.tables.Twine;
+import org.quasiliteral.astro.Astro;
import org.quasiliteral.astro.AstroSchema;
-import org.quasiliteral.astro.AstroToken;
import org.quasiliteral.astro.BaseSchema;
import org.quasiliteral.syntax.SyntaxException;
@@ -1307,23 +1307,23 @@
/**
*
*/
-private int yylex() {
- AstroToken token = null;
+private short yylex() {
+ Astro token = null;
try {
- token = (AstroToken)myLexer.nextToken();
+ token = myLexer.nextToken();
} catch (IOException ex) {
yyerror("io: " + ex);
}
yylval = token;
- return token.getType();
+ return token.getOptTagCode();
}
/**
*
*/
private void yyerror(String s) throws SyntaxException {
- int ttype = ((AstroToken)yylval).getType();
- if (EParser.EOFTOK == ttype && "syntax error".equals(s)) {
+ short tagCode = ((Astro)yylval).getOptTagCode();
+ if (EParser.EOFTOK == tagCode && "syntax error".equals(s)) {
myLexer.needMore("Unexpected EOF");
} else {
syntaxError(s);
@@ -1356,12 +1356,12 @@
*
*/
private boolean isTokenKind(Object tok, int[] members) {
- if (! (tok instanceof AstroToken)) {
+ if (! (tok instanceof Astro)) {
return false;
}
- int ttype = ((AstroToken)tok).getType();
+ short tagCode = ((Astro)tok).getOptTagCode();
for (int i = 0; i < members.length; i++) {
- if (ttype == members[i]) {
+ if (tagCode == members[i]) {
return true;
}
}
@@ -1662,7 +1662,7 @@
};
/**
- * TheContinuers[tokenType] says whether this is a continuation
+ * TheContinuers[tagCode] says whether this is a continuation
* operator.
*/
static private boolean[] TheContinuers = new boolean[yyname.length];
@@ -1680,8 +1680,8 @@
* If this token appears at the end of a line, does that make the next
* line a (to be indented) continuation line?
*/
-static public boolean isContinuer(int tokenType) {
- return TheContinuers[tokenType];
+static public boolean isContinuer(int tagCode) {
+ return TheContinuers[tagCode];
}
//#line 5602 "EParser.java"
//###############################################################
@@ -2660,12 +2660,12 @@
break;
case 260:
//#line 977 "e.y"
-{ yyval = ((AstroToken)val_peek(0)).getOptTokenData(); }
+{ yyval = ((Astro)val_peek(0)).getOptArgString(ID); }
break;
case 261:
//#line 978 "e.y"
{ reserved("keyword \"" +
- ((AstroToken)val_peek(0)).getText() +
+ ((Astro)val_peek(0)).getTag().getTagName() +
"\""); }
break;
case 262:
1.6 +1 -1 e/src/jsrc/org/erights/e/elang/syntax/PrettyFeeder.java
Index: PrettyFeeder.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/elang/syntax/PrettyFeeder.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- PrettyFeeder.java 2001/12/02 18:42:01 1.5
+++ PrettyFeeder.java 2001/12/10 06:11:01 1.6
@@ -24,8 +24,8 @@
import org.erights.e.elib.tables.FlexList;
import org.erights.e.elib.tables.Twine;
import org.quasiliteral.syntax.LineFeeder;
-import org.quasiliteral.syntax.TwineFeeder;
import org.quasiliteral.syntax.NeedMoreException;
+import org.quasiliteral.syntax.TwineFeeder;
import java.io.IOException;
1.99 +47 -47 e/src/jsrc/org/erights/e/elang/syntax/e.y
Index: e.y
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/elang/syntax/e.y,v
retrieving revision 1.98
retrieving revision 1.99
diff -u -r1.98 -r1.99
--- e.y 2001/12/05 00:46:10 1.98
+++ e.y 2001/12/10 06:11:01 1.99
@@ -40,8 +40,8 @@
import org.erights.e.elib.tables.IdentityCacheTable;
import org.erights.e.elib.tables.IntTable;
import org.erights.e.elib.tables.Twine;
+import org.quasiliteral.astro.Astro;
import org.quasiliteral.astro.AstroSchema;
-import org.quasiliteral.astro.AstroToken;
import org.quasiliteral.astro.BaseSchema;
import org.quasiliteral.syntax.SyntaxException;
@@ -76,31 +76,31 @@
/* Keywords */
%token BIND CATCH CLASS DEF DELEGATE
%token ELSE ESCAPE FINALLY FOR IF IN
-%token MATCH META PRAGMA SWITCH
+%token MATCH META PRAGMA SWITCH
%token THUNK TO TRY VAR WHEN WHILE _
/* Pseudo-reserved (Reserved, but used in reserved productions) */
-%token DEFINE ON SELECT TYPEDEF
+%token DEFINE ON SELECT TYPEDEF
/* Reserved Keywords */
-%token ABSTRACT AN AS ATTRIBUTE
-%token BE BEGIN BEHALF BELIEF BELIEVE BELIEVES
-%token CASE CONST CONSTRUCTOR CONTEXT
+%token ABSTRACT AN AS ATTRIBUTE
+%token BE BEGIN BEHALF BELIEF BELIEVE BELIEVES
+%token CASE CONST CONSTRUCTOR CONTEXT
%token DECLARE DEFAULT DEFMACRO DEPRECATED DISPATCH DO
%token ENCAPSULATE ENCAPSULATED ENCAPSULATES
%token END ENSURE ENUM EVENTUAL EVENTUALLY
%token EXPORT EXTENDS FACET FORALL FUNCTION GIVEN HIDDEN
%token HIDES IMPLEMENTS INTERFACE IS
-%token KNOW KNOWS LAMBDA LET METHOD METHODS MODULE
+%token KNOW KNOWS LAMBDA LET METHOD METHODS MODULE
%token NAMESPACE NATIVE
-%token OBEYS OCTET ONEWAY
-%token PACKAGE PRIVATE PROTECTED PUBLIC
+%token OBEYS OCTET ONEWAY
+%token PACKAGE PRIVATE PROTECTED PUBLIC
%token RAISES RELIANCE RELIANT RELIES RELY REVEAL
-%token SAKE SIGNED STATIC STRUCT
+%token SAKE SIGNED STATIC STRUCT
%token SUCHTHAT SUPPORTS SUSPECT SUSPECTS SYNCHRONIZED
-%token THIS THROWS TRANSIENT TRUNCATABLE
-%token UNSIGNED UNUM USES USING UTF8 UTF16
-%token VALUETYPE VIRTUAL VOLATILE WSTRING
+%token THIS THROWS TRANSIENT TRUNCATABLE
+%token UNSIGNED UNUM USES USING UTF8 UTF16
+%token VALUETYPE VIRTUAL VOLATILE WSTRING
/* The magical end-of-line token, not considered whitespace */
@@ -151,7 +151,7 @@
%%
-/**
+/**
* JAY - added EOLs to start production so we can accept
* "comment-only" programs.
*/
@@ -371,11 +371,11 @@
prefix
| prefix OpPow nPrefix { $$ = call($1, "pow", $3); }
;
-
+
/**
* unary !, ~, -, and & are non associative, and don't associate with
- * calls.
+ * calls.
*/
nPrefix:
prefix { $$ = list($1); }
@@ -393,7 +393,7 @@
/**
* All calls and sends are left associative, but split into postfix and
* call to resolve an ambiguity. The source of the ambiguity is now
- * in the pocket, so this issue may instead go away.
+ * in the pocket, so this issue may instead go away.
*/
postfix:
call
@@ -730,7 +730,7 @@
/**
* The name pattern, or literal name, for an object definition
- * expression
+ * expression
*/
oName:
noun { $$ = finalPattern($1); }
@@ -881,13 +881,13 @@
/**
* XXX Note that the 'begin' in the when-clauses form cannot be
- * positioned properly
+ * positioned properly
*/
whenHead:
whenArgs OpWhen audits begin '(' patterns ')' resultGuard
{ $$ = list($1, $3, $6, $8); }
- | audits begin '(' whenClauses ')' resultGuard
+ | audits begin '(' whenClauses ')' resultGuard
{ pocket("when-clauses");
$$ = list($1, $4, $6); }
;
@@ -974,9 +974,9 @@
* A non-reserved ID (as a String)
*/
ident:
- ID { $$ = ((AstroToken)$1).getData(); }
+ ID { $$ = ((Astro)$1).getOptArgString(ID); }
| reserved { reserved("keyword \"" +
- ((AstroToken)$1).getText() +
+ ((Astro)$1).getTag().getTagName() +
"\""); }
;
@@ -1059,7 +1059,7 @@
/**
* Middle path of a 'when' expression -- an least one catch clause is
- * required
+ * required
*/
catches:
catchList catchClause { $$ = with($1, $2); }
@@ -1165,22 +1165,22 @@
reserved:
ABSTRACT | AN | AS | ATTRIBUTE
| BE | BEGIN | BEHALF | BELIEF | BELIEVE | BELIEVES
- | CASE | CONST | CONSTRUCTOR | CONTEXT
+ | CASE | CONST | CONSTRUCTOR | CONTEXT
| DECLARE | DEFAULT | DEFMACRO | DEPRECATED | DISPATCH | DO
| ENCAPSULATE | ENCAPSULATED | ENCAPSULATES
| END | ENSURE | ENUM | EVENTUAL | EVENTUALLY
| EXPORT | EXTENDS | FACET | FORALL | FUNCTION | GIVEN | HIDDEN
| HIDES | IMPLEMENTS | INTERFACE | IS
- | KNOW | KNOWS | LAMBDA | LET | METHOD | METHODS | MODULE
+ | KNOW | KNOWS | LAMBDA | LET | METHOD | METHODS | MODULE
| NAMESPACE | NATIVE
- | OBEYS | OCTET | ONEWAY
- | PACKAGE | PRIVATE | PROTECTED | PUBLIC
+ | OBEYS | OCTET | ONEWAY
+ | PACKAGE | PRIVATE | PROTECTED | PUBLIC
| RAISES | RELIANCE | RELIANT | RELIES | RELY | REVEAL
- | SAKE | SIGNED | STATIC | STRUCT
+ | SAKE | SIGNED | STATIC | STRUCT
| SUCHTHAT | SUPPORTS | SUSPECT | SUSPECTS | SYNCHRONIZED
- | THIS | THROWS | TRANSIENT | TRUNCATABLE
+ | THIS | THROWS | TRANSIENT | TRUNCATABLE
| UNSIGNED | UNUM | USES | USING | UTF8 | UTF16
- | VALUETYPE | VIRTUAL | VOLATILE | WSTRING
+ | VALUETYPE | VIRTUAL | VOLATILE | WSTRING
;
@@ -1193,7 +1193,7 @@
static public final StaticMaker EParserMaker =
StaticMaker.make(EParser.class);
-/**
+/**
* caches previous simple parses (as is used for quasi-parsing)
*/
static private IdentityCacheTable OurCache =
@@ -1202,7 +1202,7 @@
/**
*
*/
-static private final ConstMap DefaultProps =
+static private final ConstMap DefaultProps =
ConstMap.fromProperties(System.getProperties());
@@ -1210,7 +1210,7 @@
/** contains all the tokens after yylval */
private ELexer myLexer;
-/**
+/**
* Do we escape after parsing only one expression, or do we parse the
* entire input?
*/
@@ -1312,7 +1312,7 @@
/**
* If the input is empty, returns the null expression e`null`, rather
- * than null.
+ * than null.
*/
public ENode parse() {
ENode result = optParse();
@@ -1354,23 +1354,23 @@
/**
*
*/
-private int yylex() {
- AstroToken token = null;
+private short yylex() {
+ Astro token = null;
try {
- token = (AstroToken)myLexer.nextToken();
+ token = myLexer.nextToken();
} catch (IOException ex) {
yyerror("io: " + ex);
}
yylval = token;
- return token.getType();
+ return token.getOptTagCode();
}
/**
*
*/
private void yyerror(String s) throws SyntaxException {
- int ttype = ((AstroToken)yylval).getType();
- if (EParser.EOFTOK == ttype && "syntax error".equals(s)) {
+ short tagCode = ((Astro)yylval).getOptTagCode();
+ if (EParser.EOFTOK == tagCode && "syntax error".equals(s)) {
myLexer.needMore("Unexpected EOF");
} else {
syntaxError(s);
@@ -1403,12 +1403,12 @@
*
*/
private boolean isTokenKind(Object tok, int[] members) {
- if (! (tok instanceof AstroToken)) {
+ if (! (tok instanceof Astro)) {
return false;
}
- int ttype = ((AstroToken)tok).getType();
+ short tagCode = ((Astro)tok).getOptTagCode();
for (int i = 0; i < members.length; i++) {
- if (ttype == members[i]) {
+ if (tagCode == members[i]) {
return true;
}
}
@@ -1652,7 +1652,7 @@
/**
* These are the tokens that may appear at the end of a line, in which
* case the next line is a (to be indented) continuation of the
- * expression.
+ * expression.
* <p>
* Note that > isn't on the list because of its role in closing a
* calculated URI expression.
@@ -1709,7 +1709,7 @@
};
/**
- * TheContinuers[tokenType] says whether this is a continuation
+ * TheContinuers[tagCode] says whether this is a continuation
* operator.
*/
static private boolean[] TheContinuers = new boolean[yyname.length];
@@ -1727,6 +1727,6 @@
* If this token appears at the end of a line, does that make the next
* line a (to be indented) continuation line?
*/
-static public boolean isContinuer(int tokenType) {
- return TheContinuers[tokenType];
+static public boolean isContinuer(int tagCode) {
+ return TheContinuers[tagCode];
}
1.37 +2 -6 e/src/jsrc/org/erights/e/elib/prim/VTable.java
Index: VTable.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/elib/prim/VTable.java,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- VTable.java 2001/12/02 06:01:46 1.36
+++ VTable.java 2001/12/10 06:11:02 1.37
@@ -335,13 +335,9 @@
return null;
}
}
- try {
- //since we have to pay the cost of a type check in order to cast,
- //let's pay it only once in the typical (no arity overloading)
- //case.
+ if (m instanceof MethodNode) {
result = (MethodNode)m;
-
- } catch (ClassCastException ex) {
+ } else {
//if it's not a MethodNode, it'd better be an array of MethodNodes
MethodNode[] arityTable = (MethodNode[])m;
if (arity < arityTable.length) {
1.4 +9 -46 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.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ASTBuilder.java 2001/12/06 09:26:41 1.3
+++ ASTBuilder.java 2001/12/10 06:11:03 1.4
@@ -3,6 +3,8 @@
import org.erights.e.elib.prim.E;
import org.erights.e.elib.tables.Twine;
+import java.math.BigInteger;
+
//This file is hereby placed in the public domain
/**
@@ -18,63 +20,32 @@
*
* @author <a href="mailto:markm@caplet.com">Mark Miller</a>
*/
-public class ASTBuilder implements AstroBuilder {
-
- /**
- *
- */
- private final AstroSchema mySchema;
+public class ASTBuilder extends BaseBuilder {
/**
*
*/
public ASTBuilder(AstroSchema schema) {
- mySchema = schema;
+ super(schema);
}
/**
*
*/
public String toString() {
- return "<building ASTs for " + mySchema.getSchemaName() + ">";
+ return "<building ASTs for " + getSchema().getSchemaName() + ">";
}
/**
*
- */
- public AstroSchema getSchema() {
- return mySchema;
- }
-
- /**
- * @return :AstroToken
*/
- public Astro leafTag(AstroTag tag, Twine source) {
- return new AstroToken(tag, null, source);
+ protected Astro leafInternal(AstroTag tag,
+ Object optData,
+ Twine source) {
+ return new AstroToken(tag, optData, source);
}
/**
- * @param data Must not be null
- * @param source
- * @return :AstroToken
- */
- public Astro leafData(Object data, Twine source) {
- return new AstroToken(mySchema.getTypeTag(data.getClass()),
- data,
- source);
- }
-
- /**
- * Returns a complex token rather than a AST.
- *
- * @param data Nust not be null
- * @return :AstroToken
- */
- public Astro composite(AstroTag tag, Object data, Twine source) {
- return new AstroToken(tag, data, source);
- }
-
- /**
* @param func :(AstroToken | AstroAST)
* @return :AstroAST
*/
@@ -153,13 +124,5 @@
*/
public AstroArg arg(Astro node) {
return (AstroAST)node;
- }
-
- /**
- *
- */
- public Object unpack(Astro litString) {
- throw new RuntimeException
- ("XXX unpack operator, '^', not yet implemented");
}
}
1.8 +19 -3 e/src/jsrc/org/quasiliteral/astro/Astro.java
Index: Astro.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/quasiliteral/astro/Astro.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Astro.java 2001/12/06 06:25:08 1.7
+++ Astro.java 2001/12/10 06:11:03 1.8
@@ -49,15 +49,31 @@
Object getOptData();
/**
- * Equivalent to either 'getOptData()' or, if that's null, to
- * 'getArgs()[0] getOptData()'.
+ * A convenience equivalent to '((Twine)getOptData()).bare()'
+ */
+ String getOptString();
+
+ /**
+ * Equivalent to 'getArgs()[0] getOptData()'.
* <p>
* This exists as an optimization for composite Tokens, which act like
* 1-argument Astros, where the 1-argument is a data argument. This
* operation allows us to avoid creating a singleton argument list just
* to access this data.
+ * <p>
+ * getOptArgData/1 should normally be used instead
+ */
+ Object getOptArgData();
+
+ /**
+ * Like getOptArgData/0, but first requires getOptTagCode() == tagCode.
+ */
+ Object getOptArgData(short tagCode);
+
+ /**
+ * A convenience equivalent to '((Twine)getOptArgData(tagCode)).bare()'
*/
- Object getOptTokenData();
+ String getOptArgString(short tagCode);
/**
* What source text was originally lexed or parsed to produce this token?
1.3 +25 -4 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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AstroAST.java 2001/12/06 09:26:41 1.2
+++ AstroAST.java 2001/12/10 06:11:03 1.3
@@ -165,12 +165,18 @@
}
/**
- * Initialize this instance with the given token.
+ * Initialize this instance with the given non-composite token.
*
- * @param optToken :AstroToken the token to associate with this instance
+ * @param optToken :AstroToken the non-composite token to associate with
+ * this instance
*/
public void initialize(Token optToken) {
myOptToken = (AstroToken)optToken;
+ if (null == myOptToken) {
+ return;
+ }
+ E.require(myOptToken.getTag().isTagForData(myOptToken.getOptData()),
+ "Must break apart composites: ", myOptToken);
}
/**
@@ -247,9 +253,24 @@
public Object getOptData() {
return myOptToken.getOptData();
}
+
+ public String getOptString() {
+ return ((Twine)getOptData()).bare();
+ }
+
+ public Object getOptArgData() {
+ return ((AstroAST)getFirstChild()).getOptData();
+ }
+
+ public Object getOptArgData(short tagCode) {
+ E.require(getTag().getOptTagCode() == tagCode,
+ "Tag mismatch: ", getTag(), " vs ",
+ getTag().getSchema().getOptTagForCode(tagCode));
+ return getOptArgData();
+ }
- public Object getOptTokenData() {
- return myOptToken.getOptTokenData();
+ public String getOptArgString(short tagCode) {
+ return ((Twine)getOptArgData(tagCode)).bare();
}
public Twine getSource() {
1.4 +46 -9 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.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- AstroBuilder.java 2001/12/06 09:26:41 1.3
+++ AstroBuilder.java 2001/12/10 06:11:03 1.4
@@ -4,6 +4,8 @@
import org.erights.e.elib.serial.Persistent;
import org.erights.e.elib.tables.Twine;
+import java.math.BigInteger;
+
//This file is hereby placed in the public domain
/**
@@ -27,21 +29,15 @@
/**
* Makes a leaf (eg, a Token) not representing literal data, but just a
- * token type, as identified by 'tag'.
+ * token tag (token type indicator) as identified by 'tag'.
* <p>
* The tag of the returned Astro should be according to the schema of this
- * builder, even though the argument tag may represent a type in a
- * different schema. In this case, the correspondence is by type name,
- * rather than type code.
+ * builder, even though the argument tag may be in a different schema.
+ * In this case, the correspondence is by tag name, rather than tag code.
*/
Astro leafTag(AstroTag tag, Twine source);
/**
- * Makes a leaf (eg, a Token) representing literal data.
- */
- Astro leafData(Object data, Twine source);
-
- /**
* Makes an Astro whose tag is according to 'tag', and whose one argument
* is a leaf according to 'data'.
* <p>
@@ -54,6 +50,47 @@
* allowed by the concrete builder.
*/
Astro composite(AstroTag tag, Object data, Twine source);
+
+ /**
+ * Makes a leaf (eg, a Token) representing literal data.
+ * <p>
+ * Once coerced, this is equivalent to one of the following leaf* methods,
+ * which are provided for efficiency
+ */
+ Astro leafData(Object data, Twine source);
+
+ /**
+ * A Unicode character
+ */
+ Astro leafChar(char data, Twine source);
+
+ /**
+ * Note that leafLong's data is a subrange of leafInteger's.
+ * <p>
+ * The former is limited to 64 bits, and the latter isn't limited.
+ */
+ Astro leafLong(long data, Twine source);
+
+ /**
+ * A precision unlimited integer
+ */
+ Astro leafInteger(BigInteger data, Twine source);
+
+ /**
+ * An IEEE double precision floating point number
+ */
+ Astro leafFloat64(double data, Twine source);
+
+ /**
+ * A String is just a bare twine
+ */
+ Astro leafString(String data, Twine source);
+
+ /**
+ * A list of characters with optional (ie, if not bare) annotation about
+ * where (source position) these characters came from.
+ */
+ Astro leafTwine(Twine data, Twine source);
/**
* At the Astro-level of semantics, for leaf Astros, this is an identity
1.8 +12 -8 e/src/jsrc/org/quasiliteral/astro/AstroSchema.java
Index: AstroSchema.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/quasiliteral/astro/AstroSchema.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- AstroSchema.java 2001/12/06 06:25:08 1.7
+++ AstroSchema.java 2001/12/10 06:11:03 1.8
@@ -22,28 +22,32 @@
String getSchemaName();
/**
- * Returns the tag represented by this type code in the grammar described
+ * Returns the tag represented by this tag code in the grammar described
* by this schema, or null.
*/
AstroTag getOptTagForCode(short tagCode);
/**
- * Returns the tag represented by this type code in the grammar described
- * by this schema
+ * Returns the tag represented by this tag code in the grammar described
+ * by this schema, or throw an exception.
*/
AstroTag getTagForCode(short tagCode);
/**
- * Returns the tag represented by this type name in the grammar described
- * by this schema, or null
+ * Returns the tag represented by this tag name in the grammar described
+ * by this schema, or null if this schema doesn't define this tagName.
*/
AstroTag getOptTagForName(String tagName);
/**
- * Returns the tag represented by this type name in the grammar described
- * by this schema
+ * Returns the tag represented by this tag name in the grammar described
+ * by this schema.
+ * <p>
+ * If there is no tag defined in this schema for this name, this still
+ * returns a (typically newly allocated) tag with this tagName and this
+ * schema, but with a tagCode of -1
*/
- AstroTag getTagForName(String tagName);
+ AstroTag obtainTagForName(String tagName);
/**
* Gets the tag for representing character literals.
1.5 +101 -43 e/src/jsrc/org/quasiliteral/astro/AstroTag.java
Index: AstroTag.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/quasiliteral/astro/AstroTag.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- AstroTag.java 2001/12/06 06:25:08 1.4
+++ AstroTag.java 2001/12/10 06:11:03 1.5
@@ -12,9 +12,9 @@
//This file is hereby placed in the public domain
/**
- * Represents both a grammar's tag-type (corresponds to the enumerated token
- * type code specific to an Antlr grammar), and a corresponding tag name (the
- * name of that enumerated code in that grammar).
+ * Represents both a grammar's tag code (corresponds to the enumerated token
+ * type code specific to an Antlr grammar -1), and a corresponding tag name
+ * (the name of that enumerated code in that grammar).
* <p>
* The notion of "specific to a grammar" is here abstracted into the notion
* of an {@link AstroSchema}, within which these tag-codes/tag-names are
@@ -49,6 +49,88 @@
}
/**
+ * If optDataType is a class of data that's promotable to one that's
+ * representable literally, then return the class that represents that
+ * literally-representable data type; otherwise null.
+ *
+ * @param optDataType null or the data type of some data we with to promote to
+ * a literal representation.
+ * @return null, or one of the classes {@link Character},
+ * @{link BigInteger}, {@link Double}, or {@link Twine}
+ */
+ static public Class optPromoteType(Class optDataType) {
+ if (null == optDataType) {
+ return null;
+ }
+ if (Character.class == optDataType) {
+ return Character.class;
+ }
+ if (String.class == optDataType ||
+ Twine.class.isAssignableFrom(optDataType)) {
+ return Twine.class;
+ }
+ if (Number.class.isAssignableFrom(optDataType)) {
+ if (Double.class == optDataType || Float.class == optDataType) {
+ return Double.class;
+ } else if (BigInteger.class == optDataType ||
+ Byte.class == optDataType ||
+ Short.class == optDataType ||
+ Integer.class == optDataType ||
+ Long.class == optDataType) {
+ return BigInteger.class;
+ } else {
+ throw new RuntimeException("Unrecognized number type: " +
+ optDataType);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * If optData is a data that's promotable to data that's representable
+ * literally, then return that literally representable; otherwise null.
+ * <p>
+ * The obvious correctness criteria must hold between optPromoteData and
+ * optPromoteType. If p := optPromoteData(d), then <pre>
+ * p.getClass() == optPromoteType(d.getClass())
+ * </pre>
+ *
+ * @param optData null or some data we with to promote to a literal
+ * representation.
+ * @return null, or a {@link Character},
+ * @{link BigInteger}, {@link Double}, or {@link Twine}
+ */
+ static public Object optPromoteData(Object optData) {
+ if (null == optData) {
+ return null;
+ }
+ if (optData instanceof Character || optData instanceof Twine) {
+ return optData;
+ }
+ if (optData instanceof String) {
+ return Twine.fromString((String)optData);
+ }
+ if (optData instanceof Number) {
+ if (optData instanceof Double || optData instanceof BigInteger) {
+ return optData;
+ }
+ if (optData instanceof Float) {
+ return new Double(((Float)optData).doubleValue());
+ }
+ if (optData instanceof Byte ||
+ optData instanceof Short ||
+ optData instanceof Integer ||
+ optData instanceof Long) {
+
+ return BigInteger.valueOf(((Number)optData).longValue());
+ }
+ throw new RuntimeException("Unrecognized number type: " +
+ optData);
+ }
+ return null;
+ }
+
+ /**
* @serial The enumerated tag code, or -1.
*/
private final short myOptTagCode;
@@ -59,9 +141,9 @@
private final String myTagName;
/**
- * @serial The schema of which this tag is a member, or null.
+ * @serial The schema of which this tag is a member.
*/
- private final AstroSchema myOptSchema;
+ private final AstroSchema mySchema;
/**
* @serial If this tag is a normal symbolic tag, this is null. If it's
@@ -74,8 +156,9 @@
/**
*
* @param optTagCode The enumerated tag code, or -1.
- * @param tagName The name of the enumerated type code.
- * @param optSchema The schema of which this tag is a member, or null.
+ * @param tagName The name of the enumerated tag code.
+ * @param optSchema The schema of which this tag is a member, or null, in
+ * which case it defaults to @{link BaseSchema#MINIMAL}.
* @param optDataType Either null, or the kind of data labeled by this
* tag.
*/
@@ -85,18 +168,12 @@
Class optDataType) {
myOptTagCode = optTagCode;
myTagName = tagName.intern();
- myOptSchema = optSchema;
- myOptDataType = optDataType;
- if (null != optDataType) {
- E.require(null != optSchema,
- "internal: Can't have a data type without a schema");
- }
+ mySchema = (null == optSchema ? BaseSchema.MINIMAL : optSchema);
+ myOptDataType = optPromoteType(optDataType);
}
public String toString() {
- return "<" + myTagName +
- (null == myOptSchema ? "" : (":" + myOptSchema)) +
- ">";
+ return "<" + myTagName + ":" + mySchema + ">";
}
/**
@@ -114,10 +191,12 @@
}
/**
- * The schema of which this tag is a member, or null.
+ * The schema of which this tag is a member.
+ * <p>
+ * If none, defaults to {@link BaseSchema#MINIMAL}
*/
- public AstroSchema getOptSchema() {
- return myOptSchema;
+ public AstroSchema getSchema() {
+ return mySchema;
}
/**
@@ -143,35 +222,14 @@
}
if (null == myOptDataType) {
return false;
- }
- //Doesn't matter what schema we use, since we're just canonicalizing
- //the data type.
- AstroTag optDataTag =
- BaseSchema.MINIMAL.getOptTypeTag(optData.getClass());
- if (null == optDataTag) {
- return false;
}
- return myOptDataType == optDataTag.getOptDataType();
+ return myOptDataType == optPromoteType(optData.getClass());
}
/**
- * if they have the same schema, or if either of both has no,
- * schema, then they are compared based on their typeNames.
- * <p>
- * Otherwise, they are incomparable.
+ * Compare on tag names regardless of schema or tag codes
*/
public double compareTo(AstroTag other) {
- if (Ref.same(myOptSchema, other.myOptSchema) ||
- null == myOptSchema ||
- null == other.myOptSchema) {
- if (myTagName == other.myTagName) {
- //since we know they're interned, it's worth doing this
- //check before the general compareTo.
- return 0.0;
- }
- return (double)myTagName.compareTo(other.myTagName);
- } else {
- return Double.NaN;
- }
+ return (double)myTagName.compareTo(other.myTagName);
}
}
1.12 +31 -18 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.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- AstroToken.java 2001/12/06 09:26:41 1.11
+++ AstroToken.java 2001/12/10 06:11:03 1.12
@@ -30,7 +30,7 @@
* {@link String}, or {@link Twine}. If not null, then the type must
* correspond to the tag.
*/
- private Object myOptData;
+ private final Object myOptData;
/**
*
@@ -45,31 +45,29 @@
*/
public AstroToken() {
super();
+ myOptData = null;
}
/**
- * Makes a Token that represents a token in some grammar.
+ * Makes a AstroToken that represents a token in some grammar.
+ * <p>
+ * The invariants of an AstroToken are not checked here, but rather are
+ * enforced by the callers in this class and in ASTBuilder.
*
* @param tag Identifies a token type in a particular grammar or set
* of related grammars.
- * @param optData {@link Character},
+ * @param optData null, {@link Character},
* {@link BigInteger}, {@link Double},
- * {@link String}, or {@link Twine} presumably calculated
+ * or {@link Twine} presumably calculated
* from lexing this token
* @param source The source text this token was extracted from. To
* provide no info, use "" rather than null.
*/
- public AstroToken(AstroTag tag, Object optData, Twine source) {
+ /*package*/ AstroToken(AstroTag tag, Object optData, Twine source) {
super(AstroTag.tagCode2typeCode(tag.getOptTagCode()));
myOptTag = tag;
- //XXX should promote optData to its canonical type if necessary
myOptData = optData;
setSource(source);
- Class type = myOptTag.getOptDataType();
- if (null != myOptData && null != type) {
- E.require(myOptData.getClass() == type,
- "Literal tag mismatch: ", tag, " vs ", optData.getClass());
- }
}
/**
@@ -160,14 +158,30 @@
}
}
+ public String getOptString() {
+ return ((Twine)getOptData()).bare();
+ }
+
/**
*
*/
- public Object getOptTokenData() {
- E.require(null != myOptData, "No data");
+ public Object getOptArgData() {
+ E.require(! (getTag().isTagForData(myOptData)),
+ "Not a composite: ", this);
return myOptData;
}
+ public Object getOptArgData(short tagCode) {
+ E.require(getTag().getOptTagCode() == tagCode,
+ "Tag mismatch: ", getTag(), " vs ",
+ getTag().getSchema().getOptTagForCode(tagCode));
+ return getOptArgData();
+ }
+
+ public String getOptArgString(short tagCode) {
+ return ((Twine)getOptArgData(tagCode)).bare();
+ }
+
/**
*
*/
@@ -266,11 +280,10 @@
if (getTag().isTagForData(myOptData)) {
return ConstList.EmptyList;
} else {
- AstroTag dataTag =
- getTag().getOptSchema().getTypeTag(myOptData.getClass());
- return ConstList.EmptyList.with(new AstroToken(dataTag,
- myOptData,
- getSource()));
+ //XXX refactor to avoid allocation
+ AstroBuilder builder = new ASTBuilder(getTag().getSchema());
+ Astro arg = builder.leafData(myOptData, getSource());
+ return ConstList.EmptyList.with(arg);
}
}
1.8 +7 -5 e/src/jsrc/org/quasiliteral/astro/BaseSchema.java
Index: BaseSchema.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/quasiliteral/astro/BaseSchema.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- BaseSchema.java 2001/12/06 06:25:08 1.7
+++ BaseSchema.java 2001/12/10 06:11:03 1.8
@@ -179,7 +179,7 @@
*/
public AstroTag getTagForCode(short tagCode) {
AstroTag optResult = getOptTagForCode(tagCode);
- E.requireSI(null != optResult, "No tag for type code: ", tagCode);
+ E.requireSI(null != optResult, "No tag for tag code: ", tagCode);
return optResult;
}
@@ -193,10 +193,12 @@
/**
*
*/
- public AstroTag getTagForName(String tagName) {
+ public AstroTag obtainTagForName(String tagName) {
AstroTag optResult = getOptTagForName(tagName);
- E.require(null != optResult, "No tag named: ", tagName);
- return optResult;
+ if (null != optResult) {
+ return optResult;
+ }
+ return new AstroTag((short)-1, tagName, this, null);
}
/**
@@ -248,7 +250,7 @@
clazz);
}
}
- if (Twine.class == clazz || String.class == clazz) {
+ if (String.class == clazz || Twine.class.isAssignableFrom(clazz)) {
return myLiteralStringTag;
}
return null;
1.1 e/src/jsrc/org/quasiliteral/astro/BaseBuilder.java
Index: BaseBuilder.java
===================================================================
package org.quasiliteral.astro;
import org.erights.e.elib.tables.Twine;
import java.math.BigInteger;
//This file is hereby placed in the public domain
/**
*
* @author <a href="mailto:markm@caplet.com">Mark Miller</a>
*/
public abstract class BaseBuilder implements AstroBuilder {
/**
*
*/
private final AstroSchema mySchema;
/**
*
*/
protected BaseBuilder(AstroSchema schema) {
mySchema = schema;
}
/**
*
*/
public AstroSchema getSchema() {
return mySchema;
}
/**
* Actually makes the kind of leaf this builder makes.
* <p>
* This is 'internal*' and 'protected' because it assumes that the
* general invariants among the arguments are already ensured. It is up
* to the callers of leafInternal to ensure this.
*
* @param tag Identifies a token type in a particular grammar or set
* of related grammars.
* @param optData null, or a {@link Character},
* {@link BigInteger}, {@link Double},
* or {@link Twine} presumably calculated from lexing this
* token. If not null, then if the tag is the
* corresponding literal-type-tag, then this is still a
* leaf. Otherwise, it's a composite.
* @param source The source text this token was presumably extracted from.
* To provide no info, use "" rather than null.
*/
protected abstract Astro leafInternal(AstroTag tag,
Object optData,
Twine source);
/**
* @return :AstroToken
*/
public Astro leafTag(AstroTag tag, Twine source) {
return leafInternal(tag, null, source);
}
/**
* Returns a complex token rather than a AST.
*
* @param data Nust not be null
* @return :AstroToken
*/
public Astro composite(AstroTag tag, Object data, Twine source) {
data = AstroTag.optPromoteData(data);
return leafInternal(tag, data, source);
}
/**
* @param data Must not be null
* @param source
* @return :AstroToken
*/
public Astro leafData(Object data, Twine source) {
data = AstroTag.optPromoteData(data);
return leafInternal(mySchema.getTypeTag(data.getClass()),
data,
source);
}
public Astro leafChar(char data, Twine source) {
return leafInternal(mySchema.getLiteralCharTag(),
new Character(data),
source);
}
public Astro leafLong(long data, Twine source) {
return leafInternal(mySchema.getLiteralIntegerTag(),
BigInteger.valueOf(data),
source);
}
public Astro leafInteger(BigInteger data, Twine source) {
return leafInternal(mySchema.getLiteralIntegerTag(),
data,
source);
}
public Astro leafFloat64(double data, Twine source) {
return leafInternal(mySchema.getLiteralFloat64Tag(),
new Double(data),
source);
}
public Astro leafString(String data, Twine source) {
return leafInternal(mySchema.getLiteralStringTag(),
Twine.fromString(data),
source);
}
public Astro leafTwine(Twine data, Twine source) {
return leafInternal(mySchema.getLiteralStringTag(),
data,
source);
}
/**
*
*/
public Object unpack(Astro litString) {
throw new RuntimeException
("XXX unpack operator, '^', not yet implemented");
}
}
1.3 +28 -2 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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- QuasiBuilderAdaptor.java 2001/12/06 09:26:41 1.2
+++ QuasiBuilderAdaptor.java 2001/12/10 06:11:03 1.3
@@ -8,6 +8,8 @@
import org.quasiliteral.astro.AstroArg;
import org.quasiliteral.term.TermBuilder;
+import java.math.BigInteger;
+
//This file is hereby placed in the public domain
/**
@@ -55,12 +57,36 @@
return myBuilder.leafTag(tag, source);
}
+ public Astro composite(AstroTag tag, Object data, Twine source) {
+ return myBuilder.composite(tag, data, source);
+ }
+
public Astro leafData(Object data, Twine source) {
return myBuilder.leafData(data, source);
}
- public Astro composite(AstroTag tag, Object data, Twine source) {
- return myBuilder.composite(tag, data, source);
+ public Astro leafChar(char data, Twine source) {
+ return myBuilder.leafChar(data, source);
+ }
+
+ public Astro leafLong(long data, Twine source) {
+ return myBuilder.leafLong(data, source);
+ }
+
+ public Astro leafInteger(BigInteger data, Twine source) {
+ return myBuilder.leafInteger(data, source);
+ }
+
+ public Astro leafFloat64(double data, Twine source) {
+ return myBuilder.leafFloat64(data, source);
+ }
+
+ public Astro leafString(String data, Twine source) {
+ return myBuilder.leafString(data, source);
+ }
+
+ public Astro leafTwine(Twine data, Twine source) {
+ return myBuilder.leafTwine(data, source);
}
public Astro node(Astro leaf) {
1.5 +4 -11 e/src/jsrc/org/quasiliteral/syntax/BaseLexer.java
Index: BaseLexer.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/quasiliteral/syntax/BaseLexer.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- BaseLexer.java 2001/12/06 06:25:09 1.4
+++ BaseLexer.java 2001/12/10 06:11:03 1.5
@@ -372,13 +372,6 @@
/**
*
*/
- protected Astro leafData(Object data, Twine source) {
- return myBuilder.leafData(data, source);
- }
-
- /**
- *
- */
protected Astro composite(short tagCode, Object data, Twine source) {
AstroTag tag = myBuilder.getSchema().getTagForCode(tagCode);
return myBuilder.composite(tag, data, source);
@@ -507,7 +500,7 @@
syntaxError("char constant must end in \"'\"");
}
nextChar();
- return leafData(new Character(value), endToken());
+ return myBuilder.leafChar(value, endToken());
}
/**
@@ -603,13 +596,13 @@
Twine tok = endToken();
String str = tok.replaceAll("_", "").bare();
if (floating) {
- return leafData(Double.valueOf(str), tok);
+ return myBuilder.leafFloat64(Double.parseDouble(str), tok);
} else {
if (radix == 16) {
//remove the leading "0x" to make BigInteger happy
str = str.substring(2);
}
- return leafData(new BigInteger(str, radix), tok);
+ return myBuilder.leafInteger(new BigInteger(str, radix), tok);
}
}
@@ -719,6 +712,6 @@
nextChar();
Twine closer = endToken();
myIndenter.pop('"', closer);
- return leafData(value.toString(), closer);
+ return myBuilder.leafString(value.toString(), closer);
}
}
1.13 +34 -7 e/src/jsrc/org/quasiliteral/term/Term.java
Index: Term.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/quasiliteral/term/Term.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- Term.java 2001/12/06 09:26:41 1.12
+++ Term.java 2001/12/10 06:11:03 1.13
@@ -82,15 +82,28 @@
private transient int myHeight = 0;
/**
- * @param tag Represents the token-type of the functor.
- * @param optData Either literal data or null. If not null, then the tag
+ * Makes a Term that represents a node in an abstract syntax tree, ie,
+ * a Term tree.
+ * <p>
+ * The invariants of a Term are not checked here, but rather are
+ * enforced by the callers in this class and in TermBuilder.
+ *
+ * @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 source What source text was originally lexed or parsed to
- * produce this token?
+ * @param source The source text this token was extracted from. To
+ * provide no info, use "" rather than null.
* @param args This Term's argument list -- a list of Terms
*/
- public Term(AstroTag tag, Object optData, Twine source, ConstList args) {
+ /*package*/ Term(AstroTag tag,
+ Object optData,
+ Twine source,
+ ConstList args) {
myTag = tag;
myOptData = optData;
mySource = source;
@@ -153,11 +166,25 @@
return myOptData;
}
+ public String getOptString() {
+ return ((Twine)getOptData()).bare();
+ }
+
/**
*
*/
- public Object getOptTokenData() {
- throw new RuntimeException("XXX not yet implemented");
+ public Object getOptArgData() {
+ return ((Term)myArgs.get(0)).getOptData();
+ }
+
+ public Object getOptArgData(short tagCode) {
+ E.require(tagCode == myTag.getOptTagCode(),
+ "Tag mismatch: ", myTag, " vs ", new Integer(tagCode));
+ return ((Term)myArgs.get(0)).getOptData();
+ }
+
+ public String getOptArgString(short tagCode) {
+ return ((Twine)getOptArgData(tagCode)).bare();
}
/**
1.13 +11 -42 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.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- TermBuilder.java 2001/12/06 09:26:41 1.12
+++ TermBuilder.java 2001/12/10 06:11:03 1.13
@@ -10,7 +10,10 @@
import org.quasiliteral.astro.Astro;
import org.quasiliteral.astro.AstroTag;
import org.quasiliteral.astro.AstroArg;
+import org.quasiliteral.astro.BaseBuilder;
+import java.math.BigInteger;
+
//This file is hereby placed in the public domain
/**
@@ -25,7 +28,7 @@
*
* @author <a href="mailto:markm@caplet.com">Mark Miller</a>
*/
-public class TermBuilder implements AstroBuilder {
+public class TermBuilder extends BaseBuilder {
/**
* Builds Term trees according to the term.y grammar
@@ -34,11 +37,6 @@
new TermBuilder(TermParser.DEFAULT_SCHEMA);
/**
- *
- */
- private AstroSchema mySchema;
-
- /**
* Builds Term trees according to the term.y grammar
*/
static public final ASTBuilder FOR_ASTS =
@@ -48,50 +46,29 @@
*
*/
public TermBuilder(AstroSchema schema) {
- mySchema = schema;
+ super(schema);
}
/**
*
*/
public String toString() {
- return "<building Term trees for " + mySchema.getSchemaName() + ">";
+ return "<building Term trees for " +
+ getSchema().getSchemaName() + ">";
}
/**
*
*/
- public AstroSchema getSchema() {
- return mySchema;
- }
-
- /**
- * @return :Term
- */
- public Astro leafTag(AstroTag tag, Twine source) {
+ protected Astro leafInternal(AstroTag tag,
+ Object optData,
+ Twine source) {
return new Term(tag,
- null,
- source,
- ConstList.EmptyList);
- }
-
- /**
- * @return :Term
- */
- public Astro leafData(Object data, Twine source) {
- return new Term(mySchema.getTypeTag(data.getClass()),
- data,
+ optData,
source,
ConstList.EmptyList);
}
- /**
- * Since Term/Functor trees don't allow composite leaves (Functors), this
- * instead returns a 1-argument Term whose functor represents the type
- * code, and whose argument represents the data.
- *
- * @return :Term
- */
public Astro composite(AstroTag tag, Object data, Twine source) {
return node(leafTag(tag, source),
argList(arg(leafData(data, source))));
@@ -170,13 +147,5 @@
*/
public AstroArg arg(Astro node) {
return (Term)node;
- }
-
- /**
- *
- */
- public Object unpack(Astro litString) {
- throw new RuntimeException
- ("XXX unpack operator, '^', not yet implemented");
}
}
1.13 +5 -12 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.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- TermParser.java 2001/12/06 06:25:09 1.12
+++ TermParser.java 2001/12/10 06:11:03 1.13
@@ -333,7 +333,7 @@
/**
* builder defaults to the quasi-adapted, non-quasi builder for
- * building Term trees.
+ * building Term trees.
*/
static public Term run(Twine source) {
return (Term)run(source, QuasiBuilderAdaptor.FOR_TERMS);
@@ -365,8 +365,8 @@
}
return null; //keep compiler happy
}
-
+
/**
*
*/
@@ -394,13 +394,6 @@
}
}
-/**
- *
- */
-static /*package*/ boolean isContinuer(int ttype) {
- return false; //for now
-}
-
/*********************************/
@@ -422,7 +415,7 @@
TheTokens[EOFTOK] = "EndOfFile";
TheTokens[ID] = "ID";
-
+
TheTokens[LiteralInteger] = "LiteralInteger";
TheTokens[LiteralFloat64] = "LiteralFloat64";
TheTokens[LiteralChar] = "LiteralChar";
@@ -439,7 +432,7 @@
static public final AstroSchema DEFAULT_SCHEMA =
new BaseSchema("Term-Tree-Language", ConstList.fromArray(TheTokens));
-//#line 391 "TermParser.java"
+//#line 384 "TermParser.java"
//###############################################################
// method: yylexdebug : check lexer state
//###############################################################
@@ -669,7 +662,7 @@
//#line 132 "term.y"
{ yyval = b.atHole( (Astro)val_peek(1)); }
break;
-//#line 618 "TermParser.java"
+//#line 611 "TermParser.java"
//########## END OF USER-SUPPLIED ACTIONS ##########
}//switch
//#### Now let's reduce... ####
1.12 +6 -13 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.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- term.y 2001/12/06 06:25:10 1.11
+++ term.y 2001/12/10 06:11:03 1.12
@@ -45,12 +45,12 @@
* functor
* | functor '(' argList ')'
* ;
- *
+ *
* argList:
* //empty
* | args
* ;
- *
+ *
* args:
* seq
* | args ',' seq
@@ -59,7 +59,7 @@
* seq:
* term
* | '^' LiteralString
- *
+ *
* functor:
* ID
* | LiteralChar
@@ -162,7 +162,7 @@
/**
* builder defaults to the quasi-adapted, non-quasi builder for
- * building Term trees.
+ * building Term trees.
*/
static public Term run(Twine source) {
return (Term)run(source, QuasiBuilderAdaptor.FOR_TERMS);
@@ -194,8 +194,8 @@
}
return null; //keep compiler happy
}
-
+
/**
*
*/
@@ -223,13 +223,6 @@
}
}
-/**
- *
- */
-static /*package*/ boolean isContinuer(int ttype) {
- return false; //for now
-}
-
/*********************************/
@@ -251,7 +244,7 @@
TheTokens[EOFTOK] = "EndOfFile";
TheTokens[ID] = "ID";
-
+
TheTokens[LiteralInteger] = "LiteralInteger";
TheTokens[LiteralFloat64] = "LiteralFloat64";
TheTokens[LiteralChar] = "LiteralChar";