use of suite.ebnf.topdown.Expect.ExpectFun in project suite by stupidsing.
the class TopDownParse method build.
private Parser build(Grammar eg) {
Parser parser, g;
List<Parser> parsers;
switch(eg.type) {
case AND___:
parsers = buildChildren(eg);
parser = (parse, st) -> {
Outlet<State> o = Outlet.of(st);
for (Parser g_ : parsers) o = o.concatMap(st_ -> st_.pr(parse, g_));
return o;
};
break;
case ENTITY:
parser = buildEntity(eg.content);
break;
case EXCEPT:
Parser parser0 = build(eg.children.get(0));
Parser parser1 = build(eg.children.get(1));
parser = (parse, st) -> st.p(parse, parser0).filter(st1 -> {
String in1 = parse.in.substring(st.pos, st1.pos);
return new State(null, 0, null, 0).p(new Parse(in1), parser1).count() == 0;
});
break;
case NAMED_:
parser = deepen(build(eg.children.get(0)), eg.content);
break;
case ONCE__:
g = build(eg.children.get(0));
parser = (parse, st) -> Outlet.of(st.pr(parse, g).take(1));
break;
case OPTION:
g = build(eg.children.get(0));
parser = (parse, st) -> st.pr(parse, g).cons(st);
break;
case OR____:
parsers = buildChildren(eg);
parser = (parse, st) -> Outlet.of(parsers).concatMap(g_ -> st.pr(parse, g_));
break;
case REPT0_:
parser = buildRepeat(eg, true);
break;
case REPT0H:
parser = buildRepeatHeadRecursion(eg);
break;
case REPT1_:
parser = buildRepeat(eg, false);
break;
case STRING:
ExpectFun e = expect.string(eg.content);
parser = skipWhitespaces((parse, st) -> parse.expect(st, e, st.pos));
break;
default:
parser = null;
}
return parser;
}
Aggregations