All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.structurizr.dsl.PluginParser Maven / Gradle / Ivy

The newest version!
package com.structurizr.dsl;

final class PluginParser extends AbstractParser {

    private static final String GRAMMAR = "!plugin ";

    private static final int FQN_INDEX = 1;

    private final static int PARAMETER_NAME_INDEX = 0;
    private final static int PARAMETER_VALUE_INDEX = 1;

    String parse(DslContext context, Tokens tokens) {
        // !plugin 

        if (tokens.hasMoreThan(FQN_INDEX)) {
            throw new RuntimeException("Too many tokens, expected: " + GRAMMAR);
        }

        if (!tokens.includes(FQN_INDEX)) {
            throw new RuntimeException("Expected: " + GRAMMAR);
        }

        return tokens.get(FQN_INDEX);
    }

    void parseParameter(PluginDslContext context, Tokens tokens) {
        //  

        if (tokens.hasMoreThan(PARAMETER_VALUE_INDEX)) {
            throw new RuntimeException("Too many tokens, expected:  ");
        }

        if (tokens.size() != 2) {
            throw new RuntimeException("Expected:  ");
        }

        String name = tokens.get(PARAMETER_NAME_INDEX);
        String value = tokens.get(PARAMETER_VALUE_INDEX);

        context.addParameter(name, value);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy