public static Tokens withLanguageError(final List<String> source) { return new Tokens(source, DocoptLanguageError.class); }
public Tokens(final List<String> source, final Class<? extends Throwable> error) { // >>> self += source.split() if hasattr(source, 'split') else source // In this implementation, source is always a list of strings, so no // need to split. addAll(source); this.error = error; }
final String token = tokens.move(); assert token.startsWith("-") && !token.startsWith("--"); String left = token.replaceFirst("^-+", ""); throw tokens.error("%s is specified ambiguously %d times", $short, similar.size()); if (tokens.getError() == DocoptExitException.class) { o = new Option($short, null, 0, true); final String u = tokens.current(); if (u == null || "--".equals(u)) { throw tokens.error("%s requires argument", $short); value = tokens.move(); if (tokens.getError() == DocoptExitException.class) { o.setValue((value != null) ? value : true);
/** * <pre> * seq ::= ( atom [ '...' ] )* ; * </pre> */ private static List<Pattern> parseSeq(final Tokens tokens, final List<Option> options) { final List<Pattern> result = list(); // >>> while tokens.current() not in [None, ']', ')', '|'] while (!in(tokens.current(), null, "]", ")", "|")) { List<? extends Pattern> atom = parseAtom(tokens, options); if ("...".equals(tokens.current())) { atom = list(new OneOrMore(atom)); tokens.move(); } result.addAll(atom); } return result; }
private static Required parsePattern(final String source, final List<Option> options) { final Tokens tokens = Tokens.fromPattern(source); final List<? extends Pattern> result = parseExpr(tokens, options); if (tokens.current() != null) { throw tokens.error("unexpected ending: %s", join(" ", tokens)); } return new Required(result); }
final String token = tokens.move(); assert token.startsWith("-") && !token.startsWith("--"); String left = token.replaceFirst("^-+", ""); throw tokens.error("%s is specified ambiguously %d times", $short, similar.size()); if (tokens.getError() == DocoptExitException.class) { o = new Option($short, null, 0, true); final String u = tokens.current(); if (u == null || "--".equals(u)) { throw tokens.error("%s requires argument", $short); value = tokens.move(); if (tokens.getError() == DocoptExitException.class) { o.setValue((value != null) ? value : true);
/** * <pre> * seq ::= ( atom [ '...' ] )* ; * </pre> */ private static List<Pattern> parseSeq(final Tokens tokens, final List<Option> options) { final List<Pattern> result = list(); // >>> while tokens.current() not in [None, ']', ')', '|'] while (!in(tokens.current(), null, "]", ")", "|")) { List<? extends Pattern> atom = parseAtom(tokens, options); if ("...".equals(tokens.current())) { atom = list(new OneOrMore(atom)); tokens.move(); } result.addAll(atom); } return result; }
private static Required parsePattern(final String source, final List<Option> options) { final Tokens tokens = Tokens.fromPattern(source); final List<? extends Pattern> result = parseExpr(tokens, options); if (tokens.current() != null) { throw tokens.error("unexpected ending: %s", join(" ", tokens)); } return new Required(result); }
final String[] a = partition(tokens.move(), "="); $long = a[0]; eq = a[1]; if (tokens.getError() == DocoptExitException.class && similar.isEmpty()) { throw tokens.error("%s is not a unique prefix: %s?", $long, join(", ", u)); if (tokens.getError() == DocoptExitException.class) { throw tokens.error("%s must not have an argument", o.getLong()); final String u = tokens.current(); if (u == null || "--".equals(u)) { throw tokens.error("%s requires argument", o.getLong()); value = tokens.move(); if (tokens.getError() == DocoptExitException.class) { o.setValue((value != null) ? value : true);
final List<LeafPattern> parsed = list(); while (tokens.current() != null) { if ("--".equals(tokens.current())) { if (tokens.current().startsWith("--")) { parsed.addAll(parseLong(tokens, options)); else if (tokens.current().startsWith("-") && !"-".equals(tokens.current())) { parsed.addAll(parseShorts(tokens, options)); parsed.add(new Argument(null, tokens.move()));
public static Tokens withExitException(final List<String> source) { return new Tokens(source, DocoptExitException.class); }
public Tokens(final List<String> source, final Class<? extends Throwable> error) { // >>> self += source.split() if hasattr(source, 'split') else source // In this implementation, source is always a list of strings, so no // need to split. addAll(source); this.error = error; }
final String[] a = partition(tokens.move(), "="); $long = a[0]; eq = a[1]; if (tokens.getError() == DocoptExitException.class && similar.isEmpty()) { throw tokens.error("%s is not a unique prefix: %s?", $long, join(", ", u)); if (tokens.getError() == DocoptExitException.class) { throw tokens.error("%s must not have an argument", o.getLong()); final String u = tokens.current(); if (u == null || "--".equals(u)) { throw tokens.error("%s requires argument", o.getLong()); value = tokens.move(); if (tokens.getError() == DocoptExitException.class) { o.setValue((value != null) ? value : true);
final List<LeafPattern> parsed = list(); while (tokens.current() != null) { if ("--".equals(tokens.current())) { if (tokens.current().startsWith("--")) { parsed.addAll(parseLong(tokens, options)); else if (tokens.current().startsWith("-") && !"-".equals(tokens.current())) { parsed.addAll(parseShorts(tokens, options)); parsed.add(new Argument(null, tokens.move()));