/** * Defines the given name as a macro. * * The String value is lexed into a token stream, which is * used as the macro expansion. * * @throws LexerException if the definition fails or is otherwise illegal. */ public void addMacro(@Nonnull String name, @Nonnull String value) throws LexerException { try { Macro m = new Macro(name); StringLexerSource s = new StringLexerSource(value); for (;;) { Token tok = s.token(); if (tok.getType() == EOF) break; m.addToken(tok); } addMacro(m); } catch (IOException e) { throw new LexerException(e); } }
StringLexerSource sl = new StringLexerSource(buf.toString());
StringLexerSource sl = new StringLexerSource(buf.toString());
private void testLexerSource(String in, int... out) throws Exception { System.out.println("Testing '" + in + "' => " + Arrays.toString(out)); StringLexerSource s = new StringLexerSource(in); for (int i = 0; i < out.length; i++) { Token tok = s.token(); System.out.println("Token is " + tok); assertEquals(out[i], tok.getType()); } assertEquals(EOF, s.token().getType()); }
StringLexerSource sl = new StringLexerSource(buf.toString());
/** * Defines the given name as a macro. * * The String value is lexed into a token stream, which is * used as the macro expansion. */ public void addMacro(String name, String value) throws LexerException { try { Macro m = new Macro(name); StringLexerSource s = new StringLexerSource(value); for (;;) { Token tok = s.token(); if (tok.getType() == EOF) break; m.addToken(tok); } addMacro(m); } catch (IOException e) { throw new LexerException(e); } }
@Test public void testAbsoluteInclude() throws Exception { File file = new File("build/resources/test/absolute.h"); assertTrue(file.exists()); String input = "#include <" + file.getAbsolutePath() + ">\n"; LOG.info("Input: " + input); Preprocessor pp = new Preprocessor(); pp.addInput(new StringLexerSource(input, true)); Reader r = new CppReader(pp); String output = CharStreams.toString(r); r.close(); LOG.info("Output: " + output); assertTrue(output.contains("absolute-result")); } }
private Token testNumericValue(String in) throws IOException, LexerException { StringLexerSource s = new StringLexerSource(in); Token tok = s.token(); System.out.println("Token is " + tok); assertEquals(NUMBER, tok.getType()); Token eof = s.token(); assertEquals("Didn't get EOF, but " + tok, EOF, eof.getType()); return tok; }
public static String preprocessSources(JNAeratorConfig config, Collection<String> includeStrings, Collection<File> files, List<Define> defines, boolean verbose, TypeConversion typeConverter, MacroUseCallback macrosDependenciesOut, Map<String, Macro> macros) throws IOException, LexerException { Preprocessor preProcessor = PreprocessorUtils.createPreProcessor(config.preprocessorConfig, macrosDependenciesOut); for (String content : includeStrings) { preProcessor.addInput(new StringLexerSource(content, true));
/** * Defines the given name as a macro. * * The String value is lexed into a token stream, which is * used as the macro expansion. */ public void addMacro(String name, String value) throws LexerException { try { Macro m = new Macro(name); StringLexerSource s = new StringLexerSource(value); for (;;) { Token tok = s.token(); if (tok.getType() == EOF) break; m.addToken(tok); } addMacro(m); } catch (IOException e) { throw new LexerException(e); } }
if (matcher.matches()) { name = matcher.group(1); Macro macro = new Macro(new StringLexerSource(value), name); String argsStr = matcher.group(2); List<String> args = new ArrayList<String>();
public static void testLexerSource(String in, boolean textmatch, int... out) throws Exception { LOG.info("Testing '" + in + "' => " + Arrays.toString(out)); StringLexerSource s = new StringLexerSource(in); StringBuilder buf = new StringBuilder(); for (int i = 0; i < out.length; i++) { Token tok = s.token(); LOG.info("Token is " + tok); assertType(out[i], tok); // assertEquals(col, tok.getColumn()); buf.append(tok.getText()); } Token tok = s.token(); LOG.info("Token is " + tok); assertType(EOF, tok); if (textmatch) assertEquals(in, buf.toString()); }
if (matcher.matches()) { name = matcher.group(1); Macro macro = new Macro(new StringLexerSource(value), name); String argsStr = matcher.group(2); List<String> args = new ArrayList<String>();
public static String preprocessSources(JNAeratorConfig config, Collection<String> includeStrings, Collection<File> files, List<Define> defines, boolean verbose, TypeConversion typeConverter, MacroUseCallback macrosDependenciesOut, Map<String, Macro> macros) throws IOException, LexerException { Preprocessor preProcessor = PreprocessorUtils.createPreProcessor(config.preprocessorConfig, macrosDependenciesOut); for (String content : includeStrings) { preProcessor.addInput(new StringLexerSource(content, true));
@Test public void testWhitespacePasting() throws IOException { Preprocessor pp = new Preprocessor(); pp.addInput(new StringLexerSource( "#define ONE(arg) one_##arg\n" + "#define TWO(arg) ONE(two_##arg)\n" + "\n" + "TWO(good)\n" + "TWO( /* evil newline */\n" + " bad)\n" + "\n" + "ONE(good)\n" + "ONE( /* evil newline */\n" + " bad)\n", true)); Reader r = new CppReader(pp); String text = CharStreams.toString(r).trim(); LOG.info("Output is:\n" + text); assertEquals("one_two_good\n" + "one_two_bad\n" + "\n" + "one_good\n" + "one_bad", text); } }
pp.addInput(new StringLexerSource( "#" + "include \"" + g.getOptarg() + "\"\n" ));
pp.addInput(new StringLexerSource( "#" + "include \"" + g.getOptarg() + "\"\n" ));
Preprocessor pp = new Preprocessor(); pp.addFeature(Feature.KEEPCOMMENTS); pp.addInput(new StringLexerSource(input, true)); Reader r = new CppReader(pp); String output = CharStreams.toString(r).trim();
for (File file : options.valuesOf(includeOption)) pp.addInput(new StringLexerSource("#" + "include \"" + file + "\"\n"));
sl = new StringLexerSource(input, true); p = new Preprocessor(); p.addFeature(Feature.CSYNTAX); sl = new StringLexerSource(input, true); p = new Preprocessor(); p.addFeature(Feature.CSYNTAX); sl = new StringLexerSource(input, true); p = new Preprocessor(); p.addInput(sl);