(sigil format)
(sigil format) - Code Formatter with Paren Inference
This library provides code formatting for Sigil with the ability to infer missing parentheses from indentation patterns.
Key insight: In Lisp, indentation encodes programmer intent. When indentation decreases, it signals that forms should close. Using 2-space convention: column 0 = depth 0, column 2 = depth 1, etc.
Example: (format-file "broken.msc") ; → <format-result> (format-string "(define (foo" "test.msc") ; → <format-result>
Exports
format-resultprocedureConstruct a format-result struct.
format-result?procedureTest if a value is a format-result struct.
format-result-fileprocedureGet the file field of a format-result struct.
format-result-successprocedureGet the success field of a format-result struct.
format-result-outputprocedureGet the output field of a format-result struct.
format-result-errorsprocedureGet the errors field of a format-result struct.
format-result-warningsprocedureGet the warnings field of a format-result struct.
format-result-inferencesprocedureGet the inferences field of a format-result struct.
%format-error--typevariableGet the inferences field of a format-result struct.
format-errorprocedureConstruct a format-error struct.
format-error?procedureTest if a value is a format-error struct.
format-error-lineprocedureGet the line field of a format-error struct.
format-error-columnprocedureGet the column field of a format-error struct.
format-error-messageprocedureGet the message field of a format-error struct.
format-error-codeprocedureGet the code field of a format-error struct.
%format-warning--typevariableGet the code field of a format-error struct.
format-warningprocedureConstruct a format-warning struct.
format-warning?procedureTest if a value is a format-warning struct.
format-warning-lineprocedureGet the line field of a format-warning struct.
format-warning-columnprocedureGet the column field of a format-warning struct.
format-warning-messageprocedureGet the message field of a format-warning struct.
format-warning-codeprocedureGet the code field of a format-warning struct.
%paren-inference--typevariableGet the code field of a format-warning struct.
paren-inferenceprocedureConstruct a paren-inference struct.
paren-inference?procedureTest if a value is a paren-inference struct.
paren-inference-lineprocedureGet the line field of a paren-inference struct.
paren-inference-columnprocedureGet the column field of a paren-inference struct.
paren-inference-typeprocedureGet the type field of a paren-inference struct.
paren-inference-confidenceprocedureGet the confidence field of a paren-inference struct.
paren-inference-reasonprocedureGet the reason field of a paren-inference struct.
token?procedureCheck if value is a token
token-typeprocedureToken type accessor
token-startprocedureToken start position accessor
token-endprocedureToken end position accessor
token-lineprocedureToken line accessor
token-columnprocedureToken column accessor
token-indentprocedureToken indent accessor
token-valueprocedureExtract the text value of a token from the source chars vector
tokenize-result-charsprocedureGet the chars vector from a tokenize result
tokenize-result-tokensprocedureGet the token list from a tokenize result
char-whitespace?procedureCheck if character is whitespace
char-digit?procedureCheck if character is a digit
delimiter?procedureCheck if character is a delimiter
looks-like-number?procedureCheck if string looks like a number
tokenizeprocedureTokenize entire source into a list of tokens Returns (cons chars tokens) where chars is the source as a vector
analyze-and-inferprocedureAnalyze tokens and infer missing parens
special-formsvariableSpecial forms that have specific indentation rules
special-form?procedureCheck if symbol is a special form
make-inference-mapprocedureBuild map of line -> inferences
make-removal-setprocedureBuild a set of tokens to remove (by line:column key)
should-remove?procedureCheck if a token should be removed
pretty-print-tokensprocedurePretty print tokens to string
format-result->stringprocedureFormat result as human-readable string
verify-syntaxprocedureTry to read a string as Scheme code to verify it's valid Returns #t if valid, #f if parse error
format-stringprocedureFormat a string of source code
format-fileprocedureFormat a file