use of de.be4.ltl.core.parser.node.Start in project probparsers by bendisposto.
the class IfThenElseExpressionTest method getTreeAsString.
private String getTreeAsString(final String testMachine) throws BCompoundException {
final Start startNode = parser.parse(testMachine, false);
final Ast2String ast2String = new Ast2String();
startNode.apply(ast2String);
return ast2String.toString();
}
use of de.be4.ltl.core.parser.node.Start in project probparsers by bendisposto.
the class Helpers method parseFile2.
public static String parseFile2(String filename) throws IOException {
final File machineFile = new File(filename);
final BParser parser = new BParser(machineFile.getAbsolutePath());
Start tree;
OutputStream output = new OutputStream() {
private StringBuilder string = new StringBuilder();
@Override
public void write(int b) throws IOException {
this.string.append((char) b);
}
public String toString() {
return this.string.toString();
}
};
try {
tree = parser.parseFile(machineFile, false);
PrintStream printStream = new PrintStream(output);
BParser.printASTasProlog(printStream, parser, machineFile, tree, new ParsingBehaviour(), parser.getContentProvider());
output.close();
return output.toString();
} catch (BCompoundException e) {
e.printStackTrace();
PrologExceptionPrinter.printException(output, e);
return output.toString();
}
}
use of de.be4.ltl.core.parser.node.Start in project probparsers by bendisposto.
the class Helpers method getMachineAsPrologTerm.
public static String getMachineAsPrologTerm(String input) {
final BParser parser = new BParser("Test");
Start start;
try {
start = parser.parse(input, true);
} catch (BCompoundException e) {
throw new RuntimeException(e);
}
OutputStream output = new OutputStream() {
private StringBuilder string = new StringBuilder();
@Override
public void write(int b) throws IOException {
this.string.append((char) b);
}
public String toString() {
return this.string.toString();
}
};
final IPrologTermOutput pout = new PrologTermOutput(output, false);
printAsProlog(start, pout);
return output.toString();
}
use of de.be4.ltl.core.parser.node.Start in project probparsers by bendisposto.
the class CliBParser method parseFormula.
private static void parseFormula(String theFormula, IDefinitions context) {
try {
BParser parser = new BParser();
parser.setDefinitions(context);
Start start = parser.parse(theFormula, false);
PrologTermStringOutput strOutput = new PrologTermStringOutput();
NodeIdAssignment na = new NodeIdAssignment();
start.apply(na);
ClassicalPositionPrinter pprinter = new ClassicalPositionPrinter(na, -1, 0);
ASTProlog printer = new ASTProlog(strOutput, pprinter);
start.apply(printer);
strOutput.fullstop();
// A Friendly Reminder: strOutput includes a newline!
String output = strOutput.toString();
print(output);
} catch (NullPointerException e) {
// Not Parseable - Sadly, calling e.getLocalizedMessage() on the
// NullPointerException returns NULL itself, thus triggering another
// NullPointerException in the catch statement. Therefore we need a
// second catch statement with a special case for the
// NullPointerException instead of catching a general Exception
// print("EXCEPTION NullPointerException" + System.lineSeparator());
PrologTermStringOutput strOutput = new PrologTermStringOutput();
strOutput.openTerm("exception").printAtom("NullPointerException").closeTerm();
strOutput.fullstop();
strOutput.flush();
String output = strOutput.toString();
print(output);
} catch (BCompoundException e) {
PrologExceptionPrinter.printException(socketOutputStream, e, false, true);
}
}
use of de.be4.ltl.core.parser.node.Start in project probparsers by bendisposto.
the class CliBParser method parseExtendedFormula.
private static void parseExtendedFormula(String theFormula, IDefinitions context) {
try {
BParser parser = new BParser();
parser.setDefinitions(context);
Start start = parser.eparse(theFormula, context);
PrologTermStringOutput strOutput = new PrologTermStringOutput();
NodeIdAssignment na = new NodeIdAssignment();
start.apply(na);
ClassicalPositionPrinter pprinter = new ClassicalPositionPrinter(na, -1, 0);
ASTProlog printer = new ASTProlog(strOutput, pprinter);
start.apply(printer);
strOutput.fullstop();
// A Friendly Reminder: strOutput includes a newline!
print(strOutput.toString());
} catch (NullPointerException e) {
// Not Parseable - Sadly, calling e.getLocalizedMessage() on the
// NullPointerException returns NULL itself, thus triggering another
// NullPointerException in the catch statement. Therefore we need a
// second catch statement with a special case for the
// NullPointerException instead of catching a general Exception
// print("EXCEPTION NullPointerException" + System.lineSeparator());
PrologTermStringOutput strOutput = new PrologTermStringOutput();
strOutput.openTerm("exception").printAtom("NullPointerException").closeTerm();
strOutput.fullstop();
strOutput.flush();
print(strOutput.toString());
} catch (BCompoundException e) {
PrologExceptionPrinter.printException(socketOutputStream, e, false, true);
} catch (LexerException e) {
PrologTermStringOutput strOutput = new PrologTermStringOutput();
strOutput.openTerm("exception").printAtom(e.getLocalizedMessage()).closeTerm();
strOutput.fullstop();
strOutput.flush();
print(strOutput.toString());
} catch (IOException e) {
PrologExceptionPrinter.printException(socketOutputStream, e, theFormula, false, true);
}
}
Aggregations