Width 12
For an indentation width of 12, assuming the tab stops at positions 0, 8, 16, etc .:
for $input.lines {
.say if not /
^ # start of line
[" " ** 8 || " " ** 0..7 \t] # whitespace up to first tab stop
[" " ** 4] # whitespace up to position 12
[\S | $] # non-space character or end of line
/;
}
Explanation:
To go from the beginning of the line (position 0) to the first tab tab (position 8), there are two possibilities that we need to match:
- 8 spaces.
- 0 to 7 spaces, and then 1 tab. (The tab goes straight to the tab stack, so that it fills any width after spaces.)
The only way to get from stopping the tab (position 8) to the indentation goal (position 12) is to use 4 spaces. (The tab will move through the target to the next tab stop at position 16.)
, , , .
named token, :
my token indent ($width) {
[" " ** 8 || " " ** 0..7 \t] ** {$width div 8}
" " ** {$width % 8}
}
.say if not /^ <indent(12)> [\S | $]/ for $input.lines;
:
, , , , , . ($width div 8 , div - ).
, , . ($width % 8 , % modulo.)
, (, ). , , :
my token indent ($width) {
:my ($before-first-stop, $numer-of-stops, $after-last-stop);
{
$before-first-stop = min $width, 8 - $/.from % 8;
$numer-of-stops = ($width - $before-first-stop) div 8;
$after-last-stop = ($width - $before-first-stop) % 8;
}
[" " ** {$before-first-stop} || " " ** {^$before-first-stop} \t]
[" " ** 8 || " " ** 0..7 \t] ** {$numer-of-stops}
" " ** {$after-last-stop}
}
:
, , , , , , .
$/.from; - .
( ) , .