Skip to content

Commit

Permalink
Perlito5 - parser: add "\033" octal string escape
Browse files Browse the repository at this point in the history
  • Loading branch information
fglock committed Apr 20, 2012
1 parent dd2fe03 commit c04399a
Show file tree
Hide file tree
Showing 31 changed files with 86 additions and 46 deletions.
23 changes: 22 additions & 1 deletion html/perlito5.js
Expand Up @@ -7830,6 +7830,10 @@ var p5100 = p5pkg['main'];
(Hash_hex = p5a_to_h(p5list_to_a(p5map(p5pkg["Perlito5::Grammar::String"], function (p5want) { (Hash_hex = p5a_to_h(p5list_to_a(p5map(p5pkg["Perlito5::Grammar::String"], function (p5want) {
return ((p5context([p5pkg["Perlito5::Grammar::String"]["v__"], 1], p5want))); return ((p5context([p5pkg["Perlito5::Grammar::String"]["v__"], 1], p5want)));
}, ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'])))); }, ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F']))));
var Hash_octal = {};
(Hash_octal = p5a_to_h(p5list_to_a(p5map(p5pkg["Perlito5::Grammar::String"], function (p5want) {
return ((p5context([p5pkg["Perlito5::Grammar::String"]["v__"], 1], p5want)));
}, ['0', '1', '2', '3', '4', '5', '6', '7']))));
p5make_sub("Perlito5::Grammar::String", "q_quote_parse", function (List__, p5want) { p5make_sub("Perlito5::Grammar::String", "q_quote_parse", function (List__, p5want) {
var v_self = null; var v_self = null;
(v_self = (List__[p5idx(List__,0)])); (v_self = (List__[p5idx(List__,0)]));
Expand Down Expand Up @@ -8557,7 +8561,24 @@ var p5100 = p5pkg['main'];
}; };
} }
else { else {
(v_m = ((new p5HashRef(p5a_to_h(p5list_to_a('str', v_str, 'from', v_pos, 'to', (p5num(v_pos) + 2), 'capture', p5call(p5pkg["Perlito5::AST::Val::Buf"], "new", ['buf', v_c2], 1))))))); if ( (Hash_octal).hasOwnProperty(v_c2) ) {
(function () {
var v_p = null;
(v_p = ((p5num(v_pos) + 2)));
if ( p5bool(Hash_octal[p5pkg["Perlito5::Grammar::String"].substr([v_str, v_p, 1], p5want)]) ) {
(v_p)++;
};
if ( p5bool(Hash_octal[p5pkg["Perlito5::Grammar::String"].substr([v_str, v_p, 1], p5want)]) ) {
(v_p)++;
};
var v_tmp = null;
(v_tmp = (p5pkg["Perlito5::Grammar::String"].oct([p5pkg["Perlito5::Grammar::String"].substr([v_str, (p5num(v_pos) + 1), (p5num(v_p) - p5num(v_pos))], 0)], 0)));
(v_m = ((new p5HashRef(p5a_to_h(p5list_to_a('str', v_str, 'from', v_pos, 'to', v_p, 'capture', p5call(p5pkg["Perlito5::AST::Apply"], "new", p5list_to_a('arguments', (new p5ArrayRef(p5list_to_a(p5call(p5pkg["Perlito5::AST::Val::Int"], "new", ['int', v_tmp], 1)))), 'code', 'chr'), 1)))))));
})();
}
else {
(v_m = ((new p5HashRef(p5a_to_h(p5list_to_a('str', v_str, 'from', v_pos, 'to', (p5num(v_pos) + 2), 'capture', p5call(p5pkg["Perlito5::AST::Val::Buf"], "new", ['buf', v_c2], 1)))))));
};
}; };
}; };
}; };
Expand Down
2 changes: 1 addition & 1 deletion lib5/Perlito5/AST.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0 # Do not edit this file - Generated by Perlito5 9.0
use v5; use v5.10;
use Perlito5::Perl5::Runtime; use Perlito5::Perl5::Runtime;
package main; package main;
undef(); undef();
Expand Down
2 changes: 1 addition & 1 deletion lib5/Perlito5/Dumper.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0 # Do not edit this file - Generated by Perlito5 9.0
use v5; use v5.10;
use Perlito5::Perl5::Runtime; use Perlito5::Perl5::Runtime;
package main; package main;
package Perlito5::Dumper; package Perlito5::Dumper;
Expand Down
2 changes: 1 addition & 1 deletion lib5/Perlito5/Emitter/Token.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0 # Do not edit this file - Generated by Perlito5 9.0
use v5; use v5.10;
use Perlito5::Perl5::Runtime; use Perlito5::Perl5::Runtime;
package main; package main;
undef(); undef();
Expand Down
2 changes: 1 addition & 1 deletion lib5/Perlito5/Eval.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0 # Do not edit this file - Generated by Perlito5 9.0
use v5; use v5.10;
use Perlito5::Perl5::Runtime; use Perlito5::Perl5::Runtime;
package main; package main;
undef(); undef();
Expand Down
2 changes: 1 addition & 1 deletion lib5/Perlito5/Expression.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0 # Do not edit this file - Generated by Perlito5 9.0
use v5; use v5.10;
use Perlito5::Perl5::Runtime; use Perlito5::Perl5::Runtime;
package main; package main;
package Perlito5::Expression; package Perlito5::Expression;
Expand Down
2 changes: 1 addition & 1 deletion lib5/Perlito5/Grammar.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0 # Do not edit this file - Generated by Perlito5 9.0
use v5; use v5.10;
use Perlito5::Perl5::Runtime; use Perlito5::Perl5::Runtime;
package main; package main;
package Perlito5::Grammar; package Perlito5::Grammar;
Expand Down
2 changes: 1 addition & 1 deletion lib5/Perlito5/Grammar/Bareword.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0 # Do not edit this file - Generated by Perlito5 9.0
use v5; use v5.10;
use Perlito5::Perl5::Runtime; use Perlito5::Perl5::Runtime;
package main; package main;
package Perlito5::Grammar::Bareword; package Perlito5::Grammar::Bareword;
Expand Down
2 changes: 1 addition & 1 deletion lib5/Perlito5/Grammar/Block.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0 # Do not edit this file - Generated by Perlito5 9.0
use v5; use v5.10;
use Perlito5::Perl5::Runtime; use Perlito5::Perl5::Runtime;
package main; package main;
package Perlito5::Grammar::Block; package Perlito5::Grammar::Block;
Expand Down
2 changes: 1 addition & 1 deletion lib5/Perlito5/Grammar/Control.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0 # Do not edit this file - Generated by Perlito5 9.0
use v5; use v5.10;
use Perlito5::Perl5::Runtime; use Perlito5::Perl5::Runtime;
package main; package main;
package Perlito5::Grammar; package Perlito5::Grammar;
Expand Down
2 changes: 1 addition & 1 deletion lib5/Perlito5/Grammar/Regex.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0 # Do not edit this file - Generated by Perlito5 9.0
use v5; use v5.10;
use Perlito5::Perl5::Runtime; use Perlito5::Perl5::Runtime;
package main; package main;
package Perlito5::Grammar::Regex; package Perlito5::Grammar::Regex;
Expand Down
2 changes: 1 addition & 1 deletion lib5/Perlito5/Grammar/Space.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0 # Do not edit this file - Generated by Perlito5 9.0
use v5; use v5.10;
use Perlito5::Perl5::Runtime; use Perlito5::Perl5::Runtime;
package main; package main;
package Perlito5::Grammar::Space; package Perlito5::Grammar::Space;
Expand Down
18 changes: 16 additions & 2 deletions lib5/Perlito5/Grammar/String.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0 # Do not edit this file - Generated by Perlito5 9.0
use v5; use v5.10;
use Perlito5::Perl5::Runtime; use Perlito5::Perl5::Runtime;
package main; package main;
undef(); undef();
Expand Down Expand Up @@ -599,6 +599,7 @@ sub Perlito5::Grammar::String::term_qr_quote {
((my %pair) = ('{', '}', '(', ')', '[', ']', '<', '>')); ((my %pair) = ('{', '}', '(', ')', '[', ']', '<', '>'));
((my %escape_sequence) = ('a', '7', 'b', '8', 'e', '27', 'f', '12', 'n', '10', 'r', '13', 't', '9')); ((my %escape_sequence) = ('a', '7', 'b', '8', 'e', '27', 'f', '12', 'n', '10', 'r', '13', 't', '9'));
((my %hex) = map(+(($_, 1)), ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'))); ((my %hex) = map(+(($_, 1)), ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F')));
((my %octal) = map(+(($_, 1)), ('0', '1', '2', '3', '4', '5', '6', '7')));
sub Perlito5::Grammar::String::q_quote_parse { sub Perlito5::Grammar::String::q_quote_parse {
((my $self) = $_[0]); ((my $self) = $_[0]);
((my $str) = $_[1]); ((my $str) = $_[1]);
Expand Down Expand Up @@ -1117,7 +1118,20 @@ sub Perlito5::Grammar::String::double_quoted_unescape {
} }
} }
else { else {
($m = {'str', $str, 'from', $pos, 'to', ($pos + 2), 'capture', Perlito5::AST::Val::Buf->new('buf', $c2)}) if (exists($octal{$c2})) {
((my $p) = ($pos + 2));
if ($octal{substr($str, $p, 1)}) {
($p)++
};
if ($octal{substr($str, $p, 1)}) {
($p)++
};
((my $tmp) = oct(substr($str, ($pos + 1), ($p - $pos))));
($m = {'str', $str, 'from', $pos, 'to', $p, 'capture', Perlito5::AST::Apply->new('arguments', [Perlito5::AST::Val::Int->new('int', $tmp)], 'code', 'chr')})
}
else {
($m = {'str', $str, 'from', $pos, 'to', ($pos + 2), 'capture', Perlito5::AST::Val::Buf->new('buf', $c2)})
}
} }
} }
}; };
Expand Down
2 changes: 1 addition & 1 deletion lib5/Perlito5/Grammar/Use.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0 # Do not edit this file - Generated by Perlito5 9.0
use v5; use v5.10;
use Perlito5::Perl5::Runtime; use Perlito5::Perl5::Runtime;
package main; package main;
package Perlito5::Grammar::Use; package Perlito5::Grammar::Use;
Expand Down
2 changes: 1 addition & 1 deletion lib5/Perlito5/Javascript/CORE.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0 # Do not edit this file - Generated by Perlito5 9.0
use v5; use v5.10;
use Perlito5::Perl5::Runtime; use Perlito5::Perl5::Runtime;
package main; package main;
undef(); undef();
Expand Down
2 changes: 1 addition & 1 deletion lib5/Perlito5/Javascript/Emitter.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0 # Do not edit this file - Generated by Perlito5 9.0
use v5; use v5.10;
use Perlito5::Perl5::Runtime; use Perlito5::Perl5::Runtime;
package main; package main;
undef(); undef();
Expand Down
2 changes: 1 addition & 1 deletion lib5/Perlito5/Javascript/IO.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0 # Do not edit this file - Generated by Perlito5 9.0
use v5; use v5.10;
use Perlito5::Perl5::Runtime; use Perlito5::Perl5::Runtime;
package main; package main;
undef(); undef();
Expand Down
2 changes: 1 addition & 1 deletion lib5/Perlito5/Javascript/Runtime.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0 # Do not edit this file - Generated by Perlito5 9.0
use v5; use v5.10;
use Perlito5::Perl5::Runtime; use Perlito5::Perl5::Runtime;
package main; package main;
undef(); undef();
Expand Down
2 changes: 1 addition & 1 deletion lib5/Perlito5/Macro.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0 # Do not edit this file - Generated by Perlito5 9.0
use v5; use v5.10;
use Perlito5::Perl5::Runtime; use Perlito5::Perl5::Runtime;
package main; package main;
undef(); undef();
Expand Down
2 changes: 1 addition & 1 deletion lib5/Perlito5/Match.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0 # Do not edit this file - Generated by Perlito5 9.0
use v5; use v5.10;
use Perlito5::Perl5::Runtime; use Perlito5::Perl5::Runtime;
package main; package main;
undef(); undef();
Expand Down
2 changes: 1 addition & 1 deletion lib5/Perlito5/Perl5/Emitter.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0 # Do not edit this file - Generated by Perlito5 9.0
use v5; use v5.10;
use Perlito5::Perl5::Runtime; use Perlito5::Perl5::Runtime;
package main; package main;
undef(); undef();
Expand Down
2 changes: 1 addition & 1 deletion lib5/Perlito5/Perl6/Emitter.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0 # Do not edit this file - Generated by Perlito5 9.0
use v5; use v5.10;
use Perlito5::Perl5::Runtime; use Perlito5::Perl5::Runtime;
package main; package main;
undef(); undef();
Expand Down
2 changes: 1 addition & 1 deletion lib5/Perlito5/Precedence.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0 # Do not edit this file - Generated by Perlito5 9.0
use v5; use v5.10;
use Perlito5::Perl5::Runtime; use Perlito5::Perl5::Runtime;
package main; package main;
package Perlito5::Precedence; package Perlito5::Precedence;
Expand Down
2 changes: 1 addition & 1 deletion lib5/Perlito5/Runtime.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0 # Do not edit this file - Generated by Perlito5 9.0
use v5; use v5.10;
use Perlito5::Perl5::Runtime; use Perlito5::Perl5::Runtime;
package main; package main;
package Perlito5::Runtime; package Perlito5::Runtime;
Expand Down
2 changes: 1 addition & 1 deletion lib5/Perlito5/Test.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0 # Do not edit this file - Generated by Perlito5 9.0
use v5; use v5.10;
use Perlito5::Perl5::Runtime; use Perlito5::Perl5::Runtime;
package main; package main;
package Perlito5::Test; package Perlito5::Test;
Expand Down
2 changes: 1 addition & 1 deletion lib5/Perlito5/bytes.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0 # Do not edit this file - Generated by Perlito5 9.0
use v5; use v5.10;
use Perlito5::Perl5::Runtime; use Perlito5::Perl5::Runtime;
package main; package main;
package Perlito5::bytes; package Perlito5::bytes;
Expand Down
2 changes: 1 addition & 1 deletion lib5/Perlito5/strict.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0 # Do not edit this file - Generated by Perlito5 9.0
use v5; use v5.10;
use Perlito5::Perl5::Runtime; use Perlito5::Perl5::Runtime;
package main; package main;
package Perlito5::strict; package Perlito5::strict;
Expand Down
2 changes: 1 addition & 1 deletion lib5/Perlito5/utf8.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0 # Do not edit this file - Generated by Perlito5 9.0
use v5; use v5.10;
use Perlito5::Perl5::Runtime; use Perlito5::Perl5::Runtime;
package main; package main;
package Perlito5::utf8; package Perlito5::utf8;
Expand Down
2 changes: 1 addition & 1 deletion lib5/Perlito5/warnings.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0 # Do not edit this file - Generated by Perlito5 9.0
use v5; use v5.10;
use Perlito5::Perl5::Runtime; use Perlito5::Perl5::Runtime;
package main; package main;
package Perlito5::warnings; package Perlito5::warnings;
Expand Down
2 changes: 1 addition & 1 deletion perlito5.pl
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0 # Do not edit this file - Generated by Perlito5 9.0
use v5; use v5.10;
use Perlito5::Perl5::Runtime; use Perlito5::Perl5::Runtime;
package main; package main;
undef(); undef();
Expand Down
35 changes: 20 additions & 15 deletions src5/lib/Perlito5/Grammar/String.pm
Expand Up @@ -91,7 +91,8 @@ my %pair = (


my %escape_sequence = qw/ a 7 b 8 e 27 f 12 n 10 r 13 t 9 /; my %escape_sequence = qw/ a 7 b 8 e 27 f 12 n 10 r 13 t 9 /;


my %hex = map +($_ => 1), qw/ 0 1 2 3 4 5 6 7 8 9 A B C D E F /; my %hex = map +($_ => 1), qw/ 0 1 2 3 4 5 6 7 8 9 A B C D E F /;
my %octal = map +($_ => 1), qw/ 0 1 2 3 4 5 6 7 /;


sub q_quote_parse { sub q_quote_parse {
my $self = $_[0]; my $self = $_[0];
Expand Down Expand Up @@ -671,25 +672,29 @@ sub double_quoted_unescape {
}; };
} }
} }
elsif ( exists $octal{$c2} ) {
# "\"+octal - initial zero is optional; max 3 digit octal (377)
my $p = $pos+2;
$p++ if $octal{ substr($str, $p, 1) };
$p++ if $octal{ substr($str, $p, 1) };
my $tmp = oct( substr($str, $pos+1, $p - $pos) );
$m = {
str => $str,
from => $pos,
to => $p,
capture => Perlito5::AST::Apply->new(
'arguments' => [
Perlito5::AST::Val::Int->new( 'int' => $tmp ),
],
'code' => 'chr',
)
};
}
else { else {
# TODO - "\"+octal - initial zero is optional; max 3 digit octal (377)
# TODO - \N{charname} - requires "use charnames" # TODO - \N{charname} - requires "use charnames"
# TODO - \L \Q \U ... \E - lowercase/uppercase/quote until /E # TODO - \L \Q \U ... \E - lowercase/uppercase/quote until /E
# TODO - \l \u - uppercase next char # TODO - \l \u - uppercase next char


## [ \[ <Perlito5::Grammar.digits> \]
## { $MATCH->{capture} = chr( Perlito5::Match::flat($MATCH->{"Perlito5::Grammar.digits"}) ) }
## | <Perlito5::Grammar.digits>
## { $MATCH->{capture} = chr( Perlito5::Match::flat($MATCH->{"Perlito5::Grammar.digits"}) ) }
## ]

## my %double_quoted_unescape = (
## '0' => \&unescape_octal,
## 'x' => \&unescape_hex,
## 'c' => \&unescape_ctrl,
## 'N' => \&unescape_charname,
## );

$m = { $m = {
'str' => $str, 'str' => $str,
'from' => $pos, 'from' => $pos,
Expand Down

0 comments on commit c04399a

Please sign in to comment.