Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions Parser/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ variable [Parser.Stream σ τ] [Parser.Error ε σ τ] [Monad m]
This is a low-level parser to customize how the parser stream is used.
-/
@[inline]
def tokenCore (next? : σ → Option (τ × σ)) : ParserT ε σ τ m (ULift τ) := do
def tokenCore (next? : σ → Option (τ × σ)) : ParserT ε σ τ m τ := do
match next? (← getStream) with
| some (tok, stream) =>
let _ ← setStream stream
return tok
return tok
| none => throwUnexpected

/--
Expand All @@ -35,7 +35,7 @@ the unexpected token.
-/
@[specialize]
def tokenMap (test : τ → Option α) : ParserT ε σ τ m α := do
let tok ← tokenCore Stream.next?
let tok ← tokenCore Stream.next?
match test tok with
| some x => return x
| none => throwUnexpected tok
Expand Down Expand Up @@ -192,6 +192,7 @@ returned values of `p`. Consumes no input on error.
def takeManyN (n : Nat) (p : ParserT ε σ τ m α) : ParserT ε σ τ m (Array α) :=
withBacktracking do foldl Array.push (← take n p) p

set_option linter.checkUnivs false in
/--
`takeUntil stop p` parses zero or more occurrences of `p` until `stop` succeeds, and returns the
array of returned values of `p` and the output of `stop`. If `p` fails before `stop` is encountered,
Expand Down Expand Up @@ -245,14 +246,14 @@ all outputs.
-/
@[inline]
def dropMany1 (p : ParserT ε σ τ m α) : ParserT ε σ τ m PUnit :=
withBacktracking p *> foldl (Function.const α) () p
withBacktracking p *> foldl (Function.const α) PUnit.unit p

/--
`dropManyN n p` parses `n` or more occurrences of `p` until it fails, ignoring all outputs.
-/
@[inline]
def dropManyN (n : Nat) (p : ParserT ε σ τ m α) : ParserT ε σ τ m PUnit :=
withBacktracking do drop n p *> foldl (Function.const α) () p
withBacktracking do drop n p *> foldl (Function.const α) PUnit.unit p

/--
`dropUntil stop p` runs `p` until `stop` succeeds, returns the output of `stop` ignoring all
Expand Down
4 changes: 2 additions & 2 deletions Parser/Parser.lean
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public import Parser.Stream
public section

/-- Parser result type. -/
protected inductive Parser.Result.{u} (ε σ α : Type u) : Type u
protected inductive Parser.Result (ε σ α : Type _) : Type u
/-- Result: success! -/
| ok : σ → α → Parser.Result ε σ α
/-- Result: error! -/
Expand Down Expand Up @@ -156,7 +156,7 @@ def withBacktracking (p : ParserT ε σ τ m α) : ParserT ε σ τ m α := do
/--
`withCapture p` parses `p` and returns the output of `p` with the corresponding stream segment.
-/
def withCapture {ε σ α : Type _} [Parser.Stream σ τ] [Parser.Error ε σ τ] (p : ParserT ε σ τ m α) :
def withCapture (p : ParserT ε σ τ m α) :
ParserT ε σ τ m (α × Stream.Segment σ) := do
let startPos ← getPosition
let x ← p
Expand Down
4 changes: 2 additions & 2 deletions lake-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "git",
"subDir": null,
"scope": "",
"rev": "cec0a48936f58f4dd77b9fdff7cd09f32104480b",
"rev": "3b873385fdbca8b43ee1e3310bf282743091a14d",
"name": "UnicodeBasic",
"manifestFile": "lake-manifest.json",
"inputRev": "main",
Expand All @@ -15,7 +15,7 @@
"type": "git",
"subDir": null,
"scope": "",
"rev": "460b61adc7d183e43db2b99ac6c1dede9f7a76df",
"rev": "954dbc9873f3b4534dc9896604593406d0383520",
"name": "batteries",
"manifestFile": "lake-manifest.json",
"inputRev": "main",
Expand Down
1 change: 1 addition & 0 deletions lakefile.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name = "Parser"
defaultTargets = ["Parser"]
allowImportAll = true

[[require]]
name = "batteries"
Expand Down
2 changes: 1 addition & 1 deletion lean-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
leanprover/lean4:v4.31.0
leanprover/lean4:v4.32.0-rc1