Hello, I wanted to use the NimbleParsec library to convert a string into the map I need. But I think I got it wrong and this is more for me to equle with something and not to make the output I need like regex. it’s true?
For example I have this string
"sanitize(trim, lowercase) validate(not_empty, max_len = 20)"
# And I need something like this:
# Output: %{sanitize: ['trim', 'lowercase'], validate: ['not_empty', {'max_len', '20'}]}
With NimbleParsec, you create rules for the things you want to parse and then define a parser, e.g parsing a gmail-like search string. Should be pretty straight forward to parse your text format.
I always wanted to use NimbleParsec, but I do not know why I can not understand it . it is good try to learn more, if I can find a good video for it, it can be help full
Yeah I can relate, it can be a bit arcane. I had some threads saved where people explain in more detail but couldn’t find them easily. Try searching for the nimbleparsec tag or just “NimbleParsec” in the title/text.
Yes and thank you, but NimbleParsec always remains a problem for me! I tried several times to solve this with NimbleParsec that were not successful even at the beginning :))
date =
choice([
string("validate"),
string("sanitize")
])
NimbleParsec is not regex. It’s not “searching” through your input.
A parser works by going though the input string front → end and at each step you need to define what can be matched next. In your example you tell it to match either "validate" or "sanitize". It starts from the front, finds "sanitize" and then the next char is (, which matches neither of your expected values, so parsing halts.