use of de.be4.eventb.core.parser.lexer.LexerException in project probparsers by bendisposto.
the class EventBLexer method endStringToken.
private void endStringToken() throws LexerException {
try {
/*
* Push back current token. We are going to insert our own string
* token into the token stream just before the current token. Reset
* state so that unread token can be recognized again in next lexer
* step.
*/
unread(token);
state = State.NORMAL;
// create text for string token
string.setText(createString());
} catch (final IOException e) {
throw new LexerException("IOException occured: " + e.getLocalizedMessage());
}
token = string;
string = null;
stringBuffer = null;
}
use of de.be4.eventb.core.parser.lexer.LexerException in project probparsers by bendisposto.
the class PrologExceptionPrinter method printBException.
public static void printBException(IPrologTermOutput pto, final BException e, boolean useIndentation, boolean lineOneOff) {
Throwable cause = e.getCause();
String filename = e.getFilename();
if (cause == null) {
printGeneralException(pto, e, filename, useIndentation, lineOneOff, true);
} else {
while (cause.getClass().equals(BException.class) && cause.getCause() != null) {
BException bex = (BException) cause;
cause = bex.getCause();
filename = bex.getFilename();
}
if (cause instanceof BLexerException) {
printBLexerException(pto, (BLexerException) cause, filename, useIndentation, lineOneOff);
} else if (cause instanceof LexerException) {
printLexerException(pto, (LexerException) cause, filename, useIndentation, lineOneOff);
} else if (cause instanceof BParseException) {
printBParseException(pto, (BParseException) cause, filename, useIndentation, lineOneOff);
} else if (cause instanceof PreParseException) {
printPreParseException(pto, (PreParseException) cause, filename, useIndentation, lineOneOff);
} else if (cause instanceof CheckException) {
printCheckException(pto, (CheckException) cause, filename, useIndentation, lineOneOff);
} else {
printGeneralException(pto, cause, filename, useIndentation, lineOneOff, false);
}
}
}
use of de.be4.eventb.core.parser.lexer.LexerException in project probparsers by bendisposto.
the class EventBParser method parse.
/**
* Parses the input string.
*
* @param input
* the {@link String} to be parsed
* @param debugOutput
* output debug messages on standard out?
* @return the root node of the AST
* @throws BException
* The {@link BException} class stores the actual exception as
* delegate and forwards all method calls to it. So it is save
* for tools to just use this exception if they want to extract
* an error message. If the tools needs to extract additional
* information, such as a sourcecode position or involved tokens
* respectively nodes, it needs to retrieve the delegate
* exception. The {@link BException} class offers a
* {@link BException#getCause()} method for this, which returns
* the delegate exception.
* <p>
* Internal exceptions:
* <ul>
* <li>{@link EventBLexerException}: If any error occurs in the
* generated or customized lexer a {@link LexerException} is
* thrown. Usually the lexer classes just throw a
* {@link LexerException}. But this class unfortunately does not
* contain any explicit information about the sourcecode
* position where the error occured. Using aspect-oriented
* programming we intercept the throwing of these exceptions to
* replace them by our own exception. In our own exception we
* provide the sourcecode position of the last characters that
* were read from the input.</li>
* <li>{@link EventBParseException}: This exception is thrown in
* two situations. On the one hand if the parser throws a
* {@link ParserException} we convert it into a
* {@link EventBParseException}. On the other hand it can be
* thrown if any error is found during the AST transformations
* after the parser has finished. We try to provide a token if a
* single token is involved in the error. Otherwise a
* {@link SourcecodeRange} is provided, which can be used to
* retrieve detailed position information from the
* {@link SourcePositions} (s. {@link #getSourcePositions()}).
* </li>
* <li>{@link CheckException}: If any problem occurs while
* performing semantic checks, a {@link CheckException} is
* thrown. We provide one or more nodes that are involved in the
* problem. For example, if we find dublicate machine clauses,
* we will list all occurances in the exception.</li>
* </ul>
*/
public Start parse(final String input, final boolean debugOutput) throws BException {
final Reader reader = new StringReader(input);
try {
/*
* Main parser
*/
final EventBLexer lexer = new EventBLexer(new PushbackReader(reader, 99));
lexer.setDebugOutput(debugOutput);
Parser parser = new Parser(lexer);
final Start rootNode = parser.parse();
final List<IToken> tokenList = ((ITokenListContainer) lexer).getTokenList();
/*
* Retrieving sourcecode positions which were found by ParserAspect
*/
final Map<PositionedNode, SourcecodeRange> positions = ((IParser) parser).getMapping();
sourcePositions = new SourcePositions(tokenList, positions);
parser = null;
return rootNode;
} catch (final LexerException e) {
/*
* Actually it's supposed to be a EventBLexerException because the
* aspect 'LexerAspect' replaces any LexerException to provide
* sourcecode position information in the BLexerException.
*/
throw new BException(e);
} catch (final ParserException e) {
throw new BException(createEventBParseException(e));
} catch (final EventBParseException e) {
throw new BException(e);
} catch (final IOException e) {
// shouldn't happen and if, we cannot handle it
throw new BException(e);
}
}
use of de.be4.eventb.core.parser.lexer.LexerException in project probparsers by bendisposto.
the class LTLFormulaVisitor method parseLTLFormula.
public static Start parseLTLFormula(String ltlFormula) throws ParserException, LexerException, IOException {
StringReader reader = new StringReader(ltlFormula);
PushbackReader r = new PushbackReader(reader);
Lexer l = new LtlLexer(r);
Parser p = new Parser(l);
Start ast = null;
ast = p.parse();
return ast;
}
use of de.be4.eventb.core.parser.lexer.LexerException in project probparsers by bendisposto.
the class LtlParser method parseFormula.
protected Start parseFormula(final String formula) throws LtlParseException, IOException {
StringReader reader = new StringReader(formula);
PushbackReader r = new PushbackReader(reader);
Lexer l = new LtlLexer(r);
Parser p = new Parser(l);
Start ast = null;
try {
ast = p.parse();
} catch (ParserException e) {
final UniversalToken token = UniversalToken.createToken(e.getToken());
throw new LtlParseException(token, e.getLocalizedMessage());
} catch (LexerException e) {
throw new LtlParseException(null, e.getLocalizedMessage());
}
return ast;
}
Aggregations