/** * Constructs a {@link SettableParser} referring to the supplied {@code parser}. */ public static SettableParser with(Parser parser) { return new SettableParser(parser); }
/** * Constructs a {@link SettableParser} that currently refers to an {@link FailureParser}. */ public static SettableParser undefined() { return undefined("Undefined parser"); }
/** * Returns a parser that points to the receiver, but can be changed to point to something else at * a later point in time. */ public SettableParser settable() { return SettableParser.with(this); }
/** * Internal method that completes the initialization. */ private void complete() { replace(delegate, ref("start")); for (Map.Entry<String, SettableParser> entry : undefined.entrySet()) { if (!defined.containsKey(entry.getKey())) { throw new IllegalStateException("Undefined production: " + entry.getKey()); } entry.getValue().replace(entry.getValue().get(), defined.get(entry.getKey())); } replace(delegate, ref("start")); defined = Collections.unmodifiableMap(defined); undefined = Collections.unmodifiableMap(new HashMap<>()); completed = true; }
/** * Internal method that completes the initialization. */ private void complete() { replace(delegate, ref("start")); for (Map.Entry<String, SettableParser> entry : undefined.entrySet()) { if (!defined.containsKey(entry.getKey())) { throw new IllegalStateException("Undefined production: " + entry.getKey()); } entry.getValue().replace(entry.getValue().get(), defined.get(entry.getKey())); } replace(delegate, ref("start")); defined = Collections.unmodifiableMap(defined); undefined = Collections.unmodifiableMap(new HashMap<>()); completed = true; }
/** * Constructs a {@link SettableParser} referring to the supplied {@code parser}. */ public static SettableParser with(Parser parser) { return new SettableParser(parser); }
/** * Returns a parser that points to the receiver, but can be changed to point to something else at * a later point in time. */ public SettableParser settable() { return SettableParser.with(this); }
/** * Constructs a {@link SettableParser} that currently refers to an {@link FailureParser}. */ public static SettableParser undefined() { return undefined("Undefined parser"); }
@Override public SettableParser copy() { return new SettableParser(delegate); } }
/** * Constructs a {@link SettableParser} that currently refers to an {@link FailureParser} with the * provided {@code message}. */ public static SettableParser undefined(String message) { return with(FailureParser.withMessage(message)); }
/** * Returns a reference to the production with the given {@code name}. * <p> * This method works during initialization and after completion of the initialization. During the * initialization it returns delegate parsers that are eventually replaced by the real parsers. * Afterwards it returns the defined parser (mostly useful for testing). */ public final Parser ref(String name) { if (completed) { if (!defined.containsKey(name)) { throw new IllegalStateException("Undefined production: " + name); } return defined.get(name); } else if (undefined.containsKey(name)) { return undefined.get(name); } else { SettableParser parser = SettableParser.undefined("Uninitialized production: " + name); undefined.put(name, parser); return parser; } }
@Override public SettableParser copy() { return new SettableParser(delegate); } }
/** * Constructs a {@link SettableParser} that currently refers to an {@link FailureParser} with the * provided {@code message}. */ public static SettableParser undefined(String message) { return with(FailureParser.withMessage(message)); }
/** * Returns a reference to the production with the given {@code name}. * <p> * This method works during initialization and after completion of the initialization. During the * initialization it returns delegate parsers that are eventually replaced by the real parsers. * Afterwards it returns the defined parser (mostly useful for testing). */ public final Parser ref(String name) { if (completed) { if (!defined.containsKey(name)) { throw new IllegalStateException("Undefined production: " + name); } return defined.get(name); } else if (undefined.containsKey(name)) { return undefined.get(name); } else { SettableParser parser = SettableParser.undefined("Uninitialized production: " + name); undefined.put(name, parser); return parser; } }