Skip to content

Commit 355fb11

Browse files
committed
Fix
1 parent f154063 commit 355fb11

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+218
-217
lines changed

src/Init/Data/String/Extra.lean

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,25 +153,25 @@ def crlfToLf (text : String) : String :=
153153
go "" 0 0
154154
where
155155
go (acc : String) (accStop pos : String.Pos.Raw) : String :=
156-
if h : text.atEnd pos then
156+
if h : pos.atEnd text then
157157
-- note: if accStop = 0 then acc is empty
158-
if accStop = 0 then text else acc ++ text.extract accStop pos
158+
if accStop = 0 then text else acc ++ accStop.extract text pos
159159
else
160-
let c := text.get' pos h
161-
let pos' := text.next' pos h
162-
if h' : ¬ text.atEnd pos' ∧ c == '\r'text.get pos' == '\n' then
163-
let acc := acc ++ text.extract accStop pos
164-
go acc pos' (text.next' pos' h'.1)
160+
let c := pos.get' text h
161+
let pos' := pos.next' text h
162+
if h' : ¬ pos'.atEnd text ∧ c == '\r'pos'.get text == '\n' then
163+
let acc := acc ++ accStop.extract text pos
164+
go acc pos' (pos'.next' text h'.1)
165165
else
166166
go acc accStop pos'
167167
termination_by text.utf8ByteSize - pos.byteIdx
168168
decreasing_by
169169
decreasing_with
170-
change text.utf8ByteSize - (text.next (text.next pos)).byteIdx < text.utf8ByteSize - pos.byteIdx
170+
change text.utf8ByteSize - ((pos.next text).next text).byteIdx < text.utf8ByteSize - pos.byteIdx
171171
have k := Nat.gt_of_not_le <| mt decide_eq_true h
172172
exact Nat.sub_lt_sub_left k (Nat.lt_trans (String.Pos.Raw.lt_next text pos) (String.Pos.Raw.lt_next _ _))
173173
decreasing_with
174-
change text.utf8ByteSize - (text.next pos).byteIdx < text.utf8ByteSize - pos.byteIdx
174+
change text.utf8ByteSize - (pos.next text).byteIdx < text.utf8ByteSize - pos.byteIdx
175175
have k := Nat.gt_of_not_le <| mt decide_eq_true h
176176
exact Nat.sub_lt_sub_left k (String.Pos.Raw.lt_next _ _)
177177

src/Init/Data/ToString/Name.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ private partial def needsNoEscapeAsciiRest (s : String) (i : Nat) : Bool :=
3737

3838
-- If you change this, also change the corresponding function in `Init.Meta`.
3939
@[inline] private def needsNoEscape (s : String) (h : s.utf8ByteSize > 0) : Bool :=
40-
needsNoEscapeAscii s h || isIdFirst (s.get 0) && (s.toSubstring.drop 1).all isIdRest
40+
needsNoEscapeAscii s h || isIdFirst s.front && (s.toSubstring.drop 1).all isIdRest
4141

4242
-- If you change this, also change the corresponding function in `Init.Meta`.
4343
@[inline] private def escape (s : String) : String :=

src/Init/System/FilePath.lean

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ There is no guarantee that two equivalent paths normalize to the same path.
7777
def normalize (p : FilePath) : FilePath := Id.run do
7878
let mut p := p
7979
-- normalize drive letter
80-
if isWindows && p.toString.length >= 2 && (p.toString.get 0).isLower && p.toString.get ⟨1⟩ == ':' then
81-
p := ⟨p.toString.set 0 (p.toString.get 0).toUpper
80+
if isWindows && p.toString.length >= 2 && p.toString.front.isLower && String.Pos.Raw.get p.toString1⟩ == ':' then
81+
p := ⟨p.toString.capitalize
8282
-- normalize separator
8383
unless pathSeparators.length == 1 do
8484
p := ⟨p.toString.map fun c => if pathSeparators.contains c then pathSeparator else c⟩
@@ -129,15 +129,15 @@ If the path is that of the root directory or the root of a drive letter, `none`
129129
Otherwise, the path's parent directory is returned.
130130
-/
131131
def parent (p : FilePath) : Option FilePath :=
132-
let extractParentPath := FilePath.mk <$> p.toString.extract {} <$> posOfLastSep p
132+
let extractParentPath := FilePath.mk <$> String.Pos.Raw.extract p.toString {} <$> posOfLastSep p
133133
if p.isAbsolute then
134134
let lengthOfRootDirectory := if pathSeparators.contains p.toString.front then 1 else 3
135135
if p.toString.length == lengthOfRootDirectory then
136136
-- `p` is a root directory
137137
none
138138
else if posOfLastSep p == some (String.Pos.Raw.mk (lengthOfRootDirectory - 1)) then
139139
-- `p` is a direct child of the root
140-
some ⟨p.toString.extract 0 ⟨lengthOfRootDirectory⟩⟩
140+
some ⟨String.Pos.Raw.extract p.toString 0 ⟨lengthOfRootDirectory⟩⟩
141141
else
142142
-- `p` is an absolute path with at least two subdirectories
143143
extractParentPath
@@ -153,7 +153,7 @@ directory.
153153
-/
154154
def fileName (p : FilePath) : Option String :=
155155
let lastPart := match posOfLastSep p with
156-
| some sepPos => p.toString.extract (sepPos + '/') p.toString.endPos
156+
| some sepPos => String.Pos.Raw.extract p.toString (sepPos + '/') p.toString.endPos
157157
| none => p.toString
158158
if lastPart.isEmpty || lastPart == "." || lastPart == ".." then none else some lastPart
159159

@@ -173,7 +173,7 @@ def fileStem (p : FilePath) : Option String :=
173173
p.fileName.map fun fname =>
174174
match fname.revPosOf '.' with
175175
| some ⟨0⟩ => fname
176-
| some pos => fname.extract 0 pos
176+
| some pos => String.Pos.Raw.extract fname 0 pos
177177
| none => fname
178178

179179
/--
@@ -192,7 +192,7 @@ def extension (p : FilePath) : Option String :=
192192
p.fileName.bind fun fname =>
193193
match fname.revPosOf '.' with
194194
| some 0 => none
195-
| some pos => some <| fname.extract (pos + '.') fname.endPos
195+
| some pos => some <| String.Pos.Raw.extract fname (pos + '.') fname.endPos
196196
| none => none
197197

198198
/--

src/Init/System/Uri.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ def pathToUri (fname : System.FilePath) : String := Id.run do
9393
if System.Platform.isWindows then
9494
-- normalize drive letter
9595
-- lower-case drive letters seem to be preferred in URIs
96-
if uri.length >= 2 && (uri.get 0).isUpper && uri.get ⟨1⟩ == ':' then
97-
uri := uri.set 0 (uri.get 0).toLower
96+
if uri.length >= 2 && uri.front.isUpper && String.Pos.Raw.get uri1⟩ == ':' then
97+
uri := uri.decapitalize
9898
uri := uri.map (fun c => if c == '\\' then '/' else c)
9999
uri := uri.foldl (fun s c => s ++ UriEscape.uriEscapeAsciiChar c) ""
100100
let result := if uri.startsWith "/" then "file://" ++ uri else "file:///" ++ uri
@@ -110,7 +110,7 @@ def fileUriToPath? (uri : String) : Option System.FilePath := Id.run do
110110
p := p.dropWhile (λ c => c != '/') -- drop the hostname.
111111
-- On Windows, the path "/c:/temp" needs to become "C:/temp"
112112
if System.Platform.isWindows && p.length >= 2 &&
113-
p.get 0 == '/' && (p.get ⟨1⟩).isAlpha && p.get ⟨2⟩ == ':' then
113+
p.front == '/' && (String.Pos.Raw.get p 1⟩).isAlpha && String.Pos.Raw.get p2⟩ == ':' then
114114
-- see also `pathToUri`
115115
p := String.Pos.Raw.modify (p.drop 1) 0 .toUpper
116116
some p

src/Lean/AddDecl.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ private def isNamespaceName : Name → Bool
3535
private def registerNamePrefixes (env : Environment) (name : Name) : Environment :=
3636
match name with
3737
| .str _ s =>
38-
if s.get 0 == '_' then
38+
if s.front == '_' then
3939
-- Do not register namespaces that only contain internal declarations.
4040
env
4141
else

src/Lean/Compiler/ExportAttr.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public section
1313
namespace Lean
1414

1515
private def isValidCppId (id : String) : Bool :=
16-
let first := id.get 0;
16+
let first := id.front;
1717
first.isAlpha && (id.toSubstring.drop 1).all (fun c => c.isAlpha || c.isDigit || c == '_')
1818

1919
private def isValidCppName : Name → Bool

src/Lean/Data/FuzzyMatching.lean

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,29 @@ section Utils
3030
if string.isEmpty then
3131
#[]
3232
else if string.length == 1 then
33-
#[f none (string.get 0) none]
33+
#[f none (String.Pos.Raw.get string 0) none]
3434
else Id.run do
3535
let mut result := Array.mkEmpty string.length
36-
result := result.push <| f none (string.get 0) (string.get ⟨1⟩)
36+
result := result.push <| f none (String.Pos.Raw.get string 0) (String.Pos.Raw.get string1⟩)
3737
-- TODO: the following code is assuming all characters are ASCII
3838
for i in [2:string.length] do
39-
result := result.push <| f (string.get ⟨i - 2⟩) (string.get ⟨i - 1⟩) (string.get ⟨i⟩)
40-
result.push <| f (string.get ⟨string.length - 2⟩) (string.get ⟨string.length - 1⟩) none
39+
result := result.push <| f (String.Pos.Raw.get string ⟨i - 2⟩) (String.Pos.Raw.get string ⟨i - 1⟩) (String.Pos.Raw.get string ⟨i⟩)
40+
result.push <| f (String.Pos.Raw.get string ⟨string.length - 2⟩) (String.Pos.Raw.get string ⟨string.length - 1⟩) none
4141

4242
private partial def containsInOrderLower (a b : String) : Bool := Id.run do
4343
go ⟨0⟩ ⟨0
4444
where
4545
go (aPos bPos : String.Pos.Raw) : Bool :=
46-
if ha : a.atEnd aPos then
46+
if ha : aPos.atEnd a then
4747
true
48-
else if hb : b.atEnd bPos then
48+
else if hb : bPos.atEnd b then
4949
false
5050
else
51-
let ac := a.get' aPos ha
52-
let bc := b.get' bPos hb
53-
let bPos := b.next' bPos hb
51+
let ac := aPos.get' a ha
52+
let bc := bPos.get' b hb
53+
let bPos := bPos.next' b hb
5454
if ac.toLower == bc.toLower then
55-
let aPos := a.next' aPos ha
55+
let aPos := aPos.next' a ha
5656
go aPos bPos
5757
else
5858
go aPos bPos
@@ -173,7 +173,7 @@ private def fuzzyMatchCore (pattern word : String) (patternRoles wordRoles : Arr
173173

174174
let mut matchScore := .awful
175175

176-
if allowMatch (pattern.get ⟨patternIdx⟩) (word.get ⟨wordIdx⟩) patternRoles[patternIdx]! wordRoles[wordIdx]! then
176+
if allowMatch (String.Pos.Raw.get pattern ⟨patternIdx⟩) (String.Pos.Raw.get word ⟨wordIdx⟩) patternRoles[patternIdx]! wordRoles[wordIdx]! then
177177
if patternIdx >= 1 then
178178
let runLength := runLengths[getIdx (patternIdx - 1) (wordIdx - 1)]! + 1
179179
runLengths := runLengths.set! (getIdx patternIdx wordIdx) runLength
@@ -248,7 +248,7 @@ private def fuzzyMatchCore (pattern word : String) (patternRoles wordRoles : Arr
248248
matchResult (patternIdx wordIdx : Nat) (patternRole wordRole : CharRole) (consecutive : Score) : Int16 := Id.run do
249249
let mut score : Int16 := 1
250250
/- Case-sensitive equality or beginning of a segment in pattern and word. -/
251-
if (pattern.get ⟨patternIdx⟩) == (word.get ⟨wordIdx⟩) || (patternRole matches CharRole.head && wordRole matches CharRole.head) then
251+
if (String.Pos.Raw.get pattern ⟨patternIdx⟩) == (String.Pos.Raw.get word ⟨wordIdx⟩) || (patternRole matches CharRole.head && wordRole matches CharRole.head) then
252252
score := score + 1
253253
/- Matched end of word with end of pattern -/
254254
if wordIdx == word.length - 1 && patternIdx == pattern.length - 1 then

src/Lean/Data/Lsp/LanguageFeatures.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ instance : ToJson CompletionIdentifier where
109109
instance : FromJson CompletionIdentifier where
110110
fromJson?
111111
| .str s =>
112-
let c := s.get 0
112+
let c := s.front
113113
if c == 'c' then
114-
let declName := s.extract ⟨1⟩ s.endPos |>.toName
114+
let declName := String.Pos.Raw.extract s1⟩ s.endPos |>.toName
115115
.ok <| .const declName
116116
else if c == 'f' then
117-
let id := ⟨s.extract ⟨1⟩ s.endPos |>.toName⟩
117+
let id := ⟨String.Pos.Raw.extract s1⟩ s.endPos |>.toName⟩
118118
.ok <| .fvar id
119119
else
120120
.error "Expected string with prefix `c` or `f` in `FromJson` instance of `CompletionIdentifier`."

src/Lean/Data/Lsp/Utf16.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def utf16Length (s : String) : Nat :=
3434

3535
private def codepointPosToUtf16PosFromAux (s : String) : Nat → Pos.Raw → Nat → Nat
3636
| 0, _, utf16pos => utf16pos
37-
| cp+1, utf8pos, utf16pos => codepointPosToUtf16PosFromAux s cp (s.next utf8pos) (utf16pos + csize16 (s.get utf8pos))
37+
| cp+1, utf8pos, utf16pos => codepointPosToUtf16PosFromAux s cp (utf8pos.next s) (utf16pos + csize16 (utf8pos.get s))
3838

3939
/-- Computes the UTF-16 offset of the `n`-th Unicode codepoint
4040
in the substring of `s` starting at UTF-8 offset `off`.
@@ -47,7 +47,7 @@ def codepointPosToUtf16Pos (s : String) (pos : Nat) : Nat :=
4747

4848
private partial def utf16PosToCodepointPosFromAux (s : String) : Nat → Pos.Raw → Nat → Nat
4949
| 0, _, cp => cp
50-
| utf16pos, utf8pos, cp => utf16PosToCodepointPosFromAux s (utf16pos - csize16 (s.get utf8pos)) (s.next utf8pos) (cp + 1)
50+
| utf16pos, utf8pos, cp => utf16PosToCodepointPosFromAux s (utf16pos - csize16 (utf8pos.get s)) (utf8pos.next s) (cp + 1)
5151

5252
/-- Computes the position of the Unicode codepoint at UTF-16 offset
5353
`utf16pos` in the substring of `s` starting at UTF-8 offset `off`. -/
@@ -60,7 +60,7 @@ def utf16PosToCodepointPos (s : String) (pos : Nat) : Nat :=
6060
/-- Starting at `utf8pos`, finds the UTF-8 offset of the `p`-th codepoint. -/
6161
def codepointPosToUtf8PosFrom (s : String) : String.Pos.Raw → Nat → String.Pos.Raw
6262
| utf8pos, 0 => utf8pos
63-
| utf8pos, p+1 => codepointPosToUtf8PosFrom s (s.next utf8pos) p
63+
| utf8pos, p+1 => codepointPosToUtf8PosFrom s (utf8pos.next s) p
6464

6565
end String
6666

src/Lean/Data/Name.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def hasNum : Name → Bool
111111
/-- The frontend does not allow user declarations to start with `_` in any of its parts.
112112
We use name parts starting with `_` internally to create auxiliary names (e.g., `_private`). -/
113113
def isInternal : Name → Bool
114-
| str p s => s.get 0 == '_' || isInternal p
114+
| str p s => s.front == '_' || isInternal p
115115
| num p _ => isInternal p
116116
| _ => false
117117

@@ -122,7 +122,7 @@ We use name parts starting with `_` internally to create auxiliary names (e.g.,
122122
This function checks if any component of the name starts with `_`, or is numeric.
123123
-/
124124
def isInternalOrNum : Name → Bool
125-
| .str p s => s.get 0 == '_' || isInternalOrNum p
125+
| .str p s => s.front == '_' || isInternalOrNum p
126126
| .num _ _ => true
127127
| _ => false
128128

0 commit comments

Comments
 (0)