WIP: Replace Laurel DDM grammar with bidirectional parser combinators#8
WIP: Replace Laurel DDM grammar with bidirectional parser combinators#8keyboardDrummer-bot wants to merge 2 commits intomainfrom
Conversation
- Strata/Util/Syntax.lean: Bidirectional parser combinator library based on Rendel & Ostermann (2010). Provides Iso, Syntax, and combinators for sequencing, alternation, mapping, repetition, and separated lists. Both parse and print directions are defined together. - Strata/Languages/Laurel/Grammar/CombinatorGrammar.lean: Laurel grammar defined using the combinator library. Covers types, expressions with precedence climbing, procedures, composites, constrained types, and datatypes. Still has compilation errors to resolve (mutual recursion between expression parsers, String API compatibility).
|
For mutual recursion, please allow naming grammars and referring to named grammars. The mapping from names to grammar can occur at a top level, so we get a Please continue with next steps |
- Add GrammarLibrary, ref combinator to Syntax.lean for named grammar mutual recursion - Add Nonempty instances for Syntax and GrammarLibrary to support partial defs - Restructure CombinatorGrammar.lean to use GrammarLibrary for the atom/postfix/prec0 mutual recursion cycle - Fix highTypeSyntax self-recursion (partial def with Unit parameter) - Fix String.Slice deprecation warnings in tryParseBinOp - Fix Inhabited Parameter issue by replacing head! with pattern matching - Fix decimal literal Int/Nat coercion
|
I've pushed a commit that fixes the mutual recursion issue and all compilation errors. Here's a summary: Changes to
|
|
The mutual recursion issue is now fixed. Here's a summary of what was done in commit 5ebdbe5:
Both files compile successfully. Next steps from the PR description:
For step 2: |
Closes #6
Summary
This PR implements a bidirectional parser combinator library and uses it to define the Laurel grammar, as described in Rendel & Ostermann (2010).
Files
Strata/Util/Syntax.lean— Combinator library ✅ buildsIso a b— partial isomorphisms (the key abstraction from the paper)Syntax a— bidirectional syntax descriptors with bothparseandprintpure,seq,map,alttext,keyword,token,skipWsAndCommentsnat,int,decimal,ident,stringLitmany,sepBy1,sepBy,optionalseqLeft,seqRight,runParse,runPrintStrata/Languages/Laurel/Grammar/CombinatorGrammar.lean— Laurel grammar 🚧 WIPint,bool,real,float64,string,Map, user-defined,Core)if/then/else,while,for,var,assert,assume,return,exit, blocksforall,existswith optional triggersparseLaurelString : String → Option Laurel.ProgramprintLaurelProgram : Laurel.Program → Option StringStatus
The combinator library (
Syntax.lean) compiles successfully. The grammar file has compilation errors to resolve:partial+whereclauses don't support the pattern needed. Need to restructure using a singlepartial defwith explicit dispatch, or useSyntaxvalues stored in a mutable reference.String.dropreturnString.Slicein Lean 4.27 and need.toStringcalls.Next steps
CombinatorGrammar.leanTestExamples.lean(replacing the DDM pipeline)StrataTest/Languages/Laurelpass