1 複製解析器工具類 java
將語法插件須要的GeneratedParserUtilBase類複製到你的源文件中。 api
2 定義單點登陸類型 app
package com.simpleplugin.psi; import com.intellij.psi.tree.IElementType; import com.simpleplugin.SimpleLanguage; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; public class SimpleTokenType extends IElementType { public SimpleTokenType(@NotNull @NonNls String debugName) { super(debugName, SimpleLanguage.INSTANCE); } @Override public String toString() { return "SimpleTokenType." + super.toString(); } }3 定義元素類型
package com.simpleplugin.psi; import com.intellij.psi.tree.IElementType; import com.simpleplugin.SimpleLanguage; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; public class SimpleElementType extends IElementType { public SimpleElementType(@NotNull @NonNls String debugName) { super(debugName, SimpleLanguage.INSTANCE); } }
4 定義語法 ide
以/com/simpleplugin/Simple.bnf文件定義屬性語言語法。 工具
{ parserClass="com.simpleplugin.parser.SimpleParser" stubParserClass="com.simpleplugin.parser.GeneratedParserUtilBase" extends="com.intellij.extapi.psi.ASTWrapperPsiElement" psiClassPrefix="Simple" psiImplClassSuffix="Impl" psiPackage="com.simpleplugin.psi" psiImplPackage="com.simpleplugin.psi.impl" elementTypeHolderClass="com.simpleplugin.psi.SimpleTypes" elementTypeClass="com.simpleplugin.psi.SimpleElementType" tokenTypeClass="com.simpleplugin.psi.SimpleTokenType" } simpleFile ::= item_* private item_ ::= (property|COMMENT|CRLF) property ::= (KEY? SEPARATOR VALUE?) | KEY
這樣一個屬性文件就能夠包含屬性、評論和換行了。 spa
語法定義能夠使語言支持變得簡單,咱們制定的屬性有值也可能沒有值。咱們指定一個屬性可能有也可能沒有鍵和值。這讓IDE仍然可以識別錯誤定義的屬性,並提供相應的代碼分析和快速修正。 插件
5 生成分析器 debug
當語法定義以後,用戶就能夠經過右鍵菜單的Generate Parser Code或者是經過Simple.bnf文件中的⌘⇧G快捷方式根據PSI類生成解析器。Grammar-Kit將在gen文件中生成一個的語法工具解析器和PSI元素。將這個文件夾做爲源根,並確保編譯沒有錯誤。 code
》》》Intelli IDEA官方最新版免費下載地址 token