org.unlaxer.tinyexpression.parser.AbstractNumberTermParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tinyExpression Show documentation
Show all versions of tinyExpression Show documentation
TinyExpression implemented with Unlaxer
The 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 extends Parser> 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;
}
}