composewell / streamly

High performance, concurrent functional programming abstractions
https://streamly.composewell.com
Other
857 stars 64 forks source link

Better error handling in "str" quasiquoter #1823

Open harendra-kumar opened 2 years ago

harendra-kumar commented 2 years ago

Unterminated interpolation is not detected and reported:

                        [str|sudo #{nixDefaultProfile/bin/usermod
                            -p '*' #{loginId}|]

The above leads to a run time error:

sudo: #{nixDefaultProfile/bin/usermod: command not found

Instead we should report an error ar compile time.

adithyaov commented 1 year ago

Some common mistakes that can be caught:

What one generally wants to do: x = "Something " ++ here

What one might end up doing:

  1. x = "Something #{here}"
  2. x = [str|"Something #{here}"|]

Not using str or additional usage of quotes should result in some warnings.

adithyaov commented 1 year ago

Another common mistake,

# and $ are very close to each other.

adithyaov commented 1 year ago

I use the following in emacs for an easier visual representation,

(highlight-regexp "#{[a-zA-Z0-9_]*}" 'hi-red-b)
(highlight-regexp "\\[str|" 'hi-green-b)
(highlight-regexp "|\\]" 'hi-green-b)

This would highlight

Screenshot from 2022-12-19 01-18-31