Skip to content

Commit c8d9c2f

Browse files
committed
Get started
1 parent 7d55c03 commit c8d9c2f

File tree

9 files changed

+353
-347
lines changed

9 files changed

+353
-347
lines changed

src/Init/Core.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1605,7 +1605,7 @@ gen_injective_theorems% PSigma
16051605
gen_injective_theorems% PSum
16061606
gen_injective_theorems% Sigma
16071607
gen_injective_theorems% String
1608-
gen_injective_theorems% String.Pos
1608+
gen_injective_theorems% String.Pos.Raw
16091609
gen_injective_theorems% Substring
16101610
gen_injective_theorems% Subtype
16111611
gen_injective_theorems% Sum

src/Init/Data/Repr.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ def String.quote (s : String) : String :=
411411
instance : Repr String where
412412
reprPrec s _ := s.quote
413413

414-
instance : Repr String.Pos where
414+
instance : Repr String.Pos.Raw where
415415
reprPrec p _ := "{ byteIdx := " ++ repr p.byteIdx ++ " }"
416416

417417
instance : Repr Substring where

src/Init/Data/String/Basic.lean

Lines changed: 290 additions & 290 deletions
Large diffs are not rendered by default.

src/Init/Data/String/Bootstrap.lean

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ public section
1414

1515
namespace String
1616

17-
instance : OfNat String.Pos (nat_lit 0) where
17+
@[deprecated Pos.Raw (since := "2025-09-30")]
18+
abbrev Pos := Pos.Raw
19+
20+
instance : OfNat String.Pos.Raw (nat_lit 0) where
1821
ofNat := {}
1922

2023
instance : Inhabited String where
@@ -57,13 +60,13 @@ end String
5760
namespace String.Internal
5861

5962
@[extern "lean_string_posof"]
60-
opaque posOf (s : String) (c : Char) : Pos
63+
opaque posOf (s : String) (c : Char) : Pos.Raw
6164

6265
@[extern "lean_string_offsetofpos"]
63-
opaque offsetOfPos (s : String) (pos : Pos) : Nat
66+
opaque offsetOfPos (s : String) (pos : Pos.Raw) : Nat
6467

6568
@[extern "lean_string_utf8_extract"]
66-
opaque extract : (@& String) → (@& Pos) → (@& Pos) → String
69+
opaque extract : (@& String) → (@& Pos.Raw) → (@& Pos.Raw) → String
6770

6871
@[extern "lean_string_length"]
6972
opaque length : (@& String) → Nat
@@ -75,7 +78,7 @@ opaque pushn (s : String) (c : Char) (n : Nat) : String
7578
opaque append : String → (@& String) → String
7679

7780
@[extern "lean_string_utf8_next"]
78-
opaque next (s : @& String) (p : @& Pos) : Pos
81+
opaque next (s : @& String) (p : @& Pos.Raw) : Pos.Raw
7982

8083
@[extern "lean_string_isempty"]
8184
opaque isEmpty (s : String) : Bool
@@ -93,16 +96,16 @@ opaque any (s : String) (p : Char → Bool) : Bool
9396
opaque contains (s : String) (c : Char) : Bool
9497

9598
@[extern "lean_string_utf8_get"]
96-
opaque get (s : @& String) (p : @& Pos) : Char
99+
opaque get (s : @& String) (p : @& Pos.Raw) : Char
97100

98101
@[extern "lean_string_capitalize"]
99102
opaque capitalize (s : String) : String
100103

101104
@[extern "lean_string_utf8_at_end"]
102-
opaque atEnd : (@& String) → (@& Pos) → Bool
105+
opaque atEnd : (@& String) → (@& Pos.Raw) → Bool
103106

104107
@[extern "lean_string_nextwhile"]
105-
opaque nextWhile (s : String) (p : Char → Bool) (i : String.Pos) : String.Pos
108+
opaque nextWhile (s : String) (p : Char → Bool) (i : String.Pos.Raw) : String.Pos.Raw
106109

107110
@[extern "lean_string_trim"]
108111
opaque trim (s : String) : String
@@ -160,7 +163,7 @@ opaque front (s : Substring) : Char
160163
opaque takeWhile : Substring → (Char → Bool) → Substring
161164

162165
@[extern "lean_substring_extract"]
163-
opaque extract : Substring → String.Pos → String.Pos → Substring
166+
opaque extract : Substring → String.Pos.Raw → String.Pos.Raw → Substring
164167

165168
@[extern "lean_substring_all"]
166169
opaque all (s : Substring) (p : Char → Bool) : Bool
@@ -172,22 +175,22 @@ opaque beq (ss1 ss2 : Substring) : Bool
172175
opaque isEmpty (ss : Substring) : Bool
173176

174177
@[extern "lean_substring_get"]
175-
opaque get : Substring → String.Pos → Char
178+
opaque get : Substring → String.Pos.Raw → Char
176179

177180
@[extern "lean_substring_prev"]
178-
opaque prev : Substring → String.Pos → String.Pos
181+
opaque prev : Substring → String.Pos.Raw → String.Pos.Raw
179182

180183
end Substring.Internal
181184

182-
namespace String.Pos.Internal
185+
namespace String.Pos.Raw.Internal
183186

184187
@[extern "lean_string_pos_sub"]
185-
opaque sub : String.Pos → String.Pos → String.Pos
188+
opaque sub : String.Pos.Raw → String.Pos.Raw → String.Pos.Raw
186189

187190
@[extern "lean_string_pos_min"]
188-
opaque min (p₁ p₂ : Pos) : Pos
191+
opaque min (p₁ p₂ : Pos.Raw) : Pos.Raw
189192

190-
end String.Pos.Internal
193+
end String.Pos.Raw.Internal
191194

192195
namespace Char
193196

src/Init/Data/String/Decode.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,7 +1315,7 @@ public theorem isUtf8FirstByte_getElem_zero_utf8EncodeChar {c : Char} :
13151315
simp
13161316

13171317
@[expose]
1318-
public def utf8ByteSize (c : UInt8) (_h : c.IsUtf8FirstByte) : String.Pos :=
1318+
public def utf8ByteSize (c : UInt8) (_h : c.IsUtf8FirstByte) : String.Pos.Raw :=
13191319
if c &&& 0x80 = 0 then
13201320
1
13211321
else if c &&& 0xe0 = 0xc0 then
@@ -1325,7 +1325,7 @@ public def utf8ByteSize (c : UInt8) (_h : c.IsUtf8FirstByte) : String.Pos :=
13251325
else
13261326
4
13271327

1328-
def _root_.ByteArray.utf8DecodeChar?.FirstByte.utf8ByteSize : FirstByte → String.Pos
1328+
def _root_.ByteArray.utf8DecodeChar?.FirstByte.utf8ByteSize : FirstByte → String.Pos.Raw
13291329
| .invalid => ⟨0
13301330
| .done => ⟨1
13311331
| .oneMore => ⟨2

src/Init/Data/ToString/Basic.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ instance : ToString Unit :=
8686
instance : ToString Nat :=
8787
fun n => Nat.repr n⟩
8888

89-
instance : ToString String.Pos :=
89+
instance : ToString String.Pos.Raw :=
9090
fun p => Nat.repr p.byteIdx⟩
9191

9292
instance : ToString Int where

src/Init/Meta/Defs.lean

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ Finds the tail position of the trailing whitespace of the first `SourceInfo` fro
560560
If no `SourceInfo` can be found or the first `SourceInfo` from the back of `stx` contains
561561
no trailing whitespace and lacks a tail position, the result is `none`.
562562
-/
563-
def getTrailingTailPos? (stx : Syntax) (canonicalOnly := false) : Option String.Pos :=
563+
def getTrailingTailPos? (stx : Syntax) (canonicalOnly := false) : Option String.Pos.Raw :=
564564
stx.getTailInfo.getTrailingTailPos? canonicalOnly
565565

566566
/--
@@ -818,7 +818,7 @@ def mkNameLit (val : String) (info := SourceInfo.none) : NameLit :=
818818
in binary, octal, decimal and hexadecimal format. `isNatLit` implements a "decoder"
819819
for Syntax objects representing these numerals. -/
820820

821-
private partial def decodeBinLitAux (s : String) (i : String.Pos) (val : Nat) : Option Nat :=
821+
private partial def decodeBinLitAux (s : String) (i : String.Pos.Raw) (val : Nat) : Option Nat :=
822822
if String.Internal.atEnd s i then some val
823823
else
824824
let c := String.Internal.get s i
@@ -827,31 +827,31 @@ private partial def decodeBinLitAux (s : String) (i : String.Pos) (val : Nat) :
827827
else if c == '_' then decodeBinLitAux s (String.Internal.next s i) val
828828
else none
829829

830-
private partial def decodeOctalLitAux (s : String) (i : String.Pos) (val : Nat) : Option Nat :=
830+
private partial def decodeOctalLitAux (s : String) (i : String.Pos.Raw) (val : Nat) : Option Nat :=
831831
if String.Internal.atEnd s i then some val
832832
else
833833
let c := String.Internal.get s i
834834
if '0' ≤ c && c ≤ '7' then decodeOctalLitAux s (String.Internal.next s i) (8*val + c.toNat - '0'.toNat)
835835
else if c == '_' then decodeOctalLitAux s (String.Internal.next s i) val
836836
else none
837837

838-
private def decodeHexDigit (s : String) (i : String.Pos) : Option (Nat × String.Pos) :=
838+
private def decodeHexDigit (s : String) (i : String.Pos.Raw) : Option (Nat × String.Pos.Raw) :=
839839
let c := String.Internal.get s i
840840
let i := String.Internal.next s i
841841
if '0' ≤ c && c ≤ '9' then some (c.toNat - '0'.toNat, i)
842842
else if 'a' ≤ c && c ≤ 'f' then some (10 + c.toNat - 'a'.toNat, i)
843843
else if 'A' ≤ c && c ≤ 'F' then some (10 + c.toNat - 'A'.toNat, i)
844844
else none
845845

846-
private partial def decodeHexLitAux (s : String) (i : String.Pos) (val : Nat) : Option Nat :=
846+
private partial def decodeHexLitAux (s : String) (i : String.Pos.Raw) (val : Nat) : Option Nat :=
847847
if String.Internal.atEnd s i then some val
848848
else match decodeHexDigit s i with
849849
| some (d, i) => decodeHexLitAux s i (16*val + d)
850850
| none =>
851851
if String.Internal.get s i == '_' then decodeHexLitAux s (String.Internal.next s i) val
852852
else none
853853

854-
private partial def decodeDecimalLitAux (s : String) (i : String.Pos) (val : Nat) : Option Nat :=
854+
private partial def decodeDecimalLitAux (s : String) (i : String.Pos.Raw) (val : Nat) : Option Nat :=
855855
if String.Internal.atEnd s i then some val
856856
else
857857
let c := String.Internal.get s i
@@ -911,7 +911,7 @@ partial def decodeScientificLitVal? (s : String) : Option (Nat × Bool × Nat) :
911911
decode 0 0
912912
else none
913913
where
914-
decodeAfterExp (i : String.Pos) (val : Nat) (e : Nat) (sign : Bool) (exp : Nat) : Option (Nat × Bool × Nat) :=
914+
decodeAfterExp (i : String.Pos.Raw) (val : Nat) (e : Nat) (sign : Bool) (exp : Nat) : Option (Nat × Bool × Nat) :=
915915
if String.Internal.atEnd s i then
916916
if sign then
917917
some (val, sign, exp + e)
@@ -928,7 +928,7 @@ where
928928
else
929929
none
930930

931-
decodeExp (i : String.Pos) (val : Nat) (e : Nat) : Option (Nat × Bool × Nat) :=
931+
decodeExp (i : String.Pos.Raw) (val : Nat) (e : Nat) : Option (Nat × Bool × Nat) :=
932932
if String.Internal.atEnd s i then none else
933933
let c := String.Internal.get s i
934934
if c == '-' then
@@ -938,7 +938,7 @@ where
938938
else
939939
decodeAfterExp i val e false 0
940940

941-
decodeAfterDot (i : String.Pos) (val : Nat) (e : Nat) : Option (Nat × Bool × Nat) :=
941+
decodeAfterDot (i : String.Pos.Raw) (val : Nat) (e : Nat) : Option (Nat × Bool × Nat) :=
942942
if String.Internal.atEnd s i then
943943
some (val, true, e)
944944
else
@@ -952,7 +952,7 @@ where
952952
else
953953
none
954954

955-
decode (i : String.Pos) (val : Nat) : Option (Nat × Bool × Nat) :=
955+
decode (i : String.Pos.Raw) (val : Nat) : Option (Nat × Bool × Nat) :=
956956
if String.Internal.atEnd s i then
957957
none
958958
else
@@ -983,7 +983,7 @@ def toNat (stx : Syntax) : Nat :=
983983
| some val => val
984984
| none => 0
985985

986-
def decodeQuotedChar (s : String) (i : String.Pos) : Option (Char × String.Pos) := do
986+
def decodeQuotedChar (s : String) (i : String.Pos.Raw) : Option (Char × String.Pos.Raw) := do
987987
let c := String.Internal.get s i
988988
let i := String.Internal.next s i
989989
if c == '\\' then pure ('\\', i)
@@ -1011,11 +1011,11 @@ Note that this function matches `"\" whitespace+` rather than
10111011
the more restrictive `"\" newline whitespace*` since this simplifies the implementation.
10121012
Justification: this does not overlap with any other sequences beginning with `\`.
10131013
-/
1014-
def decodeStringGap (s : String) (i : String.Pos) : Option String.Pos := do
1014+
def decodeStringGap (s : String) (i : String.Pos.Raw) : Option String.Pos.Raw := do
10151015
guard <| (String.Internal.get s i).isWhitespace
10161016
some <| String.Internal.nextWhile s Char.isWhitespace (String.Internal.next s i)
10171017

1018-
partial def decodeStrLitAux (s : String) (i : String.Pos) (acc : String) : Option String := do
1018+
partial def decodeStrLitAux (s : String) (i : String.Pos.Raw) (acc : String) : Option String := do
10191019
let c := String.Internal.get s i
10201020
let i := String.Internal.next s i
10211021
if c == '\"' then
@@ -1038,7 +1038,7 @@ The position `i` should start at `1`, which is the character after the leading `
10381038
The algorithm is simple: we are given `r##...#"...string..."##...#` with zero or more `#`s.
10391039
By counting the number of leading `#`'s, we can extract the `...string...`.
10401040
-/
1041-
partial def decodeRawStrLitAux (s : String) (i : String.Pos) (num : Nat) : String :=
1041+
partial def decodeRawStrLitAux (s : String) (i : String.Pos.Raw) (num : Nat) : String :=
10421042
let c := String.Internal.get s i
10431043
let i := String.Internal.next s i
10441044
if c == '#' then
@@ -1097,7 +1097,7 @@ private partial def splitNameLitAux (ss : Substring) (acc : List Substring) : Li
10971097
let curr := Substring.Internal.front ss
10981098
if isIdBeginEscape curr then
10991099
let escapedPart := Substring.Internal.takeWhile ss (!isIdEndEscape ·)
1100-
let escapedPart := { escapedPart with stopPos := String.Pos.Internal.min ss.stopPos (String.Internal.next escapedPart.str escapedPart.stopPos) }
1100+
let escapedPart := { escapedPart with stopPos := String.Pos.Raw.Internal.min ss.stopPos (String.Internal.next escapedPart.str escapedPart.stopPos) }
11011101
if !isIdEndEscape (Substring.Internal.get escapedPart <| Substring.Internal.prev escapedPart ⟨escapedPart.bsize⟩) then []
11021102
else splitRest (Substring.Internal.extract ss ⟨escapedPart.bsize⟩ ⟨ss.bsize⟩) (escapedPart :: acc)
11031103
else if isIdFirst curr then
@@ -1462,7 +1462,7 @@ end Lean.Syntax
14621462

14631463
namespace Lean.Syntax
14641464

1465-
private def decodeInterpStrQuotedChar (s : String) (i : String.Pos) : Option (Char × String.Pos) := do
1465+
private def decodeInterpStrQuotedChar (s : String) (i : String.Pos.Raw) : Option (Char × String.Pos.Raw) := do
14661466
match decodeQuotedChar s i with
14671467
| some r => some r
14681468
| none =>
@@ -1472,7 +1472,7 @@ private def decodeInterpStrQuotedChar (s : String) (i : String.Pos) : Option (Ch
14721472
else none
14731473

14741474
private partial def decodeInterpStrLit (s : String) : Option String :=
1475-
let rec loop (i : String.Pos) (acc : String) : Option String :=
1475+
let rec loop (i : String.Pos.Raw) (acc : String) : Option String :=
14761476
let c := String.Internal.get s i
14771477
let i := String.Internal.next s i
14781478
if c == '\"' || c == '{' then
@@ -1533,7 +1533,7 @@ def expandInterpolatedStr (interpStr : TSyntax interpolatedStrKind) (type : Term
15331533

15341534
def getDocString (stx : TSyntax `Lean.Parser.Command.docComment) : String :=
15351535
match stx.raw[1] with
1536-
| Syntax.atom _ val => String.Internal.extract val 0 (String.Pos.Internal.sub val.endPos ⟨2⟩)
1536+
| Syntax.atom _ val => String.Internal.extract val 0 (String.Pos.Raw.Internal.sub val.endPos ⟨2⟩)
15371537
| _ => ""
15381538

15391539
end TSyntax

0 commit comments

Comments
 (0)