1

I'm working on modifying Haxe mode for Emacs. It is based on c-mode, Java language.

After this mode was created, the language introduced new construct, it is similar in style to Java annotations, except for one thing:

@:macro public function foo() { ... }

is an annotation too. I.e. the part "@:macro" is an annotation, but c-mode treats the annotation as if it had to be "@" symbol followed by letters (once it sees ":", it thinks it's the end of the annotation).

What is the rule it is using for parsing annotations and how would I modify it?

Below is something that I've tried to do, but it neither works, nor am I sure it's the right way to do it.

(defadvice c-forward-annotation
  (around haxe-forward-annotation ())
  "Overrides `c-forward-annotation' to be able to use @:\w+ syntax as well
as the Java original syntax."
  (message "c-forward-annotation overloaded")
  (and (looking-at "@")
       (progn (forward-char) t)
       (if (looking-at ":")
           (progn
             (forward-char)
             (c-forward-type))
         (c-forward-type))
       (progn (c-forward-syntactic-ws) t)
       (if (looking-at "(")
           (c-go-list-forward)
         t)))

The function seems to actually do the job properly, what doesn't work later is the c-beginning-of-statement-1 - but it's too complex to find out what is actually happening...

One more thing I've tried:

(c-lang-defconst c-symbol-start
  haxe (concat "[" c-alpha "_@]:?"))

but didn't help either. Even some more info: if I C-c C-s on the line containing @:macro I get cpp-macro syntax, which is so ironically close, but not what I need.

More info: by overriding c-beginning-of-macro I could make it believe it is not a cpp-macro, however it is still not recognized as annotation. I've also overridden the place in c-forward-decl-or-cast-1 where it had a hardcoded regexp for testing for Java-style identifiers... still no go :(

Also changed in the (c-lang-defconst c-basic-matchers-after ...) to the below, but still no go...

,@(when (c-major-mode-is 'java-mode)
    `((eval . (list "\\<\\(@:?[a-zA-Z0-9]+\\)\\>" 1 c-annotation-face))))
4

1 回答 1

1

我想我终于找到了!

(c-lang-defconst c-cpp-matchers
  haxe (append
        (c-lang-const c-cpp-matchers c)
        '(("\\<\\([A-Z][A-Za-z0-9_]*\\)\\>" 1 font-lock-type-face))
        '(("\\<\\(@:?[A-Za-z]+\\)\\>" 1 c-annotation-face))))

我必须添加最后一个匹配器正则表达式以使其识别元数据中的冒号。我仍然不确定我所做的其他更改以及其中任何更改对于完成它的最终更改的重要性,但肯定这是一个重要的更改。

于 2012-10-13T12:06:41.533 回答