Luke Palmer wrote:

Mailing-List: contact [EMAIL PROTECTED]; run by ezmlm
Date: Mon, 9 Dec 2002 23:43:44 +0000
Cc: "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
Content-Disposition: inline
From: Nicholas Clark <[EMAIL PROTECTED]>
X-SMTPD: qpsmtpd/0.20, http://develooper.com/code/qpsmtpd/

On Sun, Dec 08, 2002 at 03:41:22PM +1100, Damian Conway wrote:

Nicholas Clark wrote:

Well, I was wondering if my function returned "CR", then
"\c[$(call_a_func())]" would mean that the "CR" gets run thought the
\c[...] conversion and a single byte ("\r") is what ends up in the string.

I seriously doubt it. %-)

So what will perl6's "" parser do if it is presented with what appears to
be a $() interpolation sequence inside some other double quoting
construction?

1: Proceed silently (so treating "\c[$(call_a_func())]" as a request for
the character literally named '$(call_a_func())'), potentially returning
whatever warnings fall out of that second stage
2: Issue a nesting warning when it finds something that seems to be an
interpolative construction occurring within another construction, but
otherwise carry on
3: Treat it as a syntax error

I suspect that the answer is "yes" - ie all of the above, with a warning on
nesting interpolative constructions, which can be made fatal, and can be made
silent.

You must remember that the Perl 6 parser is one-pass now. An
interpolating string has a rule set of its own, whose simplified
version might look like this:

grammar interpolating_string {

rule string { " <string_thing>* " }

rule string_thing { \$\( <Perl::expression> \)
| \\c \[ .*? \] | <character> }
rule character { \\ \\ | \\ " | . }
}

A fuller version might look like this:

(Note that this is with only allowing [] for internal brackets and
without accounting for the "balanced-brackets are ok" rule (out of
curiousity, is that still allowed?))


grammar Interpolating_String {

rule string {
$delim := <head>
{ $delim = %matching{$delim} || $delim }
(<body($delim)>+)
$delim
}

rule head {
(") | qq (<special_delim>) (
}

rule special_delim {
<-[\w\s]>
}

rule body(Str $delim) {
\\ <backslashed_expr>
| <interpolated_value>
| <interpolated_variable>
| <-[ \\\$\@\%\&$delim ]>*
}

rule interpolated_variable {
<Perl::Expression::variable>
<str_subscript>*
<!before <[ \[\{\( ]> >
}

rule backslashed_expr {
\\Q <!before \[>
| <before \\<[qQ]>\[ >
<Perl::Literal::Non_Interpolating_String::body(']')>
| c \[ <string_set> \]
| \: \[ <string_set> \]
| x \[ <set <Perl::Literal::Hex::number>>+ \]
| x <Perl::Literal::Hex::number>
| <[UL]> \[ <Perl::Literal::Non_Interpolating_String::body(']')>
| 0 <Perl::Literal::number>
| 0 \[ <Perl::Literal::number> \]
| <[ule]> .
| .
}
rule string_set {
[
<!before <[:\]]>+ \] >
<Perl::Literal::Non_Interpolating_String::body(';')>
]*
<Perl::Literal::Non_Interpolating_String::body(']')>
}

rule set($item) {
$item [ <before ;$item | \] ]
}

rule str_subscript {
<!before \s|\Q>
<Perl::Expression::subscript>
}

rule interpolated_value {
<Perl::Expression::Variable::sigil>
\( <Perl::Expression::comma> \)
}
}




Reply via email to