public static String generateToken(Predicate predicate) { TokenBuilder builder = new TokenBuilder(); for (int c = 0; c <= 0xffff; ++c) { if (!predicate.accepts((char)c)) { continue; } builder.add(c); } return builder.build(); }
void add(int c) { if (prevC + 1 == c) { // in range } else { flushRange(); fromC = c; } prevC = c; }
public static String unquote(String str) { return UnicodeUtilities.unquote(str); } }
public static String quote(String str, char quote) { return UnicodeUtilities.quote(str, quote); }
public String formatException(String parseException) { int errPos = findErrPos(parseException); if (errPos < 0 || errPos > inputArr.length + 1) { return parseException; } int errLine = 0; int errColumn = 0; for (int i = 0; i < errPos - 1; ++i) { if (inputStr.charAt(i) == '\n') { ++errLine; errColumn = 0; } else { ++errColumn; } } StringBuilder out = new StringBuilder(); out.append(parseException.replace(JAVACC_EXCEPTION_FORMAT + errPos, "line " + (errLine + 1) + ", column " + (errColumn + 1))); out.append("\nAt position:\n"); appendErrorPosition(errLine, out); for (int i = 0; i < errColumn; ++i) { out.append(" "); } out.append("^"); return out.toString(); }
public char beginToken() throws IOException { tokenPos = readPos; return readChar(); }
/** * Adds a leading and trailing double quotation mark to the given string. This will escape whatever content is * within the string literal. * * @param str The string to quote. * @param quote The quote character. * @return The quoted string. */ public static String quote(String str, char quote) { StringBuilder ret = new StringBuilder(); ret.append(quote); for (int i = 0; i < str.length(); ++i) { char c = str.charAt(i); if (c == quote) { ret.append("\\").append(c); } else { ret.append(escape(c)); } } ret.append(quote); return ret.toString(); }
private static <T extends Expression> T parse(ScriptParserContext config, ParserMethod<T> method) throws ParseException { CharStream input = config.getInputStream(); IndexingParser parser = new IndexingParser(input); parser.setAnnotatorConfig(config.getAnnotatorConfig()); parser.setDefaultFieldName(config.getDefaultFieldName()); parser.setLinguistics(config.getLinguistcs()); try { return method.call(parser); } catch (ParseException e) { if (!(input instanceof FastCharStream)) { throw e; } throw new ParseException(((FastCharStream)input).formatException(e.getMessage())); } finally { if (parser.token != null && parser.token.next != null) { input.backup(parser.token.next.image.length()); } } } }
final public String literal() throws ParseException { jj_consume_token(LITERAL); {if ("" != null) return UnicodeUtilities.unquote(token.image);} throw new IllegalStateException ("Missing return statement in function"); }
/** * Returns a string representation of an object that can be used in the 'image' constructor argument of {@link * GroupingNode}. This method ensures that strings are quoted, and that all complex characters are escaped. * * @param obj The object to output. * @return The string representation. */ public static String asImage(Object obj) { if (!(obj instanceof String)) { return obj.toString(); } return UnicodeUtilities.quote((String)obj, '"'); }
String build() { flushRange(); return token.toString(); } }
final public StringValue stringValue() throws ParseException {String str; jj_consume_token(STRING); str = UnicodeUtilities.unquote(token.image); space(); {if ("" != null) return new StringValue(str);} throw new IllegalStateException ("Missing return statement in function"); }
ret = UnicodeUtilities.unquote(token.image); space(); break;