dundalek / closh

Bash-like shell based on Clojure
Eclipse Public License 1.0
1.62k stars 66 forks source link

Add tilde expansion as a string before symbols are parsed #37

Closed mnewt closed 6 years ago

mnewt commented 6 years ago

Work in progress

The idea is to parse the string straight from readline and make modifications before the reader touches it. A basic assumption is that we want to expand all tildes outside of parens but leave everything inside parens untouched. This seems to me to be what a user would expect.

Examples:

$ echo ~
/Users/user
$ echo ~ (str "hi ~") "~"
/Users/user hi ~ /Users/user
$ echo "\~"
~

@dundalek I have some questions for you:

TODO:

mnewt commented 6 years ago

Addresses #8

dundalek commented 6 years ago

I think a proper parser is a way to go. I haven't looked too deeply into this yet. If we could extend the clojure reader that would the best. Otherwise some hybrid approach to have parser for the command mode and hand the the clojure parts to the reader.

I think the string based approaches might not be viable. It is not hard to come up with counter examples which blow up like: echo (str "(") ~.

I've been collecting forms that are broken and would be fixed by improved reader, I created an issue so where we can track it https://github.com/dundalek/closh/issues/39

mnewt commented 6 years ago

Withdrawing this in favor of a more considered approach