當前位置: 首頁>>代碼示例>>Java>>正文


Java ANTLRFileStream類代碼示例

本文整理匯總了Java中org.antlr.v4.runtime.ANTLRFileStream的典型用法代碼示例。如果您正苦於以下問題:Java ANTLRFileStream類的具體用法?Java ANTLRFileStream怎麽用?Java ANTLRFileStream使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ANTLRFileStream類屬於org.antlr.v4.runtime包,在下文中一共展示了ANTLRFileStream類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: checkValidYangFileForNoSyntaxError

import org.antlr.v4.runtime.ANTLRFileStream; //導入依賴的package包/類
/**
 * Checks that no exception is generated for YANG file with valid syntax.
 */
@Test
public void checkValidYangFileForNoSyntaxError() throws IOException {

    ANTLRInputStream input = new ANTLRFileStream("src/test/resources/YangFileWithoutSyntaxError.yang");

    // Create a lexer that feeds off of input char stream.
    GeneratedYangLexer lexer = new GeneratedYangLexer(input);
    // Create a buffer of tokens pulled from the lexer.
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    // Create a parser that feeds off the tokens buffer.
    GeneratedYangParser parser = new GeneratedYangParser(tokens);
    // Remove console error listener.
    parser.removeErrorListeners();
    // Create instance of customized error listener.
    ParseTreeErrorListener parseTreeErrorListener = new ParseTreeErrorListener();
    // Add customized error listener to catch errors during parsing.
    parser.addErrorListener(parseTreeErrorListener);
    // Begin parsing YANG file and generate parse tree.
    ParseTree tree = parser.yangfile();
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:24,代碼來源:ParseTreeErrorListenerTest.java

示例2: checkInvalidYangFileForSyntaxError

import org.antlr.v4.runtime.ANTLRFileStream; //導入依賴的package包/類
/**
 * Checks that exception is generated for YANG file with invalid syntax.
 */
@Test
public void checkInvalidYangFileForSyntaxError() throws IOException {

    // Get the exception occurred during parsing.
    thrown.expect(ParserException.class);
    thrown.expect(CustomExceptionMatcher.errorLocation(3, 0));
    thrown.expectMessage("no viable alternative at input 'yang-version 1\\nnamespace'");

    ANTLRInputStream input = new ANTLRFileStream("src/test/resources/YangFileWithSyntaxError.yang");

    // Create a lexer that feeds off of input char stream.
    GeneratedYangLexer lexer = new GeneratedYangLexer(input);
    // Create a buffer of tokens pulled from the lexer.
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    // Create a parser that feeds off the tokens buffer.
    GeneratedYangParser parser = new GeneratedYangParser(tokens);
    // Remove console error listener.
    parser.removeErrorListeners();
    // Create instance of customized error listener.
    ParseTreeErrorListener parseTreeErrorListener = new ParseTreeErrorListener();
    // Add customized error listener to catch errors during parsing.
    parser.addErrorListener(parseTreeErrorListener);
    // Begin parsing YANG file and generate parse tree.
    ParseTree tree = parser.yangfile();
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:29,代碼來源:ParseTreeErrorListenerTest.java

示例3: main

import org.antlr.v4.runtime.ANTLRFileStream; //導入依賴的package包/類
public static void main(String[] args) throws IOException {
	CoqLexer lexer = new CoqLexer(new ANTLRFileStream("../TestProgramC.v"));
	CoqFTParser parser = new CoqFTParser(new CommonTokenStream(lexer));
	
	//Listener listener = new Listener(parser);
	//parser.addParseListener(listener);
	//CoqParser.ProgContext ctx = parser.prog();
	//System.out.println(ctx.toStringTree(Arrays.asList(CoqParser.ruleNames)));
	
	Prog prog = parser.parseProg();
	for(Command command : prog) {
		if(command instanceof AssertionAndProof) {
			AssertionAndProof ap = (AssertionAndProof) command;
			System.out.println(ap.getAssertion());
			System.out.println("Proof:");
			for(Tactic tactic : ap.getProof().getTactics()) {
				System.out.println(tactic);
			}
		} else {
			System.out.println(command);
		}
	}
}
 
開發者ID:jhuapl-saralab,項目名稱:exterminator,代碼行數:24,代碼來源:Test.java

示例4: main

import org.antlr.v4.runtime.ANTLRFileStream; //導入依賴的package包/類
/**
 * @param args
 * @throws IOException 
 * @throws SQLException 
 */
public static void main(String[] args) throws IOException, SQLException {
	
       TPKBLexer lexer = new TPKBLexer(new ANTLRFileStream("test.kb"));
       TPKBParser parser = new TPKBParser(new CommonTokenStream(lexer));
       
       TPKBClassListener listener = new TPKBClassListener();
       
       ParseTree tree = parser.tpkb();
       ParseTreeWalker walker = new ParseTreeWalker();
       walker.walk(listener, tree);
       
       MySQLEngine engine = new MySQLEngine();
       engine.processTSubRaw();
       engine.processTIsRaw();
       
       double Z = engine.computeZ();
       System.out.println("Z = "+Z);
       
       Z = engine.computeZWithEvidence();
       System.out.println("Z(E) = "+Z);     
}
 
開發者ID:mniepert,項目名稱:TPKB,代碼行數:27,代碼來源:TPKB.java

示例5: main

import org.antlr.v4.runtime.ANTLRFileStream; //導入依賴的package包/類
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);
	}
}
 
開發者ID:parrt,項目名稱:cs652,代碼行數:17,代碼來源:Load.java

示例6: testParseWorkingExamples

import org.antlr.v4.runtime.ANTLRFileStream; //導入依賴的package包/類
@Test
public void testParseWorkingExamples() throws IOException {
	FileVisitor<Path> workingFilesVisitior = new SimpleFileVisitor<Path>() {
		@Override
		public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
			System.out.println("Testing parser input from file \""+file.toString()+"\"");
			ANTLRFileStream antlrStream = new ANTLRFileStream(file.toString());
			MiniJLexer lexer = new MiniJLexer(antlrStream);
			TokenStream tokens = new CommonTokenStream(lexer);
			MiniJParser parser = new MiniJParser(tokens);
			parser.setErrorHandler(new BailErrorStrategy());
			parser.prog();
			return super.visitFile(file, attrs);
		}
	};
	Files.walkFileTree(EXAMPLE_PROGRAM_PATH_WORKING, workingFilesVisitior);
}
 
開發者ID:tiborgo,項目名稱:MiniJCompiler,代碼行數:18,代碼來源:MiniJParserTest.java

示例7: testParseFailingExamples

import org.antlr.v4.runtime.ANTLRFileStream; //導入依賴的package包/類
@Test
public void testParseFailingExamples() throws IOException {
	FileVisitor<Path> workingFilesVisitior = new SimpleFileVisitor<Path>() {
		@Override
		public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
			System.out.println("Testing parser input from file \""+file.toString()+"\"");
			ANTLRFileStream antlrStream = new ANTLRFileStream(file.toString());
			MiniJLexer lexer = new MiniJLexer(antlrStream);
			TokenStream tokens = new CommonTokenStream(lexer);
			MiniJParser parser = new MiniJParser(tokens);
			parser.setErrorHandler(new BailErrorStrategy());
			/*
			 * Catch all exceptions first, to ensure that every single
			 * compilation unit exits with an Exception. Otherwise, this
			 * method will return after the first piece of code.
			 */
			try {
				parser.prog();
				fail("The example "+file.toString()+" should have failed, but was accepted by the parser.");
			} catch (ParseCancellationException e) {
			}
			return super.visitFile(file, attrs);
		}
	};
	Files.walkFileTree(EXAMPLE_PROGRAM_PATH_FAILING, workingFilesVisitior);
}
 
開發者ID:tiborgo,項目名稱:MiniJCompiler,代碼行數:27,代碼來源:MiniJParserTest.java

示例8: testVisitTypeErrorExamples

import org.antlr.v4.runtime.ANTLRFileStream; //導入依賴的package包/類
@Test
public void testVisitTypeErrorExamples() throws Exception {
	FileVisitor<Path> failingFilesVisitior = new SimpleFileVisitor<Path>() {
		@Override
		public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
			if (file.toString().endsWith("LinkedListBUG.java")) {
				return super.visitFile(file, attrs);
			}
			System.out.println("Testing type checker with file \""+file.toString()+"\"");
			ANTLRFileStream reader = new ANTLRFileStream(file.toString());
			MiniJLexer lexer = new MiniJLexer((CharStream) reader);
			TokenStream tokens = new CommonTokenStream(lexer);
			MiniJParser parser = new MiniJParser(tokens);
			ParseTree parseTree = parser.prog();
			ASTVisitor astVisitor = new ASTVisitor();
			Program ast = (Program) astVisitor.visit(parseTree);
			TypeInferenceVisitor typeInferenceVisitor = new TypeInferenceVisitor();
			ast.accept(typeInferenceVisitor);
			TypeCheckVisitor visitor = new TypeCheckVisitor();
			boolean typesCorrect = ast.accept(visitor);
			assertFalse("\"" + file.toString() + "\" passed type check but it shouldn't", typesCorrect);
			return super.visitFile(file, attrs);
		}
	};
	Files.walkFileTree(EXAMPLE_PROGRAM_PATH_FAILING, failingFilesVisitior);
}
 
開發者ID:tiborgo,項目名稱:MiniJCompiler,代碼行數:27,代碼來源:TypeCheckVisitorTest.java

示例9: visitIncludeFile

import org.antlr.v4.runtime.ANTLRFileStream; //導入依賴的package包/類
@Override
public String visitIncludeFile(QPLParser.IncludeFileContext ctx) {
    String filePath = ctx.path.getText().trim();
    filePath = filePath.substring(1, filePath.length() - 1);
    if (filePath.charAt(0) != '/') {
        filePath = Paths.get(__FILE_PATH__, filePath).toString();
    }
    try {
        ANTLRInputStream ais = new ANTLRFileStream(filePath);
        QPLLexer lex = new QPLLexer(ais);
        TokenStream toks = new CommonTokenStream(lex);
        QPLParser parse = new QPLParser(toks);
        ParseTree tree = parse.prog();
        return new ImpVisitor(filePath).visit(tree);
    } catch (IOException ex) {
        System.err.println(filePath + " cannot be found! Ignoring");
        return "";
    }
}
 
開發者ID:raphydaphy,項目名稱:Q-Programming-Language,代碼行數:20,代碼來源:Main.java

示例10: compile

import org.antlr.v4.runtime.ANTLRFileStream; //導入依賴的package包/類
public static Walk compile( File file, IcosahedralSymmetry symm ) {
String fileName = file.getAbsolutePath();
Walk program = null;
ErrorHandler.Default errors = new ErrorHandler.Default();
ZomicASTCompiler compiler = new ZomicASTCompiler(symm );
try {
	ANTLRFileStream fileStream = new ANTLRFileStream(fileName);
	program = compiler.compile( fileStream, errors );
	if( program != null ) {
		program.setErrors( errors.getErrors() );
	}
} catch (IOException ex) {
	errors.parseError( ErrorHandler.UNKNOWN, ErrorHandler.UNKNOWN, ex.getMessage() );
}
      return program;
  }
 
開發者ID:vZome,項目名稱:vzome-core,代碼行數:17,代碼來源:ZomicASTCompiler.java

示例11: main

import org.antlr.v4.runtime.ANTLRFileStream; //導入依賴的package包/類
public static void main(String[] args) throws Exception
 {
  String testFile = "";
// set test input
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new java.io.File("."));
chooser.setDialogTitle("Please choose the master file");
chooser.setAcceptAllFileFilterUsed(false);

if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
  testFile = chooser.getSelectedFile().getAbsolutePath();
} else {
  System.exit(0);
}

   Calculator4Lexer lexer = new Calculator4Lexer(new ANTLRFileStream(testFile));
   CommonTokenStream tokens = new CommonTokenStream(lexer);
   Calculator4Parser p = new Calculator4Parser(tokens);
   p.setBuildParseTree(true);
   p.addParseListener(new CalculatorListener());
   ParserRuleContext t = p.program();
 }
 
開發者ID:software-engineering-amsterdam,項目名稱:poly-ql,代碼行數:23,代碼來源:Calculator.java

示例12: main

import org.antlr.v4.runtime.ANTLRFileStream; //導入依賴的package包/類
public static void main(String[] args) throws Exception {

		String testFile = "";
		// set test input
		JFileChooser chooser = new JFileChooser();
		chooser.setCurrentDirectory(new java.io.File("."));
		chooser.setDialogTitle("Please choose the master file");
		chooser.setAcceptAllFileFilterUsed(false);

		if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
			testFile = chooser.getSelectedFile().getAbsolutePath();
		} else {
			System.exit(0);
		}

		FormLexer lexer = new FormLexer(
				new ANTLRFileStream(testFile));
		CommonTokenStream tokens = new CommonTokenStream(lexer);
		System.out.println(tokens);
		FormParser p = new FormParser(tokens);
		p.setBuildParseTree(true);
		p.addParseListener(new FormListener());
		ParserRuleContext t = p.form();
	}
 
開發者ID:software-engineering-amsterdam,項目名稱:poly-ql,代碼行數:25,代碼來源:Form.java

示例13: main

import org.antlr.v4.runtime.ANTLRFileStream; //導入依賴的package包/類
public static void main(String[] args) throws Exception {

		String testFile = "";
		// set test input
		JFileChooser chooser = new JFileChooser();
		chooser.setCurrentDirectory(new java.io.File("."));
		chooser.setDialogTitle("Please choose the master file");
		chooser.setAcceptAllFileFilterUsed(false);

		if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
			testFile = chooser.getSelectedFile().getAbsolutePath();
		} else {
			System.exit(0);
		}

		WordSeparationLexer lexer = new WordSeparationLexer(
				new ANTLRFileStream(testFile));
		CommonTokenStream tokens = new CommonTokenStream(lexer);
		System.out.println(tokens);
		WordSeparationParser p = new WordSeparationParser(tokens);
		p.setBuildParseTree(true);
		p.addParseListener(new WordSeparationListener());
		ParserRuleContext t = p.program();
	}
 
開發者ID:software-engineering-amsterdam,項目名稱:poly-ql,代碼行數:25,代碼來源:WordSeparation.java

示例14: main

import org.antlr.v4.runtime.ANTLRFileStream; //導入依賴的package包/類
public static void main(String[] args) throws Exception {

		String testFile = "";
		// set test input
		JFileChooser chooser = new JFileChooser();
		chooser.setCurrentDirectory(new java.io.File("."));
		chooser.setDialogTitle("Please choose the master file");
		chooser.setAcceptAllFileFilterUsed(false);

		if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
			testFile = chooser.getSelectedFile().getAbsolutePath();
		} else {
			System.exit(0);
		}

		// create lexer and perser
		Form2Lexer lexer = new Form2Lexer(new ANTLRFileStream(testFile));
		Form2Parser parser = new Form2Parser(new CommonTokenStream(lexer));
		
		// generate tree and visitor
		ParseTree tree = parser.form();
		Form2Visitor visitor = new Form2CustomVisitor();
		visitor.visit(tree);
	}
 
開發者ID:software-engineering-amsterdam,項目名稱:poly-ql,代碼行數:25,代碼來源:Form2.java

示例15: parseFile

import org.antlr.v4.runtime.ANTLRFileStream; //導入依賴的package包/類
@SuppressWarnings("unused")
private ParsedContext parseFile(final File rootDir, final String protoName) {
  Throwable exception = null;

  try {
    final File file = new File(rootDir, protoName);
    final ANTLRFileStream ais = new ANTLRFileStream(file.getCanonicalPath());
    return parseProto(ais, protoName);
  } catch (final IOException e) {
    exception = e;
  } finally {
    if (exception != null) {
      throw new RuntimeException(exception);
    }
  }

  return null;
}
 
開發者ID:protobufel,項目名稱:protobuf-el,代碼行數:19,代碼來源:ProtoFiles.java


注:本文中的org.antlr.v4.runtime.ANTLRFileStream類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。