/** * <code>TokenGroup</code> is created for each directive in * the recipe. This method creates a new <code>TokenGroup</code> * by passing the <code>SourceInfo</code>, which represents the * information of the source parsed. * * @param info about the source directive being parsed. */ public void createTokenGroup(SourceInfo info) { if (group != null) { groups.add(group); } this.group = new TokenGroup(info); }
/** * This method provides a way to add a <code>Token</code> to the <code>TokenGroup</code>. * * @param token to be added to the token group. */ public void addToken(Token token) { group.add(token); }
public MapArguments(UsageDefinition definition, TokenGroup group) throws DirectiveParseException { this.tokens = new HashMap<>(); this.lineno = group.getSourceInfo().getLineNumber(); this.columnno = group.getSourceInfo().getColumnNumber(); this.source = group.getSourceInfo().getSource(); int required = definition.getTokens().size() - definition.getOptionalTokensCount(); if ((required > group.size() - 1) || ((group.size() - 1) > definition.getTokens().size())) { throw new DirectiveParseException( String.format("Improper usage of directive '%s', usage - '%s'", definition.getDirectiveName(), definition.toString()) Iterator<Token> it = group.iterator(); int pos = 0; String.format("Expected argument '%s' to be of type '%s', but it is of type '%s' - %s", specification.name(), specification.type().name(), token.type().name(), group.getSourceInfo().toString()) );
/** * This method <code>toJson</code> returns the <code>JsonElement</code> object * representation of this object. * * @return An instance of <code>JsonElement</code> representing this object. */ public JsonElement toJson() { JsonObject output = new JsonObject(); output.addProperty("class", this.getClass().getSimpleName()); output.addProperty("count", tokens.size()); JsonArray array = new JsonArray(); Iterator<TokenGroup> iterator = tokens.iterator(); while(iterator.hasNext()) { JsonArray darray = new JsonArray(); Iterator<Token> it = iterator.next().iterator(); while(it.hasNext()) { Token tok = it.next(); JsonObject object = new JsonObject(); object.addProperty("token", tok.type().toString()); object.addProperty("value", tok.value().toString()); darray.add(object); } array.add(darray); } output.add("value", array); return output; }
continue; String command = ((DirectiveName) next.get(0)).value(); String root = command; if (context.hasAlias(root)) {