use of de.be4.classicalb.core.parser.analysis.prolog.ASTProlog in project probparsers by bendisposto.
the class CreateFreetypeTest method printProlog.
private void printProlog(final IPrologTermOutput pto) {
final Start machine = createMachine(MACHINE_NAME);
final ASTProlog printer = new ASTProlog(pto, null);
machine.apply(printer);
}
use of de.be4.classicalb.core.parser.analysis.prolog.ASTProlog in project probparsers by bendisposto.
the class RecursiveMachineLoader method printAsProlog.
public void printAsProlog(final IPrologTermOutput pout) {
final ClassicalPositionPrinter pprinter = new ClassicalPositionPrinter(getNodeIdMapping());
pprinter.printSourcePositions(parsingBehaviour.isAddLineNumbers());
final ASTProlog prolog = new ASTProlog(pout, pprinter);
// parser version
pout.openTerm("parser_version");
pout.printAtom(BParser.getBuildRevision());
pout.closeTerm();
pout.fullstop();
// machine
pout.openTerm("classical_b");
pout.printAtom(main);
pout.openList();
List<File> allFiles = new ArrayList<>();
allFiles.addAll(machineFilesLoaded);
allFiles.addAll(definitionFilesLoaded);
for (final File file : allFiles) {
try {
pout.printAtom(file.getCanonicalPath());
} catch (IOException e) {
pout.printAtom(file.getPath());
}
}
pout.closeList();
pout.closeTerm();
pout.fullstop();
for (final Map.Entry<String, Start> entry : getParsedMachines().entrySet()) {
pout.openTerm("machine");
entry.getValue().apply(prolog);
pout.closeTerm();
pout.fullstop();
}
pout.flush();
}
use of de.be4.classicalb.core.parser.analysis.prolog.ASTProlog 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.classicalb.core.parser.analysis.prolog.ASTProlog 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);
}
}
use of de.be4.classicalb.core.parser.analysis.prolog.ASTProlog in project probparsers by bendisposto.
the class ConsoleTest method testFormulaOutput.
@Test
public void testFormulaOutput() throws BCompoundException {
Start start = BParser.parse("#FORMULA 1+1");
PrologTermStringOutput strOutput = new PrologTermStringOutput();
ASTProlog printer = new ASTProlog(strOutput, null);
start.apply(printer);
strOutput.fullstop();
// A Friendly Reminder: strOutput includes a newline!
String output = strOutput.toString().trim();
assertEquals(output, "add(none,integer(none,1),integer(none,1)).");
}
Aggregations