use of de.be4.eventb.core.parser.parser.Parser in project probparsers by bendisposto.
the class BParser method eparse.
public Start eparse(String input, IDefinitions context) throws BCompoundException, LexerException, IOException {
final Reader reader = new StringReader(input);
Start ast = null;
List<String> ids = new ArrayList<>();
final DefinitionTypes defTypes = new DefinitionTypes();
defTypes.addAll(context.getTypes());
BLexer bLexer = new BLexer(new PushbackReader(reader, BLexer.PUSHBACK_BUFFER_SIZE), defTypes);
bLexer.setParseOptions(parseOptions);
Token t;
do {
t = bLexer.next();
if (t instanceof TIdentifierLiteral) {
if (!ids.contains(t.getText())) {
ids.add(t.getText());
}
}
} while (!(t instanceof EOF));
Parser p = new Parser(new EBLexer(input, BigInteger.ZERO, ids, defTypes));
boolean ok;
try {
ast = p.parse();
ok = true;
} catch (Exception e) {
handleException(e);
ok = false;
}
BigInteger b = new BigInteger("2");
b = b.pow(ids.size());
b = b.subtract(BigInteger.ONE);
while (!ok && b.compareTo(BigInteger.ZERO) > 0) {
p = new Parser(new EBLexer(input, b, ids, defTypes));
try {
ast = p.parse();
ok = true;
} catch (ParserException e) {
b = b.subtract(BigInteger.ONE);
handleException(e);
}
}
return ast;
}
Aggregations