@@ -342,110 +342,70 @@ position C<pos>.
342
342
= end
343
343
344
344
method peek_delimiters (str $ target , int $ pos ) {
345
- Q : PIR {
346
- .local pmc self
347
- self = find_lex 'self'
348
- .local string target
349
- target = find_lex '$target'
350
- .local int pos
351
- pos = find_lex '$pos'
352
-
353
- .local string brackets, start, stop
354
- $P0 = find_lex '$brackets'
355
- brackets = $P0
356
-
357
- # peek at the next character
358
- start = substr target, pos, 1
359
- # colon and word characters aren't valid delimiters
360
- if start == ' : ' goto err_colon_delim
361
- $I0 = is_cclass .CCLASS_WORD, start, 0
362
- if $I0 goto err_word_delim
363
- $I0 = is_cclass .CCLASS_WHITESPACE, start, 0
364
- if $I0 goto err_ws_delim
365
-
366
- # assume stop delim is same as start, for the moment
367
- stop = start
368
-
369
- # see if we have an opener or closer
370
- $I0 = index brackets, start
371
- if $I0 < 0 goto bracket_end
345
+ # peek at the next character
346
+ my str $ start := nqp :: substr ($ target , $ pos , 1 );
347
+
348
+ # colon, word and whitespace characters aren't valid delimiters
349
+ if $ start eq ' :' {
350
+ self . panic(' Colons may not be used to delimit quoting constructs' );
351
+ }
352
+ if nqp ::iscclass(pir::const::CCLASS_WORD, $ start , 0 ) {
353
+ self . panic(' Alphanumeric character is not allowed as a delimiter' );
354
+ }
355
+ if nqp ::iscclass(pir::const::CCLASS_WHITESPACE, $ start , 0 ) {
356
+ self . panic(' Whitespace character is not allowed as a delimiter' );
357
+ }
358
+
359
+ # assume stop delim is same as start, for the moment
360
+ my str $ stop := $ start ;
361
+ my int $ brac := nqp :: index ($ brackets , $ start );
362
+ if $ brac >= 0 {
372
363
# if it's a closing bracket, that's an error also
373
- $ I1 = $ I0 % 2
374
- if $ I1 goto err_close
364
+ if $ brac % 2 {
365
+ self . panic(' Use of a closing delimiter for an opener is reserved' );
366
+ }
367
+
375
368
# it's an opener, so get the closing bracket
376
- inc $ I0
377
- stop = substr brackets, $ I0 , 1
369
+ $ stop := nqp :: substr ($ brackets , $ brac + 1 , 1 );
378
370
379
371
# see if the opening bracket is repeated
380
- . local int len
381
- len = 0
382
- bracket_loop:
383
- inc pos
384
- inc len
385
- $ S0 = substr target, pos , 1
386
- if $ S0 == start goto bracket_loop
387
- if len == 1 goto bracket_end
388
- start = repeat start , len
389
- stop = repeat stop, len
390
- bracket_end:
391
- . return (start , stop, pos )
392
-
393
- err_colon_delim:
394
- self . ' panic' (' Colons may not be used to delimit quoting constructs' )
395
- err_word_delim:
396
- self . ' panic' (' Alphanumeric character is not allowed as a delimiter' )
397
- err_ws_delim:
398
- self . ' panic' (' Whitespace character is not allowed as a delimiter' )
399
- err_close:
400
- self . ' panic' (' Use of a closing delimiter for an opener is reserved' )
401
- };
372
+ my int $ len := 1 ;
373
+ while nqp :: substr ($ target , ++ $ pos , 1 ) eq $ start {
374
+ $ len ++ ;
375
+ }
376
+ if $ len > 1 {
377
+ $ start := nqp ::x ($ start , $ len );
378
+ $ stop := nqp ::x ($ stop , $ len );
379
+ }
380
+ }
381
+ [$ start , $ stop ]
402
382
}
403
383
384
+ my $ TRUE := 1 ;
404
385
token quote_EXPR (* @ args ) {
405
386
:my % * QUOTEMOD ;
406
387
:my $ * QUOTE_START ;
407
388
:my $ * QUOTE_STOP ;
408
389
{
409
- Q : PIR {
410
- .local pmc self, cur_class, args
411
- self = find_lex 'self'
412
- cur_class = find_lex '$cursor_class'
413
- args = find_lex '@args'
414
-
415
- .local pmc quotemod, true
416
- quotemod = find_lex '%*QUOTEMOD'
417
- true = box 1
418
-
419
- args_loop :
420
- unless args goto args_done
421
- . local string mod
422
- mod = shift args
423
- mod = substr mod , 1
424
- quotemod[mod ] = true
425
- if mod == ' qq' goto opt_qq
426
- if mod == ' b' goto opt_b
427
- goto args_loop
428
- opt_qq:
429
- quotemod[' s' ] = true
430
- quotemod[' a' ] = true
431
- quotemod[' h' ] = true
432
- quotemod[' f' ] = true
433
- quotemod[' c' ] = true
434
- quotemod[' b' ] = true
435
- opt_b:
436
- quotemod[' q' ] = true
437
- goto args_loop
438
- args_done:
439
-
440
- . local pmc start , stop
441
- . local string target
442
- . local int pos
443
- target = repr_get_attr_str self , cur_class, ' $!target'
444
- pos = repr_get_attr_int self , cur_class, ' $!pos'
445
- (start , stop) = self . ' peek_delimiters' (target, pos )
446
- store_lex ' $*QUOTE_START' , start
447
- store_lex ' $*QUOTE_STOP' , stop
390
+ for @ args -> $ mod {
391
+ $ mod := nqp :: substr ($ mod , 1 );
392
+ % * QUOTEMOD {$ mod } := $ TRUE ;
393
+ if $ mod eq ' qq' {
394
+ % * QUOTEMOD {' s' } := $ TRUE ;
395
+ % * QUOTEMOD {' a' } := $ TRUE ;
396
+ % * QUOTEMOD {' h' } := $ TRUE ;
397
+ % * QUOTEMOD {' f' } := $ TRUE ;
398
+ % * QUOTEMOD {' c' } := $ TRUE ;
399
+ % * QUOTEMOD {' b' } := $ TRUE ;
400
+ }
401
+ elsif $ mod eq ' b' {
402
+ % * QUOTEMOD {' q' } := $ TRUE ;
403
+ }
448
404
}
405
+
406
+ my @ delims := self . peek_delimiters(self . target, self . pos );
407
+ $ * QUOTE_START := @ delims [0 ];
408
+ $ * QUOTE_STOP := @ delims [1 ];
449
409
}
450
410
<quote_delimited >
451
411
}
0 commit comments