use of org.antlr.runtime.CommonTokenStream in project rsense by m2ym.
the class AnnotationHelper method parseAnnotation.
public static TypeAnnotation parseAnnotation(String annot, int lineno) {
if (annot.startsWith("#%")) {
ANTLRStringStream in = new ANTLRStringStream(annot.substring(2));
in.setLine(lineno);
TypeAnnotationLexer lex = new TypeAnnotationLexer(in);
CommonTokenStream tokens = new CommonTokenStream(lex);
TypeAnnotationParser parser = new TypeAnnotationParser(tokens);
try {
return parser.type();
} catch (RecognitionException e) {
}
}
return null;
}
use of org.antlr.runtime.CommonTokenStream in project otertool by wuntee.
the class SmaliWorkshop method buildDex.
private static void buildDex(File smaliSourceDirectory, File destination) throws RecognitionException, SmaliSyntaxException, SmaliDexException, IOException {
DexFile dexFile = new DexFile();
// Load files into set
logger.debug("Loading smali files");
LinkedHashSet<File> filesToProcess = new LinkedHashSet<File>();
getSmaliFilesInDir(smaliSourceDirectory, filesToProcess);
// Process each file
logger.debug("Processing files");
for (File file : filesToProcess) {
logger.debug("Processing: " + file.getAbsolutePath());
FileInputStream fis = new FileInputStream(file.getAbsolutePath());
InputStreamReader reader = new InputStreamReader(fis, "UTF-8");
LexerErrorInterface lexer = new smaliFlexLexer(reader);
((smaliFlexLexer) lexer).setSourceFile(file);
CommonTokenStream tokens = new CommonTokenStream((TokenSource) lexer);
smaliParser parser = new smaliParser(tokens);
smaliParser.smali_file_return result = parser.smali_file();
// Errors
if (parser.getNumberOfSyntaxErrors() > 0) {
throw new SmaliSyntaxException(file, parser.getNumberOfSyntaxErrors());
}
if (lexer.getNumberOfSyntaxErrors() > 0) {
throw new SmaliSyntaxException(file, lexer.getNumberOfSyntaxErrors());
}
CommonTree t = (CommonTree) result.getTree();
CommonTreeNodeStream treeStream = new CommonTreeNodeStream(t);
treeStream.setTokenStream(tokens);
smaliTreeWalker dexGen = new smaliTreeWalker(treeStream);
dexGen.dexFile = dexFile;
dexGen.smali_file();
if (dexGen.getNumberOfSyntaxErrors() > 0) {
throw new SmaliDexException(file, dexGen.getNumberOfSyntaxErrors());
}
}
// Calculate signatures and write file
logger.debug("Writing dex file.");
dexFile.place();
ByteArrayAnnotatedOutput out = new ByteArrayAnnotatedOutput();
dexFile.writeTo(out);
byte[] bytes = out.toByteArray();
DexFile.calcSignature(bytes);
DexFile.calcChecksum(bytes);
FileOutputStream fileOutputStream = new FileOutputStream(destination);
fileOutputStream.write(bytes);
fileOutputStream.close();
}
use of org.antlr.runtime.CommonTokenStream in project drill by apache.
the class PhysicalOpUnitTestBase method parseExpr.
@Override
protected LogicalExpression parseExpr(String expr) {
ExprLexer lexer = new ExprLexer(new ANTLRStringStream(expr));
CommonTokenStream tokens = new CommonTokenStream(lexer);
ExprParser parser = new ExprParser(tokens);
try {
return parser.parse().e;
} catch (RecognitionException e) {
throw new RuntimeException("Error parsing expression: " + expr);
}
}
use of org.antlr.runtime.CommonTokenStream in project drill by apache.
the class TestEvaluationVisitor method getExpr.
private LogicalExpression getExpr(String expr) throws Exception {
ExprLexer lexer = new ExprLexer(new ANTLRStringStream(expr));
CommonTokenStream tokens = new CommonTokenStream(lexer);
// tokens.fill();
// for(Token t : (List<Token>) tokens.getTokens()){
// System.out.println(t + "" + t.getType());
// }
// tokens.rewind();
ExprParser parser = new ExprParser(tokens);
parse_return ret = parser.parse();
return ret.e;
}
use of org.antlr.runtime.CommonTokenStream in project drill by apache.
the class ExecTest method parseExpr.
protected LogicalExpression parseExpr(String expr) throws RecognitionException {
final ExprLexer lexer = new ExprLexer(new ANTLRStringStream(expr));
final CommonTokenStream tokens = new CommonTokenStream(lexer);
final ExprParser parser = new ExprParser(tokens);
final ExprParser.parse_return ret = parser.parse();
return ret.e;
}
Aggregations