use of org.antlr.runtime.CommonTokenStream in project binnavi by google.
the class DebuggerMemoryExpressionParser method parse.
/**
* Parses a single memory expression string.
*
* @param memoryExpression The memory expression string to parse.
*
* @return The parsed memory expression tree.
*
* @throws RecognitionException Thrown if parsing failed.
*/
public static MemoryExpressionElement parse(final String memoryExpression) throws RecognitionException {
final CharStream charStream = new ANTLRStringStream(memoryExpression);
final MemoryExpressionLexer lexer = new MemoryExpressionLexer(charStream);
final CommonTokenStream tokens = new CommonTokenStream();
tokens.setTokenSource(lexer);
final MemoryExpressionParser parser = new MemoryExpressionParser(tokens) {
@Override
public void recover(final IntStream input, final RecognitionException exception) {
// Nothing to do
}
@Override
public Object recoverFromMismatchedToken(final IntStream input, final int ttype, final org.antlr.runtime.BitSet follow) throws RecognitionException {
throw new MismatchedTokenException(ttype, input);
}
@Override
public void reportError(final RecognitionException exception) {
// Nothing to do
}
};
parser.setTreeAdaptor(adaptor);
final MemoryExpressionParser.prog_return parserResult = parser.prog();
final CommonTree ast = (CommonTree) parserResult.getTree();
return convert(ast);
}
use of org.antlr.runtime.CommonTokenStream in project dex2jar by pxb1988.
the class Jasmin2JarCmd method assemble1.
private void assemble1(Path file, Path output) throws IOException {
try (BufferedReader bufferedReader = Files.newBufferedReader(file, Charset.forName(encoding))) {
ANTLRStringStream is = new ANTLRReaderStream(bufferedReader);
is.name = file.toString();
JasminLexer lexer = new JasminLexer(is);
CommonTokenStream ts = new CommonTokenStream(lexer);
JasminParser parser = new JasminParser(ts);
parser.rebuildLine = autogenLines;
ClassWriter cw = new ClassWriter(noComputeMax ? 0 : ClassWriter.COMPUTE_MAXS);
ClassNode cn = parser.parse();
if (cn.version == 0) {
cn.version = versions[classVersion];
}
if (dump) {
new JasminDumper(new PrintWriter(new OutputStreamWriter(System.out, StandardCharsets.UTF_8), true)).dump(cn);
}
cn.accept(cw);
Path clzFile = output.resolve(cn.name.replace('.', '/') + ".class");
createParentDirectories(clzFile);
Files.write(clzFile, cw.toByteArray());
} catch (RecognitionException e) {
System.err.println("Fail to assemble " + file);
e.printStackTrace();
}
}
use of org.antlr.runtime.CommonTokenStream in project dex2jar by pxb1988.
the class Jasmins method parse.
public static ClassNode parse(String fileName, Reader bufferedReader) throws IOException, RecognitionException {
ANTLRStringStream is = new ANTLRReaderStream(bufferedReader);
is.name = fileName;
JasminLexer lexer = new JasminLexer(is);
CommonTokenStream ts = new CommonTokenStream(lexer);
JasminParser parser = new JasminParser(ts);
return parser.parse();
}
use of org.antlr.runtime.CommonTokenStream in project smali by JesusFreke.
the class SmaliTestUtils method compileSmali.
public static ClassDef compileSmali(String smaliText, int apiLevel) throws RecognitionException, IOException {
CommonTokenStream tokens;
LexerErrorInterface lexer;
DexBuilder dexBuilder = new DexBuilder(Opcodes.forApi(apiLevel));
Reader reader = new StringReader(smaliText);
lexer = new smaliFlexLexer(reader);
tokens = new CommonTokenStream((TokenSource) lexer);
smaliParser parser = new smaliParser(tokens);
parser.setVerboseErrors(true);
parser.setAllowOdex(false);
parser.setApiLevel(apiLevel);
smaliParser.smali_file_return result = parser.smali_file();
if (parser.getNumberOfSyntaxErrors() > 0 || lexer.getNumberOfSyntaxErrors() > 0) {
throw new RuntimeException("Error occured while compiling text");
}
CommonTree t = result.getTree();
CommonTreeNodeStream treeStream = new CommonTreeNodeStream(t);
treeStream.setTokenStream(tokens);
smaliTreeWalker dexGen = new smaliTreeWalker(treeStream);
dexGen.setApiLevel(apiLevel);
dexGen.setVerboseErrors(true);
dexGen.setDexBuilder(dexBuilder);
dexGen.smali_file();
if (dexGen.getNumberOfSyntaxErrors() > 0) {
throw new RuntimeException("Error occured while compiling text");
}
MemoryDataStore dataStore = new MemoryDataStore();
dexBuilder.writeTo(dataStore);
DexBackedDexFile dexFile = new DexBackedDexFile(Opcodes.forApi(apiLevel), dataStore.getData());
return Iterables.getFirst(dexFile.getClasses(), null);
}
use of org.antlr.runtime.CommonTokenStream in project freud by LMAX-Exchange.
the class CssJdomParser method parseCssToDocument.
private static Document parseCssToDocument(final Reader reader) throws RecognitionException, IOException {
CssParser parser = new CssParser(new CommonTokenStream(new CssLexer(new ANTLRReaderStream(reader))));
final JdomTreeAdaptor treeAdaptor = new JdomTreeAdaptor(CSS_ROOT_ELEMENT_NAME, CSS_TOKEN_TYPES);
parser.setTreeAdaptor(treeAdaptor);
parser.stylesheet();
return treeAdaptor.getDocument();
}
Aggregations