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

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

There is a newer version: 1.4.6
Show newest version
package org.unlaxer.tinyexpression.parser;

import java.util.Optional;
import java.util.stream.Stream;

import org.unlaxer.Token.ScanDirection;
import org.unlaxer.TokenPredicators;
import org.unlaxer.TypedToken;
import org.unlaxer.parser.Parser;
import org.unlaxer.parser.Parsers;
import org.unlaxer.parser.combinator.LazyChain;
import org.unlaxer.parser.combinator.ZeroOrMore;
import org.unlaxer.parser.posix.CommaParser;
import org.unlaxer.tinyexpression.parser.javalang.JavaStyleDelimitedLazyChain;
import org.unlaxer.util.annotation.TokenExtractor;

public class MethodParametersElementParser extends LazyChain{

  @Override
  public org.unlaxer.parser.Parsers getLazyParsers() {
    return new Parsers(
        Parser.get(MethodParameterParser.class),
        new ZeroOrMore(
            new JavaStyleDelimitedLazyChain() {

              @Override
              public org.unlaxer.parser.Parsers getLazyParsers() {
                return new Parsers(
                    Parser.get(CommaParser.class),
                    Parser.get(MethodParameterParser.class)
                );
              }
            }
        )
    );
  }
  
  @TokenExtractor
  public Stream> typedVariableParsersAsStream(TypedToken thisParserParsed){
   
    //最終的にExpressionTypeを得てOperatorOperandTreeCreatorで型解決を行う
    return thisParserParsed.flatten(ScanDirection.Breadth).stream()
          .filter(TokenPredicators.parserImplements(TypedVariableParser.class))
          .map(token->token.typed(TypedVariableParser.class));
  }
  
  @TokenExtractor
  public Optional> typedVariableParsers(
      TypedToken thisParserParsed, String parameterName){
   
    //最終的にExpressionTypeを得てOperatorOperandTreeCreatorで型解決を行う
    Optional> collect = 
        typedVariableParsersAsStream(thisParserParsed)
          .filter(token->parameterName.equals(token.getParser().getVariableName(token)))
          .findFirst();
    
    return collect;
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy