public static <T> PathMatcher<T> match(String pattern, Func2<FalcorPath, PathTree, Matching<T>> matcher) { return match(new StringKey('{' + pattern + '}'), matcher); }
@Override public String toString() { return asString(); }
static PathMatcher<String> key(String value) { return key(new StringKey(value), KeySegment::asString); }
public static <T> PathMatcher<T> match(String pattern, Predicate<KeySegment> predicate, Func1<KeySegment, T> f) { return match(new StringKey('{' + pattern + '}'), predicate, f); }
private static FalcorNode _deserializeEntries(JsonParser jp, DeserializationContext ctxt) throws IOException { JsonFactory factory = new JsonFactory(jp.getCodec()); FalcorTree node = new FalcorTree(); for (; jp.getCurrentToken() == JsonToken.FIELD_NAME; jp.nextToken()) { // Must point to field name now String fieldName = jp.getCurrentName(); SimpleKey key = new StringKey(fieldName); // try { // key = factory.createParser(fieldName).readValueAs(SimpleKey.class); // } catch (IOException e) { // key = new StringKey(fieldName); // } // And then the value... JsonToken t = jp.nextToken(); FalcorNode value = jp.readValueAs(FalcorNode.class); node.put(key, value); } return node; } }
static PathMatcher<String> regex(String regex) { final Pattern pattern = Pattern.compile(regex); final StringKey stringKey = new StringKey('{' + regex + '}'); return match(stringKey, (matched, unmatched) -> { if (!unmatched.isEmpty()) { KeySegment head = unmatched.head(); if (head.isString()) { String value = head.asString(); Matcher matcher = pattern.matcher(value); switch (matcher.groupCount()) { case 0: if (matcher.matches()) { return Matched(matched.append(head), unmatched.tail(), value); } break; case 1: if (matcher.find()) { return Matched(matched.append(head), unmatched.tail(), matcher.group()); } break; default: throw new IllegalArgumentException( String.format("Path regex '%s' must not contain more than one capturing group", pattern.pattern())); } } } return Unmatched(); }); }
Rule stringKey(ListVar<? super SimpleKey> keys) { StringVar string = new StringVar(); return sequence('"', zeroOrMore(character()), string.set(match()), '"', keys.add(new StringKey(string.get()))); }
Rule identifier(ListVar<? super SimpleKey> keys) { return sequence(oneOrMore(firstOf(alpha(), digit(), anyOf("_$"))), keys.add(new StringKey(match()))); }
model.put(FalcorPath.of(new StringKey("_")), result.getError()); } else { model.put(result.matchedPath(), result.getError());