From 1611c10388973b411eb197f1a59d06d2a02d43d7 Mon Sep 17 00:00:00 2001 From: Panos Vagenas Date: Thu, 13 Aug 2026 11:32:52 +0200 Subject: [PATCH] expose DocLang special-token vocabulary for tokenizer integration - Add doclang.tokenization.get_special_tokens(), a spec.md-derived list of special tokens ready to plug into any tokenizer's added-tokens API - Drop / from spec.md's Token vocabulary table: it contradicted the custom-vocabulary namespacing guidance stated a few paragraphs earlier, and a properly namespaced example already exists elsewhere in the spec - Test the vocabulary against spec.md's own table so the two can't drift Signed-off-by: Panos Vagenas --- doclang/__init__.py | 2 + doclang/tokenization.py | 128 +++++++++++++++++++++++++++++++++++++ spec.md | 2 - tests/test_tokenization.py | 46 +++++++++++++ 4 files changed, 176 insertions(+), 2 deletions(-) create mode 100644 doclang/tokenization.py create mode 100644 tests/test_tokenization.py diff --git a/doclang/__init__.py b/doclang/__init__.py index 611bd2f..edcc478 100644 --- a/doclang/__init__.py +++ b/doclang/__init__.py @@ -2,6 +2,7 @@ from doclang.packaging import PackagingError, pack from doclang.schematron import SchematronBackendNotFound, SchematronValidator, SchematronViolation +from doclang.tokenization import get_special_tokens from doclang.validation import ValidationError, validate __all__ = [ @@ -10,6 +11,7 @@ "SchematronValidator", "SchematronViolation", "ValidationError", + "get_special_tokens", "pack", "validate", ] diff --git a/doclang/tokenization.py b/doclang/tokenization.py new file mode 100644 index 0000000..81d603a --- /dev/null +++ b/doclang/tokenization.py @@ -0,0 +1,128 @@ +"""DocLang special-token vocabulary, per spec.md's (non-normative) "Token vocabulary" recommendation.""" + +from __future__ import annotations + +DEFAULT_MAX_RESOLUTION = 512 + +_HEADING_LEVELS = range(2, 7) +_FIELD_HEADING_LEVELS = range(2, 7) + +_FIXED_TOKENS: tuple[str, ...] = ( + "", + "", + "", + '"/>', + "", + "", + "", + *(f'' for level in _HEADING_LEVELS), + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + '', + "", + "", + "
", + "", + "", + "", + "", + '