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

org.unlaxer.tinyexpression.parser.RootVariableParser Maven / Gradle / Ivy

The newest version!
package org.unlaxer.tinyexpression.parser;

import java.util.List;

import org.unlaxer.RangedString;
import org.unlaxer.Token;
import org.unlaxer.TokenKind;
import org.unlaxer.TypedToken;
import org.unlaxer.parser.Parser;

public interface RootVariableParser extends TypedVariableParser{
  
  public default TypedToken newWithTypedParser(
      TypedToken tokenOfNakedVariable) {
    
    RootVariableParser typedVariable = Parser.get(rootOfTypedVariableParser());
    TypedToken root = tokenOfNakedVariable.newWithReplaceTyped(typedVariable);
    TypedToken child = tokenOfNakedVariable.newWithReplaceTyped(Parser.get(oneOfTypedVariableParser()));
    
    ExpressionType expressionType = typedVariable.typeAsOptional().get();

    Token typePrefix = new Token(TokenKind.consumed, new RangedString(0, expressionType.javaType().getSimpleName()), Parser.get(typeHintVariableParser()));
    
    TypedToken newCreatesOfTyped = child.newCreatesOfTyped(typePrefix ,
        tokenOfNakedVariable.newWithReplaceTyped(Parser.get(NakedVariableParser.class)));
    root = root.newCreatesOfTyped(List.of(newCreatesOfTyped));
    return root;
  }
  
  public Class rootOfTypedVariableParser();
  public Class oneOfTypedVariableParser();
  public Class typeHintVariableParser();
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy