bosatsu icon indicating copy to clipboard operation
bosatsu copied to clipboard

better errors in parser

Open johnynek opened this issue 7 years ago • 2 comments

The parser needs better error messages. When we fail to parse e.g. missing ) it does not give very good messages.

One interesting law: if we make a random package and then modify a random character in it, we should either continue to parse (it was a legal change) or we should point to the position where we made the change.

This is probably hard to pass that law, but it would be awesome if we could.

johnynek avatar Oct 26 '18 02:10 johnynek

I'm pretty sure the built-in cons-list structure of Statement/Declaration is a disaster for parsing.

If you have:

x = 1
y = 4
{'x' : 'x' : x }

it is the dict that doesn't parse, but since it doesn't parse, the lets don't parse, so the error you get is that x=1 can't parse. This is pretty terrible.

A minimal solution would to change the parser to be something like P[List[A] => List[A]] where we give a function that if you pass the tail, it can make the list, so basically we just do { t => h :: t } in that function. Then we make a P[List[Declaration => Declaration]], finally we foldRight on that pushing the final declaration/statement into it.

johnynek avatar Apr 06 '19 18:04 johnynek

Here's another bad example:

5|export [ BinNat(), toInt, , toNat, toBinNat, next, add_BinNat, times2 ]
  ^

Note, we should point to the , , part, not to the export.

johnynek avatar Nov 04 '19 00:11 johnynek