Closed martinkoslof closed 1 year ago
Hi Martin! Thanks for your message. Unfortunately I'm low on time to dig in right now - I do know a few people chime in on parsers
, superpower
, and some other Stack Overflow tags, though, so may be quicker to get some help if you post your question there, too? Cheers!
Hi Nick,
I understand completely. If you have any ideas or suggestions without having to over extend yourself, let me know. I skimmed over StackOverflow and didn't really see anything related.
I can use a Regex Match in the TokenBuilder to set explicit Tokens For DateTime and Guid. I have booleans handled and strings are self explanatory. I'm not sure how to handle the numeric types. For example, say I have property called SecurityLevel. This is defined as a double. Within a string I need to parse, I receive: "SecurityLevel eq 10". I believe any out of the box parse here would assume it's an int32 and then when building the expression for SecurityLevel, an error would occur because the code is attempting to assign and Int32 Expression to the double property. I'm not sure if there is an obvious solution I'm just not aware about.
Hello,
I've been taking a crash course in Superpower the last few days and I have a working prototype. However, there is one thing I'm missing and I'd like some advise on how to proceed.
At the moment I am using the default TokenizerBuilder, I really don't want to write a custom tokenizer because at the moment, 90% of everything I need is working. Here is current code for that:
Notice the Matches I have for "Numerics", "String" and QueryDateTimeParser? I borrowed the DateTime parse from here, verbatim: https://github.com/datalust/superpower/blob/dev/sample/DateTimeTextParser/DateTimeTextParser.cs. Unfortunately it doesn't appear to be working for me. I am getting parsing errors when trying to provide a date time. Is this the proper way to integrate this into an existing tokenizer? I realize there is a
public static DateTime Parse(string input)
method in that parser, but I want it to be indirectly invoked via the template.The other issue I have is, and maybe I'm missing a better way to do this, but I have several different CLR types I need to support -> int, decimal double, float, guid, datetime and enum for example. It appears for numeric types, there is a generic Numerics class. However, how do I actually map these to the proper CLR property type when building the expression? For example, this is what I have now (On the Parser side of things):
As noted above, I can't map any tokens to the DateTime enum yet, but even if that works, how do I explicitly set the Expressions for my double, float, guid and other types? In the past I would have a parsed "object" value and do something like this manually, in a helper method that has been provided the property type of the field:
Then I would build my expression constant off this casted value. I'm not sure how to use my tokenizer and parsers to accomplish similar. I hope this question makes sense.