syntax

package
v0.20.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2026 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package syntax is a tiny, dependency-free syntax highlighter for the TUI previews. It tokenises source into per-line coloured Spans; the caller maps each Span's Kind to a terminal colour.

Rather than hand-roll a Go lexer (or pull in a heavyweight highlighter such as github.com/alecthomas/chroma, whose transitive deps would break this repo's dependency-free axiom), the Go path reuses the standard library's go/scanner -- the canonical Go tokeniser, zero extra dependencies. Markdown and the plain fallback are trivial line passes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Highlight

func Highlight(code, filename string) [][]Span

Highlight tokenises code and returns one []Span per line (split on "\n"). The language is chosen from filename's extension; unknown extensions fall back to a single Plain span per line.

Types

type Kind

type Kind int

Kind categorises a run of source text.

const (
	// Plain is uncoloured text (identifiers, whitespace, operators left in the
	// foreground colour).
	Plain Kind = iota
	// Keyword is a language keyword (Go's `func`; a Markdown heading line).
	Keyword
	// String is a string / rune / raw-string literal.
	String
	// Comment is a line or block comment.
	Comment
	// Number is a numeric literal.
	Number
	// Type is a predeclared type name (int, string, …).
	Type
	// Func is an identifier used as a call (immediately followed by "(").
	Func
	// Punct is a bracket / operator / separator.
	Punct
)

type Span

type Span struct {
	Text string
	Kind Kind
}

Span is a run of text sharing a single Kind.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL