Determine type with NimbleParsec?

i want to parse string and determine if value is string/number/boolean/date/time/datetime/probably many more distinct value value types in future.

How to approach this. do i create parse for each separate option and than one choice?

But i have this caveat. for example for boolean, either it is word true or number 1 they can be casted to string or number respectively. Workaround for this might be, that seems ok from business point of view to have prefix or suffix, like boolean:1 or 1:boolean. and if this type casting prefix/suffix is present force that type for parser.

I don’t understand nimble parsec at that level, but i believe prefix is a lot easier (but still pretty hard - at least for me), but bossiness much rather would prefer suffix :expressionless:

someStringValue β†’ string someStringValue
1 β†’ integer 1
1.4 β†’ float 1.4
1.4:string β†’ string 1.4
1:boolean β†’ boolean true

etc. If you have some hints, ideas how to approach this, i would greatly appreciate it.

I’d separate parsing the string to tokens of interest and then bringing those tokens together with whatever business logic you have around it.

1 Like