Not signed in (Sign In)

Categories

Vanilla 1.1.1 is a product of Lussumo. More Information: Documentation, Community Support.

    • CommentAuthorBen
    • CommentTimeFeb 5th 2007 edited
     permalink

    I found a small error in the JavaScript.itGrammar (and maybe in other grammar too). It concern the swallow in the definition.

    try this in Intype in a JavaScript mode:

    inspect: function() { return "'" + this.replace('\\', '\\\\').replace("'", '\\\'') + "'"; } });
    You will see that the string scope '\\\'' does not terminate rightly. It should stop ath the ), but it doesn’t.

    the definition in the itGrammar is:
    { begin: /'/ end: /'/ name: 'string.quoted.single.js' swallow: '\\.' }

    I first tried to use the regexp syntax for the swallow:
    { begin: /'/ end: /'/ name: 'string.quoted.single.js' swallow: /\\./ }

    but it still doesn’t work.
    I could change the definition to use a single more complex regexp, but the swallow artefact would be nicer.

    Is it a bug or am I completly wrong?

    Ben

    • CommentAuthorBrendonKoz
    • CommentTimeFeb 5th 2007 edited
     permalink

    '\\\\\\''
    There’s one too many backslashes there (if your goal is to escape a single quote, otherwise there’s one too many single quotes). I personally wouldn’t expect any termination in syntax highlighting.

    • CommentAuthorBen
    • CommentTimeFeb 5th 2007
     permalink

    You are right,

    It is just an escape bug in the forum. The preview showed me \\ escaped, so I had to double it. But the submit would not escaped it…

    Whatever… I edit my first post, and now it shows the right code.

    Can you have a second look at it?

    • CommentAuthorBrendonKoz
    • CommentTimeFeb 5th 2007 edited
     permalink

    Change the end line:
    end: /[^\\]?'/

    Note: I only checked to make sure it fixed THIS problem, I don’t know if this will introduce any new errors. I’m kinda at work right now, so… ;) I also don’t know what swallow means (in this context, anyway). I presume this error could probably be found in quite a few language grammar files. The double backslash is purposeful.

    Full Disclosure: – Line 61 – 66 in JavaScript.itGrammar (as of Intype Alpha 0.2.0.236)
    { begin: /'/ end: /[^\\]?'/ name: 'string.quoted.single.js' swallow: '\\.' }

    • CommentAuthorBen
    • CommentTimeFeb 5th 2007
     permalink

    Yeah you are still right, changing the end regexp will fix the syntax highlithing, but I think that in your case, the swallow parameter is not used anymore, so the bug in swallow is just hidden (I would say swallowed if I dare).

    And as I understand by swallow, it would ‘ignore’ (accept) all escaped character in the string, this would be very usefull not only there but in other grammar I think.

    So I’d like to know if the swallow parameter is already implemented, and if so if there is a bug or not in its implementation.

    Nervertheless, thank you BrendonKoz to fix this specific problem, even at work ;-)

  1.  permalink

    Anyone else able to verify the swallow issue, and/or test whether or not it’s used? I can never seem to remember where to find TextMate’s bundle grammar information. I should bookmark it…I’ve just been waiting for official documentation before I start bug fixing the bundles themselves.

    Oh, you’re welcome, Ben.

    • CommentAuthori
    • CommentTimeFeb 6th 2007 edited
     permalink

    In TextMate, the swallow parameter has been deprecated. It’s listed under “invalid keywords” in the Textmate grammar file.

    Take a look at the following posting to a TextMate mailing list :

    —————————BEGIN—————————————

    On 25/2/2006, at 7:53, Corey O’Connor wrote:

    > What is the meaning of the “swallow” key for language rules? I
    > searched the archives, wiki and documentation but I couldn’t find a
    > good definition. Did I miss something?

    It’s deprecated. But it is shorthand for having one sub-rule, e.g.:

    { begin = '"'; end = '"'; swallow = '\\.'; }

    Is the same as:

    { begin = '"'; end = '"'; patterns = ( { match = '\\.'; } ); }
    —————————END——————————————

    Currently the “swallow” keyword only appears in Intype’s grammars because they are converted Textmate bundles. I don’t think the keyword is implemented, the problem is not with the swallow keyword. You can verify this by removing the swallow keyword altogether from the grammar file and rerun Intype.

    The problem here is that the regex pattern matched the first and second single quote marks in this:

    ... replace("'", '\\\'') + "'"; ...

    But there is a third single quote that wasn’t matched with a fourth.

    • CommentAuthorBrendonKoz
    • CommentTimeFeb 6th 2007 edited
     permalink

    Oh good, so I did fix it. :P Thanks for the clarification, idyllrain.

    As stated, I suspect this’ll be in a lot of grammar files…however, I may be wrong. The PHP Grammar file fixes it with a subpattern:
    string-single-quoted: { begin: /'/ end: /'/ name: 'string.quoted.single.php' patterns: [ { match: /\\./ } ] }

    I think either should suffice.

    • CommentAuthorBen
    • CommentTimeFeb 6th 2007
     permalink

    Ok I will remove all swallow instances from the grammars and send it back to Martin