Make it possible to report multiple errors.

This commit is contained in:
norris%netscape.com 1999-12-16 18:47:27 +00:00
Родитель 0582508d69
Коммит 7d795f197b
6 изменённых файлов: 26 добавлений и 66 удалений

Просмотреть файл

@ -72,14 +72,9 @@ class Parser {
private void reportError(TokenStream ts, String messageId)
throws JavaScriptException
{
if (this.ok) {
this.ok = false;
// Only report the error if the TokenStream hasn't had a chance to.
if ((ts.flags & ts.TSF_ERROR) == 0) {
ts.reportSyntaxError(messageId, null);
}
}
this.ok = false;
ts.reportSyntaxError(messageId, null);
/* Throw an exception to unwind the recursive descent parse.
* We use JavaScriptException here even though it is really
* a different use of the exception than it is usually used
@ -113,7 +108,7 @@ class Parser {
* we've collected all the source */
Object tempBlock = nf.createLeaf(TokenStream.BLOCK);
while (this.ok) {
while (true) {
ts.flags |= ts.TSF_REGEXP;
tt = ts.getToken();
ts.flags &= ~ts.TSF_REGEXP;
@ -134,6 +129,7 @@ class Parser {
wellTerminated(ts, ts.FUNCTION);
} catch (JavaScriptException e) {
this.ok = false;
break;
}
} else {
ts.ungetToken(tt);
@ -141,9 +137,10 @@ class Parser {
}
}
if (this.ok == false)
if (!this.ok) {
// XXX ts.clearPushback() call here?
return null;
}
Object pn = nf.createScript(tempBlock, ts.getSourceName(),
baseLineno, ts.getLineno(),
@ -274,7 +271,6 @@ class Parser {
{
int tt = ts.peekTokenSameLine();
if (tt == ts.ERROR) {
reportError(ts, "msg.scanner.caught.error");
return false;
}
@ -717,7 +713,6 @@ class Parser {
break;
case ts.ERROR:
reportError(ts, "msg.scanner.caught.error");
// Fall thru, to have a node for error recovery to work on
case ts.EOL:
case ts.SEMI:
@ -1045,7 +1040,6 @@ class Parser {
return nf.createUnary(ts.DELPROP, unaryExpr(ts, source));
case ts.ERROR:
reportError(ts, "msg.scanner.caught.error");
break;
default:
@ -1179,8 +1173,6 @@ class Parser {
break;
}
}
if (tt == ts.ERROR)
reportError(ts, "msg.scanner.caught.error");
return pn;
}
@ -1342,7 +1334,6 @@ class Parser {
case ts.ERROR:
/* the scanner or one of its subroutines reported the error. */
reportError(ts, "msg.scanner.caught.error");
break;
default:

Просмотреть файл

@ -57,16 +57,11 @@ public class TokenStream {
*/
public final static int
TSF_ERROR = 0x0001, // fatal error while scanning
// TSF_EOF = 0x0002, // hit end of file
TSF_NEWLINES = 0x0004, // tokenize newlines
TSF_FUNCTION = 0x0008, // scanning inside function body
TSF_RETURN_EXPR = 0x0010, // function has 'return expr;'
TSF_RETURN_VOID = 0x0020, // function has 'return;'
// TSF_INTERACTIVE = 0x0040, // interactive parsing mode
// TSF_COMMAND = 0x0080, // command parsing mode
// TSF_LOOKAHEAD = 0x0100, // looking ahead for a token
TSF_REGEXP = 0x0200; // looking for a regular expression
TSF_NEWLINES = 0x0001, // tokenize newlines
TSF_FUNCTION = 0x0002, // scanning inside function body
TSF_RETURN_EXPR = 0x0004, // function has 'return expr;'
TSF_RETURN_VOID = 0x0008, // function has 'return;'
TSF_REGEXP = 0x0010; // looking for a regular expression
/*
* For chars - because we need something out-of-range
@ -724,9 +719,6 @@ public class TokenStream {
public int getToken() throws IOException {
int c;
tokenno++;
// If there was a fatal error, keep returning TOK_ERROR.
if ((flags & TSF_ERROR) != 0)
return ERROR;
// Check for pushed-back token
if (this.pushbackToken != EOF) {
@ -1303,12 +1295,12 @@ public class TokenStream {
public void reportSyntaxError(String messageProperty, Object[] args) {
String message = Context.getMessage(messageProperty, args);
if (scope != null) {
// We're probably in an eval. Need to throw an exception.
throw NativeGlobal.constructError(
Context.getContext(), "SyntaxError",
message, scope, getSourceName(),
getLineno());
} else {
flags |= TSF_ERROR;
Context.reportError(message, getSourceName(),
getLineno(), getLine(), getOffset());
}

Просмотреть файл

@ -331,9 +331,6 @@ msg.no.paren =\
msg.reserved.id =\
identifier is a reserved word
msg.scanner.caught.error =\
scanner caught an error
msg.no.paren.catch =\
missing ( before catch-block condition

Просмотреть файл

@ -72,14 +72,9 @@ class Parser {
private void reportError(TokenStream ts, String messageId)
throws JavaScriptException
{
if (this.ok) {
this.ok = false;
// Only report the error if the TokenStream hasn't had a chance to.
if ((ts.flags & ts.TSF_ERROR) == 0) {
ts.reportSyntaxError(messageId, null);
}
}
this.ok = false;
ts.reportSyntaxError(messageId, null);
/* Throw an exception to unwind the recursive descent parse.
* We use JavaScriptException here even though it is really
* a different use of the exception than it is usually used
@ -113,7 +108,7 @@ class Parser {
* we've collected all the source */
Object tempBlock = nf.createLeaf(TokenStream.BLOCK);
while (this.ok) {
while (true) {
ts.flags |= ts.TSF_REGEXP;
tt = ts.getToken();
ts.flags &= ~ts.TSF_REGEXP;
@ -134,6 +129,7 @@ class Parser {
wellTerminated(ts, ts.FUNCTION);
} catch (JavaScriptException e) {
this.ok = false;
break;
}
} else {
ts.ungetToken(tt);
@ -141,9 +137,10 @@ class Parser {
}
}
if (this.ok == false)
if (!this.ok) {
// XXX ts.clearPushback() call here?
return null;
}
Object pn = nf.createScript(tempBlock, ts.getSourceName(),
baseLineno, ts.getLineno(),
@ -274,7 +271,6 @@ class Parser {
{
int tt = ts.peekTokenSameLine();
if (tt == ts.ERROR) {
reportError(ts, "msg.scanner.caught.error");
return false;
}
@ -717,7 +713,6 @@ class Parser {
break;
case ts.ERROR:
reportError(ts, "msg.scanner.caught.error");
// Fall thru, to have a node for error recovery to work on
case ts.EOL:
case ts.SEMI:
@ -1045,7 +1040,6 @@ class Parser {
return nf.createUnary(ts.DELPROP, unaryExpr(ts, source));
case ts.ERROR:
reportError(ts, "msg.scanner.caught.error");
break;
default:
@ -1179,8 +1173,6 @@ class Parser {
break;
}
}
if (tt == ts.ERROR)
reportError(ts, "msg.scanner.caught.error");
return pn;
}
@ -1342,7 +1334,6 @@ class Parser {
case ts.ERROR:
/* the scanner or one of its subroutines reported the error. */
reportError(ts, "msg.scanner.caught.error");
break;
default:

Просмотреть файл

@ -57,16 +57,11 @@ public class TokenStream {
*/
public final static int
TSF_ERROR = 0x0001, // fatal error while scanning
// TSF_EOF = 0x0002, // hit end of file
TSF_NEWLINES = 0x0004, // tokenize newlines
TSF_FUNCTION = 0x0008, // scanning inside function body
TSF_RETURN_EXPR = 0x0010, // function has 'return expr;'
TSF_RETURN_VOID = 0x0020, // function has 'return;'
// TSF_INTERACTIVE = 0x0040, // interactive parsing mode
// TSF_COMMAND = 0x0080, // command parsing mode
// TSF_LOOKAHEAD = 0x0100, // looking ahead for a token
TSF_REGEXP = 0x0200; // looking for a regular expression
TSF_NEWLINES = 0x0001, // tokenize newlines
TSF_FUNCTION = 0x0002, // scanning inside function body
TSF_RETURN_EXPR = 0x0004, // function has 'return expr;'
TSF_RETURN_VOID = 0x0008, // function has 'return;'
TSF_REGEXP = 0x0010; // looking for a regular expression
/*
* For chars - because we need something out-of-range
@ -724,9 +719,6 @@ public class TokenStream {
public int getToken() throws IOException {
int c;
tokenno++;
// If there was a fatal error, keep returning TOK_ERROR.
if ((flags & TSF_ERROR) != 0)
return ERROR;
// Check for pushed-back token
if (this.pushbackToken != EOF) {
@ -1303,12 +1295,12 @@ public class TokenStream {
public void reportSyntaxError(String messageProperty, Object[] args) {
String message = Context.getMessage(messageProperty, args);
if (scope != null) {
// We're probably in an eval. Need to throw an exception.
throw NativeGlobal.constructError(
Context.getContext(), "SyntaxError",
message, scope, getSourceName(),
getLineno());
} else {
flags |= TSF_ERROR;
Context.reportError(message, getSourceName(),
getLineno(), getLine(), getOffset());
}

Просмотреть файл

@ -331,9 +331,6 @@ msg.no.paren =\
msg.reserved.id =\
identifier is a reserved word
msg.scanner.caught.error =\
scanner caught an error
msg.no.paren.catch =\
missing ( before catch-block condition