Skip to content

Commit 835c45f

Browse files
committed
Totally broken state
1 parent 4325b45 commit 835c45f

Some content is hidden

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

49 files changed

+244
-218
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/String/Basic.lean

Lines changed: 135 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: 17 additions & 17 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,8 +3501,8 @@ 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
-/
35073507
@[inline] def String.rawEndPos (s : String) : String.Pos.Raw where
35083508
byteIdx := utf8ByteSize s
@@ -4718,7 +4718,7 @@ inductive SourceInfo where
47184718
The `leading` whitespace is inferred after parsing by `Syntax.updateLeading`. This is because the
47194719
“preceding token” is not well-defined during parsing, especially in the presence of backtracking.
47204720
-/
4721-
| original (leading : Substring) (pos : String.Pos.Raw) (trailing : Substring) (endPos : String.Pos.Raw)
4721+
| original (leading : Substring) (pos : String.Pos.Raw) (trailing : Substring) (rawEndPos : String.Pos.Raw)
47224722
/--
47234723
Synthetic syntax is syntax that was produced by a metaprogram or by Lean itself (e.g. by a
47244724
quotation). Synthetic syntax is annotated with a source span from the original syntax, which
@@ -4742,7 +4742,7 @@ inductive SourceInfo where
47424742
```
47434743
In these cases, if the user hovers over `h` they will see information about both binding sites.
47444744
-/
4745-
| synthetic (pos : String.Pos.Raw) (endPos : String.Pos.Raw) (canonical := false)
4745+
| synthetic (pos : String.Pos.Raw) (rawEndPos : String.Pos.Raw) (canonical := false)
47464746
/-- A synthesized token without position information. -/
47474747
| protected none
47484748

@@ -4769,9 +4769,9 @@ will also return `none`.
47694769
-/
47704770
def getTailPos? (info : SourceInfo) (canonicalOnly := false) : Option String.Pos.Raw :=
47714771
match info, canonicalOnly with
4772-
| original (endPos := endPos) .., _
4773-
| synthetic (endPos := endPos) (canonical := true) .., _
4774-
| synthetic (endPos := endPos) .., false => some endPos
4772+
| original (rawEndPos := rawEndPos) .., _
4773+
| synthetic (rawEndPos := rawEndPos) (canonical := true) .., _
4774+
| synthetic (rawEndPos := rawEndPos) .., false => some rawEndPos
47754775
| _, _ => none
47764776

47774777
/--
@@ -5152,15 +5152,15 @@ position information.
51525152
-/
51535153
partial def getTailPos? (stx : Syntax) (canonicalOnly := false) : Option String.Pos.Raw :=
51545154
match stx, canonicalOnly with
5155-
| atom (SourceInfo.original (endPos := pos) ..) .., _
5156-
| atom (SourceInfo.synthetic (endPos := pos) (canonical := true) ..) _, _
5157-
| atom (SourceInfo.synthetic (endPos := pos) ..) _, false
5158-
| ident (SourceInfo.original (endPos := pos) ..) .., _
5159-
| ident (SourceInfo.synthetic (endPos := pos) (canonical := true) ..) .., _
5160-
| ident (SourceInfo.synthetic (endPos := pos) ..) .., false
5161-
| node (SourceInfo.original (endPos := pos) ..) .., _
5162-
| node (SourceInfo.synthetic (endPos := pos) (canonical := true) ..) .., _
5163-
| node (SourceInfo.synthetic (endPos := pos) ..) .., false => some pos
5155+
| atom (SourceInfo.original (rawEndPos := pos) ..) .., _
5156+
| atom (SourceInfo.synthetic (rawEndPos := pos) (canonical := true) ..) _, _
5157+
| atom (SourceInfo.synthetic (rawEndPos := pos) ..) _, false
5158+
| ident (SourceInfo.original (rawEndPos := pos) ..) .., _
5159+
| ident (SourceInfo.synthetic (rawEndPos := pos) (canonical := true) ..) .., _
5160+
| ident (SourceInfo.synthetic (rawEndPos := pos) ..) .., false
5161+
| node (SourceInfo.original (rawEndPos := pos) ..) .., _
5162+
| node (SourceInfo.synthetic (rawEndPos := pos) (canonical := true) ..) .., _
5163+
| node (SourceInfo.synthetic (rawEndPos := pos) ..) .., false => some pos
51645164
| node _ _ args, _ =>
51655165
let rec loop (i : Nat) : Option String.Pos.Raw :=
51665166
match decide (LT.lt i args.size) with

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
| _ =>

src/Lean/DocString/Links.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ where
152152
Returns `true` if `goal` is a prefix of the string at the position pointed to by `iter`.
153153
-/
154154
lookingAt (goal : String) (iter : String.Iterator) : Bool :=
155-
String.Pos.Raw.substrEq iter.s iter.i goal 0 goal.endPos.byteIdx
155+
String.Pos.Raw.substrEq iter.s iter.i goal 0 goal.rawEndPos.byteIdx
156156

157157
/--
158158
Rewrites Lean reference manual links in `docstring` to point at the reference manual.

0 commit comments

Comments
 (0)