File tree Expand file tree Collapse file tree 3 files changed +30
-9
lines changed Expand file tree Collapse file tree 3 files changed +30
-9
lines changed Original file line number Diff line number Diff line change @@ -1998,18 +1998,26 @@ pub fn ident_modifier_args(ident: &str) -> usize {
1998
1998
count
1999
1999
}
2000
2000
2001
- /// Get the maximum placeholder index in a list of words
2002
- pub fn max_placeholder ( words : & [ Sp < Word > ] ) -> Option < usize > {
2001
+ /// Get the maximum placeholder index in a list of words,
2002
+ /// as well as the span of a placeholder shorthand
2003
+ pub fn max_placeholder ( words : & [ Sp < Word > ] ) -> Option < ( usize , Option < CodeSpan > ) > {
2003
2004
let mut max: Option < usize > = None ;
2004
- let mut set = |i : Option < usize > | {
2005
- if let Some ( i) = i {
2005
+ let mut shorthand_span = None ;
2006
+ let mut set = |is : Option < ( usize , Option < CodeSpan > ) > | {
2007
+ if let Some ( ( i, s) ) = is {
2006
2008
let max = max. get_or_insert ( 0 ) ;
2007
2009
* max = ( * max) . max ( i) ;
2010
+ if shorthand_span. is_none ( ) && s. is_some ( ) {
2011
+ shorthand_span = s;
2012
+ }
2008
2013
}
2009
2014
} ;
2010
2015
for word in words {
2011
2016
match & word. value {
2012
- Word :: Placeholder ( i) => set ( Some ( i. unwrap_or ( 0 ) ) ) ,
2017
+ Word :: Placeholder ( i) => set ( Some ( (
2018
+ i. unwrap_or ( 0 ) ,
2019
+ i. is_none ( ) . then ( || word. span . clone ( ) ) ,
2020
+ ) ) ) ,
2013
2021
Word :: Strand ( items) => set ( max_placeholder ( items) ) ,
2014
2022
Word :: Array ( arr) => {
2015
2023
for line in arr. word_lines ( ) {
@@ -2033,7 +2041,7 @@ pub fn max_placeholder(words: &[Sp<Word>]) -> Option<usize> {
2033
2041
_ => { }
2034
2042
}
2035
2043
}
2036
- max
2044
+ max. map ( |i| ( i , shorthand_span ) )
2037
2045
}
2038
2046
2039
2047
/// Trim space words
Original file line number Diff line number Diff line change @@ -183,7 +183,7 @@ impl Compiler {
183
183
return Ok ( ( ) ) ;
184
184
}
185
185
// Index macro
186
- match ( ident_margs, max_placeholder) {
186
+ match ( ident_margs, & max_placeholder) {
187
187
( 0 , None ) => { }
188
188
( _, None ) => {
189
189
self . add_error (
@@ -204,7 +204,7 @@ impl Compiler {
204
204
) ;
205
205
return Ok ( ( ) ) ;
206
206
}
207
- ( n, Some ( max) ) => {
207
+ ( n, Some ( ( max, shorthand_span ) ) ) => {
208
208
if max + 1 > n {
209
209
self . emit_diagnostic (
210
210
format ! (
@@ -216,6 +216,17 @@ impl Compiler {
216
216
span. clone ( ) ,
217
217
) ;
218
218
}
219
+ if let Some ( span) = shorthand_span {
220
+ if * max > 0 {
221
+ self . add_error (
222
+ span. clone ( ) ,
223
+ format ! (
224
+ "`{name}` cannot use the placeholder shorthand \
225
+ because it contains a ^{max}. Use explicit ^0 instead."
226
+ ) ,
227
+ )
228
+ }
229
+ }
219
230
}
220
231
}
221
232
if max_placeholder. is_some ( ) || ident_margs > 0 {
Original file line number Diff line number Diff line change @@ -186,4 +186,6 @@ F ← |0.1000 ⍢(F F F|1)
186
186
187
187
|
188
188
189
- +⊸¤⇡1e5
189
+ +⊸¤⇡1e5
190
+
191
+ F‼ ← ^^1
You can’t perform that action at this time.
0 commit comments