Skip to content

Commit 8dda686

Browse files
committed
Perlito5 - string parser flags \E \L \U \Q (more)
1 parent 96ad233 commit 8dda686

File tree

4 files changed

+85
-10
lines changed

4 files changed

+85
-10
lines changed

TODO-perlito5

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,10 @@ TODO list for Perlito5
373373
exists 1
374374
exists 1
375375

376+
-- delete() in src5/lib/Perlito5/Grammar/String.pm doesn't seem to work:
377+
delete($quote_flags->{$flag_to_reset});
378+
delete($quote_flags->{last_flag});
379+
376380
-- "or" has SCALAR context (Abigail++):
377381
See: t5/01-perlito/23-eval.t
378382

html/perlito5.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6511,12 +6511,37 @@ return (p5call(p5pkg["Perlito5::AST::Val::Buf"], "new", ['buf', p5pkg["Perlito5:
65116511
else if ( (p5str(v_c) == String.fromCharCode(92)) ) {
65126512
if ( p5bool(v_interpolate) ) {
65136513
if ( (p5str(v_c2) == 'E') ) {
6514-
v_quote_flags = ((new p5HashRef({})));
6514+
(function () {
6515+
var v_flag_to_reset;
6516+
v_flag_to_reset = ((v_quote_flags || (v_quote_flags = new p5HashRef({})))._hash_.p5hget('last_flag'));
6517+
if ( p5bool(v_flag_to_reset) ) {
6518+
(v_quote_flags || (v_quote_flags = new p5HashRef({})))._hash_.p5hset(p5str(v_flag_to_reset), (0));
6519+
(v_quote_flags || (v_quote_flags = new p5HashRef({})))._hash_.p5hset('last_flag', (0));
6520+
}
6521+
else {
6522+
v_quote_flags = ((new p5HashRef({})));
6523+
};
6524+
(v_p = ((p5num(v_p) + 1)));
6525+
v_c = ('');
6526+
})();
6527+
}
6528+
else if ( (p5str(v_c2) == 'L') ) {
6529+
(v_quote_flags || (v_quote_flags = new p5HashRef({})))._hash_.p5hset(p5str(v_c2), (1));
6530+
(delete (v_quote_flags || (v_quote_flags = new p5HashRef({})))._hash_.p5hget('U'));
6531+
(v_quote_flags || (v_quote_flags = new p5HashRef({})))._hash_.p5hset('last_flag', (v_c2));
6532+
(v_p = ((p5num(v_p) + 1)));
6533+
v_c = ('');
6534+
}
6535+
else if ( (p5str(v_c2) == 'U') ) {
6536+
(v_quote_flags || (v_quote_flags = new p5HashRef({})))._hash_.p5hset(p5str(v_c2), (1));
6537+
(delete (v_quote_flags || (v_quote_flags = new p5HashRef({})))._hash_.p5hget('L'));
6538+
(v_quote_flags || (v_quote_flags = new p5HashRef({})))._hash_.p5hset('last_flag', (v_c2));
65156539
(v_p = ((p5num(v_p) + 1)));
65166540
v_c = ('');
65176541
}
6518-
else if ( (((p5str(v_c2) == 'L') || (p5str(v_c2) == 'U')) || (p5str(v_c2) == 'Q')) ) {
6542+
else if ( (p5str(v_c2) == 'Q') ) {
65196543
(v_quote_flags || (v_quote_flags = new p5HashRef({})))._hash_.p5hset(p5str(v_c2), (1));
6544+
(v_quote_flags || (v_quote_flags = new p5HashRef({})))._hash_.p5hset('last_flag', (v_c2));
65206545
(v_p = ((p5num(v_p) + 1)));
65216546
v_c = ('');
65226547
};

perlito5.pl

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4489,12 +4489,34 @@ sub Perlito5::Grammar::String::string_interpolation_parse {
44894489
elsif ($c eq chr(92)) {
44904490
if ($interpolate) {
44914491
if ($c2 eq 'E') {
4492-
$quote_flags = {};
4492+
my $flag_to_reset = $quote_flags->{'last_flag'};
4493+
if ($flag_to_reset) {
4494+
$quote_flags->{$flag_to_reset} = 0;
4495+
$quote_flags->{'last_flag'} = 0
4496+
}
4497+
else {
4498+
$quote_flags = {}
4499+
}
4500+
$p += 1;
4501+
$c = ''
4502+
}
4503+
elsif ($c2 eq 'L') {
4504+
$quote_flags->{$c2} = 1;
4505+
delete($quote_flags->{'U'});
4506+
$quote_flags->{'last_flag'} = $c2;
4507+
$p += 1;
4508+
$c = ''
4509+
}
4510+
elsif ($c2 eq 'U') {
4511+
$quote_flags->{$c2} = 1;
4512+
delete($quote_flags->{'L'});
4513+
$quote_flags->{'last_flag'} = $c2;
44934514
$p += 1;
44944515
$c = ''
44954516
}
4496-
elsif ($c2 eq 'L' || $c2 eq 'U' || $c2 eq 'Q') {
4517+
elsif ($c2 eq 'Q') {
44974518
$quote_flags->{$c2} = 1;
4519+
$quote_flags->{'last_flag'} = $c2;
44984520
$p += 1;
44994521
$c = ''
45004522
}

src5/lib/Perlito5/Grammar/String.pm

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -384,16 +384,40 @@ sub string_interpolation_parse {
384384
}
385385
elsif ($c eq '\\') {
386386
if ($interpolate) {
387-
if ( $c2 eq 'E' ) {
388-
$quote_flags = {}; # reset all $quote_flags
387+
# \L \U \Q .. \E - lowercase/uppercase/quotemeta until /E or end-of-string
388+
if ($c2 eq 'E') {
389+
my $flag_to_reset = $quote_flags->{last_flag};
390+
if ($flag_to_reset) {
391+
# delete($quote_flags->{$flag_to_reset});
392+
# delete($quote_flags->{last_flag});
393+
$quote_flags->{$flag_to_reset} = 0;
394+
$quote_flags->{last_flag} = 0;
395+
}
396+
else {
397+
$quote_flags = {}
398+
}
399+
$p += 1;
400+
$c = ''
401+
}
402+
elsif ($c2 eq 'L') {
403+
$quote_flags->{$c2} = 1;
404+
delete $quote_flags->{U};
405+
$quote_flags->{last_flag} = $c2;
406+
$p += 1;
407+
$c = ''
408+
}
409+
elsif ($c2 eq 'U') {
410+
$quote_flags->{$c2} = 1;
411+
delete $quote_flags->{L};
412+
$quote_flags->{last_flag} = $c2;
389413
$p += 1;
390-
$c = '';
414+
$c = ''
391415
}
392-
elsif ( $c2 eq 'L' || $c2 eq 'U' || $c2 eq 'Q' ) {
393-
# \L \U \Q .. \E - lowercase/uppercase/quotemeta until /E or end-of-string
416+
elsif ($c2 eq 'Q') {
394417
$quote_flags->{$c2} = 1;
418+
$quote_flags->{last_flag} = $c2;
395419
$p += 1;
396-
$c = '';
420+
$c = ''
397421
}
398422
}
399423
if ($c) {

0 commit comments

Comments
 (0)