Skip to documentation
SLOP

tiny.syn.span.model

Reference tiny.syn span model

Defined in span.

A scan produces marked byte ranges for one line, each with the role of the text it covers, and whether the marks of the line were kept.

API (4)

Types and contracts

Public types and contracts.

No direct callersNo direct callsspanmodel
Static calls · unresolved targets: unknown · external targets: unknown.

Source

Source: lib/syn/src/span/model.zig

zig
//! A scan produces marked byte ranges for one line, each with the role of the text it covers, and//! whether the marks of the line were kept. A renderer needs each range as offsets into the line//! and a role it can map to a color, and nothing more.//!//! The roles differ by language: code has keywords and types, a Lisp list has its head, TOML has//! tables, Markdown has headings, and a diff has added and removed lines.//!//! One list of roles (*span kind*) covers every scanner, so a renderer maps each role to a style//! once and every language can use it. A marked range (*span*) is a plain value of two byte offsets//! and a role, with no pointer into the text. A scan of one line reports whether the storage kept//! the line's marks or discarded them (*materialization*), and a line that does not fit the storage//! reports that they were discarded.//!//! - *text limit*: the longest line, in bytes, whose marks the storage keeps//! - *span storage*: the caller's buffer that receives one line's marks//! - *continuation state*: what one line leaves open for the next line/// The role of the text one span covers. A renderer switches on this role to pick a color or style/// for each span. Thirty-one roles serve every scanner, and each scanner uses the roles that fit/// its languages. The package attaches no color or style to any role.pub const Kind = enum {    /// A reserved word of the language, such as `if`, `return` or `const`, or a CSS rule that    /// starts with `@`, such as `@media`.    keyword,    /// A built-in type name, such as `u8`, `int` or `String`, marked by the generic scanner.    type,    /// A name followed by an opening parenthesis, marked by the generic scanner.    function,    /// A shell, PHP or Perl variable such as `$HOME`, or a Rust lifetime such as `'a`.    variable,    /// A name after a dot in code, a CSS property name inside a rule, or a command-line option such    /// as `--help` in shell.    property,    /// A quoted string, including a Python or TOML triple-quoted string that runs over more than    /// one line.    string,    /// A numeric literal, including hexadecimal and exponent forms, and a CSS number with its unit,    /// such as `1rem`.    number,    /// A named constant value, such as `true`, `false`, `null` or `None`.    literal,    /// A comment: a line comment to the end of the line, or a block comment up to its closing    /// delimiter, which can run over more than one line.    comment,    /// A bracket, brace, comma, colon, semicolon or dot, or an angle bracket around a markup tag.    punctuation,    /// A run of operator characters, such as `=`, `+=` or `->`, marked by the generic scanner.    operator,    /// An annotation such as `@Override` in Java, C#, Kotlin, Scala or Dart, or a Python decorator.    decorator,    /// A parenthesis in Lisp or Clojure code.    delimiter,    /// The first symbol after an opening parenthesis in Lisp or Clojure code, the position of the    /// operator in a list.    head,    /// A key in JSON or YAML before a colon, or a key in TOML before an equals sign.    key,    /// A TOML table header, such as `[server]`.    table,    /// A TOML date or date and time.    date,    /// A YAML anchor or alias, such as `&base` or `*base`.    anchor,    /// An element name in HTML, XML, Vue or Svelte, or a YAML tag such as `!!str`.    tag,    /// An attribute name inside a markup tag.    attribute,    /// A CSS name outside the property position of a rule, which covers selectors and also property    /// values.    selector,    /// The text of a Markdown heading after its `#` marks.    heading,    /// A Markdown structure mark: the `#` run of a heading, a `>` quote mark, or a list bullet or    /// number.    marker,    /// Markdown emphasis or strong emphasis, delimiters included, such as `*word*` or `__word__`.    emphasis,    /// Markdown strikethrough between `~~` marks.    strike,    /// Markdown inline code between backticks.    code,    /// A Markdown inline link, from its `[` through the `)` that closes its address.    link,    /// A whole diff header line, such as one starting with `diff `, `index `, `--- `, `+++ ` or    /// `rename from `.    header,    /// A whole diff hunk line, starting with `@@`.    hunk,    /// A whole diff line starting with `+`, other than a `+++ ` header.    addition,    /// A whole diff line starting with `-`, other than a `--- ` header.    deletion,};/// One marked byte range of a line and its role. A renderer reads the spans of a line from/// `Storage.items` and styles each byte range. The spans of one line come in order and never/// overlap or have zero length. Touching spans of the same kind are merged into one. Bytes that no/// span covers carry no role.pub const Span = struct {    /// The offset of the first covered byte, counted from the start of the line passed to the scan.    start: usize,    /// The offset one past the last covered byte, so `text[span.start..span.end]` is the covered    /// text. The offset is always greater than `start` and at most the length of the line.    end: usize,    /// The role of the covered text.    kind: Kind,};/// What happened to the spans of one line. A caller checks it after each call to know whether the/// storage holds the spans of the line. Both outcomes leave the continuation state exact.pub const Materialization = enum {    /// The line fit within the text limit, and the storage holds its spans.    complete,    /// The line was longer than the text limit, and the storage holds no spans for it. The line was    /// still scanned in full, and the storage added one to its count of discarded lines.    discarded,};/// The one error that span storage raises when a line is too long to keep:/// `MaterializationCapacityExceeded`. `Storage.prepare` returns it for a line that is too long, and/// `highlight` and `highlightLine` catch it and return `.discarded`, so their callers never receive/// it. The repository's allocation check requires a storage type of this shape to name such an/// error.pub const Exhaustion = error{MaterializationCapacityExceeded};

Source: lib/syn/src/span/root.zig:10

zig
pub const model = @import("model.zig");

Audit

Definitions2
Public names2
Members1
Version26.7.0
Revisiondaab053ee433