Repository navigation
feat(regulations): parse the grammar, assign ids, merge and diff by structure - #111
Draft
lorenzocorallo wants to merge 2 commits into
Draft
lorenzocorallo wants to merge 2 commits into
lorenzocorallo wants to merge 2 commits into
Conversation
Contributor
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
lorenzocorallo
force-pushed
the
feat/regulations-latex
branch
from
November 2, 2026 19:38
b47283b to
f5e8279
Compare
…nd diff by structure A parser for the legal repository's grammar (\regolamento, the capo environment, \articolo, commi, lettere, \rif) that never fails: it builds the structure tree across \input files with numbers recomputed from order, and reports problems with positions. Missing or duplicate ids get edits that assign new ones. A 3-way merge per structure node (a comma is the smallest unit) merges different nodes automatically and reports the same node changed on both sides as a conflict to resolve. A structural diff classifies articles as added, removed, modified, moved or renumbered with word-level changes, and the delibera macros are set for emanation.
lorenzocorallo
force-pushed
the
feat/regulations-latex
branch
from
November 2, 2026 19:42
f5e8279 to
5fdbe7a
Compare
This was referenced Nov 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #110. The LaTeX layer of the regulations editor, as a pure library (
src/regulations/latex), against thegrammar the legal thread is publishing (
legal/docs/grammar.md,shared/polinetwork-regolamento.cls):\regolamento[id=…]{…}, the nestablecapoenvironment,\articolo[id=…]{…},commi/\comma[id=…],lettere/\lettera,\rif{id},\approvazione{direttivo|assemblea}{YYYY-MM-DD},\rettifica[delegato]{…}.parse.ts,document.ts): never throws. It builds one structure tree across\inputfiles: anincluded file's nodes join the tree where it is included, e.g. a capo included inside a regolamento. Numbers are
recomputed from order the way the class numbers headings: capi and articles share a counter at each level.
Issues carry file, line, column and UTF-16 offsets (the same units as CodeMirror and Y.Text): syntax (braces,
environments), structure (misplaced commands), ids (missing, invalid, duplicate), unknown
\rif, and commandsoutside the inline subset (warning).
ids.ts): 6-char base36 ids, generated by the system.idEditsgives the text edits that add missingids and replace invalid or duplicate ones (the later copy). The collab service applies them while people type.
merge.ts): per structure node keyed by id. A comma is the smallest unit and keeps its lettere.Different nodes merge automatically. The same node changed on both sides, or changed on one side and deleted on
the other, is a conflict, resolved with
ours,theirsor custom text. Parent and order merge too, so moves andinsertions land where they were made. A kept comma brings back its deleted parent, with a warning. Trailing
whitespace doesn't count as a change. Merging is refused while any side doesn't parse or lacks ids.
diff.ts,plain.ts): articles are added, removed, modified, moved (another parent, or outof order by LIS) or renumbered. Each change has a word-level diff of the plain text: commi are numbered, lettere
are
a), and\rifis shown as its current number. Changes to regolamenti, capi and free text are listed apart.delibera.ts): sets\approvazione, or adds or replaces\rettificain the entry preamble foremanation.
Tests
tests/regulations-latex.test.tsruns on a synthetic fixture: the backend repo is public and the RRI sources areprivate, so the RRI isn't committed here. With
REGULATIONS_LEGAL_DIRset to a clone ofPoliNetworkOrg/legal,it also checks the real RRI as converted by the legal thread: