sprache

Recursive expression parsing in Sprache

荒凉一梦 提交于 2020-01-02 21:53:13
问题 I am building a Sprache parser to parse expressions similar to SQL search conditions. e.g Property = 123 or Property > AnotherProperty So far both of those examples work, however I am struggling to figure out what I need to do to allow ANDing/ORing conditions and parenthesis. Basically I have this so far: private static readonly Parser<string> Operators = Parse.String("+").Or(Parse.String("-")).Or(Parse.String("=")) .Or(Parse.String("<")).Or(Parse.String(">")) .Or(Parse.String("<=")).Or(Parse

How to parse Conditional Ternary syntax (a > b ? a : b) using Sprache

倖福魔咒の 提交于 2019-12-13 16:29:02
问题 I keep thinking I understand Sprache parsing the more I use it, but then I come across a new syntax that baffles me, and there are not a lot of examples online. At this time, I'm trying to allow my string to have conditional syntax (like C#) such as: (A > B ? A : B) A+2 > 7 ? (A + 2) : -1 (A*B) < 12 ? "Real" : "Fake" I have the regular operators working fine (>,<,!,=,etc.) using the following parse: private Parser<ExpressionType> Operator(string op, ExpressionType opType) => Parse.String(op)

Recursive expression parsing in Sprache

孤人 提交于 2019-12-08 19:00:31
I am building a Sprache parser to parse expressions similar to SQL search conditions. e.g Property = 123 or Property > AnotherProperty So far both of those examples work, however I am struggling to figure out what I need to do to allow ANDing/ORing conditions and parenthesis. Basically I have this so far: private static readonly Parser<string> Operators = Parse.String("+").Or(Parse.String("-")).Or(Parse.String("=")) .Or(Parse.String("<")).Or(Parse.String(">")) .Or(Parse.String("<=")).Or(Parse.String(">=")).Or(Parse.String("<>")) .Text(); private static readonly Parser<IdentifierExpression>