@Override public String toString() { return String.format("%s(%s)", getClass().getSimpleName(), children.isEmpty() ? "" : join(", ", children)); }
@Override protected final List<Pattern> flat(final Class<?>... types) { if (in(getClass(), types)) { return list((Pattern) this); } // >>> return sum([child.flat(*types) for child in self.children], []) { final List<Pattern> result = list(); for (final Pattern child : children) { result.addAll(child.flat(types)); } return result; } }
public BranchPattern(final List<? extends Pattern> children) { this.children = list(children); }
final String[] a = partition(optionDescription.trim(), " "); options = a[0]; description = a[2]; for (final String s : split(options)) { if (s.startsWith("--")) { $long = s; final List<String> matched = Re.findAll("\\[default: (.*)\\]", description, Re.IGNORECASE); value = bool(matched) ? matched.get(0) : null;
/** * Make pattern-tree tips point to same object if they are equal. */ private void fixIdentities(List<Pattern> uniq) { // >>> if not hasattr(self, 'children') if (!(this instanceof BranchPattern)) { return; } if (uniq == null) { uniq = list(set(flat())); } final List<Pattern> children = ((BranchPattern) this).getChildren(); for (int i = 0; i < children.size(); i++) { final Pattern child = children.get(i); if (!(child instanceof BranchPattern)) { assert uniq.contains(child); children.set(i, uniq.get(uniq.indexOf(child))); } else { child.fixIdentities(uniq); } } }
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); }
private static String formalUsage(String section) { // >>> u, u, section = section.partition(':') { final String[] u = partition(section, ":"); section = u[2]; } final List<String> pu = split(section); // @formatter:off // >>> return '( ' + ' '.join(') | (' if s == pu[0] else s for s in pu[1:]) + ' )' // @formatter:on { final StringBuilder sb = new StringBuilder(); sb.append("( "); final String u = pu.remove(0); if (!pu.isEmpty()) { for (final String s : pu) { if (s.equals(u)) { sb.append(") | ("); } else { sb.append(s); } sb.append(" "); } sb.setLength(sb.length() - 1); } sb.append(" )"); return sb.toString(); } }
final String token = tokens.current(); List<Pattern> result = list(); result = list((Pattern) new Required(u)); result = list((Pattern) new Optional(u)); return list(result); return list(new OptionsShortcut()); if ((token.startsWith("<") && token.endsWith(">")) || isUpper(token)) { return list(new Argument(tokens.move())); return list(new Command(tokens.move()));
collected = list(); left_ = list(); left_.addAll(left.subList(0, pos)); sameName = list(); increment = (v instanceof String) ? list(v) : v; match.setValue(increment); return new MatchResult(true, left_, plus(collected, list(match))); return new MatchResult(true, left_, plus(collected, list(match)));
public BranchPattern(final List<? extends Pattern> children) { this.children = list(children); }
final String[] a = partition(optionDescription.trim(), " "); options = a[0]; description = a[2]; for (final String s : split(options)) { if (s.startsWith("--")) { $long = s; final List<String> matched = Re.findAll("\\[default: (.*)\\]", description, Re.IGNORECASE); value = bool(matched) ? matched.get(0) : null;
@Override protected final List<Pattern> flat(final Class<?>... types) { if (in(getClass(), types)) { return list((Pattern) this); } // >>> return sum([child.flat(*types) for child in self.children], []) { final List<Pattern> result = list(); for (final Pattern child : children) { result.addAll(child.flat(types)); } return result; } }