Skip to content

comfit.Document

Incremental source document sharing compiled grammars with the calling thread.

Use create_document() to construct a session. A session snapshots the currently loaded languages. Dispose it explicitly or use it as a context manager.

Functions:

  • dispose – Release retained trees. Existing snapshots remain valid. Repeated calls are harmless.
  • highlight – Return an owned snapshot. Changes to source or rainbow options invalidate the cache.
  • update – Incrementally parse changed source, releasing the GIL. If the source is unchanged, do nothing.

Attributes:

comfit.Document.dispose

Python
dispose() -> None

Release retained trees. Existing snapshots remain valid. Repeated calls are harmless.

comfit.Document.highlight

Python
highlight(config: HighlightConfig | None = None) -> HighlightResult

Return an owned snapshot. Changes to source or rainbow options invalidate the cache.

comfit.Document.source

Python
source: str

comfit.Document.update

Python
update(source: str) -> None

Incrementally parse changed source, releasing the GIL. If the source is unchanged, do nothing.