[e-cvs] cvs commit: e/src/jsrc/org/quasiliteral/astro MilkAST.java MilkToken.java Functor.java TermTree.java
markm@eros.cs.jhu.edu
markm@eros.cs.jhu.edu
Thu, 1 Nov 2001 01:56:50 -0500
markm 01/11/01 01:56:50
Modified: src/jsrc/org/erights/e/elang/syntax ELexer.java EParser.java
QuasiPart.java Token.java e.y
src/jsrc/org/quasiliteral/astro Functor.java TermTree.java
Added: src/esrc/com/skyhunter/installer testAgreedCapsVow.e
src/jsrc/org/quasiliteral/astro MilkAST.java MilkToken.java
Log:
Closer to switching to MilkToken
Revision Changes Path
1.1 e/src/esrc/com/skyhunter/installer/testAgreedCapsVow.e
Index: testAgreedCapsVow.e
===================================================================
//Copyright (C) 2001 Combex. All Rights Reserved.
def capsPetsMaker := <import:com.skyhunter.installer.agreedCapsPetsVowMakerAuthor> run(
unsafe__uriGetter, file__uriGetter)
var capPetvow := capsPetsMaker new("
<requests>
<urlProtocols>
<protocol>
<name>http</name>
<why>Just Because</why>
</protocol>
<protocol>
<name>ftp</name>
<why>I need it!</why>
</protocol>
<protocol>
<name>file</name>
<why>I really need it!</why>
</protocol>
</urlProtocols>
<pet>
<name>TestName</name>
<suffix>txt</suffix>
<icon>data/capEdit.gif</icon>
</pet>
</requests>",
<c:/eProjects/capEdit/capEdit.caplet> getParent())
#capPetvow := capsPetsMaker new("<requests></requests>")
println(`capPet promise: $capPetvow`)
when (capPetvow) -> done(capPet) {
println("got answer, xml: " + capPet getCapsXML())
println("appMap: " + capPet getPetMap())
} catch prob {println("prob: " + prob)}
interp blockAtTop()
1.57 +4 -4 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.56
retrieving revision 1.57
diff -u -r1.56 -r1.57
--- ELexer.java 2001/11/01 06:32:24 1.56
+++ ELexer.java 2001/11/01 06:56:50 1.57
@@ -255,7 +255,7 @@
myOptStartPos = -1;
myOptStartText = null;
}
- if (EParser.isContinuer(result.tokenType())) {
+ if (EParser.isContinuer(result.getType())) {
return continuer(result);
} else {
return result;
@@ -642,7 +642,7 @@
skipLine();
stopToken();
Token result = getNextToken();
- if (result.tokenType() == EParser.EOFTOK) {
+ if (result.getType() == EParser.EOFTOK) {
needMore("continued line");
return null; //make compiler happy
} else {
@@ -1232,10 +1232,10 @@
do {
t = lex.nextToken();
stdout.println(t);
- if (t.tokenType() == '\n') {
+ if (t.getType() == '\n') {
stdout.println(lex.myIndenter.toString());
}
- } while (t.tokenType() != EParser.EOFTOK);
+ } while (t.getType() != EParser.EOFTOK);
return;
} catch (SyntaxException sex) {
TextWriter err = new TextWriter(PrintStreamWriter.err(),
1.94 +2 -2 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.93
retrieving revision 1.94
diff -u -r1.93 -r1.94
--- EParser.java 2001/11/01 06:32:24 1.93
+++ EParser.java 2001/11/01 06:56:50 1.94
@@ -1309,14 +1309,14 @@
}
yytext = token.getText();
yylval = token;
- return token.tokenType();
+ return token.getType();
}
/**
*
*/
private void yyerror(String s) throws SyntaxException {
- int ttype = ((Token)yylval).tokenType();
+ int ttype = ((Token)yylval).getType();
if (EParser.EOFTOK == ttype && "syntax error".equals(s)) {
myLexer.needMore("Unexpected EOF");
1.13 +0 -1 e/src/jsrc/org/erights/e/elang/syntax/QuasiPart.java
Index: QuasiPart.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/elang/syntax/QuasiPart.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- QuasiPart.java 2001/09/06 09:55:46 1.12
+++ QuasiPart.java 2001/11/01 06:56:50 1.13
@@ -30,7 +30,6 @@
*/
public class QuasiPart extends Token {
- private String myToken;
private String myValue;
/**
1.11 +1 -1 e/src/jsrc/org/erights/e/elang/syntax/Token.java
Index: Token.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/elang/syntax/Token.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- Token.java 2001/11/01 06:32:25 1.10
+++ Token.java 2001/11/01 06:56:50 1.11
@@ -53,7 +53,7 @@
/**
*
*/
- public int tokenType() { return myTokenType; }
+ public int getType() { return myTokenType; }
/**
*
1.88 +2 -2 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.87
retrieving revision 1.88
diff -u -r1.87 -r1.88
--- e.y 2001/11/01 06:32:25 1.87
+++ e.y 2001/11/01 06:56:50 1.88
@@ -1355,14 +1355,14 @@
}
yytext = token.getText();
yylval = token;
- return token.tokenType();
+ return token.getType();
}
/**
*
*/
private void yyerror(String s) throws SyntaxException {
- int ttype = ((Token)yylval).tokenType();
+ int ttype = ((Token)yylval).getType();
if (EParser.EOFTOK == ttype && "syntax error".equals(s)) {
myLexer.needMore("Unexpected EOF");
1.4 +1 -1 e/src/jsrc/org/quasiliteral/astro/Functor.java
Index: Functor.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/quasiliteral/astro/Functor.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Functor.java 2001/11/01 06:32:25 1.3
+++ Functor.java 2001/11/01 06:56:50 1.4
@@ -104,7 +104,7 @@
/**
*
*/
- public Token asToken(ConstMap typeNums) {
+ public MilkToken asToken(ConstMap typeNums) {
int tokenTypeInt = E.asInt(typeNums.get(myTokenType));
return new MilkToken(tokenTypeInt, mySource, myOptValue);
}
1.2 +8 -10 e/src/jsrc/org/quasiliteral/astro/TermTree.java
Index: TermTree.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/quasiliteral/astro/TermTree.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TermTree.java 2001/10/26 07:56:09 1.1
+++ TermTree.java 2001/11/01 06:56:50 1.2
@@ -72,19 +72,17 @@
/**
* Converts an Antlr AST to a TermTree, while preserving all the vanilla
* AST semantics.
- * <p>
- * XXX Currently, this just uses the information that's universal to all
- * Antlr ASTs. Unfortunately, this loses extra information provided by
- * subclasses. There's nothing we can do about this in general, but we
- * should at least define Danfuzz-like subclasses that represent the
- * extra info that TermTrees can represent, and convert to an from these
- * faithfully if we encounter them.
*/
static public TermTree fromAST(AST ast,
String url,
ConstList typeNames)
{
- Token token = new CommonToken(ast.getType(), ast.getText());
+ Token token;
+ if (ast instanceof MilkAST) {
+ token = ((MilkAST)ast).getToken();
+ } else {
+ token = new CommonToken(ast.getType(), ast.getText());
+ }
FlexList args = FlexList.fromType(TermTree.class);
for (AST arg = ast.getFirstChild();
null != arg;
@@ -99,9 +97,9 @@
/**
* Convert this TermTree to an equivalent Antlr AST representation.
*/
- public AST asAST(ConstMap typeNums) {
+ public MilkAST asAST(ConstMap typeNums) {
Token token = myFunctor.asToken(typeNums);
- AST result = new CommonAST(token);
+ MilkAST result = new MilkAST(token);
for (int i = 0; i < myArgs.size(); i++) {
result.addChild(((TermTree)myArgs.get(i)).asAST(typeNums));
}
1.1 e/src/jsrc/org/quasiliteral/astro/MilkAST.java
Index: MilkAST.java
===================================================================
package org.quasiliteral.astro;
import antlr.Token;
import antlr.CommonToken;
import antlr.BaseAST;
import antlr.collections.AST;
/**
* AST node implementation which stores tokens explicitly. This
* is handy if you'd rather derive information from tokens on an
* as-needed basis instead of snarfing data from a token as an AST
* is being built.
*
* @author <a href="mailto:markm@caplet.com">Mark S Miller</a>
* @author Based on Danfuzz Bornstien's TokenAST
*/
public class MilkAST extends BaseAST {
/**
*
*/
private Token myToken;
/**
* Construct an instance which (at least initially) is not associated
* with a token.
*/
public MilkAST() {
myToken = null;
}
/**
* Construct an instance which is associated with the given token.
*
* @param tok null-ok; the token to associate this instance with
*/
public MilkAST(Token tok) {
initialize(tok);
}
// ------------------------------------------------------------------------
// public instance methods
/**
* Get the token text for this instance. If there is no token associated
* with this instance, then this returns the empty string
* (<code>""</code>), not <code>null</code>.
*
* @return non-null; the token text
*/
public String getText() {
if (myToken == null) {
return "";
} else {
return myToken.getText();
}
}
/**
* Get the token type for this instance. If there is no token associated
* with this instance, then this returns {@link Token#INVALID_TYPE}.
*
* @return the token type
*/
public int getType() {
if (myToken == null) {
return Token.INVALID_TYPE;
} else {
return myToken.getType();
}
}
/**
* Get the token associated with this instance. If there is no token
* associated with this instance, then this returns <code>null</code>.
*
* @return null-ok; the token associated with this instance or
* <code>mull</code> if there is no associated token
*/
public Token getToken() {
return myToken;
}
/**
* Set the token associated with this instance.
*
* @param tok null-ok; the new token to associate with this instance
*/
public void setToken(Token tok) {
myToken = tok;
}
/**
* Initialize this instance with the given token.
*
* @param tok null-ok; the token to associate with this instance
*/
public void initialize(Token tok) {
myToken = tok;
}
/**
* Initialize this instance with the given token type and text.
* This will construct a new {@link CommonToken} with the given
* parameters and associate this instance with it.
*
* @param type the token type
* @param text null-ok; the token text
*/
public void initialize(int type, String text) {
initialize(new CommonToken(type, text));
}
/**
* Initialize this instance based on the given {@link AST}.
* If the given <code>AST</code> is in fact an instance of
* <code>MilkAST</code>, then this instance will be initialized
* to point at the same token as the given one. If not, then this
* instance will be initialized with the same token type and text
* as the given one.
*
* @param ast non-null; the <code>AST</code> to base this instance on
*/
public void initialize(AST ast) {
if (ast instanceof MilkAST) {
initialize(((MilkAST)ast).getToken());
} else {
initialize(ast.getType(), ast.getText());
}
}
/**
* Set the token text for this node. If this instance is already
* associated with a token, then that token is destructively modified
* by this operation. If not, then a new token is constructed with
* the type {@link Token#INVALID_TYPE} and the given text.
*
* @param text the new token text
*/
public void setText(String text) {
if (myToken == null) {
initialize(Token.INVALID_TYPE, text);
} else {
myToken.setText(text);
}
}
/**
* Set the token type for this node. If this instance is already
* associated with a token, then that token is destructively modified
* by this operation. If not, then a new token is constructed with
* the given type and an empty (<code>""</code>, not <code>null</code>)
* text string.
*
* @param type the new token type
*/
public void setType(int type) {
if (myToken == null) {
initialize(type, "");
} else {
myToken.setType(type);
}
}
}
1.1 e/src/jsrc/org/quasiliteral/astro/MilkToken.java
Index: MilkToken.java
===================================================================
package org.quasiliteral.astro;
import antlr.CommonToken;
import antlr.Token;
import org.erights.e.elib.tables.Twine;
import org.erights.e.elib.base.SourceSpan;
/**
* A Kind of Antlr {@link Token} that preserves all the information in a
* {@link Functor}, except that it uses an int rather that a string for the
* token-type.
*
* @author <a href="mailto:markm@caplet.com">Mark S Miller</a>
* @author Based on ValueExtentToken by Danfuzz Bornstien
*/
public class MilkToken extends CommonToken {
/**
*
*/
private Twine mySource;
/**
*
*/
private Object myOptValue;
/**
* Construct an instance. The instance will be of type {@link
* #INVALID_TYPE}, and have empty (<code>""</code>, not
* <code>null</code>) twine.
*/
public MilkToken() {
this(Twine.fromString(""));
}
/**
* Construct an instance. The instance will be of type {@link
* #INVALID_TYPE}
*/
public MilkToken(Twine source) {
this(INVALID_TYPE, source);
}
/**
*
*/
public MilkToken(int ttype, Twine source) {
this(ttype, source, null);
}
/**
*
*/
public MilkToken(int ttype, Twine source, Object optValue) {
super(ttype, source.bare());
setSource(source);
myOptValue = optValue;
}
/**
*
*/
public Twine getSource() {
return mySource;
}
/**
*
*/
public void setSource(Twine source) {
mySource = source;
setText(source.bare());
SourceSpan optSpan = source.optSourceSpan();
if (null != optSpan) {
setLine(optSpan.getStartLine());
setColumn(optSpan.getStartCol());
}
}
/**
*
*/
public Object getOptValue() {
return myOptValue;
}
/**
*
*/
public void setOptValue(Object optValue) {
myOptValue = optValue;
}
}