Intellij idea 自定义语言的BNF规则语法突出显示

Intellij idea 自定义语言的BNF规则语法突出显示,intellij-idea,bnf,intellij-plugin,jflex,grammar-kit,Intellij Idea,Bnf,Intellij Plugin,Jflex,Grammar Kit,我正在尝试使用语法工具包插件为IntelliJ开发一个自定义语言插件。我可以很容易地为定义的标记提供语法高亮显示,但我不知道如何在元素或标记父级高亮显示 下面是一个快速而肮脏的示例语言- 解决方案 正如@ignatov所建议的,扩展注释器类并将其注册到plugin.xml中。在下面的示例中,我们通过定义visitCommand方法来突出显示命令元素 public class SimpleAnnotator implements Annotator { @Override publ

我正在尝试使用语法工具包插件为IntelliJ开发一个自定义语言插件。我可以很容易地为定义的标记提供语法高亮显示,但我不知道如何在元素或标记父级高亮显示

下面是一个快速而肮脏的示例语言-

解决方案

正如@ignatov所建议的,扩展注释器类并将其注册到
plugin.xml
中。在下面的示例中,我们通过定义
visitCommand
方法来突出显示
命令
元素

public class SimpleAnnotator implements Annotator {
    @Override
    public void annotate(@NotNull final PsiElement element, @NotNull final AnnotationHolder holder) {
        element.accept(new SimpleVisitor() {
            @Override
            public void visitCommand(@NotNull SimpleCommand o) {
                super.visitCommand(o);
                setHighlighting(o, holder, SimpleSyntaxHighlighter.COMMAND);
            }
        });
    }

    private static void setHighlighting(@NotNull PsiElement element, @NotNull AnnotationHolder holder,
                                        @NotNull TextAttributesKey key) {
        holder.createInfoAnnotation(element, null).setEnforcedTextAttributes(TextAttributes.ERASE_MARKER);
        holder.createInfoAnnotation(element, null).setEnforcedTextAttributes(
                EditorColorsManager.getInstance().getGlobalScheme().getAttributes(key));
    }
}

使用
com.intellij.lang.annotation.Annotator的自定义实现。对于那些感兴趣的人,请检查我的问题,了解如何做到这一点。从性能角度看,它与基于令牌的高亮显示(即使用SyntaxHighlighter)相比如何?