Skip to content

feat(Parsing): add the chapter from CSwFP/9.1–9.2 - #45

Open
arademaker wants to merge 1 commit into
mainfrom
feat/parsing
Open

arademaker wants to merge 1 commit into
mainfrom
feat/parsing

Conversation

@arademaker

Copy link
Copy Markdown
Member

Adds the Parsing chapter, ported from CSwFP/9 (CSwFP/8 is skipped for now). Only 9.1 and 9.2 are written, terse first; the full text is marked with :::dev BeforeNextRelease TODOs.

  • 9.1: ParseTree, positions, and the tree relations as lists of pairs; exercises 9.1–9.5.
  • 9.2: recognition and parsing of palindromes by splitting, with partial def; agreement with Mathlib's List.Palindrome checked up to length 6 by native_decide; exercise 9.6 (9.7 is absorbed into the cue on partial def).
  • CSwFP.yaml, DEVIATIONS.md, STYLE-CODE.md and check-cswfp.py are updated.

Conflicts with the Composition pull request in Book.lean, CSwFP.yaml, DEVIATIONS.md, STYLE-CODE.md and check-cswfp.py; they will be resolved by merging main here once that one is in, with Parsing placed after Composition.

🤖 Generated with Claude Code

https://claude.ai/code/session_01UFZtiDzfskeJTJ2ntCt2vh

Start the parsing chapter with CSwFP 9.1 and 9.2, skipping CSwFP 8.
Parse trees carry positions and the tree relations of dominance,
sisterhood, c-command and precedence, as lists of pairs. Recognition
and parsing by splitting the input are shown on the palindrome
grammar, with `partial def`, and checked against Mathlib's
`List.Palindrome` up to length 6. Exercises 9.1-9.6 are ported; 9.7
goes into the cue on `partial def`.

Claude Code (Opus 5.5) drafted these changes and this message under
the author's direction; the author reviewed them.
Copilot AI balanced review requested due to automatic review settings October 30, 2026 03:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The split helpers mishandle unary and zero-piece cases, tree output uses incorrect brackets, and the left-recursion guidance omits a necessary guard.

5 open issues
What changed in this PR

Adds the first two sections of the Parsing chapter, bringing parse-tree relations and palindrome recognition into the Lean textbook. The chapter is written for the terse variant first, with full-prose translations left as explicit TODOs.

Changes:

  • Introduces parse trees, positions, tree relations, and exercises.
  • Adds splitting-based recognition and parsing, with a bounded check against Mathlib’s palindrome predicate.
  • Integrates the chapter into the book and updates coverage tracking and style documentation.
File Description
STYLE-CODE.md Records newly introduced Lean features.
scripts/​check-cswfp.py Adds the exercise count for CSwFP chapter 9.
README.md Marks Parsing as partially implemented.
DEVIATIONS.md Documents adaptations and omitted material.
CSwL/​Parsing/​Recognition.lean Adds palindrome recognition, parsing, generation, and splitting exercises.
CSwL/​Parsing/​ParseTrees.lean Defines trees, position relations, and related exercises.
CSwL/​Parsing.lean Assembles the chapter and records remaining plans.
CSwFP.yaml Maps chapter 9 sections and exercises to the port.
Book.lean Imports and includes the Parsing chapter.

Review effort: Balanced

| .leaf a => toString a
| .branch b ts =>
"[." ++ toString b ++ " " ++
toString (ts.map toText) ++ "]"
#eval split2 "Jan".toList

def splitN {α : Type} : Nat → List α → List (List (List α))
| 0, _ | 1, _ => []
(x :: us, vs))

def splitN' {α : Type} : Nat → List α → List (List (List α))
| 0, _ | 1, _ => []
Comment thread CSwL/Parsing.lean
#doc (Manual) "Análise sintática" =>
%%%
tag := "Parsing"
htmlSplit := .never
Comment on lines +68 to +70
- Ela termina: `ys` tem dois elementos a menos. Uma regra recursiva à
esquerda, V → V T, também não seria problema, porque V recebe um pedaço
menor da entrada, desde que o pedaço de T não seja vazio.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants