@Override public ParsedLine parse(final String line, final int cursor, final ParseContext context) { final String trimmed = line.trim(); final int adjCursor = adjustCursor(line, trimmed, cursor); return delegate.parse(trimmed, adjCursor, context); }
@Override public ParsedLine parse(final String line, final int cursor, final ParseContext context) { final ParsedLine parsed = delegate.parse(line, cursor, context); if (context != ParseContext.ACCEPT_LINE) { return parsed; } final String bare = CommentStripper.strip(parsed.line()); if (bare.isEmpty()) { return parsed; } if (cliCmdPredicate.test(bare)) { return parsed; } if (!bare.endsWith(TERMINATION_CHAR)) { throw new EOFError(-1, -1, "Missing termination char", "termination char"); } return parsed; } }
@Test public void shouldPassThroughAnyLineThatDoesNotNeedTrimming() { expect(delegate.parse("line without spaces at ends", 4, ACCEPT_LINE)) .andReturn(parsedLine); replay(delegate); final ParsedLine line = parser.parse("line without spaces at ends", 4, ACCEPT_LINE); assertThat(line, is(parsedLine)); } }
@Test public void shouldCallDelegateWithCorrectParams() { // Given: EasyMock.expect(parsedLine.line()).andReturn(TERMINATED_LINE).anyTimes(); EasyMock.expect(delegate.parse("some-string", 55, ParseContext.ACCEPT_LINE)) .andReturn(parsedLine); EasyMock.replay(delegate, parsedLine); // When: parser.parse("some-string", 55, ParseContext.ACCEPT_LINE); // Then: EasyMock.verify(delegate); }
private void givenDelegateWillReturn(final String line) { EasyMock.expect(parsedLine.line()).andReturn(line).anyTimes(); EasyMock.expect(delegate.parse(anyObject(), anyInt(), anyObject())).andReturn(parsedLine); EasyMock.replay(delegate, parsedLine); }
try { line = reader.readLine(prompt, rightPrompt, (MaskingCallback) null, null); ParsedLine pl = reader.getParser().parse(line, 0); String[] arguments = pl.words().toArray(new String[0]); CommandLine.run(commands, arguments);
default ParsedLine parse(String line, int cursor) throws SyntaxError { return parse(line, cursor, ParseContext.UNSPECIFIED); }
public LineReaderBuilder parser(Parser parser) { if (parser != null) { try { if (!Boolean.parseBoolean(LineReader.PROP_SUPPORT_PARSEDLINE) && !(parser.parse("", 0) instanceof CompletingParsedLine)) { Log.warn("The Parser of class " + parser.getClass().getName() + " does not support the CompletingParsedLine interface. " + "Completion with escaped or quoted words won't work correctly."); } } catch (Throwable t) { // Ignore } } this.parser = parser; return this; }
@Override public Input readInput() { StringBuilder sb = new StringBuilder(); boolean continued = false; String line; try { do { line = reader.readLine(); if (line == null) { break; } continued = line.matches(BACKSLASH_AT_EOL_REGEX); sb.append(line.replaceFirst(BACKSLASH_AT_EOL_REGEX, "$1 ")); } while (continued); } catch (IOException e) { throw new RuntimeException(e); } if (line == null) { return null; } else { ParsedLine parsedLine = parser.parse(sb.toString(), sb.toString().length()); return new ParsedLineInput(parsedLine); } }
ParsedLine pl = reader.getParser().parse(line, line.length()); String cmd = resolveCommand(pl.words().get(0)); ActionMaskingCallback repl = regexs.get(cmd);
parser.parse(cmd.toString(), cmd.length(), Parser.ParseContext.ACCEPT_LINE); } catch (EOFError e) {
ParsedLine pl = reader.getParser().parse(line, line.length()); String cmd = resolveCommand(pl.words().get(0)); ActionMaskingCallback repl = regexs.get(cmd);
if (needsMessage) { try { parser.parse(buf.toString(), buf.length(), ParseContext.SECONDARY_PROMPT); } catch (EOFError e) { missing = e.getMissing(); if (missings.isEmpty()) { try { parser.parse(buf.toString(), buf.length(), ParseContext.SECONDARY_PROMPT); } catch (EOFError e) { missing = e.getMissing();
ParsedLine pl = reader.getParser().parse(line, 0); if (querying) { query.append('\n');
line = wrap(parser.parse(buf.toString(), buf.cursor(), ParseContext.COMPLETE)); } catch (Exception e) { Log.info("Error while parsing line", e);
protected boolean acceptLine() { parsedLine = null; if (!isSet(Option.DISABLE_EVENT_EXPANSION)) { try { String str = buf.toString(); String exp = expander.expandHistory(history, str); if (!exp.equals(str)) { buf.clear(); buf.write(exp); if (isSet(Option.HISTORY_VERIFY)) { return true; } } } catch (IllegalArgumentException e) { // Ignore } } try { parsedLine = parser.parse(buf.toString(), buf.cursor(), ParseContext.ACCEPT_LINE); } catch (EOFError e) { buf.write("\n"); return true; } catch (SyntaxError e) { // do nothing } callWidget(CALLBACK_FINISH); state = State.DONE; return true; }