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); }
@Override protected MatchResult match(List<LeafPattern> left, List<LeafPattern> collected) { if (collected == null) { collected = list(); } for (final Pattern pattern : getChildren()) { final MatchResult u = pattern.match(left, collected); left = u.getLeft(); collected = u.getCollected(); } return new MatchResult(true, left, collected); } }
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; }
public static Tokens fromPattern(String source) { source = Re.sub("([\\[\\]\\(\\)\\|]|\\.\\.\\.)", " $1 ", source); List<String> $source; // >>> source = [s for s in re.split('\s+|(\S*<.*?>)', source) if s] { $source = list(); for (final String s : Re.split("\\s+|(\\S*<.*?>)", source)) { if (bool(s)) { $source.add(s); } } } return Tokens.withLanguageError($source); }
@Override protected SingleMatchResult singleMatch(final List<LeafPattern> left) { for (int n = 0; n < left.size(); n++) { final LeafPattern pattern = left.get(n); if (getName().equals(pattern.getName())) { return new SingleMatchResult(n, pattern); } } return new SingleMatchResult(null, null); }
public Pattern fix() { fixIdentities(null); fixRepeatingArguments(); return this; }
/** * Constructs an argument parser from a POSIX-style help message. * * @param stream * a UTF-8 encoded stream containing a POSIX-style help message * @throws DocoptLanguageError * if the help message is malformed * @see Docopt */ public Docopt(final InputStream stream) { this(read(stream)); }
public static Tokens withLanguageError(final List<String> source) { return new Tokens(source, DocoptLanguageError.class); }
public BranchPattern(final List<? extends Pattern> children) { this.children = list(children); }
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); }
@Override protected MatchResult match(List<LeafPattern> left, List<LeafPattern> collected) { if (collected == null) { collected = list(); } for (final Pattern pattern : getChildren()) { final MatchResult u = pattern.match(left, collected); left = u.getLeft(); collected = u.getCollected(); } return new MatchResult(true, left, collected); } }
public static Tokens fromPattern(String source) { source = Re.sub("([\\[\\]\\(\\)\\|]|\\.\\.\\.)", " $1 ", source); List<String> $source; // >>> source = [s for s in re.split('\s+|(\S*<.*?>)', source) if s] { $source = list(); for (final String s : Re.split("\\s+|(\\S*<.*?>)", source)) { if (bool(s)) { $source.add(s); } } } return Tokens.withLanguageError($source); }
@Override protected SingleMatchResult singleMatch(final List<LeafPattern> left) { for (int n = 0; n < left.size(); n++) { final LeafPattern pattern = left.get(n); if (getName().equals(pattern.getName())) { return new SingleMatchResult(n, pattern); } } return new SingleMatchResult(null, null); }
public Pattern fix() { fixIdentities(null); fixRepeatingArguments(); return this; }
/** * Constructs an argument parser from a POSIX-style help message. * * @param stream * a UTF-8 encoded stream containing a POSIX-style help message * @throws DocoptLanguageError * if the help message is malformed * @see Docopt */ public Docopt(final InputStream stream) { this(read(stream)); }
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; }
/** * If set to a non-{@code null} value, the {@code --version} option will be * cause the parser to display the specified string and exit. * * @param stream * a UTF-8 encoded stream to read containing the version * information * @return this object */ public Docopt withVersion(final InputStream stream) { this.version = read(stream); return this; }
/** * If set to a non-{@code null} value, the {@code --version} option will be * cause the parser to display the specified string and exit. * * @param stream * a UTF-8 encoded stream to read containing the version * information * @return this object */ public Docopt withVersion(final InputStream stream) { this.version = read(stream); return this; }