org.unlaxer.tinyexpression.parser.javalang.VariableDeclarationsParser Maven / Gradle / Ivy
package org.unlaxer.tinyexpression.parser.javalang;
import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.unlaxer.Token;
import org.unlaxer.TokenPredicators;
import org.unlaxer.parser.Parser;
import org.unlaxer.parser.combinator.LazyZeroOrMore;
import org.unlaxer.util.annotation.TokenExtractor;
import org.unlaxer.util.annotation.TokenExtractor.Timing;
public class VariableDeclarationsParser extends LazyZeroOrMore{
@Override
public Supplier getLazyParser() {
return VariableDeclarationParser::new;
}
@Override
public Optional getLazyTerminatorParser() {
return Optional.empty();
}
@TokenExtractor(timings = Timing.CreateOperatorOperandTree)
public static List extractVariables(Token thisParserParsed){
if(false == thisParserParsed.parser instanceof VariableDeclarationsParser) {
throw new IllegalArgumentException();
}
boolean isOperatorOperandTree = thisParserParsed.getChildren(TokenPredicators.parserImplements(VariableDeclaration.class))
.findFirst().isPresent();
Stream children = isOperatorOperandTree ?
thisParserParsed.getAstNodeChildren().stream():
thisParserParsed.getChildren(TokenPredicators.parsers(VariableDeclarationParser.class))
.map(token->token.getChild(TokenPredicators.allMatch()));
List collect1 = children.collect(Collectors.toList());
List collect = collect1.stream().map(token->{
AbstractVariableDeclarationParser parser = (AbstractVariableDeclarationParser) token.parser;
Token extractVariable = parser.extractVariable(token);
return extractVariable;
}).collect(Collectors.toList());
return collect;
}
} © 2015 - 2025 Weber Informatics LLC | Privacy Policy