(?<EscapeChar>
\x5C # leading \
(?:
- [\x5C/"btnfr] # escapes: \\ \/ \b \t \n \f \r
+ [\x5C"btnfr] # escapes: \\ \b \t \n \f \r
| (?: u [_0-9a-fA-F]{4} ) # unicode (4 bytes)
| (?: U [_0-9a-fA-F]{8} ) # unicode (8 bytes)
)
use strict;
use warnings;
no warnings qw(experimental);
+use charnames qw(:full);
use v5.18;
-use Carp;
use TOML::Tiny::Grammar;
use Class::Struct 'TOML::Tiny::Token' => {
my $token = shift;
my $msg = shift // 'unknown';
my $line = $token ? $token->line : $self->{line};
- croak "toml: parse error at line $line: $msg\n";
+ die "toml: parse error at line $line: $msg\n";
}
sub tokenize_key {
$str =~ s/^(?&WS) (?&NL) $TOML//x;
$str =~ s/\\(?&NL)\s* $TOML//xgs;
- $str = unescape_str($str);
+ $str = $self->unescape_str($str);
}
when (/^ ((?&BasicString)) $TOML/x) {
$str = substr($1, 1, length($1) - 2);
- $str = unescape_str($str);
+ $str = $self->unescape_str($str);
}
when (/^ ((?&MultiLineStringLiteral)) $TOML/x) {
# Adapted from TOML::Parser::Util
sub unescape_str {
+ my $self = shift;
my $str = shift;
$str =~ s/((?&EscapeChar)) $TOML/
$ch = "\x22" when '\"';
$ch = "\x2F" when '\/';
$ch = "\x5C" when '\\\\';
+
default{
- my $c = substr $1, 2;
- $c = chr(hex($c));
- if ($c ne "\0") {
- $ch = $c;
+ my $hex = hex substr($ch, 2);
+ if (charnames::viacode($hex)) {
+ $ch = chr $hex;
+ } else {
+ $self->error(undef, "invalid unicode escape: $ch");
}
}
}