Java Code Examples for org.antlr.v4.runtime.ANTLRFileStream

The following examples show how to use org.antlr.v4.runtime.ANTLRFileStream. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: cs652   Source File: Load.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void main(String[] args) throws IOException {
	ANTLRInputStream input = new ANTLRFileStream("colleges.csv");
	CSVLexer lexer = new CSVLexer(input);
	CommonTokenStream tokens = new CommonTokenStream(lexer);
	CSVParser parser = new CSVParser(tokens);
	ParseTree tree = parser.file();
	System.out.println(tree.toStringTree(parser));

	ParseTreeWalker walker = new ParseTreeWalker();
	CSVLoader loader = new CSVLoader();
	walker.walk(loader, tree);

	for (List<String> row : loader.data) {
		System.out.println(row);
	}
}
 
Example 2
Source Project: cs652   Source File: Load.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void main(String[] args) throws IOException {
	ANTLRInputStream input = new ANTLRFileStream("colleges.csv");
	CSVLexer lexer = new CSVLexer(input);
	CommonTokenStream tokens = new CommonTokenStream(lexer);
	CSVParser parser = new CSVParser(tokens);
	ParseTree tree = parser.file();
	System.out.println(tree.toStringTree(parser));

	ParseTreeWalker walker = new ParseTreeWalker();
	CSVLoader loader = new CSVLoader();
	walker.walk(loader, tree);

	for (List<String> row : loader.data) {
		System.out.println(row);
	}
}
 
Example 3
Source Project: arcusplatform   Source File: IrisProtoCompiler.java    License: Apache License 2.0 5 votes vote down vote up
private static void parse(ASTBuilder builder, String path) throws Exception {
   ProtocLexer lexer = new ProtocLexer(new ANTLRFileStream(path));
   CommonTokenStream tokens = new CommonTokenStream(lexer);
   ProtocParser parser = new ProtocParser(tokens);
   FileContext file = parser.file();

   ParseTreeWalker walker = new ParseTreeWalker();
   walker.walk(builder, file);
}
 
Example 4
Source Project: codebuff   Source File: Dbg.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void main(String[] args) throws Exception {
	ANTLRv4Lexer lexer = new ANTLRv4Lexer(new ANTLRFileStream("grammars/org/antlr/codebuff/ANTLRv4Lexer.g4"));
	CommonTokenStream tokens = new CodeBuffTokenStream(lexer);
	ANTLRv4Parser parser = new ANTLRv4Parser(tokens);
	ANTLRv4Parser.GrammarSpecContext tree = parser.grammarSpec();
	System.out.println(tree.toStringTree(parser));
}
 
Example 5
Source Project: codebuff   Source File: ProfileJava.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void main(String[] args) throws Exception {
		Thread.sleep(10000);
		ANTLRFileStream input = new ANTLRFileStream(args[0]);
		JavaLexer lexer = new JavaLexer(input);
		CommonTokenStream tokens = new CommonTokenStream(lexer);
		JavaParser parser = new JavaParser(tokens);
		JavaParser.CompilationUnitContext tree = parser.compilationUnit();
//		System.out.println(tree.toStringTree(parser));
		Thread.sleep(10000);
	}
 
Example 6
Source Project: openCypher   Source File: BNFProcessor.java    License: Apache License 2.0 5 votes vote down vote up
public Grammar processFile(String fileName)
{
    try
    {
        // when back on antrl 4.7.1, use CharStreams.fromFileName(scriptFile)
        return processAntrlStream(new ANTLRFileStream(fileName));
    } catch (IOException e)
    {
        throw new RuntimeException("Failed to find or read " + fileName, e);
    }

}
 
Example 7
Source Project: openCypher   Source File: G4Processor.java    License: Apache License 2.0 5 votes vote down vote up
public Grammar processFile(String fileName)
{
    try
    {
        // when back on antrl 4.7.1, use CharStreams.fromFileName(scriptFile)
        return processAntrlStream(new ANTLRFileStream(fileName));
    } catch (IOException e)
    {
        throw new RuntimeException("Failed to find or read " + fileName, e);
    }

}
 
Example 8
Source Project: cs652   Source File: Test.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void main(String[] args) throws IOException {
		ANTLRInputStream input = new ANTLRFileStream(args[0]);
		SimpleLexer l = new SimpleLexer(input);
		TokenStream tokens = new CommonTokenStream(l);

		SimpleParser parser = new SimpleParser(tokens);
		ParserRuleContext tree = parser.file();
		System.out.println(tree.toStringTree(parser));
//		tree.inspect(parser);

		DefSymbolsAndScopes def = new DefSymbolsAndScopes();
		ParseTreeWalker walker = new ParseTreeWalker();
		walker.walk(def, tree);
	}
 
Example 9
Source Project: cs652   Source File: TestFaLaLa.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void main(String[] args) throws Exception {
	ANTLRInputStream input = new ANTLRFileStream("test.falala");
	FaLaLaLexer lexer = new FaLaLaLexer(input);
	CommonTokenStream tokens = new CommonTokenStream(lexer);
	FaLaLaParser parser = new FaLaLaParser(tokens);
	ParseTree tree = parser.prog();
	System.out.println(tree.toStringTree(parser));

	ParseTreeWalker walker = new ParseTreeWalker();
	DefSymbols def = new DefSymbols();
	walker.walk(def, tree);
}
 
Example 10
Source Project: cs652   Source File: TestLaLa.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void main(String[] args) throws Exception {
	ANTLRInputStream input = new ANTLRFileStream("bad.lala");
	LaLaLexer lexer = new LaLaLexer(input);
	CommonTokenStream tokens = new CommonTokenStream(lexer);
	LaLaParser parser = new LaLaParser(tokens);
	ParseTree tree = parser.prog();
	System.out.println(tree.toStringTree(parser));

	ParseTreeWalker walker = new ParseTreeWalker();
	DefSymbols def = new DefSymbols();
	walker.walk(def, tree);

	System.out.println(def.globals.symbols);
}
 
Example 11
Source Project: cs652   Source File: Test.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void main(String[] args) throws IOException {
		ANTLRInputStream input = new ANTLRFileStream(args[0]);
		SimpleLexer l = new SimpleLexer(input);
		TokenStream tokens = new CommonTokenStream(l);

		SimpleParser parser = new SimpleParser(tokens);
		ParserRuleContext tree = parser.file();
		System.out.println(tree.toStringTree(parser));
//		tree.inspect(parser);

		DefSymbolsAndScopes def = new DefSymbolsAndScopes();
		ParseTreeWalker walker = new ParseTreeWalker();
		walker.walk(def, tree);
	}
 
Example 12
Source Project: cs652   Source File: TestFaLaLa.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void main(String[] args) throws Exception {
	ANTLRInputStream input = new ANTLRFileStream("test.falala");
	FaLaLaLexer lexer = new FaLaLaLexer(input);
	CommonTokenStream tokens = new CommonTokenStream(lexer);
	FaLaLaParser parser = new FaLaLaParser(tokens);
	ParseTree tree = parser.prog();
	System.out.println(tree.toStringTree(parser));

	ParseTreeWalker walker = new ParseTreeWalker();
	DefSymbols def = new DefSymbols();
	walker.walk(def, tree);
}
 
Example 13
Source Project: cs652   Source File: TestLaLa.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void main(String[] args) throws Exception {
	ANTLRInputStream input = new ANTLRFileStream("bad.lala");
	LaLaLexer lexer = new LaLaLexer(input);
	CommonTokenStream tokens = new CommonTokenStream(lexer);
	LaLaParser parser = new LaLaParser(tokens);
	ParseTree tree = parser.prog();
	System.out.println(tree.toStringTree(parser));

	ParseTreeWalker walker = new ParseTreeWalker();
	DefSymbols def = new DefSymbols();
	walker.walk(def, tree);

	System.out.println(def.globals.symbols);
}
 
Example 14
Source Project: QuickProject   Source File: Module.java    License: Apache License 2.0 5 votes vote down vote up
private void parseBean(File sqlFile, GlobalConfig globalConfig) throws IOException {
    CharStream input = new ANTLRFileStream(sqlFile.getAbsolutePath());
    CreateTableLexer lexer = new CreateTableLexer(input);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    CreateTableParser parser = new CreateTableParser(tokens);
    ParseTree tree = parser.sql();

    ParseTreeWalker walker = new ParseTreeWalker();
    CreateTableListenerImpl extractor = new CreateTableListenerImpl(globalConfig);
    walker.walk(extractor, tree);
    beans = extractor.getTables();
}
 
Example 15
Source Project: arcusplatform   Source File: ExpressionCompiler.java    License: Apache License 2.0 4 votes vote down vote up
public static Predicate<Model> compile(File file) throws IOException {
   return compile(new ANTLRFileStream(file.getAbsolutePath()));
}
 
Example 16
Source Project: gdl   Source File: GDLHandler.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Initializes GDL Handler from given file.
 *
 * @param fileName GDL file (must not be {@code null}).
 * @return GDL handler
 */
public GDLHandler buildFromFile(String fileName) throws IOException {
  ANTLRInputStream antlrInputStream = new ANTLRFileStream(fileName);
  return build(antlrInputStream);
}