On Monday, 13 April 2015 at 15:08:47 UTC, Jacob Carlborg wrote:
On 2015-04-13 13:39, biozic wrote:


The only quirk I can see so far is that `xxx yyy(` is always parsed so that yyy is considered to be the symbol of a function, is highlighted as such, and appears in the symbol tree. Is it a limitation of Textmate?

No, it's more the order of how rules implemented. I know I had this problem with "static assert". The solution I used was to added the rule for "static assert" before the rule for a method. What particular code is there a problem with?

For example:
version (all)
    struct foo { int i; }

    auto bar()
        static if (true) {}
        static assert(true);
        return foo(1);

In the body of the bar function, `if`, `assert` and `foo` are parsed as a method definition and appear in the symbol tree.

Perhaps I should just move the rule for a method to be the last rule.

Not enough I think. Rather, the method rule shouldn't match if the method name is a keyword or if it starts with `return`. This seems to work around these problems:
{       name = 'meta.definition.method.d';
                        begin = '(?x)^\s*(?!\breturn\b)
((?:\b(?:public|private|protected|package|static|final|synchronized|abstract|export|override|auto|nothrow|immutable|const|inout|ref|shared)\b\s*)*) # modifier
                                        (?:([^\s]+))\s+ # return type
                                        ((?!\bif\b)(?!\bassert\b)\w+)\s* # 
                        end = '(?={|;)';
                        beginCaptures = {
                                1 = { name = 'storage.modifier.d'; };
                                2 = { patterns = ( { include = '$base'; } ); };
                                3 = { name = 'entity.name.function.d'; };
                        patterns = (
                                {       include = '$base'; },
                                {       include = '#block'; },

Also, you forgot the `package` protection keyword (plus optional identifier list) in several places.

Reply via email to