technomancy / grenchman

Sorry about the name
GNU General Public License v3.0
217 stars 8 forks source link

Multiline input #16

Closed technomancy closed 7 years ago

technomancy commented 10 years ago

If a form is incomplete, we need to read more input.

We might be able to just send it to the server and rely on its parser to avoid reinventing the reader. Just read another line if it returns an "EOF while reading".

hypirion commented 10 years ago

I think it would be sufficient to check if a form is incomplete is by doing delimiter balancing (and handle the character, comment and string special cases), and send off the data when the work is properly balanced.

I'm not sure whether Grench or the Clojure Reader should return an error when the delimiters are unmatched, although I'd guess the safest is to just pass it over to the Reader.

technomancy commented 10 years ago

My gut feeling is that there are enough edge cases (comments, strings, escapes inside strings, single chars) that it would be difficult to match the Clojure reader in a high-fidelity way, but if someone wants to take a crack at it, they'd be welcome. =)

hypirion commented 10 years ago

Probably. Considering people would use different versions of the Reader as well, it may be better to just pass it over.

trptcolin commented 10 years ago

A few things to consider if you want to just use the reader on the server side:

user=> (+ 1 2 3
) (+ 4 5
)

Going straight to the reader on the other side completes the first expression fine, but then there's a bit of a dilemma: what lets you know to start reading the second expression (and that it's a multiline expression that needs completing on the next line)?

I agree about the edge cases being nasty in balancing delimiters / parsing a complete form out. I was lucky on REPLy that there was already a near-complete clojure parser available... too bad there's no official yacc / antlr grammar for clojure that you could use to generate a parser.