BlockstreamResearch / simfony

Rust-like high-level language that compiles down to Simplicity bytecode. Work in progress.
25 stars 9 forks source link

Make parser more accepting #57

Open uncomputable opened 3 months ago

uncomputable commented 3 months ago

Parse errors are hard to understand. These errors come directly from the PEST grammar, which no Simfony developer will have read. It would be better to accept incomplete program components during parsing and to produce an expressive user-facing error when the AST is generated.

https://github.com/BlockstreamResearch/simfony/pull/56#issuecomment-2215325192

Like, right now if you remove type annotations from your example programs you get something like expected match_pattern but it'd be nicer if we'd parse these things, mark them as "unknown type" and then during AST conversion we'd give the user an error like "No type was specified for x. You need to provide a type annotation, like x: bool."

The scope of this change is unclear, but grammar errors are hard to understand so we never want to show them to users.

apoelstra commented 3 months ago

Well, not never. If they input actual nonsense we don't have much choice. But if they write something that "looks like it should work" then we should try to provide our own error message.

For the sake of making this issue closeable, I'd say that if you can remove the type annotations (especially the ::<u8> ones) and the resulting error message tells you to put them back, I'd call this issue closed. But in general, we should strive toward doing this in many different places.