Fork me on GitHub
#instaparse
<
2018-04-09
>
aengelberg02:04:31

@misha I think you are just under-escaping. Try

(insta/parse
  (insta/parser "s = #'\\\\\\\\'")
  "\\\\")

aengelberg02:04:58

Since instaparse and Clojure strings both have their own notation of backslash escaping, you unfortunately have to use an obscene amount of backslashes to convey a legitimate backslash character

aengelberg02:04:10

As that section in the readme explains, one way to get more predictable escaping behavior is to store your grammar in a separate resource file, and that removes one of the layers of escaping (Clojure strings)

misha06:04:10

@aengelberg thank you, that works. I already put grammar and source string into their own files, before asking for help, might have missed something (like ns reload).

misha06:04:01

how can I distinguish between \n within a text, and a line end in multiline text? Can I do it without relying on next line's grammar/content? For example, here I need to extract "Simple__ communication example\non several lines" as a single value, w/o including "Alice". Is there a landmark I can use to stop at "visual" line's end?:

title __Simple__ communication example\non several lines
Alice -> Bob: Authentication Request
I tried #'(?m)...$' regex flag, but I doubt it will receive "visual" line as an input.

aengelberg15:04:48

@misha yeah, from the regex's perspective it's matching against the entire rest of the string, so $ means "end of file", not "end of line". You could use regex's lookahead feature to detect and end of line, like (?=\r?\n)