3 ms·
It means that a parser for Rust doesn't also have to be a parser for every embedded language - which is particularly important for things like syntax highlighte
by geofft 6y ago
It means that a parser for Rust doesn't also have to be a parser for every embedded language - which is particularly important for things like syntax highlighters in text editors or HTML renderers or whatever.
For example, in most languages including Rust, parentheses are balanced as a rule, but they might not be in some inner language. So if you want to define a syntax where you can say
inner_language!( smiley = :-) );
while you can certainly write a parser that understands what's going on there, any existing Rust parser will get very confused. So, unless you're confident the inner language is syntactically compatible (even if it's meaningless) with the outer language, you'd need to protect it somehow.
Making the inner language quoted means that existing parsers that already know how to handle the outer language's string syntax (where to find the close quote, how close quotes might be escape, etc.) work seamlessly. You could also define some other syntax for it, but it's fundamentally the same requirement - it's a well-defined open and close syntax - and most other syntaxes end up uglier (think of <script>//<!-- ... //--></script or <script>//<![CDATA[ ... //]]></script> in HTML/XHTML.)
And there's nothing preventing a particularly clever parser from recognizing the asm! macro specifically and syntax-highlighting (or otherwise tokenizing/processing/etc.) the text inside, if it wants to.