@Override public String getMessage() { // sb is the next 100 characters of the text being parsed StringBuilder sb = new StringBuilder(); int curr; int counter = 0; curr = state.curr(); while (-1 != curr && ++counter < 100) { sb.append((char) curr); curr = state.next(); } String charInfo = "at or before character " + state.getCharPosition(); String lineInfo = "on or before line " + state.getLine(); return message + "\n" + charInfo + "\n" + lineInfo + "\n" + sb.toString(); }
@Override public ExpectationResult parse(ParserState input) { StringBuilder sb = new StringBuilder(); int curr = input.curr(); while (curr != -1 && sb.length() < expectation.length()) { sb.append((char) curr); curr = input.next(); } if (sb.toString().equals(expectation)) { return ExpectationResult.CORRECT; } else { return ExpectationResult.INCORRECT; } }
@Override public T parse(ParserState input) throws ParseException { T lastResult = null; while (input.curr() != -1) { input.mark(); input.rewind(); break; } else { input.release(); lastResult = map.get(directive).parse(input); input.rewind(); input.release(); throw new ParseException("Unknown directive '" + directive + "' and no default parser specified.", input);
@Override public T parse(ParserState input) throws ParseException { T result = parser.parse(input); if (input.next() != -1) { return null; } return result; } };
@Override public T parse(ParserState input) throws ParseException { T lastResult = null; while (input.curr() != -1) { String directive = Parsers.gingerly(inputStringParser).parse(input); if (Parsers.nullOrEmpty(directive)) { break; } else if (parserLookup.containsKey(directive)) { lastResult = parserLookup.get(directive).parse(input); } else { throw new ParseException("Unknown directive '" + directive + "'.", input); } } return lastResult; }
@Override public String parse(ParserState input) { StringBuilder sb = new StringBuilder(); int curr = input.curr(); // not at end of the file and character is explicitly allowed while (curr != -1 && condition.isAllowed((char) curr)) { sb.append((char) curr); curr = input.next(); } return sb.length() > 0 ? sb.toString() : null; }
@Override public LocalReferenceType parse(ParserState input) throws ParseException { input.mark(); String typeReference = REF_PARSER.parse(input); if (typeReference == null) { input.rewind(); return null; } input.release(); ConjureMetrics.incrementCounter(LocalReferenceType.class); return LocalReferenceType.of(TypeName.of(typeReference)); } }
@Override public String parse(ParserState input) throws ParseException { StringBuilder sb = new StringBuilder(); if (input.curr() != '"') { throw new ParseException("Expected a quoted string, but didn't observe a quote.", input); } int curr; boolean escaped = false; while ((curr = input.next()) != -1) { if (escaped) { escaped = false; } else { if (curr == '\\') { escaped = true; continue; } else if (curr == '"') { input.next(); break; } } if (curr == -1) { throw new ParseException("Reached end of file while processing quoted string.", input); } if (respectLineBreaks || curr != '\n') { sb.append((char) curr); } } return sb.toString(); }