[wadler] Cons has a list of documents in it
I think I want to start thinking about "leftmost" and "rightmost" and it's just easier and faster if cons has an actual list in it instead of dotted pairs.
This commit is contained in:
parent
d5ccd5b147
commit
9d55588a35
3 changed files with 38 additions and 28 deletions
|
|
@ -11,8 +11,6 @@ from parser.parser import (
|
|||
alt,
|
||||
indent,
|
||||
seq,
|
||||
Rule,
|
||||
Assoc,
|
||||
sp,
|
||||
nl,
|
||||
br,
|
||||
|
|
@ -129,9 +127,14 @@ def flatten_document(doc: wadler.Document, src: str) -> list:
|
|||
case wadler.Lazy():
|
||||
return flatten_document(doc.resolve(), src)
|
||||
case wadler.Cons():
|
||||
return flatten_document(doc.left, src) + flatten_document(doc.right, src)
|
||||
result = []
|
||||
for d in doc.docs:
|
||||
result += flatten_document(d, src)
|
||||
return result
|
||||
case None:
|
||||
return []
|
||||
case wadler.Marker():
|
||||
return [f"<marker {repr(doc.meta)}>", flatten_document(doc.child, src)]
|
||||
case _:
|
||||
typing.assert_never(doc)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue