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

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

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

import java.util.Optional;

import org.unlaxer.Token;
import org.unlaxer.TypedToken;
import org.unlaxer.parser.Parser;
import org.unlaxer.parser.Parsers;
import org.unlaxer.parser.combinator.LazyChoice;
import org.unlaxer.util.cache.SupplierBoundCache;

@SuppressWarnings("serial")
public class NumberVariableParser extends LazyChoice implements RootVariableParser , NumberExpression {
  
  static final SupplierBoundCache SINGLETON = new SupplierBoundCache<>(NumberVariableParser::new);


  public NumberVariableParser() {
    super();
  }
  
  @Override
  public org.unlaxer.parser.Parsers getLazyParsers() {
    return 
      new Parsers(//
          Parser.get(NumberVariableMatchedWithVariableDeclarationParser.class),
          Parser.get(NumberPrefixedVariableParser.class), 
          Parser.get(NumberSuffixedVariableParser.class)
      );
  }
  
  public String getVariableName(Token thisParserParsed) {
    TypedToken typed = thisParserParsed.typed(VariableParser.class);
    VariableParser parser = typed.getParser();
    return parser.getVariableName(typed);
  }

  @Override
  public Optional typeAsOptional() {
    return Optional.of(ExpressionTypes.number);
  }
  
  public static NumberVariableParser get() {
    return SINGLETON.get();
  }

  @Override
  public Class rootOfTypedVariableParser() {
    return NumberVariableParser.class;
  }

  @Override
  public Class oneOfTypedVariableParser() {
    return NumberPrefixedVariableParser.class;
  }

  @Override
  public Class typeHintVariableParser() {
    return NumberTypeHintPrefixParser.class;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy