Skip to content

Commit f154063

Browse files
committed
WIP
1 parent df95634 commit f154063

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

src/Init/Data/String/Repr.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Examples:
3939
* `"0xff".toInt? = none`
4040
-/
4141
def String.toInt? (s : String) : Option Int := do
42-
if s.get 0 = '-' then do
42+
if s.front = '-' then do
4343
let v ← (s.toSubstring.drop 1).toNat?;
4444
pure <| - Int.ofNat v
4545
else
@@ -67,7 +67,7 @@ Examples:
6767
* `"0xff".isInt = false`
6868
-/
6969
def String.isInt (s : String) : Bool :=
70-
if s.get 0 = '-' then
70+
if s.front = '-' then
7171
(s.toSubstring.drop 1).isNat
7272
else
7373
s.isNat

src/Init/Data/String/Stream.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ public import Init.Data.Stream
1212
public instance : Std.Stream Substring Char where
1313
next? s :=
1414
if s.startPos < s.stopPos then
15-
some (s.str.get s.startPos, { s with startPos := s.str.next s.startPos })
15+
some (s.startPos.get s.str, { s with startPos := s.startPos.next s.str })
1616
else
1717
none

src/lake/Lake/Util/Cli.lean

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,27 +69,27 @@ variable [Monad m] [MonadStateOf ArgList m]
6969

7070
/-- Process a short option of the form `-x=arg`. -/
7171
@[inline] public def shortOptionWithEq (handle : Char → m α) (opt : String) : m α := do
72-
consArg (opt.drop 3); handle (opt.get ⟨1⟩)
72+
consArg (opt.drop 3); handle (String.Pos.Raw.get opt1⟩)
7373

7474
/-- Process a short option of the form `"-x arg"`. -/
7575
@[inline] public def shortOptionWithSpace (handle : Char → m α) (opt : String) : m α := do
76-
consArg <| opt.drop 2 |>.trimLeft; handle (opt.get ⟨1⟩)
76+
consArg <| opt.drop 2 |>.trimLeft; handle (String.Pos.Raw.get opt1⟩)
7777

7878
/-- Process a short option of the form `-xarg`. -/
7979
@[inline] public def shortOptionWithArg (handle : Char → m α) (opt : String) : m α := do
80-
consArg (opt.drop 2); handle (opt.get ⟨1⟩)
80+
consArg (opt.drop 2); handle (String.Pos.Raw.get opt1⟩)
8181

8282
/-- Process a multiple short options grouped together (ex. `-xyz` as `x`, `y`, `z`). -/
8383
@[inline] public def multiShortOption (handle : Char → m PUnit) (opt : String) : m PUnit := do
8484
let rec loop (p : String.Pos.Raw) := do
85-
if h : opt.atEnd p then
85+
if h : p.atEnd opt then
8686
return
8787
else
88-
handle (opt.get' p h)
89-
loop (opt.next' p h)
88+
handle (p.get' opt h)
89+
loop (p.next' opt h)
9090
termination_by opt.utf8ByteSize - p.byteIdx
9191
decreasing_by
92-
simp [String.atEnd] at h
92+
simp [String.Pos.Raw.atEnd] at h
9393
apply Nat.sub_lt_sub_left h
9494
exact String.Pos.Raw.byteIdx_lt_byteIdx_next opt p
9595
loop ⟨1
@@ -100,17 +100,17 @@ variable [Monad m] [MonadStateOf ArgList m]
100100
if pos = opt.endPos then
101101
handle opt
102102
else do
103-
consArg <| opt.extract (opt.next pos) opt.endPos
104-
handle <| opt.extract 0 pos
103+
consArg <| (pos.next opt).extract opt opt.endPos
104+
handle <| String.Pos.Raw.extract opt 0 pos
105105

106106
/-- Splits a long option of the form `--long=arg` into `--long` and `arg`. -/
107107
@[inline] public def longOptionOrEq (handle : String → m α) (opt : String) : m α :=
108108
let pos := opt.posOf '='
109109
if pos = opt.endPos then
110110
handle opt
111111
else do
112-
consArg <| opt.extract (opt.next pos) opt.endPos
113-
handle <| opt.extract 0 pos
112+
consArg <| (pos.next opt).extract opt opt.endPos
113+
handle <| String.Pos.Raw.extract opt 0 pos
114114

115115
/-- Process a long option of the form `--long`, `--long=arg`, `"--long arg"`. -/
116116
@[inline] public def longOption (handle : String → m α) : String → m α :=
@@ -122,9 +122,9 @@ variable [Monad m] [MonadStateOf ArgList m]
122122
(opt : String)
123123
: m α :=
124124
if opt.length == 2 then -- `-x`
125-
shortHandle (opt.get ⟨1⟩)
125+
shortHandle (String.Pos.Raw.get opt1⟩)
126126
else -- `-c(.+)`
127-
match opt.get ⟨2with
127+
match String.Pos.Raw.get opt2with
128128
| '=' => -- `-x=arg`
129129
shortOptionWithEq shortHandle opt
130130
| ' ' => -- `"-x arg"`
@@ -138,7 +138,7 @@ An option is an argument of length > 1 starting with a dash (`-`).
138138
An option may consume additional elements of the argument list.
139139
-/
140140
@[inline] public def option (handlers : OptionHandlers m α) (opt : String) : m α :=
141-
if opt.get ⟨1⟩ == '-' then -- `--(.*)`
141+
if String.Pos.Raw.get opt1⟩ == '-' then -- `--(.*)`
142142
longOption handlers.long opt
143143
else
144144
shortOption handlers.short handlers.longShort opt
@@ -148,7 +148,7 @@ public def processLeadingOption (handle : String → m PUnit) : m PUnit := do
148148
match (← getArgs) with
149149
| [] => pure ()
150150
| arg :: args =>
151-
if arg.length > 1 && arg.get 0 == '-' then -- `-(.+)`
151+
if arg.length > 1 && String.Pos.Raw.get arg 0 == '-' then -- `-(.+)`
152152
setArgs args
153153
handle arg
154154

@@ -159,7 +159,7 @@ Consumes empty leading arguments in the argument list.
159159
public partial def processLeadingOptions (handle : String → m PUnit) : m PUnit := do
160160
if let arg :: args ← getArgs then
161161
let len := arg.length
162-
if len > 1 && arg.get 0 == '-' then -- `-(.+)`
162+
if len > 1 && String.Pos.Raw.get arg 0 == '-' then -- `-(.+)`
163163
setArgs args
164164
handle arg
165165
processLeadingOptions handle
@@ -173,7 +173,7 @@ public partial def collectArgs
173173
: m (Array String) := do
174174
if let some arg ← takeArg? then
175175
let len := arg.length
176-
if len > 1 && arg.get 0 == '-' then -- `-(.+)`
176+
if len > 1 && String.Pos.Raw.get arg 0 == '-' then -- `-(.+)`
177177
option arg
178178
collectArgs option args
179179
else if len == 0 then -- skip empty args

0 commit comments

Comments
 (0)