Documentation
¶
Index ¶
- func Format(source string, filename string, opts FormatOptions) (string, error)
- func FormatCheck(source string, filename string, opts FormatOptions) (bool, error)
- func ProcessSource(source string) string
- type Comment
- type CommentAttachment
- type CommentMap
- type FormatOptions
- type Preprocessor
- type Printer
- type PrinterWithComments
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Format ¶
func Format(source string, filename string, opts FormatOptions) (string, error)
Format formats Kukicha source code and returns the formatted result
func FormatCheck ¶
func FormatCheck(source string, filename string, opts FormatOptions) (bool, error)
FormatCheck checks if the source is already formatted Returns true if the source matches the formatted output
func ProcessSource ¶
ProcessSource is a convenience function to preprocess source code
Types ¶
type Comment ¶
type Comment struct {
Text string // The comment text including the # prefix
Line int // Line number where the comment appears
Column int // Column number where the comment starts
IsTrailing bool // True if comment is on same line as code
}
Comment represents a comment in the source code
func ExtractComments ¶
ExtractComments extracts all comment tokens from a token stream
type CommentAttachment ¶
type CommentAttachment struct {
Leading []Comment // Comments on lines immediately before the node
Trailing *Comment // Comment on same line after the node (optional)
}
CommentAttachment holds comments attached to an AST node
type CommentMap ¶
type CommentMap map[ast.Node]*CommentAttachment
CommentMap maps AST nodes to their attached comments
func AttachComments ¶
func AttachComments(comments []Comment, program *ast.Program) CommentMap
AttachComments attaches comments to AST nodes Comments are attached based on line proximity: - Leading comments: on lines immediately before the node (no blank lines between) - Trailing comments: on the same line as the node
type FormatOptions ¶
type FormatOptions struct {
// PreprocessGoStyle converts Go-style braces/semicolons to Kukicha style
PreprocessGoStyle bool
}
FormatOptions contains options for formatting
func DefaultOptions ¶
func DefaultOptions() FormatOptions
DefaultOptions returns the default formatting options
type Preprocessor ¶
type Preprocessor struct {
// contains filtered or unexported fields
}
Preprocessor converts Go-style syntax to Kukicha-style indentation
func NewPreprocessor ¶
func NewPreprocessor(source string) *Preprocessor
NewPreprocessor creates a new preprocessor
func (*Preprocessor) Process ¶
func (p *Preprocessor) Process() string
Process converts Go-style braces to Kukicha-style indentation It handles: - Lines ending with { -> remove brace, increase indent for following lines - Lines that are just } -> remove brace, decrease indent - Trailing semicolons -> remove - Struct/map literals are preserved (braces in expressions)
type Printer ¶
type Printer struct {
// contains filtered or unexported fields
}
Printer prints an AST as formatted Kukicha source code
type PrinterWithComments ¶
type PrinterWithComments struct {
*Printer
// contains filtered or unexported fields
}
PrinterWithComments extends the basic printer with comment support
func NewPrinterWithComments ¶
func NewPrinterWithComments(comments CommentMap) *PrinterWithComments
NewPrinterWithComments creates a printer that includes comments