squiggle icon indicating copy to clipboard operation
squiggle copied to clipboard

Prettier seems to have trouble with tags

Open OAGr opened this issue 1 year ago • 1 comments

Description of suggestion or shortcoming:

https://www.squiggle-language.com/playground?v=0.9.5#code=eNqdVs1u00AQfpWpe8BO05S0PaCIVggoSKhICHKre9gm68TgrIt3w48aH7nxCPByfRJmdnaddX6Ulotlz87PNzPf7PguGstMzAvzqhzLaBC90EZU5lVRajlO1aiSwsiLH7dyZITJSxWLkZmLIoEzuEsVgClfygG%2FAiykVZTjBX%2FnGbA67J2BPwMzlQrS6MJ%2FpxEcLE8P6PtmbmBSGnvErsB7koWWYKq5JHnd9RjeWqDVcCrUA%2BA83wXH6VkwpoQbCRMOgOpCtXA1jrYgu5RaPxDW%2BeNhFej98ZiGKEE8iwUF33NeVyOSWasTay1YOnwjUNZ43OIwI6XdHutUpaqaq6HUJjb4aMiWqY9SI1Xxm%2BS9TMUJyV1hlZghBntCr12W3gqNVB4Exmc2lDuWVVVWA0LdKOyxAuNvpBZjGqWRNawdzva4TKSSFdKEoH%2BUt2VlYovEgmI%2FusmGgZGqRtFlTgnlBXIsDrS7WFOzANNj7drmm4m8eKjlXmhKxlecdxrt7wO5gE%2Fz3GDdbD8ILdMLXKL00ukMS0MNpYidjtO1cQupJmYat%2FLbYP%2FBQthoGpRho%2Bkbm%2BxG06AOSWPRMnaYBp1O4%2FV6Y%2BeyspoJM2zSCDKihsXIj6XEVdQT%2FP7PL4Tm%2BHH%2F93caJTyKnAu%2FB9ZcZBKuuLVcJPpRFt47J3N4eAgXTNWOrcOa2UGT9RLMChJK%2B%2BgI3otcgf46zyeTQr4jCmQVQvpeVl9Wy9LScrzly2UAa7uh6%2FOki4B5n6kF3LnB9BIaRaj57hhLParym2CFLOdFu%2Fsx4JZn%2B0zc2gYhyd1FkbBuZYcO1R40iUv%2Fr6VBLq35b0ZplR7O1CqPSjUSJubQ3dBdAofnrPO5zFVsGxAl%2Fiq2LDRc2LDOPZKlypdm9dTLU8WNWD1nKbf6yE54ribEn1TNcMUX1EbAiZ%2FpAVz1u3DchZNrus%2BQIapdax8qZgq9t%2BZ23NwsXS0rGPvdk0ZToTkAfM%2FNFHhY4aQZTLB7gnHG4TxbfD1rmiQ92ivxSVKzkR9wjhVleYWFI1XINfTRd%2Bg0cHT19Nq56id120kDuBCBr9aiP94MOvR%2F7PwHfyAUahPqJqCWSJpxE3K5xE92x%2Bu7eP6%2FIn62IxiGQjYqTUvNTH%2FCN1Hg%2F8D2ZuhyJsOIVNkc9zqcw9Pa9YV%2BIOIdccel1OqJARcfTv8nJi7rUx%2FU%2FmRsiRqZKRbSTpOelvNibJfkCi36jgnHngm4C5Ko%2Fgdd058Y

You can see here that the @startClosed tags are different colors.

OAGr avatar Aug 10 '24 21:08 OAGr

There are two problems here, both related to Lezer grammar (not Prettier).

  1. {|| ... was parsed as {, || (OR operator); I fixed this in e16dc56ba1b402bba29799628c4571a98252d760 (it's in my semantic-analysis branch, sorry, I should've sent it in a separate PR)

  2. Ambiguity around whitespace and end expressions, also mentioned here: https://github.com/quantified-uncertainty/squiggle/issues/1736#issuecomment-1522582929

Basically, this is ambiguous without distinguishing between " " and "\n":

{
  x = [0]
  [0]
  [0]
}

Could be either { x=[0][0]; [0] } // returns [0] or { x=[0]; [0][0] } // returns 0. In practice, Peggy parser would just fail because it doesn't allow whitespace before [], but Lezer doesn't know that. It just behaves greedily, eats the entire x[0][0][0] and fails the block. This breaks the syntax in the following lines.

The problem is that whitespace tokens in Lezer are configured globally. There are some ways around that, but the grammar would become much more complicated.

berekuk avatar Aug 30 '24 14:08 berekuk