php.sugar icon indicating copy to clipboard operation
php.sugar copied to clipboard

Backslash escaped quotes are closing string

Open onecrayon opened this issue 15 years ago • 2 comments

Given this code:

echo '<p>Select the people whose favorites you\'d like to see.</p>';

The apostrophe in "you'd", although backslash escaped, is closing the string (leaving everything else afterward identified as keyword.constant.other).

onecrayon avatar May 08 '09 18:05 onecrayon

Damn. I am thinking I won't be able to keep HTML support in php strings.

The HTML syntax won't go past the ' and the backslash is ignored because it's not seen as a php string technically.

Anything you can think of?

derekr avatar May 08 '09 18:05 derekr

So dig this: look-behinds work (!?):

<zone name="literal.string.html.quoted.single">
    <starts-with>
        <expression>(')(?=(&lt;)/?([a-zA-Z]))</expression>
        <capture number="1" name="delimiter.balanced.quote.single.begin"/>
    </starts-with>
    <ends-with>
        <expression>(?&lt;!\\)(')</expression>
        <capture number="1" name="delimiter.balanced.quote.single.end"/>
    </ends-with>
    <subzones>
        <cut-off>[^\\]'</cut-off>
        <include syntax="text.html.basic" />
        <zone name="literal.escape.brief">
            <!-- 'A single-quoted string with \'escape sequences\'' -->
            <expression>(\\)('|\\)</expression>
            <capture number="1" name="delimiter.seperator.escape"/>
            <capture number="2" name="character"/>
        </zone>
    </subzones>
</zone>

This zone is working perfectly for me with the test file:

<?php
$something = '<p>This is what I\'d like to do.</p>';
?>

onecrayon avatar May 09 '09 14:05 onecrayon