@Override public CommandLine parse(Session session, String command, int cursor) { GogoParser parser = new GogoParser(command, cursor); List<String> args = parser.statement(); return new CommandLineImpl( args.toArray(new String[args.size()]), parser.cursorArgumentIndex(), parser.argumentPosition(), cursor, command.substring(0, parser.position())); }
public void ws() { // derek: BUGFIX: loop if comment at beginning of input //while (!eof() && isWhitespace(peek())) { while (!eof() && (!escaped && isWhitespace(peek()) || current == 0)) { if (current != 0 || !escaped && isWhitespace(peek())) { current++; } if (peek() == '/' && current < text.length() - 2 && text.charAt(current + 1) == '/') { comment(); } if (current == 0) { break; } } }
public List<List<List<String>>> program() { program = new ArrayList<>(); ws(); if (!eof()) { program.add(pipeline()); while (peek() == ';' || peek() == '\n') { current++; List<List<String>> pipeline = pipeline(); program.add(pipeline); } } if (!eof()) { throw new RuntimeException("Program has trailing text: " + context(current)); } List<List<List<String>>> p = program; program = null; return p; }
public String value() { ws(); char c = next(); if (!escaped) { switch (c) { case '{': return text.substring(start, find('}', '{')); case '(': return text.substring(start, find(')', '(')); case '[': return text.substring(start, find(']', '[')); case '<': return text.substring(start, find('>', '<')); case '=': return text.substring(start, current); case '"': case '\'': quote(c); break; while (!eof()) { c = peek(); if (!escaped) { if (isWhitespace(c) || c == ';' || c == '|' || c == '=') { break; next(); find('}', '{');
public List<List<String>> pipeline() { statements = new ArrayList<>(); statements.add(statement()); while (peek() == '|') { current++; ws(); if (!eof()) { statements.add(statement()); } else { statements.add(new ArrayList<>()); break; } } List<List<String>> s = statements; statements = null; return s; }
public String messy() { start = current; char c = peek(); if (c > 0 && SPECIAL.indexOf(c) < 0) { current++; try { while (!eof()) { c = peek(); if (!escaped && (c == ';' || c == '|' || c == '\n' || isWhitespace(c))) { break; } next(); } return text.substring(start, current); } finally { start = -1; } } else { return value(); } }
CharSequence findVar() { int start = current; char c = peek(); if (c == '{') { next(); int end = find('}', '{'); return text.subSequence(start, end); } if (c == '(') { next(); int end = find(')', '('); return text.subSequence(start, end); } if (Character.isJavaIdentifierPart(c)) { while (c == '$') { c = next(); } while (!eof() && (Character.isJavaIdentifierPart(c) || c == '.') && c != '$') { next(); c = peek(); } return text.subSequence(start, current); } throw new IllegalArgumentException( "Reference to variable does not match syntax of a variable: " + context(start)); }
while (pos < command.length()) { String rem = command.substring(pos); GogoParser cmdNameParser = new GogoParser(rem, rem.length()); String name = cmdNameParser.value(); name = session.resolveCommand(name);
public String toString() { return "..." + context(current) + "..."; }
public String value() { ws(); char c = next(); if (!escaped) { switch (c) { case '{': return text.substring(start, find('}', '{')); case '(': return text.substring(start, find(')', '(')); case '[': return text.substring(start, find(']', '[')); case '<': return text.substring(start, find('>', '<')); case '=': return text.substring(start, current); case '"': case '\'': quote(c); break; while (!eof()) { c = peek(); if (!escaped) { if (isWhitespace(c) || c == ';' || c == '|' || c == '=') { break; next(); find('}', '{');
public List<List<String>> pipeline() { statements = new ArrayList<>(); statements.add(statement()); while (peek() == '|') { current++; ws(); if (!eof()) { statements.add(statement()); } else { statements.add(new ArrayList<>()); break; } } List<List<String>> s = statements; statements = null; return s; }
public String messy() { start = current; char c = peek(); if (c > 0 && SPECIAL.indexOf(c) < 0) { current++; try { while (!eof()) { c = peek(); if (!escaped && (c == ';' || c == '|' || c == '\n' || isWhitespace(c))) { break; } next(); } return text.substring(start, current); } finally { start = -1; } } else { return value(); } }
CharSequence findVar() { int start = current; char c = peek(); if (c == '{') { next(); int end = find('}', '{'); return text.subSequence(start, end); } if (c == '(') { next(); int end = find(')', '('); return text.subSequence(start, end); } if (Character.isJavaIdentifierPart(c)) { while (c == '$') { c = next(); } while (!eof() && (Character.isJavaIdentifierPart(c) || c == '.') && c != '$') { next(); c = peek(); } return text.subSequence(start, current); } throw new IllegalArgumentException( "Reference to variable does not match syntax of a variable: " + context(start)); }