JavaScriptRegexpChannel extends Channel<Lexer> { @VisibleForTesting static boolean guessNextIsRegexp(String preceder) { if (WHOLE_TOKENS.contains(preceder)) { return true; } for (String end : ENDS) { if (preceder.endsWith(end)) { return true; } } return false; } JavaScriptRegexpChannel(); @Override boolean consume(CodeReader code, Lexer output); static final String REGULAR_EXPRESSION; }
@Test public void test() throws Exception { assertThat(JavaScriptRegexpChannel.guessNextIsRegexp("break")).isTrue(); assertThat(JavaScriptRegexpChannel.guessNextIsRegexp("&")).isTrue(); assertThat(JavaScriptRegexpChannel.guessNextIsRegexp("1")).isFalse(); assertThat(JavaScriptRegexpChannel.guessNextIsRegexp("identifier")).isFalse(); }