From ad7c97dfb4b1e62592c259ac99bd1d92c7a2df5a Mon Sep 17 00:00:00 2001 From: Samantha McVey Date: Tue, 7 Nov 2017 16:44:22 -0800 Subject: [PATCH] Fix LTA error when starter is followed by a combining codeponit Affects q quoting, s/// and possibly tr///. Notifies the user that they are using a combining codepoint after the starter and to remove it for it to properly parse. --- src/Perl6/Grammar.nqp | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/Perl6/Grammar.nqp b/src/Perl6/Grammar.nqp index e7b72b0a07f..815cde720b5 100644 --- a/src/Perl6/Grammar.nqp +++ b/src/Perl6/Grammar.nqp @@ -216,7 +216,26 @@ role STD { nqp::push(@herestub_queue, Herestub.new(:$delim, :$grammar, :orignode(self))); return self; } - + method fail-terminator ($/, $start, $stop, $line?) { + my $message; + if $start ne nqp::chr(nqp::ord($start)) { + $message := "Starter $start is immediately followed by a combining codepoint. Please use {nqp::chr(nqp::ord($start))} without a combining glyph"; + if $line { + $message := "$message ($start was at line $line)"; + } + } + else { + $message := "Couldn't find terminator $stop"; + if $line { + $message := "$message (cooresponding $start was at line $line)"; + } + } + $/.typed_panic('X::Comp::AdHoc', + payload => $message, + expected => [$stop] + ); + } + # nibbler for q quoting token quibble($l, *@base_tweaks) { :my $lang; :my $start; @@ -224,7 +243,7 @@ role STD { { my $B := $.ast; $lang := $B[0]; $start := $B[1]; $stop := $B[2]; } - $start [ $stop || { $/.typed_panic('X::Comp::AdHoc', payload => "Couldn't find terminator $stop (corresponding $start was at line {HLL::Compiler.lineof($.orig(), $.from(), :cache(1))})", expected => [$stop] ) } ] + $start [ $stop || { self.fail-terminator($/, $start, $stop, HLL::Compiler.lineof($.orig(), $.from(), :cache(1) )) } ] { nqp::can($lang, 'herelang') && self.queue_heredoc( @@ -3819,6 +3838,7 @@ grammar Perl6::Grammar is HLL::Grammar does STD { token setup_quotepair { '' } + # nibbler for s/// token sibble($l, $lang2, @lang2tweaks?) { :my $lang; :my $start; @@ -3828,7 +3848,7 @@ grammar Perl6::Grammar is HLL::Grammar does STD { { my $B := $.ast; $lang := $B[0]; $start := $B[1]; $stop := $B[2]; } { $*SUBST_LHS_BLOCK := $*W.push_lexpad($/) } - $start [ $stop || <.panic("Couldn't find terminator $stop")> ] + $start [ $stop || { self.fail-terminator($/, $start, $stop) } ] { $*W.pop_lexpad() } { $*SUBST_RHS_BLOCK := $*W.push_lexpad($/) } [ @@ -3859,7 +3879,7 @@ grammar Perl6::Grammar is HLL::Grammar does STD { ?? self.slang_grammar('P5Regex') !! self.slang_grammar('Regex'), self.slang_grammar('Quote'), ['qq'])> [ }> || <.old_rx_mods>? ] } - + # nibbler for tr/// token tribble ($l, $lang2 = $l, @lang2tweaks?) { :my $lang; :my $start; @@ -3868,10 +3888,10 @@ grammar Perl6::Grammar is HLL::Grammar does STD { { my $B := $.ast; $lang := $B[0]; $start := $B[1]; $stop := $B[2]; } - $start [ $stop || <.panic: "Couldn't find terminator $stop"> ] + $start [ $stop || { self.fail-terminator($/, $start, $stop) } ] { $*CCSTATE := ''; } [ - $start [ $stop || { $/.panic("Couldn't find terminator $stop") } ] + $start [ $stop || { self.fail-terminator($/, $start, $stop) } ] || { $lang := self.quote_lang($lang2, $stop, $stop, @lang2tweaks); } $stop || <.panic("Malformed replacement part; couldn't find final $stop")>