use of org.antlr.v4.runtime.tree.ParseTree in project titan.EclipsePlug-ins by eclipse.
the class IncludeItemTransfer method nativeToJava.
@Override
protected ParseTree[] nativeToJava(final TransferData transferData) {
byte[] bytes = (byte[]) super.nativeToJava(transferData);
DataInputStream in = new DataInputStream(new ByteArrayInputStream(bytes));
try {
int n = in.readInt();
ParseTree[] items = new ParseTree[2 * n];
String fileName;
String hiddenBefore;
for (int i = 0; i < n; i++) {
hiddenBefore = in.readUTF();
fileName = in.readUTF();
items[2 * i] = ConfigTreeNodeUtilities.createHiddenTokenNode(hiddenBefore);
items[2 * i + 1] = new AddedParseTree(fileName);
}
return items;
} catch (IOException e) {
ErrorReporter.logExceptionStackTrace(e);
return new ParseTree[] {};
}
}
use of org.antlr.v4.runtime.tree.ParseTree in project titan.EclipsePlug-ins by eclipse.
the class IncludeItemTransfer method javaToNative.
@Override
protected void javaToNative(final Object object, final TransferData transferData) {
ParseTree[] items = (ParseTree[]) object;
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(byteOut);
byte[] bytes = null;
try {
out.writeInt(items.length);
for (int i = 0; i < items.length; i++) {
out.writeUTF(convertToString(items[2 * i]));
out.writeUTF(convertToString(items[2 * i + 1]));
}
out.close();
bytes = byteOut.toByteArray();
} catch (IOException e) {
ErrorReporter.logExceptionStackTrace(e);
}
if (bytes != null) {
super.javaToNative(bytes, transferData);
}
}
use of org.antlr.v4.runtime.tree.ParseTree in project titan.EclipsePlug-ins by eclipse.
the class IncludeSectionDragSourceListener method dragStart.
@Override
public void dragStart(final DragSourceEvent event) {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
event.doit = !selection.isEmpty() && (selection.getFirstElement() instanceof ParseTree);
}
use of org.antlr.v4.runtime.tree.ParseTree in project titan.EclipsePlug-ins by eclipse.
the class IncludeSectionDragSourceListener method dragSetData.
@Override
public void dragSetData(final DragSourceEvent event) {
if (IncludeItemTransfer.getInstance().isSupportedType(event.dataType)) {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
List<ParseTree> items = new ArrayList<ParseTree>();
if (!selection.isEmpty()) {
for (Iterator<?> it = selection.iterator(); it.hasNext(); ) {
Object element = it.next();
if (element instanceof ParseTree) {
items.add((ParseTree) element);
}
}
event.data = items.toArray(new ParseTree[items.size()]);
}
}
}
use of org.antlr.v4.runtime.tree.ParseTree in project inmemantlr by julianthome.
the class TestSimple method testOclStringParsing.
@Test
public void testOclStringParsing() throws IOException {
try (InputStream sgrammar = getClass().getClassLoader().getResourceAsStream("inmemantlr/DeepOcl.g4")) {
sgrammarcontent = FileUtils.getStringFromStream(sgrammar);
}
String toParse = "context Dependent inv inv54: (self.birthyear " + ">=2012 and self.allowances->size()=1) or (self.birthyear < " + "2012 and self.birthyear >= 1996)";
GenericParser gp = new GenericParser(sgrammarcontent);
DefaultTreeListener t = new DefaultTreeListener();
gp.setListener(t);
boolean compile;
try {
gp.compile();
compile = true;
} catch (CompilationException e) {
compile = false;
LOGGER.debug(e.getMessage());
}
Assertions.assertTrue(compile);
try {
ParserRuleContext ctx = gp.parse(toParse);
LOGGER.info("ctx {}", ctx.getChild(0).getText());
} catch (IllegalWorkflowException | ParsingException e) {
Assertions.assertTrue(false);
}
ParseTree a = t.getParseTree();
Assertions.assertTrue(a.getNodes().size() > 1);
LOGGER.debug(a.toDot());
}
Aggregations