Skip to content

Commit b28daa6

Browse files
authored
chore: rename String.endPos -> String.rawEndPos (#10853)
This PR renames `String.endPos` to `String.rawEndPos`, as in a future release the name `String.endPos` will be taken by the function that is currently called `String.endValidPos`.
1 parent 196d501 commit b28daa6

Some content is hidden

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

48 files changed

+238
-205
lines changed

script/Modulize.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,19 @@ def main (args : List String) : IO Unit := do
5757
sec := "\n\n" ++ sec
5858
if insertPos?.isNone then
5959
sec := sec ++ "\n\n"
60-
text := text.extract 0 insertPos ++ sec ++ text.extract insertPos text.endPos
60+
text := text.extract 0 insertPos ++ sec ++ text.extract insertPos text.rawEndPos
6161

6262
-- prepend each import with `public `
6363
for imp in imps.reverse do
6464
let insertPos := imp.raw.getPos?.get!
6565
let prfx := if doMeta then "public meta " else "public "
66-
text := text.extract 0 insertPos ++ prfx ++ text.extract insertPos text.endPos
66+
text := text.extract 0 insertPos ++ prfx ++ text.extract insertPos text.rawEndPos
6767

6868
-- insert `module` header
6969
let mut initText := text.extract 0 startPos
7070
if !initText.trim.isEmpty then
7171
-- If there is a header comment, preserve it and put `module` in the line after
7272
initText := initText.trimRight ++ "\n"
73-
text := initText ++ "module\n\n" ++ text.extract startPos text.endPos
73+
text := initText ++ "module\n\n" ++ text.extract startPos text.rawEndPos
7474

7575
IO.FS.writeFile path text

script/Shake.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,14 +563,14 @@ def main (args : List String) : IO UInt32 := do
563563
if remove.contains mod || seen.contains mod then
564564
out := out ++ text.extract pos stx.raw.getPos?.get!
565565
-- We use the end position of the syntax, but include whitespace up to the first newline
566-
pos := text.findAux (· == '\n') text.endPos stx.raw.getTailPos?.get! + ⟨1
566+
pos := text.findAux (· == '\n') text.rawEndPos stx.raw.getTailPos?.get! + ⟨1
567567
seen := seen.insert mod
568568
out := out ++ text.extract pos insertion
569569
for mod in add do
570570
if !seen.contains mod then
571571
seen := seen.insert mod
572572
out := out ++ s!"{mod}\n"
573-
out := out ++ text.extract insertion text.endPos
573+
out := out ++ text.extract insertion text.rawEndPos
574574

575575
IO.FS.writeFile path out
576576
return count + 1

src/Init/Data/Format/Basic.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ private def spaceUptoLine : Format → Bool → Int → Nat → SpaceResult
170170
| text s, flatten, _, _ =>
171171
let p := String.Internal.posOf s '\n'
172172
let off := String.Internal.offsetOfPos s p
173-
{ foundLine := p != s.endPos, foundFlattenedHardLine := flatten && p != s.endPos, space := off }
173+
{ foundLine := p != s.rawEndPos, foundFlattenedHardLine := flatten && p != s.rawEndPos, space := off }
174174
| append f₁ f₂, flatten, m, w => merge w (spaceUptoLine f₁ flatten m w) (spaceUptoLine f₂ flatten m)
175175
| nest n f, flatten, m, w => spaceUptoLine f flatten (m - n) w
176176
| group f _, _, m, w => spaceUptoLine f true m w
@@ -264,14 +264,14 @@ private partial def be (w : Nat) [Monad m] [MonadPrettyFormat m] : List WorkGrou
264264
| nest n f => be w (gs' ({ i with f, indent := i.indent + n }::is))
265265
| text s =>
266266
let p := String.Internal.posOf s '\n'
267-
if p == s.endPos then
267+
if p == s.rawEndPos then
268268
pushOutput s
269269
endTags i.activeTags
270270
be w (gs' is)
271271
else
272272
pushOutput (String.Internal.extract s {} p)
273273
pushNewline i.indent.toNat
274-
let is := { i with f := text (String.Internal.extract s (String.Internal.next s p) s.endPos) }::is
274+
let is := { i with f := text (String.Internal.extract s (String.Internal.next s p) s.rawEndPos) }::is
275275
-- after a hard line break, re-evaluate whether to flatten the remaining group
276276
-- note that we shouldn't start flattening after a hard break outside a group
277277
if g.fla == .disallow then

src/Init/Data/String/Basic.lean

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

src/Init/Meta/Defs.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1550,7 +1550,7 @@ def expandInterpolatedStr (interpStr : TSyntax interpolatedStrKind) (type : Term
15501550

15511551
def getDocString (stx : TSyntax `Lean.Parser.Command.docComment) : String :=
15521552
match stx.raw[1] with
1553-
| Syntax.atom _ val => String.Internal.extract val 0 (String.Pos.Raw.Internal.sub val.endPos2⟩)
1553+
| Syntax.atom _ val => String.Internal.extract val 0 (String.Pos.Raw.Internal.sub val.rawEndPos2⟩)
15541554
| _ => ""
15551555

15561556
end TSyntax

src/Init/Prelude.lean

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3441,7 +3441,7 @@ Character positions (counting the Unicode code points rather than bytes) are rep
34413441
`Nat`s. Indexing a `String` by a `String.Pos.Raw` takes constant time, while character positions need to
34423442
be translated internally to byte positions, which takes linear time.
34433443
3444-
A byte position `p` is *valid* for a string `s` if `0 ≤ p ≤ s.endPos` and `p` lies on a UTF-8
3444+
A byte position `p` is *valid* for a string `s` if `0 ≤ p ≤ s.rawEndPos` and `p` lies on a UTF-8
34453445
character boundary, see `String.Pos.IsValid`.
34463446
34473447
There is another type, `String.ValidPos`, which bundles the validity predicate. Using `String.ValidPos`
@@ -3501,10 +3501,10 @@ def String.utf8ByteSize (s : @& String) : Nat :=
35013501
/--
35023502
A UTF-8 byte position that points at the end of a string, just after the last character.
35033503
3504-
* `"abc".endPos = ⟨3⟩`
3505-
* `"L∃∀N".endPos = ⟨8⟩`
3504+
* `"abc".rawEndPos = ⟨3⟩`
3505+
* `"L∃∀N".rawEndPos = ⟨8⟩`
35063506
-/
3507-
@[inline] def String.endPos (s : String) : String.Pos.Raw where
3507+
@[inline] def String.rawEndPos (s : String) : String.Pos.Raw where
35083508
byteIdx := utf8ByteSize s
35093509

35103510
/--
@@ -3513,7 +3513,7 @@ Converts a `String` into a `Substring` that denotes the entire string.
35133513
@[inline] def String.toSubstring (s : String) : Substring where
35143514
str := s
35153515
startPos := {}
3516-
stopPos := s.endPos
3516+
stopPos := s.rawEndPos
35173517

35183518
/--
35193519
Converts a `String` into a `Substring` that denotes the entire string.

src/Init/System/FilePath.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ directory.
153153
-/
154154
def fileName (p : FilePath) : Option String :=
155155
let lastPart := match posOfLastSep p with
156-
| some sepPos => String.Pos.Raw.extract p.toString (sepPos + '/') p.toString.endPos
156+
| some sepPos => String.Pos.Raw.extract p.toString (sepPos + '/') p.toString.rawEndPos
157157
| none => p.toString
158158
if lastPart.isEmpty || lastPart == "." || lastPart == ".." then none else some lastPart
159159

@@ -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 <| String.Pos.Raw.extract fname (pos + '.') fname.endPos
195+
| some pos => some <| String.Pos.Raw.extract fname (pos + '.') fname.rawEndPos
196196
| none => none
197197

198198
/--

src/Lean/Data/Lsp/LanguageFeatures.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@ instance : FromJson CompletionIdentifier where
111111
| .str s =>
112112
let c := s.front
113113
if c == 'c' then
114-
let declName := String.Pos.Raw.extract s ⟨1⟩ s.endPos |>.toName
114+
let declName := String.Pos.Raw.extract s ⟨1⟩ s.rawEndPos |>.toName
115115
.ok <| .const declName
116116
else if c == 'f' then
117-
let id := ⟨String.Pos.Raw.extract s ⟨1⟩ s.endPos |>.toName⟩
117+
let id := ⟨String.Pos.Raw.extract s ⟨1⟩ s.rawEndPos |>.toName⟩
118118
.ok <| .fvar id
119119
else
120120
.error "Expected string with prefix `c` or `f` in `FromJson` instance of `CompletionIdentifier`."

src/Lean/DocString/Add.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ def parseVersoDocString
6666

6767
-- Skip trailing `-/`
6868
let endPos := String.Pos.Raw.prev text.source <| endPos.prev text.source
69-
let endPos := if endPos ≤ text.source.endPos then endPos else text.source.endPos
70-
have endPos_valid : endPos ≤ text.source.endPos := by
69+
let endPos := if endPos ≤ text.source.rawEndPos then endPos else text.source.rawEndPos
70+
have endPos_valid : endPos ≤ text.source.rawEndPos := by
7171
unfold endPos
7272
split <;> simp [*]
7373

src/Lean/DocString/Extension.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,11 @@ def getModuleDoc? (env : Environment) (moduleName : Name) : Option (Array Module
210210
def getDocStringText [Monad m] [MonadError m] (stx : TSyntax `Lean.Parser.Command.docComment) : m String :=
211211
match stx.raw[1] with
212212
| Syntax.atom _ val =>
213-
return String.Pos.Raw.extract val 0 (val.endPos.unoffsetBy ⟨2⟩)
213+
return String.Pos.Raw.extract val 0 (val.rawEndPos.unoffsetBy ⟨2⟩)
214214
| Syntax.node _ `Lean.Parser.Command.versoCommentBody _ =>
215215
match stx.raw[1][0] with
216216
| Syntax.atom _ val =>
217-
return String.Pos.Raw.extract val 0 (val.endPos.unoffsetBy ⟨2⟩)
217+
return String.Pos.Raw.extract val 0 (val.rawEndPos.unoffsetBy ⟨2⟩)
218218
| _ =>
219219
throwErrorAt stx "unexpected doc string{indentD stx}"
220220
| _ =>

0 commit comments

Comments
 (0)