Raw string literals and Unicode escapes

Alex Buckley alex.buckley at oracle.com
Wed Feb 14 21:43:27 UTC 2018

On 2/14/2018 12:42 PM, John Rose wrote:
> On Feb 14, 2018, at 12:24 PM, Alex Buckley <alex.buckley at oracle.com
> <mailto:alex.buckley at oracle.com>> wrote:
>> There is plenty of precedent for semantic rules
> In my draft version this is done with "where" clauses on the
> grammar rules:
>> RawStringLiteral:
>>   RawQuote RawStringBody RawQuote
>>   where the two raw-quotes are constrained to be identical
>> RawQuote:
>>   ` {`}
>>   where the preimage is constrained to be unescaped

We're dancing on the head of a pin now, but as a matter of 
specificational style I'm wary of too many rules in the grammar itself, 
especially a context-sensitive rule like raw-quotes-must-balance.

JLS 3.10.5 is a good specimen to study: there is a context-free rule in 
the grammar:

     InputCharacter but not " or \

and a context-sensitive semantic rule:

   It is a compile-time error for a line terminator to appear
   after the opening " and before the closing matching ".

Strictly speaking, the semantic rule is unnecessary because 
InputCharacter is DEFINED to exclude the CR and LF line terminators! But 
the semantic rule makes the intent very very clear. Writing rules in 
this form also prevents the spec from becoming a soup of statements that 
are more than just observations but less than full-throated assertions.

Anyway, the draft was very useful, thanks!


More information about the amber-spec-observers mailing list