Replace core language HexStrings with library entity

Artur Skawina via Digitalmars-d digitalmars-d at puremagic.com
Tue Mar 17 14:05:50 PDT 2015


On 03/17/15 20:47, deadalnix via Digitalmars-d wrote:
> 
> Not that much. But q{ string are a pain in the ass.

Why? I'm not sure if you're referring to using or parsing them.
The only problem with the former is the lack of a non-brace-nesting
variant.
Lexing is quite trivial, as long as the lexer supports recursion.
For example, this is a complete implementation:

   TokenString:  "q{" TokenStringBody "}"
   TokenStringBody:          ( ( ![{}] TokenClass )+ / BracedTokenSequence )*
   BracedTokenSequence:  "{" ( ( ![{}] TokenClass )+ / BracedTokenSequence )* "}"

That's PEG, but the mapping to code should be fairly obvious.

For syntax highlighting purposes it can actually be even simpler - it's
enough to treat a `q{` token just like a `{`; everything that follows
will be valid D tokens.

artur


More information about the Digitalmars-d mailing list