Give factories a default parser.

Later registered parsers will always come before the default, ensuring
that the default parser is used when no other parser can match the input,
and that errors may be thrown by it to signify the end of the line.
This commit is contained in:
wizjany
2019-05-27 00:35:26 -04:00
parent 6962b2e7b6
commit ab1e09fdaf
6 changed files with 12 additions and 16 deletions

View File

@ -46,10 +46,13 @@ public abstract class AbstractFactory<E> {
* Create a new factory.
*
* @param worldEdit the WorldEdit instance
* @param defaultParser the parser to fall back to
*/
protected AbstractFactory(WorldEdit worldEdit) {
protected AbstractFactory(WorldEdit worldEdit, InputParser<E> defaultParser) {
checkNotNull(worldEdit);
checkNotNull(defaultParser);
this.worldEdit = worldEdit;
this.parsers.add(defaultParser);
}
/**
@ -91,6 +94,6 @@ public abstract class AbstractFactory<E> {
public void register(InputParser<E> inputParser) {
checkNotNull(inputParser);
parsers.add(inputParser);
parsers.add(parsers.size() - 1, inputParser);
}
}