I like the idea of a Fluent Parser, but I find the syntax you're using very confusing, which probably isn't what you wanted to hear.
Some feedback:
- Productions, Production, Onreduce, these terms have no meaning for me. So they don't feel fluent at all. They might be fluent in the world of a parser, but as you want to abstract the parser away, I think you need to think more in terms of the resulting structure or the expressions. Kind of Parser.Add("ElementList").AddOption().Start().FollowedByLiteral("{").FollowedByList<int>(",").FollowedByLiteral("}");
Parser.Add("ElementList").AddOption().Start().FollowedByLiteral("{").FollowedByList<int>(",").FollowedByLiteral("}");
or something, that expresses the structure being parsed, but not the process underneath. (not the best example, but still more understandable than Productions.AddProduction.OnReduce(f => f[0][1].ToString());Productions.AddProduction.OnReduce(f => f[0][1].ToString());
- What's meant by f => f[1]
f => f[1]
? It's unclear for the reader, can't you write this as OnReduce().SkipLiteral("}").Take();OnReduce<returnType>().SkipLiteral("}").Take<returnType>();
or something else that stays fluent and removed the need for these lambda's if possible? - I'd try to refactor OnReduce (whatever it does) to be a generic method, so that OnReduce(f => ((List<object>)f[1]).ToArray())
OnReduce(f => ((List<object>)f[1]).ToArray())
would become OnReduce<object[]>(f => f[1]);OnReduce<object[]>(f => f[1]);
And then you need to figure out a way to remove the f => f[1] part.