Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Perlito5 - parser: add "\033" octal string escape

  • Loading branch information...
commit c04399abc7045f83ba414bfe99caeca01e0d63c6 1 parent dd2fe03
@fglock authored
Showing with 86 additions and 46 deletions.
  1. +22 −1 html/perlito5.js
  2. +1 −1  lib5/Perlito5/AST.pm
  3. +1 −1  lib5/Perlito5/Dumper.pm
  4. +1 −1  lib5/Perlito5/Emitter/Token.pm
  5. +1 −1  lib5/Perlito5/Eval.pm
  6. +1 −1  lib5/Perlito5/Expression.pm
  7. +1 −1  lib5/Perlito5/Grammar.pm
  8. +1 −1  lib5/Perlito5/Grammar/Bareword.pm
  9. +1 −1  lib5/Perlito5/Grammar/Block.pm
  10. +1 −1  lib5/Perlito5/Grammar/Control.pm
  11. +1 −1  lib5/Perlito5/Grammar/Regex.pm
  12. +1 −1  lib5/Perlito5/Grammar/Space.pm
  13. +16 −2 lib5/Perlito5/Grammar/String.pm
  14. +1 −1  lib5/Perlito5/Grammar/Use.pm
  15. +1 −1  lib5/Perlito5/Javascript/CORE.pm
  16. +1 −1  lib5/Perlito5/Javascript/Emitter.pm
  17. +1 −1  lib5/Perlito5/Javascript/IO.pm
  18. +1 −1  lib5/Perlito5/Javascript/Runtime.pm
  19. +1 −1  lib5/Perlito5/Macro.pm
  20. +1 −1  lib5/Perlito5/Match.pm
  21. +1 −1  lib5/Perlito5/Perl5/Emitter.pm
  22. +1 −1  lib5/Perlito5/Perl6/Emitter.pm
  23. +1 −1  lib5/Perlito5/Precedence.pm
  24. +1 −1  lib5/Perlito5/Runtime.pm
  25. +1 −1  lib5/Perlito5/Test.pm
  26. +1 −1  lib5/Perlito5/bytes.pm
  27. +1 −1  lib5/Perlito5/strict.pm
  28. +1 −1  lib5/Perlito5/utf8.pm
  29. +1 −1  lib5/Perlito5/warnings.pm
  30. +1 −1  perlito5.pl
  31. +20 −15 src5/lib/Perlito5/Grammar/String.pm
View
23 html/perlito5.js
@@ -7830,6 +7830,10 @@ var p5100 = p5pkg['main'];
(Hash_hex = 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', '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) {
var v_self = null;
(v_self = (List__[p5idx(List__,0)]));
@@ -8557,7 +8561,24 @@ var p5100 = p5pkg['main'];
};
}
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)))))));
+ };
};
};
};
View
2  lib5/Perlito5/AST.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0
-use v5;
+use v5.10;
use Perlito5::Perl5::Runtime;
package main;
undef();
View
2  lib5/Perlito5/Dumper.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0
-use v5;
+use v5.10;
use Perlito5::Perl5::Runtime;
package main;
package Perlito5::Dumper;
View
2  lib5/Perlito5/Emitter/Token.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0
-use v5;
+use v5.10;
use Perlito5::Perl5::Runtime;
package main;
undef();
View
2  lib5/Perlito5/Eval.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0
-use v5;
+use v5.10;
use Perlito5::Perl5::Runtime;
package main;
undef();
View
2  lib5/Perlito5/Expression.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0
-use v5;
+use v5.10;
use Perlito5::Perl5::Runtime;
package main;
package Perlito5::Expression;
View
2  lib5/Perlito5/Grammar.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0
-use v5;
+use v5.10;
use Perlito5::Perl5::Runtime;
package main;
package Perlito5::Grammar;
View
2  lib5/Perlito5/Grammar/Bareword.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0
-use v5;
+use v5.10;
use Perlito5::Perl5::Runtime;
package main;
package Perlito5::Grammar::Bareword;
View
2  lib5/Perlito5/Grammar/Block.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0
-use v5;
+use v5.10;
use Perlito5::Perl5::Runtime;
package main;
package Perlito5::Grammar::Block;
View
2  lib5/Perlito5/Grammar/Control.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0
-use v5;
+use v5.10;
use Perlito5::Perl5::Runtime;
package main;
package Perlito5::Grammar;
View
2  lib5/Perlito5/Grammar/Regex.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0
-use v5;
+use v5.10;
use Perlito5::Perl5::Runtime;
package main;
package Perlito5::Grammar::Regex;
View
2  lib5/Perlito5/Grammar/Space.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0
-use v5;
+use v5.10;
use Perlito5::Perl5::Runtime;
package main;
package Perlito5::Grammar::Space;
View
18 lib5/Perlito5/Grammar/String.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0
-use v5;
+use v5.10;
use Perlito5::Perl5::Runtime;
package main;
undef();
@@ -599,6 +599,7 @@ sub Perlito5::Grammar::String::term_qr_quote {
((my %pair) = ('{', '}', '(', ')', '[', ']', '<', '>'));
((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 %octal) = map(+(($_, 1)), ('0', '1', '2', '3', '4', '5', '6', '7')));
sub Perlito5::Grammar::String::q_quote_parse {
((my $self) = $_[0]);
((my $str) = $_[1]);
@@ -1117,7 +1118,20 @@ sub Perlito5::Grammar::String::double_quoted_unescape {
}
}
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)})
+ }
}
}
};
View
2  lib5/Perlito5/Grammar/Use.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0
-use v5;
+use v5.10;
use Perlito5::Perl5::Runtime;
package main;
package Perlito5::Grammar::Use;
View
2  lib5/Perlito5/Javascript/CORE.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0
-use v5;
+use v5.10;
use Perlito5::Perl5::Runtime;
package main;
undef();
View
2  lib5/Perlito5/Javascript/Emitter.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0
-use v5;
+use v5.10;
use Perlito5::Perl5::Runtime;
package main;
undef();
View
2  lib5/Perlito5/Javascript/IO.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0
-use v5;
+use v5.10;
use Perlito5::Perl5::Runtime;
package main;
undef();
View
2  lib5/Perlito5/Javascript/Runtime.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0
-use v5;
+use v5.10;
use Perlito5::Perl5::Runtime;
package main;
undef();
View
2  lib5/Perlito5/Macro.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0
-use v5;
+use v5.10;
use Perlito5::Perl5::Runtime;
package main;
undef();
View
2  lib5/Perlito5/Match.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0
-use v5;
+use v5.10;
use Perlito5::Perl5::Runtime;
package main;
undef();
View
2  lib5/Perlito5/Perl5/Emitter.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0
-use v5;
+use v5.10;
use Perlito5::Perl5::Runtime;
package main;
undef();
View
2  lib5/Perlito5/Perl6/Emitter.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0
-use v5;
+use v5.10;
use Perlito5::Perl5::Runtime;
package main;
undef();
View
2  lib5/Perlito5/Precedence.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0
-use v5;
+use v5.10;
use Perlito5::Perl5::Runtime;
package main;
package Perlito5::Precedence;
View
2  lib5/Perlito5/Runtime.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0
-use v5;
+use v5.10;
use Perlito5::Perl5::Runtime;
package main;
package Perlito5::Runtime;
View
2  lib5/Perlito5/Test.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0
-use v5;
+use v5.10;
use Perlito5::Perl5::Runtime;
package main;
package Perlito5::Test;
View
2  lib5/Perlito5/bytes.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0
-use v5;
+use v5.10;
use Perlito5::Perl5::Runtime;
package main;
package Perlito5::bytes;
View
2  lib5/Perlito5/strict.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0
-use v5;
+use v5.10;
use Perlito5::Perl5::Runtime;
package main;
package Perlito5::strict;
View
2  lib5/Perlito5/utf8.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0
-use v5;
+use v5.10;
use Perlito5::Perl5::Runtime;
package main;
package Perlito5::utf8;
View
2  lib5/Perlito5/warnings.pm
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0
-use v5;
+use v5.10;
use Perlito5::Perl5::Runtime;
package main;
package Perlito5::warnings;
View
2  perlito5.pl
@@ -1,5 +1,5 @@
# Do not edit this file - Generated by Perlito5 9.0
-use v5;
+use v5.10;
use Perlito5::Perl5::Runtime;
package main;
undef();
View
35 src5/lib/Perlito5/Grammar/String.pm
@@ -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 %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 {
my $self = $_[0];
@@ -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 {
- # TODO - "\"+octal - initial zero is optional; max 3 digit octal (377)
# TODO - \N{charname} - requires "use charnames"
# TODO - \L \Q \U ... \E - lowercase/uppercase/quote until /E
# 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 = {
'str' => $str,
'from' => $pos,
Please sign in to comment.
Something went wrong with that request. Please try again.