sigildocs

(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-resultprocedure

Construct a format-result struct.

Test if a value is a format-result struct.

Get the file field of a format-result struct.

Get the success field of a format-result struct.

Get the output field of a format-result struct.

Get the errors field of a format-result struct.

Get the warnings field of a format-result struct.

Get the inferences field of a format-result struct.

Get the inferences field of a format-result struct.

format-errorprocedure

Construct a format-error struct.

format-error?procedure

Test if a value is a format-error struct.

Get the line field of a format-error struct.

Get the column field of a format-error struct.

Get the message field of a format-error struct.

Get the code field of a format-error struct.

Get the code field of a format-error struct.

Construct a format-warning struct.

Test if a value is a format-warning struct.

Get the line field of a format-warning struct.

Get the column field of a format-warning struct.

Get the message field of a format-warning struct.

Get the code field of a format-warning struct.

Get the code field of a format-warning struct.

Construct a paren-inference struct.

Test if a value is a paren-inference struct.

Get the line field of a paren-inference struct.

Get the column field of a paren-inference struct.

Get the type field of a paren-inference struct.

Get the confidence field of a paren-inference struct.

Get the reason field of a paren-inference struct.

token?procedure

Check if value is a token

token-typeprocedure

Token type accessor

token-startprocedure

Token start position accessor

token-endprocedure

Token end position accessor

token-lineprocedure

Token line accessor

token-columnprocedure

Token column accessor

token-indentprocedure

Token indent accessor

token-valueprocedure

Extract the text value of a token from the source chars vector

Get the chars vector from a tokenize result

Get the token list from a tokenize result

Check if character is whitespace

char-digit?procedure

Check if character is a digit

delimiter?procedure

Check if character is a delimiter

Check if string looks like a number

tokenizeprocedure

Tokenize entire source into a list of tokens Returns (cons chars tokens) where chars is the source as a vector

Analyze tokens and infer missing parens

Special forms that have specific indentation rules

special-form?procedure

Check if symbol is a special form

Build map of line -> inferences

Build a set of tokens to remove (by line:column key)

Check if a token should be removed

Pretty print tokens to string

Format result as human-readable string

verify-syntaxprocedure

Try to read a string as Scheme code to verify it's valid Returns #t if valid, #f if parse error

format-stringprocedure

Format a string of source code

format-fileprocedure

Format a file