org.unlaxer.sample.calc.parser.TermParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of calculator Show documentation
Show all versions of calculator Show documentation
a simple parser combinator inspired by RelaxNG
package org.unlaxer.sample.calc.parser;
import org.unlaxer.parser.Parser;
import org.unlaxer.parser.ascii.DivisionParser;
import org.unlaxer.parser.combinator.Chain;
import org.unlaxer.parser.combinator.Choice;
import org.unlaxer.parser.combinator.NoneChildCollectingParser;
import org.unlaxer.parser.combinator.ZeroOrMore;
import org.unlaxer.parser.elementary.MultipleParser;
public class TermParser extends NoneChildCollectingParser {
private static final long serialVersionUID = 1430560948407993197L;
Parser factorParser;
public TermParser(Parser factorParser) {
super();
this.factorParser = factorParser;
}
@Override
public Parser createParser() {
// ::= [('*'|'/')]*
return
new Chain(
factorParser,
new ZeroOrMore(
new Chain(
new Choice(
new MultipleParser(),
new DivisionParser()
),
factorParser
)
)
);
}
}