larsbrinkhoff / forth-mode

Wants to be the SLIME of Forth
GNU General Public License v3.0
61 stars 17 forks source link

Proposed fix for issue#11 #12

Closed ellerh closed 7 years ago

ellerh commented 7 years ago

This is a possible way to handle ( ...) comments. Unfortunatly, forth--syntax-propertize is already quite complicated and will only become more so if it needs to handle more cases.

larsbrinkhoff commented 7 years ago

Thanks! I'm not up to speed on Emacs syntax tables. Could you please give me a brief description on what's going on in forth--syntax-propertize?

By the way, thank you so much for your work with SLIME. It's a pleasure to work with.

ellerh commented 7 years ago

Could you please give me a brief description on what's going on in forth--syntax-propertize

In general terms: it sets the syntax-table text-property at places where the normal syntax-table is not sufficient.

Specifically it searches occurrences of ( and \ and if those chars are not surrounded by whitespace sets the syntax to "symbol". It uses syntax-ppss to skip occurrences eg. in strings. Additionally for ( it searches the next ) and sets its syntax to "generic comment delimiter". All this is fused into one loop for efficiency but obvoiusly not easy to read.

Actually I found a case that is still not handled correclty: "( ( )".

Maybe it would be clearer to make forth--syntax-propertize a small state machine with four states: comment, string, word and whitespace. After figuring out the initial state it seems easy to scan forward for the next potential state switch.

larsbrinkhoff commented 7 years ago

Thanks for the explanation.

Wouldn't it be possible to mimic the Forth parser? Just look at whitespace-delimited tokens and skip ahead if there's a comment or a string?

ellerh commented 7 years ago

Wouldn't it be possible to mimic the Forth parser? Just look at whitespace-delimited tokens and skip ahead if there's a comment or a string?

Yes, probably. That's roughly what I meant with the 4-state state machine.