Search in sources :

Example 1 with MismatchedCharException

use of antlr.MismatchedCharException in project groovy-core by groovy.

the class SourceUnit method failedWithUnexpectedEOF.

/**
     * Convenience routine, primarily for use by the InteractiveShell,
     * that returns true if parse() failed with an unexpected EOF.
     */
public boolean failedWithUnexpectedEOF() {
    // If you find another way, please add it.
    if (getErrorCollector().hasErrors()) {
        Message last = (Message) getErrorCollector().getLastError();
        Throwable cause = null;
        if (last instanceof SyntaxErrorMessage) {
            cause = ((SyntaxErrorMessage) last).getCause().getCause();
        }
        if (cause != null) {
            if (cause instanceof NoViableAltException) {
                return isEofToken(((NoViableAltException) cause).token);
            } else if (cause instanceof NoViableAltForCharException) {
                char badChar = ((NoViableAltForCharException) cause).foundChar;
                return badChar == CharScanner.EOF_CHAR;
            } else if (cause instanceof MismatchedCharException) {
                char badChar = (char) ((MismatchedCharException) cause).foundChar;
                return badChar == CharScanner.EOF_CHAR;
            } else if (cause instanceof MismatchedTokenException) {
                return isEofToken(((MismatchedTokenException) cause).token);
            }
        }
    }
    return false;
}
Also used : SimpleMessage(org.codehaus.groovy.control.messages.SimpleMessage) Message(org.codehaus.groovy.control.messages.Message) SyntaxErrorMessage(org.codehaus.groovy.control.messages.SyntaxErrorMessage) SyntaxErrorMessage(org.codehaus.groovy.control.messages.SyntaxErrorMessage) NoViableAltForCharException(antlr.NoViableAltForCharException) NoViableAltException(antlr.NoViableAltException) MismatchedTokenException(antlr.MismatchedTokenException) MismatchedCharException(antlr.MismatchedCharException)

Example 2 with MismatchedCharException

use of antlr.MismatchedCharException in project groovy by apache.

the class SourceUnit method failedWithUnexpectedEOF.

/**
     * Convenience routine, primarily for use by the InteractiveShell,
     * that returns true if parse() failed with an unexpected EOF.
     */
public boolean failedWithUnexpectedEOF() {
    // If you find another way, please add it.
    if (getErrorCollector().hasErrors()) {
        Message last = (Message) getErrorCollector().getLastError();
        Throwable cause = null;
        if (last instanceof SyntaxErrorMessage) {
            cause = ((SyntaxErrorMessage) last).getCause().getCause();
        }
        if (cause != null) {
            if (cause instanceof NoViableAltException) {
                return isEofToken(((NoViableAltException) cause).token);
            } else if (cause instanceof NoViableAltForCharException) {
                char badChar = ((NoViableAltForCharException) cause).foundChar;
                return badChar == CharScanner.EOF_CHAR;
            } else if (cause instanceof MismatchedCharException) {
                char badChar = (char) ((MismatchedCharException) cause).foundChar;
                return badChar == CharScanner.EOF_CHAR;
            } else if (cause instanceof MismatchedTokenException) {
                return isEofToken(((MismatchedTokenException) cause).token);
            }
        }
    }
    return false;
}
Also used : SimpleMessage(org.codehaus.groovy.control.messages.SimpleMessage) Message(org.codehaus.groovy.control.messages.Message) SyntaxErrorMessage(org.codehaus.groovy.control.messages.SyntaxErrorMessage) SyntaxErrorMessage(org.codehaus.groovy.control.messages.SyntaxErrorMessage) NoViableAltForCharException(antlr.NoViableAltForCharException) NoViableAltException(antlr.NoViableAltException) MismatchedTokenException(antlr.MismatchedTokenException) MismatchedCharException(antlr.MismatchedCharException)

Aggregations

MismatchedCharException (antlr.MismatchedCharException)2 MismatchedTokenException (antlr.MismatchedTokenException)2 NoViableAltException (antlr.NoViableAltException)2 NoViableAltForCharException (antlr.NoViableAltForCharException)2 Message (org.codehaus.groovy.control.messages.Message)2 SimpleMessage (org.codehaus.groovy.control.messages.SimpleMessage)2 SyntaxErrorMessage (org.codehaus.groovy.control.messages.SyntaxErrorMessage)2