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

pyr*_*ade 6 intellij-idea bnf jflex intellij-plugin grammar-kit

我正在尝试使用Grammar-Kit插件为IntelliJ开发自定义语言插件.我很容易为定义的标记提供语法高亮,但我无法弄清楚如何在元素或标记 - 父级别突出显示.

这是一个快速而又脏的示例语言 - https://github.com/carymrobbins/intellij-plugin-example

正如@ignatov建议的那样,扩展Annotator类并在你的注册表中注册它plugin.xml.在下面的示例中,我们command通过定义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));
    }
}
Run Code Online (Sandbox Code Playgroud)

ign*_*tov 5

使用自定义实现com.intellij.lang.annotation.Annotator.

  • 完善.对于那些感兴趣的人,请查看我的问题以了解如何执行此操作. (2认同)