
org.jsimpledb.cli.CommandListParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jsimpledb-cli Show documentation
Show all versions of jsimpledb-cli Show documentation
JSimpleDB classes supporting command line interfaces.
/*
* Copyright (C) 2015 Archie L. Cobbs. All rights reserved.
*/
package org.jsimpledb.cli;
import com.google.common.base.Preconditions;
import java.util.ArrayList;
import java.util.List;
import org.jsimpledb.parse.ParseException;
import org.jsimpledb.parse.ParseSession;
import org.jsimpledb.parse.Parser;
import org.jsimpledb.util.ParseContext;
public class CommandListParser implements Parser> {
private final Parser commandParser;
/**
* Constructor.
*
* @param commandParser single command parser
*/
public CommandListParser(Parser commandParser) {
Preconditions.checkArgument(commandParser != null, "null commandParser");
this.commandParser = commandParser;
}
/**
* Parse one or more commands and return the {@link CliSession.Action}s corresponding to the parsed commands.
*/
@Override
public List parse(ParseSession session, ParseContext ctx, boolean complete) {
final ArrayList actions = new ArrayList<>();
while (true) {
ctx.skipWhitespace();
if (ctx.isEOF() && !complete)
break;
actions.add(this.commandParser.parse(session, ctx, complete));
if (ctx.isEOF() && !complete)
break;
if (!ctx.tryLiteral(";"))
throw new ParseException(ctx).addCompletion("; ");
}
return actions;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy