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()); }
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()); }
/** * 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); } }
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; }
/** * 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); } }
/** * 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); } }