instaparse

If you're not trampolining your parser, why bother getting up in the morning?
aengelberg 2018-04-09T02:04:31.000026Z

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

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

aengelberg 2018-04-09T02:05:58.000189Z

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

aengelberg 2018-04-09T02:06:02.000213Z

https://github.com/engelberg/instaparse#escape-characters

aengelberg 2018-04-09T02:07:10.000089Z

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)

misha 2018-04-09T06:43:10.000140Z

@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).

misha 2018-04-09T06:59:01.000003Z

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.

aengelberg 2018-04-09T15:29:48.000413Z

@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)