Skip to content

Add option to allow unbalanced quotes in line comment (lisp)#157

Open
jimwhite wants to merge 1 commit intoeraserhd:masterfrom
jimwhite:line-comment-quotes
Open

Add option to allow unbalanced quotes in line comment (lisp)#157
jimwhite wants to merge 1 commit intoeraserhd:masterfrom
jimwhite:line-comment-quotes

Conversation

@jimwhite
Copy link

Fixes #156

Add --line-comment-quotes / --no-line-comment-quotes option

Summary

Adds a new --line-comment-quotes / --no-line-comment-quotes CLI option to control whether parinfer checks for balanced quotes inside line comments. When disabled, quote_danger state is reset at newlines when leaving a ; line comment, since line comments are self-contained and cannot carry string state across lines.

Motivation

Valid Common Lisp source files (e.g., ACL2's 28,000-line axioms.lisp) contain many comment blocks where quoted phrases wrap across multiple ; comment lines. These trigger false quote-danger errors, making parinfer unusable on these files.

In CL, ; comments end at the newline — a " inside one is just prose text. The existing quote_danger tracking was designed for languages where comment-embedded quotes might interact with the parser, but this doesn't apply to line comments in any language.

Changes

src/types.rs

  • Added line_comment_quotes: bool field to Options (serde default: true for backward compatibility)

src/parinfer.rs

  • Added line_comment_quotes_enabled: bool to State
  • In on_newline(): when leaving a line comment and line_comment_quotes_enabled is false, reset quote_danger to false

src/cli_options.rs

  • Added --line-comment-quotes / --no-line-comment-quotes as a YesNoDefaultOption
  • Language defaults: true for all languages except lisp (which defaults to false)
  • Wired through LanguageFeatures, Options, and both text and kakoune input paths
  • Added unit tests for the new option

Language defaults

Language line_comment_quotes
clojure true (unchanged)
guile true
hy true
janet true
lisp false
picolisp true
racket true
scheme true

The option can always be overridden explicitly:

  • --line-comment-quotes forces checking on (even for -l lisp)
  • --no-line-comment-quotes forces checking off (even for -l clojure)

Testing

  • All 34 existing tests pass (no regressions)
  • New unit tests cover language defaults and explicit flag overrides
  • Verified on ACL2 axioms.lisp (28,000+ lines) — processes successfully with -l lisp
  • Backward compatible: no behavior change for clojure or other languages

@eraserhd
Copy link
Owner

This approach defeats a mechanism that's there to prevent the Parinfer algorithm from corrupting the code, and the corruption can occur in Common Lisp as well as (AFAIK) every other lisp.

I'm not sure an option to disable this feature is the right thing. It may be that to safely edit files like this, you'll have to disable parinfer. In any case, the option wouldn't be language specific or have language-specific defaults.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unbalanced quotes in line comments cause false quote-danger errors for Common Lisp

2 participants