Open shaunlebron opened 1 year ago
Rough plan:
For example, I built a minimal auto-formatting tool for Clojure as a set of callbacks to Parinfer’s reader here:
https://github.com/parinfer/parindent/blob/gh-pages/read.js
This reader takes a hooks
object of callbacks— each triggered at certain times when reading:
onInitState
onInitLine
onOpener
onIndent
onFinalState
This might help me think more generally about what Parinfer needs to do and when.
featureFlags
or dialect
optionIf it is tractable, all featureFlags
may be built into one reader, with combination presets supported with a dialect
option.
These feature flags may create more possibilities for unintended changes to strings or comments. (e.g. ERROR_QUOTE_DANGER
)
The crux of the issue I believe is how non-directional delimiters like "
(and now |
) can be reversed while the document is being edited— i.e. a character can suddenly switch from meaning “open” to “close” if one is typed behind it. And rather than it becoming imbalanced (thus suspending Parinfer), the newly opened delimiter can become closed by another character— accidentally entering into a valid but unintended “inside-out” state, erroneously allowing Parinfer to run and make changes to non-structural parts of the code.
We can use onecompiler.com to test Racket and Common Lisp:
https://onecompiler.com/racket/3xjvghuay https://onecompiler.com/commonlisp/3xjvgwzbj
Parinfer is a lazy, partial reader— allowing it the opportunity to ignore most irrelevant differences between dialects, but it needs to support more specific dialect features
Parinfer assumes Clojure-like syntax— blowing past characters presumed to have no effect on parens and indentation. This allows some flexibility with other dialects, but eventually causes problems with other language features below:
See issues:
172
195
197
Some dialects we look at:
Here-strings
strings delimited by custom phrases
#<<FOO\n ... \nFOO>>\n
doc-racket-here#[FOO[ ... ]FOO]
doc-hy-hereMulti-line strings
`
or``
doc-janet-multiNestable block comments
may be nested, unlike in C
/*.../*...*/...*/
)#|...|#
doc-racket-block#|...|#
doc-cl-block#{...}#
doc-pico-blockBracket types
(
)
are significant— allowing unbalanced{
[
in symbols doc-cl-bracketComment lines
# ...
doc-janet-commentComment forms
A preceding
#
can re-interpret the usual;
comment as commenting the next form instead of to the end of line:#; ...
doc-racket-comment-form and R6RS SchemeLiteral symbols
pipes
|...|
allow special characters inside symbols. Sometimes\|
is allowed inside (CL, not Racket):|foo;bar(baz|
orfoo|;|bar|(|baz
doc-racket-pipe, doc-racket-pipe-sym|foo;\|bar(baz|
doc-cl-pipe