This commit was generated by cvs2svn to compensate for changes in r4,
which included commits to RCS files with non-trunk default branches.
This commit is contained in:
parent
af35ca5581
commit
ee13186158
148 changed files with 34934 additions and 0 deletions
184
src/FESI/Exceptions/EcmaScriptException.java
Normal file
184
src/FESI/Exceptions/EcmaScriptException.java
Normal file
|
@ -0,0 +1,184 @@
|
|||
// EcmaScriptException.java
|
||||
// FESI Copyright (c) Jean-Marc Lugrin, 1999
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package FESI.Exceptions;
|
||||
|
||||
import java.util.Vector;
|
||||
import FESI.Interpreter.*;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* Superclass of all common exceptions used by the FESI system
|
||||
*/
|
||||
public class EcmaScriptException extends Exception {
|
||||
|
||||
/**
|
||||
* The end of line string for this machine.
|
||||
*/
|
||||
static protected String eol = System.getProperty("line.separator", "\n");
|
||||
|
||||
|
||||
/**
|
||||
* The list of EcmaScript evaluation sources at this error
|
||||
* @serial EcmaScritp sources callback
|
||||
*/
|
||||
protected Vector evaluationSources = new Vector();
|
||||
|
||||
/**
|
||||
* @serial The original exception which trigerred this exception
|
||||
*/
|
||||
private Throwable originatingException = null; // If the exception package another one
|
||||
|
||||
|
||||
/**
|
||||
* Create a generic exception with cause "reason"
|
||||
*
|
||||
* @param reason the reason of the exception
|
||||
*/
|
||||
public EcmaScriptException(String reason) {
|
||||
super(reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a generic exception with cause "reason", originially caused
|
||||
* by the originatingException
|
||||
*
|
||||
* @param reason the reason of the exception
|
||||
* @param originatingException the original exception creating this exception
|
||||
*/
|
||||
public EcmaScriptException(String reason, Throwable originatingException) {
|
||||
super(reason);
|
||||
this.originatingException = originatingException;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the originating exception (if any) or null
|
||||
*
|
||||
* @return originating exception or null.
|
||||
*/
|
||||
public Throwable getOriginatingException() {
|
||||
return originatingException;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append an evaluation source to the list of evaluation sources
|
||||
*
|
||||
* @param es The evaluation source to add
|
||||
*/
|
||||
public void appendEvaluationSource(EvaluationSource es) {
|
||||
evaluationSources.addElement(es);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line number of the error if possible
|
||||
*/
|
||||
public int getLineNumber() {
|
||||
|
||||
if (evaluationSources.size()>0) {
|
||||
EvaluationSource es = (EvaluationSource) evaluationSources.elementAt(0);
|
||||
return es.getLineNumber();
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the message, the originating exception and the
|
||||
* EmcaScript callback chain.
|
||||
* <P>If cause by another exception displays its callback chain
|
||||
*/
|
||||
public String getMessage() {
|
||||
String msg = "Runtime error " + super.getMessage();
|
||||
if (originatingException!=null) {
|
||||
msg += eol + "Caused by exception: " + eol + " " + originatingException.getMessage();
|
||||
}
|
||||
if (originatingException != null) {
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
originatingException.printStackTrace(pw);
|
||||
msg += eol;
|
||||
pw.close();
|
||||
/*
|
||||
// THIS WAS NOT NEEDED AND IS AN INCOMPATIBILITY
|
||||
// BETWEEN JDK 1.1/.2
|
||||
try {
|
||||
sw.close();
|
||||
if (false) throw new IOException(); // to make JDK 1.1 Happy
|
||||
} catch (IOException ignore) {
|
||||
; // To make JDK 1.2 happy
|
||||
}
|
||||
*/
|
||||
msg += sw.toString();
|
||||
}
|
||||
for (int i = 0; i<evaluationSources.size(); i++) {
|
||||
EvaluationSource es = (EvaluationSource) evaluationSources.elementAt(i);
|
||||
msg += eol + (i==0 ? "detected " : "called ") + es;
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* If true would the the parser error detected when a statement is incomplete.
|
||||
*/
|
||||
public boolean isIncomplete() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prints this <code>Throwable</code> and its backtrace to the
|
||||
* standard error stream.
|
||||
*/
|
||||
public void printStackTrace() {
|
||||
System.err.println(this);
|
||||
printStackTrace0(new PrintWriter(System.err));
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints this <code>Throwable</code> and its backtrace to the
|
||||
* specified print stream.
|
||||
*/
|
||||
public void printStackTrace(java.io.PrintStream s) {
|
||||
s.println(this);
|
||||
PrintWriter w = new PrintWriter(s);
|
||||
printStackTrace0(w);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints this <code>Throwable</code> and its backtrace to the specified
|
||||
* print writer.
|
||||
*/
|
||||
public void printStackTrace(java.io.PrintWriter w) {
|
||||
w.println(this);
|
||||
printStackTrace0(w);
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the stack trace to a stream, with the backtrace of
|
||||
* the originating exception if any.
|
||||
*/
|
||||
private void printStackTrace0(PrintWriter w) {
|
||||
super.printStackTrace(w);
|
||||
|
||||
if (originatingException != null) {
|
||||
w.println("due to:");
|
||||
originatingException.printStackTrace(w);
|
||||
}
|
||||
w.flush();
|
||||
}
|
||||
|
||||
}
|
78
src/FESI/Exceptions/EcmaScriptLexicalException.java
Normal file
78
src/FESI/Exceptions/EcmaScriptLexicalException.java
Normal file
|
@ -0,0 +1,78 @@
|
|||
// EcmaScriptLexicalException.java
|
||||
// FESI Copyright (c) Jean-Marc Lugrin, 1999
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package FESI.Exceptions;
|
||||
|
||||
import FESI.Parser.*;
|
||||
import FESI.Interpreter.*;
|
||||
|
||||
/**
|
||||
* Exception used to signal lexical error during parsing
|
||||
*/
|
||||
public class EcmaScriptLexicalException extends EcmaScriptException
|
||||
implements EcmaScriptConstants {
|
||||
|
||||
/** @serial Token creating the error */
|
||||
private TokenMgrError tokenMgrError;
|
||||
|
||||
/** @serial Identification of source creating the error */
|
||||
private EvaluationSource evaluationSource;
|
||||
|
||||
/**
|
||||
* Create a new lexical exception
|
||||
*
|
||||
* @param e The error from the token manager
|
||||
* @param s The evaluation source location of the error
|
||||
*/
|
||||
public EcmaScriptLexicalException(TokenMgrError e, EvaluationSource s) {
|
||||
super("Lexical error");
|
||||
tokenMgrError = e;
|
||||
evaluationSource = s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line number of the error if possible
|
||||
*/
|
||||
public int getLineNumber() {
|
||||
|
||||
if (evaluationSource != null) {
|
||||
return evaluationSource.getLineNumber();
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the text of the token error and the location
|
||||
*/
|
||||
public String getMessage() {
|
||||
String retval = tokenMgrError.getMessage();
|
||||
retval += eol + evaluationSource;
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true in case of unclosed comment, as in this case
|
||||
* the statement is not complete and the user may be prompted
|
||||
* to complete the statement.
|
||||
*/
|
||||
public boolean isIncomplete() {
|
||||
String s = tokenMgrError.getMessage();
|
||||
return s.indexOf(". Probably unclosed comment.")!= -1;
|
||||
// See TokenMgrError
|
||||
}
|
||||
}
|
135
src/FESI/Exceptions/EcmaScriptParseException.java
Normal file
135
src/FESI/Exceptions/EcmaScriptParseException.java
Normal file
|
@ -0,0 +1,135 @@
|
|||
// EcmaScriptParseException.java
|
||||
// FESI Copyright (c) Jean-Marc Lugrin, 1999
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package FESI.Exceptions;
|
||||
|
||||
import FESI.Parser.*;
|
||||
import FESI.Interpreter.*;
|
||||
|
||||
/**
|
||||
* Exception used to signal parsing errors
|
||||
*/
|
||||
public class EcmaScriptParseException extends EcmaScriptException
|
||||
implements EcmaScriptConstants {
|
||||
|
||||
/** @serial Original parse exception */
|
||||
private ParseException parseException;
|
||||
/** @serial Source description */
|
||||
private EvaluationSource evaluationSource;
|
||||
/** @serial true if the synatx error may be that the
|
||||
source is not yet complete (for interactive usage) */
|
||||
private boolean canBeIncomplete = true;
|
||||
|
||||
/**
|
||||
* Create a new parsing exception
|
||||
*
|
||||
* @param e The error from the parser
|
||||
* @param s The evaluation source location of the error
|
||||
*/
|
||||
public EcmaScriptParseException(ParseException e, EvaluationSource s) {
|
||||
super("Parsing error");
|
||||
parseException = e;
|
||||
evaluationSource = s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line number of the error if possible
|
||||
*/
|
||||
public int getLineNumber() {
|
||||
|
||||
Token next = null;
|
||||
Token tok = parseException.currentToken;
|
||||
if (tok != null && tok.next != null) next = tok.next; // get offending token
|
||||
|
||||
if (next!=null) {
|
||||
return next.beginLine;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* return true if incomplete parse (maybe the user
|
||||
* is given a chance to complete it)
|
||||
*/
|
||||
public boolean isIncomplete() {
|
||||
if (!canBeIncomplete) return false; // Some inner error
|
||||
Token tok = parseException.currentToken;
|
||||
if (tok != null && tok.next != null) tok = tok.next; // get offending token
|
||||
return (tok.kind == EOF);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that this cannot be a recoverable incomplete error because,
|
||||
* for example, the evaluation source is a string passed as
|
||||
* a parameter to eval, not a stream read from an user.
|
||||
*/
|
||||
public void setNeverIncomplete() {
|
||||
canBeIncomplete = false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Print the error message with helpfull comments if possible
|
||||
*/
|
||||
public String getMessage() {
|
||||
Token tok = parseException.currentToken;
|
||||
Token next = null;
|
||||
String retval;
|
||||
if (tok != null && tok.kind==UNTERMINATED_STRING_LITERAL) {
|
||||
retval = "Unterminated string constant near line " + tok.beginLine +
|
||||
", column " + tok.beginColumn;
|
||||
} else {
|
||||
if (tok != null && tok.next != null) next = tok.next; // get offending token
|
||||
if (next != null & isForFutureExtension(next.kind)) {
|
||||
retval = "Keyword '" + next.image +
|
||||
"' reserved for future extension near line " +
|
||||
next.beginLine +
|
||||
", column " + next.beginColumn;
|
||||
} else {
|
||||
retval = "Syntax error detected near line " + next.beginLine +
|
||||
", column " + next.beginColumn;
|
||||
}
|
||||
if (tok != null) {
|
||||
retval += ", after " + parseException.tokenImage[tok.kind];
|
||||
}
|
||||
}
|
||||
retval += eol + evaluationSource;
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
private boolean isForFutureExtension(int k) {
|
||||
return
|
||||
k==CASE ||
|
||||
k==CATCH||
|
||||
k==CLASS ||
|
||||
k==CONST ||
|
||||
k==DEBUGGER ||
|
||||
k==_DEFAULT ||
|
||||
k==DO ||
|
||||
k==ENUM ||
|
||||
k==EXPORT ||
|
||||
k==EXTENDS ||
|
||||
k==FINALLY ||
|
||||
k==IMPORT ||
|
||||
k==SUPER ||
|
||||
k==SWITCH ||
|
||||
k==THROW ||
|
||||
k==TRY;
|
||||
}
|
||||
}
|
49
src/FESI/Exceptions/ProgrammingError.java
Normal file
49
src/FESI/Exceptions/ProgrammingError.java
Normal file
|
@ -0,0 +1,49 @@
|
|||
// ProgrammingError.java
|
||||
// FESI Copyright (c) Jean-Marc Lugrin, 1999
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package FESI.Exceptions;
|
||||
|
||||
/**
|
||||
* Exception used to signal internal programming error (assert error)
|
||||
*/
|
||||
public class ProgrammingError extends Error {
|
||||
|
||||
private static String eol = System.getProperty("line.separator", "\n");
|
||||
|
||||
/**
|
||||
* Create an anonymous programming error exception
|
||||
*/
|
||||
public ProgrammingError() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a programming error exception with explanatory test
|
||||
* @param message Reason of the error
|
||||
*/
|
||||
public ProgrammingError(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the internal error asking to contact the author
|
||||
*/
|
||||
public String getMessage() {
|
||||
String m = super.getMessage();
|
||||
m += eol + "*** FESI Internal error - contact the author ***";
|
||||
return m;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue