mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Final adjustment on error handling.
This commit is contained in:
parent
177ee8cfb2
commit
efab1f2f3d
2 changed files with 47 additions and 35 deletions
|
@ -227,7 +227,6 @@ public class ExpressionParser implements IExpressionParser, IParserData {
|
||||||
try {
|
try {
|
||||||
if (firstErrorOffset == FIRST_ERROR_OFFSET_UNSET)
|
if (firstErrorOffset == FIRST_ERROR_OFFSET_UNSET)
|
||||||
firstErrorOffset = LA(1).getOffset();
|
firstErrorOffset = LA(1).getOffset();
|
||||||
consume(); // get past this token
|
|
||||||
} catch (EndOfFileException eof) {
|
} catch (EndOfFileException eof) {
|
||||||
// do nothing
|
// do nothing
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -2771,4 +2770,31 @@ public class ExpressionParser implements IExpressionParser, IParserData {
|
||||||
protected void throwBacktrack(BacktrackException bt) throws BacktrackException {
|
protected void throwBacktrack(BacktrackException bt) throws BacktrackException {
|
||||||
throw bt;
|
throw bt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws EndOfFileException
|
||||||
|
*/
|
||||||
|
protected void errorHandling() throws EndOfFileException {
|
||||||
|
int depth = ( LT(1) == IToken.tLBRACE ) ? 1 : 0;
|
||||||
|
consume();
|
||||||
|
while (!((LT(1) == IToken.tSEMI && depth == 0)
|
||||||
|
|| (LT(1) == IToken.tRBRACE && depth == 1)))
|
||||||
|
{
|
||||||
|
switch (LT(1))
|
||||||
|
{
|
||||||
|
case IToken.tLBRACE :
|
||||||
|
++depth;
|
||||||
|
break;
|
||||||
|
case IToken.tRBRACE :
|
||||||
|
--depth;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if( depth < 0 )
|
||||||
|
return;
|
||||||
|
|
||||||
|
consume();
|
||||||
|
}
|
||||||
|
// eat the SEMI/RBRACE as well
|
||||||
|
consume();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -199,7 +199,7 @@ public abstract class Parser extends ExpressionParser implements IParser
|
||||||
int checkOffset = LA(1).hashCode();
|
int checkOffset = LA(1).hashCode();
|
||||||
declaration(compilationUnit, null, null, KeywordSetKey.DECLARATION);
|
declaration(compilationUnit, null, null, KeywordSetKey.DECLARATION);
|
||||||
if (LA(1).hashCode() == checkOffset)
|
if (LA(1).hashCode() == checkOffset)
|
||||||
errorHandling();
|
failParseWithErrorHandling();
|
||||||
}
|
}
|
||||||
catch (EndOfFileException e)
|
catch (EndOfFileException e)
|
||||||
{
|
{
|
||||||
|
@ -216,7 +216,7 @@ public abstract class Parser extends ExpressionParser implements IParser
|
||||||
{
|
{
|
||||||
// we haven't progressed from the last backtrack
|
// we haven't progressed from the last backtrack
|
||||||
// try and find tne next definition
|
// try and find tne next definition
|
||||||
errorHandling();
|
failParseWithErrorHandling();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -232,7 +232,10 @@ public abstract class Parser extends ExpressionParser implements IParser
|
||||||
catch( Exception e )
|
catch( Exception e )
|
||||||
{
|
{
|
||||||
logException( "translationUnit", e ); //$NON-NLS-1$
|
logException( "translationUnit", e ); //$NON-NLS-1$
|
||||||
failParse();
|
try {
|
||||||
|
failParseWithErrorHandling();
|
||||||
|
} catch (EndOfFileException e3) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch( ParseError perr )
|
catch( ParseError perr )
|
||||||
{
|
{
|
||||||
|
@ -241,7 +244,10 @@ public abstract class Parser extends ExpressionParser implements IParser
|
||||||
catch (Throwable e)
|
catch (Throwable e)
|
||||||
{
|
{
|
||||||
logThrowable( "translationUnit", e ); //$NON-NLS-1$
|
logThrowable( "translationUnit", e ); //$NON-NLS-1$
|
||||||
failParse();
|
try {
|
||||||
|
failParseWithErrorHandling();
|
||||||
|
} catch (EndOfFileException e3) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
compilationUnit.exitScope( requestor, astFactory.getReferenceManager() );
|
compilationUnit.exitScope( requestor, astFactory.getReferenceManager() );
|
||||||
|
@ -265,7 +271,7 @@ public abstract class Parser extends ExpressionParser implements IParser
|
||||||
log.traceLog( buffer.toString() );
|
log.traceLog( buffer.toString() );
|
||||||
// log.errorLog( buffer.toString() );
|
// log.errorLog( buffer.toString() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -278,30 +284,10 @@ public abstract class Parser extends ExpressionParser implements IParser
|
||||||
* We can potentially hit EndOfFile here as we are skipping
|
* We can potentially hit EndOfFile here as we are skipping
|
||||||
* ahead.
|
* ahead.
|
||||||
*/
|
*/
|
||||||
protected void errorHandling() throws EndOfFileException
|
protected void failParseWithErrorHandling() throws EndOfFileException
|
||||||
{
|
{
|
||||||
failParse();
|
failParse();
|
||||||
int depth = ( LT(1) == IToken.tLBRACE ) ? 1 : 0;
|
errorHandling();
|
||||||
consume();
|
|
||||||
while (!((LT(1) == IToken.tSEMI && depth == 0)
|
|
||||||
|| (LT(1) == IToken.tRBRACE && depth == 1)))
|
|
||||||
{
|
|
||||||
switch (LT(1))
|
|
||||||
{
|
|
||||||
case IToken.tLBRACE :
|
|
||||||
++depth;
|
|
||||||
break;
|
|
||||||
case IToken.tRBRACE :
|
|
||||||
--depth;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if( depth < 0 )
|
|
||||||
return;
|
|
||||||
|
|
||||||
consume();
|
|
||||||
}
|
|
||||||
// eat the SEMI/RBRACE as well
|
|
||||||
consume();
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* The merger of using-declaration and using-directive in ANSI C++ grammar.
|
* The merger of using-declaration and using-directive in ANSI C++ grammar.
|
||||||
|
@ -457,11 +443,11 @@ public abstract class Parser extends ExpressionParser implements IParser
|
||||||
{
|
{
|
||||||
failParse(bt);
|
failParse(bt);
|
||||||
if (checkToken == LA(1).hashCode())
|
if (checkToken == LA(1).hashCode())
|
||||||
errorHandling();
|
failParseWithErrorHandling();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (checkToken == LA(1).hashCode())
|
if (checkToken == LA(1).hashCode())
|
||||||
errorHandling();
|
failParseWithErrorHandling();
|
||||||
}
|
}
|
||||||
// consume the }
|
// consume the }
|
||||||
IToken lastTokenConsumed = consume();
|
IToken lastTokenConsumed = consume();
|
||||||
|
@ -1002,11 +988,11 @@ public abstract class Parser extends ExpressionParser implements IParser
|
||||||
{
|
{
|
||||||
failParse(bt);
|
failParse(bt);
|
||||||
if (checkToken == LA(1).hashCode())
|
if (checkToken == LA(1).hashCode())
|
||||||
errorHandling();
|
failParseWithErrorHandling();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (checkToken == LA(1).hashCode())
|
if (checkToken == LA(1).hashCode())
|
||||||
errorHandling();
|
failParseWithErrorHandling();
|
||||||
}
|
}
|
||||||
setCompletionValues(scope, CompletionKind.NO_SUCH_KIND,KeywordSetKey.EMPTY );
|
setCompletionValues(scope, CompletionKind.NO_SUCH_KIND,KeywordSetKey.EMPTY );
|
||||||
// consume the }
|
// consume the }
|
||||||
|
@ -2762,11 +2748,11 @@ public abstract class Parser extends ExpressionParser implements IParser
|
||||||
KeywordSetKey.MEMBER);
|
KeywordSetKey.MEMBER);
|
||||||
} catch (BacktrackException bt) {
|
} catch (BacktrackException bt) {
|
||||||
if (checkToken == LA(1).hashCode())
|
if (checkToken == LA(1).hashCode())
|
||||||
errorHandling();
|
failParseWithErrorHandling();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (checkToken == LA(1).hashCode())
|
if (checkToken == LA(1).hashCode())
|
||||||
errorHandling();
|
failParseWithErrorHandling();
|
||||||
}
|
}
|
||||||
// consume the }
|
// consume the }
|
||||||
IToken lt = consume(IToken.tRBRACE);
|
IToken lt = consume(IToken.tRBRACE);
|
||||||
|
@ -3192,7 +3178,7 @@ public abstract class Parser extends ExpressionParser implements IParser
|
||||||
} catch (BacktrackException b) {
|
} catch (BacktrackException b) {
|
||||||
failParse(b);
|
failParse(b);
|
||||||
if (LA(1).hashCode() == checkToken)
|
if (LA(1).hashCode() == checkToken)
|
||||||
errorHandling();
|
failParseWithErrorHandling();
|
||||||
}
|
}
|
||||||
setCompletionValues(((createNewScope ? newScope : scope)),
|
setCompletionValues(((createNewScope ? newScope : scope)),
|
||||||
CompletionKind.SINGLE_NAME_REFERENCE,
|
CompletionKind.SINGLE_NAME_REFERENCE,
|
||||||
|
|
Loading…
Add table
Reference in a new issue