org.antlr.runtime.NoViableAltException Java Examples

The following examples show how to use org.antlr.runtime.NoViableAltException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
Token ESCAPE() {
startCharIndex = input.index();
startCharPositionInLine = input.getCharPositionInLine();
consume(); // kill \\
if ( c=='u') return UNICODE();
String text;
      switch ( c ) {
          case '\\' : LINEBREAK(); return SKIP;
	case 'n'  : text = "\n"; break;
	case 't'  : text = "\t"; break;
	case ' '  : text = " "; break;
          default :
              NoViableAltException e = new NoViableAltException("",0,0,input);
              errMgr.lexerError(input.getSourceName(), "invalid escaped char: '"+str(c)+"'", templateToken, e);
		consume();
		match(delimiterStopChar);
		return SKIP;
      }
      consume();
Token t = newToken(TEXT, text, input.getCharPositionInLine()-2);
      match(delimiterStopChar);
      return t;
  }
 
Example #2
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
Token ESCAPE() {
    startCharIndex = input.index();
    startCharPositionInLine = input.getCharPositionInLine();
    consume(); // kill \\
    if ( c=='u' ) return UNICODE();
    String text;
    switch ( c ) {
        case '\\' :
            LINEBREAK();
            return SKIP;
        case 'n' :
            text = "\n";
            break;
        case 't' :
            text = "\t";
            break;
        case ' ' :
            text = " ";
            break;
        default:
            NoViableAltException e = new NoViableAltException("", 0, 0, input);
            errMgr.lexerError(input.getSourceName(), "invalid escaped char: '"+str(c)+"'",
                              templateToken,
                              e);
            consume();
            match(delimiterStopChar);
            return SKIP;
    }
    consume();
    Token t = newToken(TEXT, text, input.getCharPositionInLine()-2);
    match(delimiterStopChar);
    return t;
}
 
Example #3
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
Token ESCAPE() {
    startCharIndex = input.index();
    startCharPositionInLine = input.getCharPositionInLine();
    consume(); // kill \\
    if ( c=='u' ) return UNICODE();
    String text;
    switch (c) {
        case '\\':
            LINEBREAK();
            return SKIP;
        case 'n':
            text = "\n";
            break;
        case 't':
            text = "\t";
            break;
        case ' ':
            text = " ";
            break;
        default:
            NoViableAltException e = new NoViableAltException("", 0, 0, input);
            errMgr.lexerError(input.getSourceName(),
                              "invalid escaped char: '" +str(c)+"'",
                              templateToken,
                              e);
            consume();
            match(delimiterStopChar);
            return SKIP;
    }
    consume();
    Token t = newToken(TEXT, text, input.getCharPositionInLine() -2);
    match(delimiterStopChar);
    return t;
}
 
Example #4
Source File: RecognizerErrorHandler.java    From legstar-core2 with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Simplify error message text for end users.
 * @param e exception that occurred
 * @param msg as formatted by ANTLR
 * @return a more readable error message
 */
public static String makeUserMsg(final RecognitionException e, final String msg) {
    if (e instanceof NoViableAltException) {
        return msg.replace("no viable alternative at", "unrecognized");
    } else if (e instanceof UnwantedTokenException) {
        return msg.replace("extraneous input", "unexpected token");
    } else if (e instanceof MismatchedTokenException) {
        if (msg.contains("mismatched input '<EOF>'")) {
            return msg.replace("mismatched input '<EOF>' expecting", "reached end of file looking for");
        } else {
            return msg.replace("mismatched input", "unexpected token");
        }
    } else if (e instanceof EarlyExitException) {
        return msg.replace("required (...)+ loop did not match anything", "required tokens not found");
    } else if (e instanceof FailedPredicateException) {
        if (msg.contains("picture_string failed predicate: {Unbalanced parentheses}")) {
            return "Unbalanced parentheses in picture string";
        }
        if (msg.contains("PICTURE_PART failed predicate: {Contains invalid picture symbols}")) {
            return "Picture string contains invalid symbols";
        }
        if (msg.contains("PICTURE_PART failed predicate: {Syntax error in last picture clause}")) {
            return "Syntax error in last picture clause";
        }
        if (msg.contains("DATA_NAME failed predicate: {Syntax error in last clause}")) {
            return "Syntax error in last COBOL clause";
        }
    }
    return msg;
}
 
Example #5
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** Consume if {@code x} is next character on the input stream.
 */

public void match(char x) {
    if ( c!= x ) {
        NoViableAltException e = new NoViableAltException("", 0, 0, input);
        errMgr.lexerError(input.getSourceName(),
                          "expecting '" +x+"', found '"+str(c)+"'",
                          templateToken,
                          e);
    }
    consume();
}
 
Example #6
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
Token ESCAPE() {
    startCharIndex = input.index();
    startCharPositionInLine = input.getCharPositionInLine();
    consume(); // kill \\
    if ( c=='u' ) return UNICODE();
    String text;
    switch (c) {
        case '\\':
            LINEBREAK();
            return SKIP;
        case 'n':
            text = "\n";
            break;
        case 't':
            text = "\t";
            break;
        case ' ':
            text = " ";
            break;
        default:
            NoViableAltException e = new NoViableAltException("", 0, 0, input);
            errMgr.lexerError(input.getSourceName(),
                              "invalid escaped char: '" +str(c)+"'",
                              templateToken,
                              e);
            consume();
            match(delimiterStopChar);
            return SKIP;
    }
    consume();
    Token t = newToken(TEXT, text, input.getCharPositionInLine() -2);
    match(delimiterStopChar);
    return t;
}
 
Example #7
Source File: DFA.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void error(NoViableAltException nvae) {
	if (nvae.token == Token.EOF_TOKEN) {
		int lookAheadAddOn = getRecognizer().lookAheadAddOn;
		int lookAhead = ((XtextTokenStream)nvae.input).getCurrentLookAhead();
		if ((lookAhead >= lookAheadAddOn && lookAheadAddOn > 0) || (lookAhead == 0 && lookAheadAddOn > 0) || lookAhead == -1)
			getRecognizer().failedPredicateAtEOF = true;
	}
	super.error(nvae);
}
 
Example #8
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
Token ESCAPE() {
    startCharIndex = input.index();
    startCharPositionInLine = input.getCharPositionInLine();
    consume(); // kill \\
    if ( c=='u' ) return UNICODE();
    String text;
    switch (c) {
        case '\\' :
            LINEBREAK();
            return SKIP;
        case 'n' :
            text = "\n";
            break;
        case 't' :
            text = "\t";
            break;
        case ' ' :
            text = " ";
            break;
        default:
            NoViableAltException e = new NoViableAltException("", 0, 0, input);
            errMgr.lexerError(input.getSourceName(), "invalid escaped char: '"+str(c)+"'", templateToken, e);
            consume();
            match(delimiterStopChar);
            return SKIP;
    }
    consume();
    Token t = newToken(TEXT, text, input.getCharPositionInLine() -2);
    match(delimiterStopChar);
    return t;
}
 
Example #9
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** Consume if {@code x} is next character on the input stream.
 */

public void match(char x) {
    if ( c!= x ) {
        NoViableAltException e = new NoViableAltException("", 0, 0, input);
        errMgr.lexerError(input.getSourceName(),
                          "expecting '" +x+"', found '"+str(c)+"'",
                          templateToken,
                          e);
    }
    consume();
}
 
Example #10
Source File: Lexer.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Token nextToken() {
	while (true) {
		this.state.token = null;
		this.state.channel = Token.DEFAULT_CHANNEL;
		this.state.tokenStartCharIndex = input.index();
		this.state.tokenStartCharPositionInLine = input.getCharPositionInLine();
		this.state.tokenStartLine = input.getLine();
		this.state.text = null;
		if (input.LA(1) == CharStream.EOF) {
			return Token.EOF_TOKEN;
		}
		try {
			mTokens();
			if (this.state.token == null) {
				emit();
			}
			else if (this.state.token == Token.SKIP_TOKEN) {
				continue;
			}
			return this.state.token;
		}
		catch (RecognitionException re) {
			reportError(re);
			if (re instanceof NoViableAltException ||
				re instanceof FailedPredicateException) {
				recover(re);
			}
			// create token that holds mismatched char
			Token t = new CommonToken(input, Token.INVALID_TOKEN_TYPE, Token.HIDDEN_CHANNEL,
					this.state.tokenStartCharIndex, getCharIndex() - 1);
			t.setLine(this.state.tokenStartLine);
			t.setCharPositionInLine(this.state.tokenStartCharPositionInLine);
			tokenErrorMap.put(t, getErrorMessage(re, this.getTokenNames()));
			emit(t);
			return this.state.token;
		}
	}
}
 
Example #11
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
Token ESCAPE() {
    startCharIndex = input.index();
    startCharPositionInLine = input.getCharPositionInLine();
    consume(); // kill \\
    if ( c=='u' ) return UNICODE();
    String text;
    switch (c) {
        case '\\':
            LINEBREAK();
            return SKIP;
        case 'n':
            text = "\n";
            break;
        case 't':
            text = "\t";
            break;
        case ' ':
            text = " ";
            break;
        default:
            NoViableAltException e = new NoViableAltException("", 0, 0, input);
            errMgr.lexerError(input.getSourceName(),
                              "invalid escaped char: '" +str(c)+"'",
                              templateToken,
                              e);
            consume();
            match(delimiterStopChar);
            return SKIP;
    }
    consume();
    Token t = newToken(TEXT, text, input.getCharPositionInLine() -2);
    match(delimiterStopChar);
    return t;
}
 
Example #12
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** Consume if {@code x} is next character on the input stream.
 */

public void match(char x) {
    if ( c!= x ) {
        NoViableAltException e = new NoViableAltException("", 0, 0, input);
        errMgr.lexerError(input.getSourceName(), "expecting '"+x+"', found '"+str(c)+"'",
                          templateToken,
                          e);
    }
    consume();
}
 
Example #13
Source File: Lexer.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Token nextToken() {
	while (true) {
		this.state.token = null;
		this.state.channel = Token.DEFAULT_CHANNEL;
		this.state.tokenStartCharIndex = input.index();
		this.state.tokenStartCharPositionInLine = input
				.getCharPositionInLine();
		this.state.tokenStartLine = input.getLine();
		this.state.text = null;
		if (input.LA(1) == CharStream.EOF) {
			return Token.EOF_TOKEN;
		}
		try {
			mTokens();
			if (this.state.token == null) {
				emit();
			} else if (this.state.token == Token.SKIP_TOKEN) {
				continue;
			}
			return this.state.token;
		} catch (RecognitionException re) {
			reportError(re);
			if (re instanceof NoViableAltException
					|| re instanceof FailedPredicateException) {
				recover(re);
			}
			// create token that holds mismatched char
			Token t = new CommonToken(input, Token.INVALID_TOKEN_TYPE,
					Token.HIDDEN_CHANNEL, this.state.tokenStartCharIndex,
					getCharIndex() - 1);
			t.setLine(this.state.tokenStartLine);
			t.setCharPositionInLine(
					this.state.tokenStartCharPositionInLine);
			tokenErrorMap.put(t, getErrorMessage(re, this.getTokenNames()));
			emit(t);
			return this.state.token;
		}
	}
}
 
Example #14
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
Token ESCAPE() {
    startCharIndex = input.index();
    startCharPositionInLine = input.getCharPositionInLine();
    consume(); // kill \\
    if ( c=='u' ) return UNICODE();
    String text;
    switch ( c ) {
        case '\\':
            LINEBREAK();
            return SKIP;
        case 'n':
            text = "\n";
            break;
        case 't':
            text = "\t";
            break;
        case ' ':
            text = " ";
            break;
        default:
            NoViableAltException e = new NoViableAltException("", 0, 0, input);
            errMgr.lexerError(input.getSourceName(), "invalid escaped char: '"+str(c)+"'",
                              templateToken,
                              e);
            consume();
            match(delimiterStopChar);
            return SKIP;
    }
    consume();
    Token t = newToken(TEXT, text, input.getCharPositionInLine()-2);
    match(delimiterStopChar);
    return t;
}
 
Example #15
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** Consume if {@code x} is next character on the input stream.
 */

public void match(char x) {
    if ( c!= x ) {
        NoViableAltException e = new NoViableAltException("", 0, 0, input);
        errMgr.lexerError(input.getSourceName(), "expecting '"+x+"', found '"+str(c)+"'",
                          templateToken,
                          e);
    }
    consume();
}
 
Example #16
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** Consume if {@code x} is next character on the input stream.
 */

public void match(char x) {
    if ( c!= x ) {
        NoViableAltException e = new NoViableAltException("", 0, 0, input);
        errMgr.lexerError(input.getSourceName(), "expecting '"+x+"', found '"+str(c)+"'", templateToken, e);
    }
    consume();
}
 
Example #17
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** Consume if {@code x} is next character on the input stream.
 */

public void match(char x) {
    if ( c!= x ) {
        NoViableAltException e = new NoViableAltException("", 0, 0, input);
        errMgr.lexerError(input.getSourceName(), "expecting '"+x+"', found '"+str(c)+"'", templateToken, e);
    }
    consume();
}
 
Example #18
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
Token ESCAPE() {
    startCharIndex = input.index();
    startCharPositionInLine = input.getCharPositionInLine();
    consume(); // kill \\
    if ( c=='u' ) return UNICODE();
    String text;
    switch ( c ) {
        case '\\' :
            LINEBREAK();
            return SKIP;
        case 'n' :
            text = "\n";
            break;
        case 't' :
            text = "\t";
            break;
        case ' ' :
            text = " ";
            break;
        default:
            NoViableAltException e = new NoViableAltException("", 0, 0, input);
            errMgr.lexerError(input.getSourceName(), "invalid escaped char: '"+str(c)+"'", templateToken, e);
            consume();
            match(delimiterStopChar);
            return SKIP;
    }
    consume();
    Token t = newToken(TEXT, text, input.getCharPositionInLine() -2);
    match(delimiterStopChar);
    return t;
}
 
Example #19
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** Consume if {@code x} is next character on the input stream.
 */

public void match(char x) {
    if ( c!= x ) {
        NoViableAltException e = new NoViableAltException("", 0, 0, input);
        errMgr.lexerError(input.getSourceName(), "expecting '"+x+"', found '"+str(c)+"'",
                          templateToken,
                          e);
    }
    consume();
}
 
Example #20
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** Consume if {@code x} is next character on the input stream.
*/
  public void match(char x) {
      if ( c != x ) {
	NoViableAltException e = new NoViableAltException("",0,0,input);
	errMgr.lexerError(input.getSourceName(), "expecting '"+x+"', found '"+str(c)+"'", templateToken, e);
}
consume();
  }
 
Example #21
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
Token ESCAPE() {
    startCharIndex = input.index();
    startCharPositionInLine = input.getCharPositionInLine();
    consume(); // kill \\
    if ( c=='u' ) return UNICODE();
    String text;
    switch ( c ) {
        case '\\':
            LINEBREAK();
            return SKIP;
        case 'n':
            text = "\n";
            break;
        case 't':
            text = "\t";
            break;
        case ' ':
            text = " ";
            break;
        default:
            NoViableAltException e = new NoViableAltException("", 0, 0, input);
            errMgr.lexerError(input.getSourceName(), "invalid escaped char: '"+str(c)+"'",
                              templateToken,
                              e);
            consume();
            match(delimiterStopChar);
            return SKIP;
    }
    consume();
    Token t = newToken(TEXT, text, input.getCharPositionInLine()-2);
    match(delimiterStopChar);
    return t;
}
 
Example #22
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** Consume if {@code x} is next character on the input stream.
 */

public void match(char x) {
    if ( c!= x ) {
        NoViableAltException e = new NoViableAltException("", 0, 0, input);
        errMgr.lexerError(input.getSourceName(), "expecting '"+x+"', found '"+str(c)+"'",
                          templateToken,
                          e);
    }
    consume();
}
 
Example #23
Source File: ToolANTLRParser.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public String getParserErrorMessage(Parser parser, RecognitionException e) {
	String msg;
	if ( e instanceof NoViableAltException) {
		String name = parser.getTokenErrorDisplay(e.token);
		msg = name+" came as a complete surprise to me";
	}
	else if ( e instanceof v4ParserException) {
		msg = ((v4ParserException)e).msg;
	}
	else {
		msg = parser.getErrorMessage(e, parser.getTokenNames());
	}
	return msg;
}
 
Example #24
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
Token ESCAPE() {
    startCharIndex = input.index();
    startCharPositionInLine = input.getCharPositionInLine();
    consume(); // kill \\
    if ( c=='u' ) return UNICODE();
    String text;
    switch ( c ) {
        case '\\':
            LINEBREAK();
            return SKIP;
        case 'n':
            text = "\n";
            break;
        case 't':
            text = "\t";
            break;
        case ' ':
            text = " ";
            break;
        default:
            NoViableAltException e = new NoViableAltException("", 0, 0, input);
            errMgr.lexerError(input.getSourceName(), "invalid escaped char: '"+str(c)+"'",
                              templateToken,
                              e);
            consume();
            match(delimiterStopChar);
            return SKIP;
    }
    consume();
    Token t = newToken(TEXT, text, input.getCharPositionInLine()-2);
    match(delimiterStopChar);
    return t;
}
 
Example #25
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** Consume if {@code x} is next character on the input stream.
 */

public void match(char x) {
    if ( c!= x ) {
        NoViableAltException e = new NoViableAltException("", 0, 0, input);
        errMgr.lexerError(input.getSourceName(),
                          "expecting '"+x+"', found '"+str(c)+"'",
                          templateToken,
                          e);
    }
    consume();
}
 
Example #26
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
Token ESCAPE() {
    startCharIndex = input.index();
    startCharPositionInLine = input.getCharPositionInLine();
    consume(); // kill \\
    if ( c=='u' ) return UNICODE();
    String text;
    switch ( c ) {
        case '\\':
            LINEBREAK();
            return SKIP;
        case 'n':
            text = "\n";
            break;
        case 't':
            text = "\t";
            break;
        case ' ':
            text = " ";
            break;
        default:
            NoViableAltException e = new NoViableAltException("", 0, 0, input);
            errMgr.lexerError(input.getSourceName(), "invalid escaped char: '"+str(c)+"'",
                              templateToken,
                              e);
            consume();
            match(delimiterStopChar);
            return SKIP;
    }
    consume();
    Token t = newToken(TEXT, text, input.getCharPositionInLine()-2);
    match(delimiterStopChar);
    return t;
}
 
Example #27
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
Token ESCAPE() {
    startCharIndex = input.index();
    startCharPositionInLine = input.getCharPositionInLine();
    consume(); // kill \\
    if ( c=='u' ) return UNICODE();
    String text;
    switch ( c ) {
        case '\\':
            LINEBREAK();
            return SKIP;
        case 'n':
            text = "\n";
            break;
        case 't':
            text = "\t";
            break;
        case ' ':
            text = " ";
            break;
        default:
            NoViableAltException e = new NoViableAltException("", 0, 0, input);
            errMgr.lexerError(input.getSourceName(),
                              "invalid escaped char: '"+str(c)+"'",
                              templateToken,
                              e);
            consume();
            match(delimiterStopChar);
            return SKIP;
    }
    consume();
    Token t = newToken(TEXT, text, input.getCharPositionInLine()-2);
    match(delimiterStopChar);
    return t;
}
 
Example #28
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** Consume if {@code x} is next character on the input stream.
 */

public void match(char x) {
    if ( c!= x ) {
        NoViableAltException e = new NoViableAltException("", 0, 0, input);
        errMgr.lexerError(input.getSourceName(), "expecting '"+x+"', found '"+str(c)+"'", templateToken, e);
    }
    consume();
}
 
Example #29
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
Token ESCAPE() {
    startCharIndex = input.index();
    startCharPositionInLine = input.getCharPositionInLine();
    consume(); // kill \\
    if ( c=='u' ) return UNICODE();
    String text;
    switch ( c ) {
        case '\\' :
            LINEBREAK();
            return SKIP;
        case 'n' :
            text = "\n";
            break;
        case 't' :
            text = "\t";
            break;
        case ' ' :
            text = " ";
            break;
        default:
            NoViableAltException e = new NoViableAltException("", 0, 0, input);
            errMgr.lexerError(input.getSourceName(), "invalid escaped char: '"+str(c)+"'", templateToken, e);
            consume();
            match(delimiterStopChar);
            return SKIP;
    }
    consume();
    Token t = newToken(TEXT, text, input.getCharPositionInLine() -2);
    match(delimiterStopChar);
    return t;
}
 
Example #30
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** Consume if {@code x} is next character on the input stream.
 */

public void match(char x) {
    if ( c!= x ) {
        NoViableAltException e = new NoViableAltException("", 0, 0, input);
        errMgr.lexerError(input.getSourceName(), "expecting '"+x+"', found '"+str(c)+"'",
                          templateToken,
                          e);
    }
    consume();
}