parinfer-rust icon indicating copy to clipboard operation
parinfer-rust copied to clipboard

ignore comments?

Open andreyorst opened this issue 4 years ago • 3 comments

Parinfer Rust should be fast enough to strip away comments before processing and migrate unbalanced quote issues that original Parinfer had. Are there any plans for such feature?

andreyorst avatar Jul 02 '20 13:07 andreyorst

The problem with the issue you've linked to is that the comment is no longer a comment, but a semicolon inside a string. There's not a way to detect that AFAIK, though if you have ideas, I'm open. When the quote is inserted, parinfer sees a valid string followed by possibly valid code.

Parinfer and parinfer-rust largely does ignore comments. Recently, I've merged some PRs that handle different cases in Scheme and Lisp that were not previously handled, thanks to recent contributors.

eraserhd avatar Jul 13 '20 18:07 eraserhd

I was thinking lately about comment caching. E.g. when Parinfer can ensure that buffer is correct, it can cache comment positions. When user removes, or inserts " Parinfer knows, that comments should not become part of the string, and by using cache skips comments inside incomplete string. Although this approach is quite fuzzy

andreyorst avatar Jul 14 '20 06:07 andreyorst

I've been thinking that the "can ensure the buffer is correct" part is an AI-complete problem. But maybe it's not a hard problem but requires the persistence of some state and the analysis of a number of cases?

  • Is it always true that a quote in a comment should not close a string when the user inserts a quote before the comment?
  • What happens if the user inserts a quote after the comment, after having inserted one before the comment?
  • What should happen if there are two, or another even number of quotes in the comment? It seems like for consistency, the file should still be considered broken even though it would parse.
  • What should happen if there are three, or another odd number of quotes in the comment?
  • What should happen if there are multiple comments with quotes in them?
  • What should happen if a quote in a comment is preceded by a backslash?
  • What should happen if a quote in a comment is preceded by a #\ in Scheme?
  • What happens if the user deletes a quote, making the file unbalanced, is it the same?
  • For opening quote?
  • For closing quote?
  • What happens if the user breaks the file by inserting a backslash before a quote?
  • How do we detect the user inserting a quote before a comment with a quote, so we store state to mark that quote as "ignored", and then the user inserts a backslash just before the quote, turning it into a character? We have to somehow make the file valid even though the user has inserted a quote.

That's off the top of my head, not a thorough analysis yet...

eraserhd avatar Jul 15 '20 14:07 eraserhd