Parinfer for Clojure source — a pure-Java rewrite of parinferish 0.8.0 that is linear in the size of the file instead of quadratic.
repair is the whole library: source in, repaired source out.
(repair "(defn f [x]\n (inc x)" {:mode :indent})
;; => "(defn f [x]\n (inc x))"
parse returns the result object when you also want the errors or the exact
edits, and flatten takes the text back out of it.
Modes: :indent trusts the indentation and moves the delimiters, :paren
trusts the delimiters and moves the indentation, :smart uses indent mode for
the collections that start before the cursor (:cursor-line,
:cursor-column, both zero-based) and paren mode for the rest, and nil only
reads — it repairs nothing and just reports error.
A source whose strings do not terminate, or that ends a line on a backslash, comes back verbatim in every mode: a file this library cannot read is a file it must not rewrite.
Parinfer for Clojure source — a pure-Java rewrite of parinferish 0.8.0 that is
linear in the size of the file instead of quadratic.
`repair` is the whole library: source in, repaired source out.
(repair "(defn f [x]\n (inc x)" {:mode :indent})
;; => "(defn f [x]\n (inc x))"
`parse` returns the result object when you also want the errors or the exact
edits, and `flatten` takes the text back out of it.
Modes: `:indent` trusts the indentation and moves the delimiters, `:paren`
trusts the delimiters and moves the indentation, `:smart` uses indent mode for
the collections that start before the cursor (`:cursor-line`,
`:cursor-column`, both zero-based) and paren mode for the rest, and `nil` only
reads — it repairs nothing and just reports `error`.
A source whose strings do not terminate, or that ends a line on a backslash,
comes back verbatim in every mode: a file this library cannot read is a file
it must not rewrite.(changed? result)True when the repair changed anything.
True when the repair changed anything.
(edits result)What the repair did, in output order: maps of :action (:insert/:remove),
:offset, :line, :column (all zero-based, in the ORIGINAL source) and
:text.
What the repair did, in output order: maps of `:action` (`:insert`/`:remove`), `:offset`, `:line`, `:column` (all zero-based, in the ORIGINAL source) and `:text`.
(error result)The last problem the read found, or nil: "Unbalanced quote",
"Backslash at end of line", "Unmatched delimiter", "EOF while reading".
The last problem the read found, or nil: `"Unbalanced quote"`, `"Backslash at end of line"`, `"Unmatched delimiter"`, `"EOF while reading"`.
(flatten result)The repaired text of a parse result.
The repaired text of a `parse` result.
(parse source)(parse source {:keys [mode cursor-line cursor-column]})Reads source, applying the repair named by :mode. Returns a
com.blockether.parinferish.Parinfer$Result: flatten it for the text,
edits it for the changes, error it for the reason it could not read.
Reads `source`, applying the repair named by `:mode`. Returns a `com.blockether.parinferish.Parinfer$Result`: `flatten` it for the text, `edits` it for the changes, `error` it for the reason it could not read.
(repair source)(repair source opts)Repairs source and returns the text — (-> source (parse opts) flatten).
Repairs `source` and returns the text — `(-> source (parse opts) flatten)`.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |