private void processTokens( final ByteArrayOutputStream bao) throws IOException { try (final PrintStream baos = new PrintStream(bao, false, "UTF-8")) { final OptionalInt version = SoShaderPreprocessorJCPP.this.config.version(); if (version.isPresent()) { baos.printf( "#version %d core\n", Integer.valueOf(version.getAsInt())); } while (true) { final Token tok = this.pp.token(); if (tok.getType() == Token.EOF) { break; } baos.print(tok.getText()); } baos.flush(); } catch (final LexerException e) { throw new IOException(e); } }
public void execute() { FileWriter writer = null; try { if (input == null) throw new BuildException("Input not specified"); if (output == null) throw new BuildException("Output not specified"); cpp.addInput(this.input); writer = new FileWriter(this.output); for (;;) { Token tok = cpp.token(); if (tok != null && tok.getType() == Token.EOF) break; writer.write(tok.getText()); } } catch (Exception e) { throw new BuildException(e); } finally { if (writer != null) { try { writer.close(); } catch (IOException e) { } } } }
public void execute() { FileWriter writer = null; try { if (input == null) throw new BuildException("Input not specified"); if (output == null) throw new BuildException("Output not specified"); cpp.addInput(this.input); writer = new FileWriter(this.output); for (;;) { Token tok = cpp.token(); if (tok != null && tok.getType() == Token.EOF) break; writer.write(tok.getText()); } } catch (Exception e) { throw new BuildException(e); } finally { if (writer != null) { try { writer.close(); } catch (IOException e) { } } } }
return false; while (idx >= token.length()) { Token tok = cpp.token(); switch (tok.getType()) { case EOF:
return false; while (idx >= token.length()) { Token tok = cpp.token(); switch (tok.getType()) { case EOF:
return false; while (idx >= token.length()) { Token tok = cpp.token(); switch (tok.getType()) { case EOF:
writer = new FileWriter(output); for (;;) { Token tok = cpp.token(); if (tok == null) break;
private boolean testError(Preprocessor p) throws LexerException, IOException { for (;;) { Token tok = p.token(); if (tok.getType() == EOF) break; if (tok.getType() == INVALID) return true; } return false; }
private boolean testError(Preprocessor p) throws LexerException, IOException { for (;;) { Token tok = p.token(); if (tok.getType() == EOF) break; if (tok.getType() == INVALID) return true; } return false; }
@Test public void testPreprocessorUnterminated() throws Exception { testInput("#ifndef X\na\n#else\nb\n"); // Bug #16 writer.close(); Token t; do { t = p.token(); LOG.warn("Remaining token " + t); } while (t.getType() != EOF); }
Token tok = pp.token(); if (tok == null) break;
Token tok = pp.token(); if (tok == null) break;
private void testInput(String in, Object... out) throws Exception { LOG.info("Input: " + in); writer.write(in); writer.flush(); for (Object v : out) { Token t = p.token(); LOG.info(String.valueOf(t)); if (v instanceof String) { if (t.getType() != STRING) fail("Expected STRING, but got " + t); assertEquals(v, t.getValue()); } else if (v instanceof I) { if (t.getType() != IDENTIFIER) fail("Expected IDENTIFIER " + v + ", but got " + t); assertEquals(((I) v).getText(), t.getText()); } else if (v instanceof Character) { assertType(((Character) v).charValue(), t); } else if (v instanceof Integer) { assertType(((Number) v).intValue(), t); } else { fail("Bad object " + v.getClass()); } } } }
Token tok = pp.token(); if (tok == null) break;
private void testInput(String in, Object... out) throws Exception { System.out.print("Input: " + in); writer.write(in); writer.flush(); for (int i = 0; i < out.length; i++) { Token t = p.token(); System.out.println(t); Object v = out[i]; if (v instanceof String) { if (t.getType() != STRING) fail("Expected STRING, but got " + t); assertEquals((String)v, (String)t.getValue()); } else if (v instanceof I) { if (t.getType() != IDENTIFIER) fail("Expected IDENTIFIER " + v + ", but got " + t); assertEquals( ((I)v).getText(), (String)t.getText()); } else if (v instanceof Character) assertEquals( (int)((Character)v).charValue(), t.getType()); else if (v instanceof Integer) assertEquals( ((Integer)v).intValue(), t.getType()); else fail("Bad object " + v.getClass()); } } }
t = p.token(); System.out.println("Remaining token " + t); } while(t.getType() != EOF);
t = p.token(); LOG.warn("Remaining token " + t); } while (t.getType() != EOF);