Hi,
I’m trying to write a parser using NimbleParsec v1.1.0 — Documentation which parses arbitrary text wrapped in a character like an underscore.
Here are some examples of what I’m hoping the parser will do:
"hello there" => ["hello there"]
"hello _Alex_!" => ["hello ", "_Alex_", "!"]
"Ũnicode is _allŏwed everywhere_ _ŏk?_" => ["Ũnicode is ", "_allŏwed everywhere_", "_ŏk?_"]
Here’s my attempt:
defmodule Txtparser do
import NimbleParsec
defcombinatorp :plain_string,
utf8_string([], min: 1)
|> lookahead_not(parsec(:wrapped_string))
defcombinatorp :wrapped_string,
string("_")
|> parsec(:plain_string)
|> string("_")
defparsec(:parse,
repeat(
choice(
[parsec(:wrapped_string), parsec(:plain_string)]
)
)
)
end
But I think I’m misundertanding how lookahead_not
works, as the following is happening
"hi _there_" => ["hi _there_"]
instead of this desired result:
"hi _there_" => ["hi ", "_there_"]