Search in sources :

Example 1 with ParameterScanner

use of com.redhat.qute.parser.parameter.scanner.ParameterScanner in project quarkus-ls by redhat-developer.

the class ParameterParser method parse.

public static List<Parameter> parse(ParametersContainer expression, boolean methodParameters, CancelChecker cancelChecker) {
    if (cancelChecker == null) {
        cancelChecker = DEFAULT_CANCEL_CHECKER;
    }
    Template template = expression.getOwnerTemplate();
    String text = template.getText();
    int start = expression.getStartParametersOffset();
    int end = expression.getEndParametersOffset();
    ParameterScanner scanner = ParameterScanner.createScanner(text, start, end, methodParameters);
    TokenType token = scanner.scan();
    List<Parameter> parameters = new ArrayList<>();
    Parameter currentParameter = null;
    while (token != TokenType.EOS) {
        cancelChecker.checkCanceled();
        int tokenOffset = scanner.getTokenOffset();
        int tokenEnd = scanner.getTokenEnd();
        switch(token) {
            case Whitespace:
                currentParameter = null;
                break;
            case ParameterName:
                currentParameter = new Parameter(tokenOffset, tokenEnd);
                currentParameter.setParameterParent(expression);
                parameters.add(currentParameter);
                break;
            case ParameterValue:
                if (currentParameter != null) {
                    // current parameter can be null when parameter name is not defined
                    // ex : {#let =123} (instead of {#let name=123})
                    currentParameter.setStartValue(tokenOffset);
                    currentParameter.setEndValue(tokenEnd);
                }
                break;
            default:
        }
        token = scanner.scan();
    }
    return parameters;
}
Also used : TokenType(com.redhat.qute.parser.parameter.scanner.TokenType) ArrayList(java.util.ArrayList) ParameterScanner(com.redhat.qute.parser.parameter.scanner.ParameterScanner) Parameter(com.redhat.qute.parser.template.Parameter) Template(com.redhat.qute.parser.template.Template)

Aggregations

ParameterScanner (com.redhat.qute.parser.parameter.scanner.ParameterScanner)1 TokenType (com.redhat.qute.parser.parameter.scanner.TokenType)1 Parameter (com.redhat.qute.parser.template.Parameter)1 Template (com.redhat.qute.parser.template.Template)1 ArrayList (java.util.ArrayList)1