diff --git a/build.gradle.kts b/build.gradle.kts index 1408587f2d..2cafd80c81 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -41,6 +41,8 @@ plugins { alias(libs.plugins.serialization) alias(libs.plugins.gradleIntelliJPlugin) + id("org.jetbrains.grammarkit") version "2022.3.2.2" + kotlin("jvm") version "1.8.22" id("net.saliman.properties") version "1.5.2" } @@ -580,6 +582,45 @@ project(":exts:ext-harmonyos") { } } +project(":exts:autoin-lang") { + apply { + plugin("org.jetbrains.grammarkit") + } + + intellij { + version.set(ideaVersion) + plugins.set(ideaPlugins) + } + dependencies { + implementation(project(":")) + implementation(project(":java")) + } + + tasks { + generateLexer { + sourceFile.set(file("src/grammar/DevInLexer.flex")) +// targetDir.set("src/gen/com/feakin/intellij/lexer") + targetOutputDir.set(file("src/gen/cc/unitmesh/language/lexer")) +// targetClass.set("_FeakinLexer") + purgeOldFiles.set(true) + } + + generateParser { + sourceFile.set(file("src/grammar/DevInParser.bnf")) +// targetRoot.set("src/gen") + targetRootOutputDir.set(file("src/gen")) + pathToParser.set("cc/unitmesh/language/parser/DevInParser.java") + pathToPsiRoot.set("cc/unitmesh/language/psi") + purgeOldFiles.set(true) + } + + withType { + dependsOn(generateLexer, generateParser) + } + } +} + + fun File.isPluginJar(): Boolean { if (!isFile) return false if (extension != "jar") return false diff --git a/exts/autoin-lang/.gitignore b/exts/autoin-lang/.gitignore new file mode 100644 index 0000000000..b6fe4a84b3 --- /dev/null +++ b/exts/autoin-lang/.gitignore @@ -0,0 +1 @@ +src/gen \ No newline at end of file diff --git a/exts/autoin-lang/src/grammar/DevInLexer.flex b/exts/autoin-lang/src/grammar/DevInLexer.flex new file mode 100644 index 0000000000..76362665d5 --- /dev/null +++ b/exts/autoin-lang/src/grammar/DevInLexer.flex @@ -0,0 +1,33 @@ +// Copyright 2000-2022 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package org.intellij.sdk.language; + +import com.intellij.lexer.FlexLexer; +import com.intellij.psi.tree.IElementType; +import cc.unitmesh.language.psi.DevInTypes; +import com.intellij.psi.TokenType; + +%% + +%class DevInLexer +%implements FlexLexer +%unicode +%function advance +%type IElementType +%eof{ return; +%eof} + +CRLF=\R +WHITE_SPACE=[\ \n\t\f] +FIRST_VALUE_CHARACTER=[^ \n\f\\] | "\\"{CRLF} | "\\". +VALUE_CHARACTER=[^\n\f\\] | "\\"{CRLF} | "\\". +END_OF_LINE_COMMENT=("#"|"!")[^\r\n]* +SEPARATOR=[:=] +KEY_CHARACTER=[^:=\ \n\t\f\\] | "\\ " + +%state WAITING_VALUE + +%% + +({CRLF}|{WHITE_SPACE})+ { yybegin(YYINITIAL); return TokenType.WHITE_SPACE; } + +[^] { return TokenType.BAD_CHARACTER; } diff --git a/exts/autoin-lang/src/grammar/DevInParser.bnf b/exts/autoin-lang/src/grammar/DevInParser.bnf new file mode 100644 index 0000000000..e6276f2aea --- /dev/null +++ b/exts/autoin-lang/src/grammar/DevInParser.bnf @@ -0,0 +1,20 @@ +// should similar to markdown syntax +// Copyright 2000-2022 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +{ + parserClass="cc.unitmesh.language.parser.DevInParser" + + extends="com.intellij.extapi.psi.ASTWrapperPsiElement" + + psiClassPrefix="DevIn" + psiImplClassSuffix="Impl" + psiPackage="cc.unitmesh.language.psi" + psiImplPackage="cc.unitmesh.language.psi.impl" + + elementTypeHolderClass="cc.unitmesh.language.psi.DevInTypes" + elementTypeClass="cc.unitmesh.language.psi.DevInElementType" + tokenTypeClass="cc.unitmesh.language.psi.DevInTokenType" +} + +DevInFile ::= item_* + +private item_ ::= (CRLF) diff --git a/exts/autoin-lang/src/main/kotlin/cc/unitmesh/language/DevInFileType.kt b/exts/autoin-lang/src/main/kotlin/cc/unitmesh/language/DevInFileType.kt new file mode 100644 index 0000000000..3c29b183e2 --- /dev/null +++ b/exts/autoin-lang/src/main/kotlin/cc/unitmesh/language/DevInFileType.kt @@ -0,0 +1,18 @@ +package cc.unitmesh.language + +import cc.unitmesh.devti.AutoDevIcons +import com.intellij.openapi.fileTypes.LanguageFileType +import com.intellij.openapi.vfs.VirtualFile +import javax.swing.Icon + +object DevInFileType : LanguageFileType(DevInLanguage) { + override fun getName(): String = "DevIn File" + + override fun getIcon(): Icon = AutoDevIcons.AI_COPILOT + + override fun getDefaultExtension(): String = "devin" + + override fun getCharset(file: VirtualFile, content: ByteArray): String = "UTF-8" + + override fun getDescription(): String = "DevIn file" +} \ No newline at end of file diff --git a/exts/autoin-lang/src/main/kotlin/cc/unitmesh/language/DevInLanguage.kt b/exts/autoin-lang/src/main/kotlin/cc/unitmesh/language/DevInLanguage.kt new file mode 100644 index 0000000000..175a4461a5 --- /dev/null +++ b/exts/autoin-lang/src/main/kotlin/cc/unitmesh/language/DevInLanguage.kt @@ -0,0 +1,10 @@ +package cc.unitmesh.language + +import com.intellij.lang.Language + +object DevInLanguage : Language("DevIn", "text/devin", "text/x-devin", "application/x-devin") { + val INSTANCE: Language = DevInLanguage + + override fun isCaseSensitive() = true + override fun getDisplayName() = "DevIn" +} \ No newline at end of file diff --git a/exts/autoin-lang/src/main/kotlin/cc/unitmesh/language/DevInParserDefinition.kt b/exts/autoin-lang/src/main/kotlin/cc/unitmesh/language/DevInParserDefinition.kt new file mode 100644 index 0000000000..6bd7304572 --- /dev/null +++ b/exts/autoin-lang/src/main/kotlin/cc/unitmesh/language/DevInParserDefinition.kt @@ -0,0 +1,51 @@ +package cc.unitmesh.language + +import com.intellij.lang.ASTNode +import com.intellij.lang.ParserDefinition +import com.intellij.lang.PsiParser +import com.intellij.lexer.Lexer +import com.intellij.openapi.project.Project +import com.intellij.psi.FileViewProvider +import com.intellij.psi.PsiElement +import com.intellij.psi.PsiFile +import com.intellij.psi.tree.IFileElementType +import com.intellij.psi.tree.TokenSet +import org.jetbrains.annotations.NotNull + + +internal class DevInParserDefinition : ParserDefinition { + @NotNull + override fun createLexer(project: Project?): Lexer { + TODO() + } + + @NotNull + override fun getCommentTokens(): TokenSet = TokenSet.EMPTY + + @NotNull + override fun getStringLiteralElements(): TokenSet = TokenSet.EMPTY + + @NotNull + override fun createParser(project: Project?): PsiParser { + TODO() + } + + @NotNull + override fun getFileNodeType(): IFileElementType { + return FILE + } + + @NotNull + override fun createFile(@NotNull viewProvider: FileViewProvider): PsiFile { + TODO() + } + + @NotNull + override fun createElement(node: ASTNode?): PsiElement { + TODO() + } + + companion object { + val FILE: IFileElementType = IFileElementType(DevInLanguage.INSTANCE) + } +} \ No newline at end of file diff --git a/exts/autoin-lang/src/main/kotlin/cc/unitmesh/language/DevInSyntaxHighlighterFactory.kt b/exts/autoin-lang/src/main/kotlin/cc/unitmesh/language/DevInSyntaxHighlighterFactory.kt new file mode 100644 index 0000000000..090fed4384 --- /dev/null +++ b/exts/autoin-lang/src/main/kotlin/cc/unitmesh/language/DevInSyntaxHighlighterFactory.kt @@ -0,0 +1,12 @@ +package cc.unitmesh.language + +import com.intellij.openapi.fileTypes.SyntaxHighlighter +import com.intellij.openapi.fileTypes.SyntaxHighlighterFactory +import com.intellij.openapi.project.Project +import com.intellij.openapi.vfs.VirtualFile + +class DevInSyntaxHighlighterFactory : SyntaxHighlighterFactory() { + override fun getSyntaxHighlighter(project: Project?, virtualFile: VirtualFile?): SyntaxHighlighter { + TODO("Not yet implemented") + } +} diff --git a/exts/autoin-lang/src/main/kotlin/cc/unitmesh/language/psi/DevInTokenType.kt b/exts/autoin-lang/src/main/kotlin/cc/unitmesh/language/psi/DevInTokenType.kt new file mode 100644 index 0000000000..5a2e085048 --- /dev/null +++ b/exts/autoin-lang/src/main/kotlin/cc/unitmesh/language/psi/DevInTokenType.kt @@ -0,0 +1,13 @@ +package cc.unitmesh.language.psi + +import com.intellij.psi.tree.IElementType +import org.jetbrains.annotations.NonNls +import org.jetbrains.annotations.NotNull + +class DevInTokenType( + @NotNull @NonNls debugName: String +): IElementType(debugName, cc.unitmesh.language.DevInLanguage.INSTANCE) { + override fun toString(): String { + return "DevInTokenType." + super.toString() + } +} \ No newline at end of file diff --git a/exts/autoin-lang/src/main/resources/cc.unitmesh.language.xml b/exts/autoin-lang/src/main/resources/cc.unitmesh.language.xml new file mode 100644 index 0000000000..12a486c8f2 --- /dev/null +++ b/exts/autoin-lang/src/main/resources/cc.unitmesh.language.xml @@ -0,0 +1,11 @@ + + + + + + + + + \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 855f092716..2e22033781 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -23,4 +23,7 @@ include( // since JetBrains also call `android.jar`, so we rename it to `ext-android` "exts:ext-android", "exts:ext-harmonyos", + + // the Input Language support for AutoDev + "exts:autoin-lang" )