chore(library/init/lean/parser/trie): add debug print
Also make sure it's in the prelude, whoops
This commit is contained in:
parent
5123148aa6
commit
203545ce99
3 changed files with 17 additions and 2 deletions
|
|
@ -9,6 +9,7 @@ prelude
|
|||
import init.lean.parser.parsec init.lean.parser.syntax init.lean.parser.rec
|
||||
import init.lean.parser.trie
|
||||
import init.lean.parser.identifier init.data.rbmap init.lean.message
|
||||
import init.control.coroutine
|
||||
|
||||
namespace lean
|
||||
namespace parser
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ Syntax-tree creating parser combinators
|
|||
-/
|
||||
prelude
|
||||
import init.lean.parser.basic
|
||||
import init.data.list.instances
|
||||
|
||||
namespace lean
|
||||
namespace parser
|
||||
|
|
|
|||
|
|
@ -5,7 +5,12 @@ Author: Sebastian Ullrich
|
|||
|
||||
Trie for tokenizing the Lean language
|
||||
-/
|
||||
namespace lean.parser
|
||||
prelude
|
||||
import init.data.rbmap
|
||||
import init.lean.format
|
||||
|
||||
namespace lean
|
||||
namespace parser
|
||||
|
||||
inductive trie (α : Type)
|
||||
| node : option α → rbnode (char × trie) → trie
|
||||
|
|
@ -44,6 +49,14 @@ private def match_prefix_aux : nat → trie α → string.iterator → option (s
|
|||
|
||||
def match_prefix {α : Type} (t : trie α) (it : string.iterator) : option (string.iterator × α) :=
|
||||
match_prefix_aux it.remaining t it none
|
||||
|
||||
private def to_string_aux {α : Type} : trie α → list format
|
||||
| (trie.node val map) := flip rbnode.fold map (λ ⟨c, t⟩ fs,
|
||||
to_format (repr c) :: (format.group $ format.nest 2 $ flip format.join_sep format.line $ to_string_aux t) :: fs) []
|
||||
|
||||
instance {α : Type} : has_to_string (trie α) :=
|
||||
⟨λ t, (flip format.join_sep format.line $ to_string_aux t).pretty 0⟩
|
||||
end trie
|
||||
|
||||
end lean.parser
|
||||
end parser
|
||||
end lean
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue