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

org.unlaxer.tinyexpression.parser.BooleanVariableParser 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.parser.Parser;
import org.unlaxer.parser.Parsers;
import org.unlaxer.parser.combinator.LazyChain;
import org.unlaxer.parser.combinator.LazyChoice;
import org.unlaxer.util.annotation.TokenExtractor;
import org.unlaxer.util.cache.SupplierBoundCache;

public class BooleanVariableParser extends LazyChoice implements RootVariableParser , BooleanExpression{

  private static final long serialVersionUID = -60484510350410L;
  
  static final SupplierBoundCache SINGLETON = new SupplierBoundCache<>(BooleanVariableParser::new);


  public BooleanVariableParser() {
    super();
  }

  @Override
  public org.unlaxer.parser.Parsers getLazyParsers() {
    return 
      new Parsers(//
          Parser.get(BooleanVariableMatchedWithVariableDeclarationParser.class),
          Parser.get(BooleanPrefixedVariableParser.class), 
          Parser.get(BooleanSuffixedVariableParser.class)
      );
  }
  
  @Override
  public Optional typeAsOptional() {
    return Optional.of(ExpressionTypes._boolean);
  }
  
  public static class BooleanVariableMatchedWithVariableDeclarationParser extends LazyChain implements BooleanExpression {

    public BooleanVariableMatchedWithVariableDeclarationParser() {
      super();
    }

    @Override
    public org.unlaxer.parser.Parsers getLazyParsers() {
      return new Parsers(//
          Parser.get(DollarParser.class), //0
          Parser.get(BooleanVariableDeclarationMatchedTokenParser.class)//1
      );
    }
    
    @TokenExtractor
    static Token getVariableNameToken(Token thisParserParsed) {
      Token token = thisParserParsed.getChildWithParser(NakedVariableParser.class);
      return token;
    }

  }
  
  public static BooleanVariableParser get() {
    return SINGLETON.get();
  }

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

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

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy