Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var CurlyBraceReferenceRegexp = regexp.MustCompile(`\{([\pL\pS_][\pL\pN\pS_-]*(?:\.[\pL\pN\pS_][\pL\pN\pS_-]*)*)\}`)
CurlyBraceReferenceRegexp matches curly brace token references: {token.reference.path} Pattern requires valid token path: one or more identifier segments separated by dots Identifiers can contain Unicode letters, numbers, symbols (emojis), underscores, and hyphens \pL = Unicode letter, \pN = Unicode number, \pS = Unicode symbol (emojis) Examples: {color}, {color.primary}, {spacing.lg}, {emoji.🎨}, {unicode.café} Does NOT match JSON syntax like {"key": ...} because quotes/colons are not valid identifier chars
var JSONPointerReferenceRegexp = regexp.MustCompile(`"?\$ref"?\s*:\s*["']?(#[^"'\s]+)["']?`)
JSONPointerReferenceRegexp matches JSON Pointer references in both JSON and YAML: JSON: "$ref": "#/path/to/token" YAML: $ref: "#/path/to/token" or $ref: '#/path/to/token'
var RootKeywordRegexp = regexp.MustCompile(`"?\$root"?\s*:`)
RootKeywordRegexp matches $root keyword in token definitions (JSON and YAML): JSON: "$root": { ... } YAML: $root: { ... }
var SchemaFieldRegexp = regexp.MustCompile(`(?m)^\s*"?\$schema"?\s*:\s*["']([^"']+)["']`)
SchemaFieldRegexp matches the $schema field with its value in JSON and YAML Anchored to line start to match only top-level $schema declarations Captures the schema URL to avoid false positives from schema versions appearing elsewhere JSON: "$schema": "https://..." YAML: $schema: "https://..." or $schema: 'https://...'
Functions ¶
func NormalizeLineEndings ¶ added in v0.1.19
NormalizeLineEndings normalizes line endings to LF for consistent processing
Types ¶
type ReferenceType ¶
type ReferenceType int
ReferenceType indicates the type of reference
const ( // CurlyBraceReference is a {token.path} style reference (both schemas) CurlyBraceReference ReferenceType = iota // JSONPointerReference is a $ref field (2025.10 only) JSONPointerReference )
type TokenReferenceWithRange ¶ added in v0.1.19
type TokenReferenceWithRange struct {
// TokenName is the normalized token name (e.g., "color-primary")
TokenName string
// RawReference is the original reference text (e.g., "color.primary" or "#/color/primary")
RawReference string
// StartChar is the UTF-16 character offset of the reference start (within the line)
StartChar uint32
// EndChar is the UTF-16 character offset of the reference end (within the line)
EndChar uint32
// Line is the line number where the reference was found
Line uint32
// Type indicates whether this is a curly brace or JSON pointer reference
Type ReferenceType
}
TokenReferenceWithRange represents a token reference found in content with position info
func FindReferenceAtPosition ¶ added in v0.1.19
func FindReferenceAtPosition(content string, line, character uint32) *TokenReferenceWithRange
FindReferenceAtPosition finds a token reference at the given position in a JSON/YAML file. Returns the TokenReferenceWithRange if found, nil otherwise.