Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 114f8ef

Browse files
committed
chore(data/buffer/parser/numeral): derive mono for numeral (#5463)
Thanks to Rob Lewis, using classes, instances, and the `delta_instance_handler`, transferring over instances becomes very easy. Co-authored-by: Yakov Pechersky <pechersky@users.noreply.github.com>
1 parent e5c7789 commit 114f8ef

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/data/buffer/parser/numeral.lean

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Yakov Pechersky
55
-/
66
import data.fintype.card
7+
import data.buffer.parser.basic
78

89
/-!
910
# Numeral parsers
@@ -43,15 +44,15 @@ variables (α : Type) [has_zero α] [has_one α] [has_add α]
4344
/--
4445
Parse a string of digits as a numeral while casting it to target type `α`.
4546
-/
46-
def numeral : parser α :=
47+
@[derive mono] def numeral : parser α :=
4748
nat.bin_cast <$> nat
4849

4950
/--
5051
Parse a string of digits as a numeral while casting it to target type `α`,
5152
which has a `[fintype α]` constraint. The parser ensures that the numeral parsed in
5253
is within the cardinality of the type `α`.
5354
-/
54-
def numeral.of_fintype [fintype α] : parser α :=
55+
@[derive mono] def numeral.of_fintype [fintype α] : parser α :=
5556
do
5657
c ← nat,
5758
decorate_error (sformat!"<numeral less than {to_string (fintype.card α)}>")
@@ -62,7 +63,7 @@ do
6263
Parse a string of digits as a numeral while casting it to target type `α`. The parsing starts
6364
at "1", so `"1"` is parsed in as `nat.cast 0`. Providing `"0"` to the parser causes a failure.
6465
-/
65-
def numeral.from_one : parser α :=
66+
@[derive mono] def numeral.from_one : parser α :=
6667
do
6768
c ← nat,
6869
decorate_error ("<positive numeral>")
@@ -75,7 +76,7 @@ which has a `[fintype α]` constraint. The parser ensures that the numeral parse
7576
is within the cardinality of the type `α`. The parsing starts
7677
at "1", so `"1"` is parsed in as `nat.cast 0`. Providing `"0"` to the parser causes a failure.
7778
-/
78-
def numeral.from_one.of_fintype [fintype α] : parser α :=
79+
@[derive mono] def numeral.from_one.of_fintype [fintype α] : parser α :=
7980
do
8081
c ← nat,
8182
decorate_error (sformat!"<positive numeral less than or equal to {to_string (fintype.card α)}>")
@@ -87,7 +88,7 @@ Parse a character as a numeral while casting it to target type `α`,
8788
The parser ensures that the character parsed in is within the bounds set by `fromc` and `toc`,
8889
and subtracts the value of `fromc` from the parsed in character.
8990
-/
90-
def numeral.char (fromc toc : char) : parser α :=
91+
@[derive mono] def numeral.char (fromc toc : char) : parser α :=
9192
do
9293
c ← decorate_error
9394
(sformat!"<char between '{fromc.to_string}' to '{toc.to_string}' inclusively>")
@@ -101,7 +102,7 @@ The parser ensures that the character parsed in is greater or equal to `fromc` a
101102
and subtracts the value of `fromc` from the parsed in character. There is also a check
102103
that the resulting value is within the cardinality of the type `α`.
103104
-/
104-
def numeral.char.of_fintype [fintype α] (fromc : char) : parser α :=
105+
@[derive mono] def numeral.char.of_fintype [fintype α] (fromc : char) : parser α :=
105106
do
106107
c ← decorate_error
107108
(sformat!"<char from '{fromc.to_string}' to '{

0 commit comments

Comments
 (0)