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

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

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

import org.unlaxer.parser.Parser;
import org.unlaxer.parser.Parsers;
import org.unlaxer.parser.combinator.Choice;
import org.unlaxer.parser.combinator.WhiteSpaceDelimitedChain;
import org.unlaxer.parser.combinator.ZeroOrMore;
import org.unlaxer.tinyexpression.parser.javalang.JavaStyleDelimitedLazyChain;

public abstract class AbstractNumberTermParser extends JavaStyleDelimitedLazyChain implements NumberExpression , VariableTypeSelectable{
	
	private static final long serialVersionUID = 1430560948407993197L;
	
	public AbstractNumberTermParser() {
		super();
	}
	

  @Override
  public org.unlaxer.parser.Parsers getLazyParsers(boolean withNakedVariable) {
    
    // ::= [('*'|'/')]*
    Parsers parsers = new Parsers();
    
    Parser.get(StrictTypedNumberFactorParser.class);
    
    Class factorParserClazz = withNakedVariable ?
       NumberFactorParser.class:
       StrictTypedNumberFactorParser.class;
    
    parsers.add(
        Parser.get(
            factorParserClazz 
        )
    );
    parsers.add(new ZeroOrMore(
          new WhiteSpaceDelimitedChain(
            new Choice(
              Parser.get(MultipleParser.class),
              Parser.get(DivisionParser.class)
            ),
            Parser.get(factorParserClazz)
          )
        )
   );
    
    
    return parsers;
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy