unisonweb / unison

A friendly programming language from the future
https://unison-lang.org
Other
5.78k stars 270 forks source link

Regression with Docs parsing #5337

Open etorreborre opened 2 months ago

etorreborre commented 2 months ago

Describe and demonstrate the bug The following Doc fails to typecheck with ucm 0.5.26:

testDoc : Doc
testDoc = {{
  key: '{{ s "value" }}'.
}}

The error is:

I got confused here:

      3 |   key: '{{ s "value" }}'.

  I was surprised to find a . here.
  I was expecting one of these instead:

  * end of input

The same code typechecks ok with 0.5.25.

sellout commented 2 months ago

So, what’s happening here is that the Doc2 parser is grabbing '{{ as a single token, so then the first }} is parsed as the end of the Doc2, with '. }} being parsed as Unison code, which it’s not happy about. I’m not sure how the previous parser wasn’t globbing those bits, but apparently it wasn’t.

A quick workaround is adding a space between ' and {{, so they parse separately.

I’m fixing this by changing the word parser to not blindly consume to the next space, because we shouldn’t force docs to have whitespace surrounding every delimiter.

etorreborre commented 1 month ago

My current workaround is to define a q: Doc -> Doc function that just surrounds a Doc term with ':

q : Doc -> Doc
q d = Doc.Join [Word "'", d, Word "'"]