-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
298 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
org.gradle.warning.mode=none | ||
kotlin.stdlib.default.dependency=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,5 +10,6 @@ include( | |
":evaluator", | ||
":stdlib", | ||
":ffi", | ||
":tool" | ||
":tool", | ||
":support:pork-idea" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
plugins { | ||
id("org.jetbrains.intellij") version "1.15.0" | ||
id("gay.pizza.pork.module") | ||
} | ||
|
||
dependencies { | ||
implementation(project(":parser")) | ||
} | ||
|
||
intellij { | ||
pluginName.set(properties["pluginName"].toString()) | ||
version.set(properties["platformVersion"].toString()) | ||
type.set(properties["platformType"].toString()) | ||
} | ||
|
||
tasks { | ||
buildSearchableOptions { | ||
enabled = false | ||
} | ||
|
||
patchPluginXml { | ||
version.set(project.properties["pluginVersion"].toString()) | ||
sinceBuild.set(project.properties["pluginSinceBuild"].toString()) | ||
untilBuild.set(project.properties["pluginUntilBuild"].toString()) | ||
pluginDescription.set("Pork Language support for IntelliJ IDEs") | ||
} | ||
} | ||
|
||
project.afterEvaluate { | ||
tasks.buildPlugin { | ||
exclude("**/lib/annotations*.jar") | ||
exclude("**/lib/kotlin*.jar") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# IntelliJ Platform Artifacts Repositories -> https://plugins.jetbrains.com/docs/intellij/intellij-artifacts.html | ||
pluginGroup = gay.pizza.plugins.pork | ||
pluginName = Pork | ||
pluginRepositoryUrl = https://github.com/GayPizzaSpecifications/pork | ||
pluginVersion = 0.1.0 | ||
|
||
# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html | ||
pluginSinceBuild = 232 | ||
pluginUntilBuild = 232.* | ||
|
||
# IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension | ||
platformType = IC | ||
platformVersion = 2023.2.1 |
26 changes: 26 additions & 0 deletions
26
support/pork-idea/src/main/kotlin/gay/pizza/pork/intellij/PorkFileType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package gay.pizza.pork.intellij | ||
|
||
import com.intellij.openapi.fileTypes.LanguageFileType | ||
import com.intellij.openapi.util.NlsContexts | ||
import com.intellij.openapi.util.NlsSafe | ||
import org.jetbrains.annotations.NonNls | ||
import javax.swing.Icon | ||
|
||
@Suppress("UnstableApiUsage") | ||
object PorkFileType : LanguageFileType(PorkLanguage) { | ||
override fun getName(): @NonNls String { | ||
return "Pork File" | ||
} | ||
|
||
override fun getDescription(): @NlsContexts.Label String { | ||
return "Pork file" | ||
} | ||
|
||
override fun getDefaultExtension(): @NlsSafe String { | ||
return "pork" | ||
} | ||
|
||
override fun getIcon(): Icon { | ||
return PorkIcon | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
support/pork-idea/src/main/kotlin/gay/pizza/pork/intellij/PorkIcons.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package gay.pizza.pork.intellij | ||
|
||
import com.intellij.openapi.util.IconLoader.getIcon | ||
import javax.swing.Icon | ||
|
||
val PorkIcon: Icon = getIcon("/icons/pork.png", PorkLanguage::class.java) |
5 changes: 5 additions & 0 deletions
5
support/pork-idea/src/main/kotlin/gay/pizza/pork/intellij/PorkLanguage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package gay.pizza.pork.intellij | ||
|
||
import com.intellij.lang.Language | ||
|
||
object PorkLanguage : Language("Pork") |
96 changes: 96 additions & 0 deletions
96
support/pork-idea/src/main/kotlin/gay/pizza/pork/intellij/PorkLexer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package gay.pizza.pork.intellij | ||
|
||
import com.intellij.lexer.LexerBase | ||
import com.intellij.openapi.diagnostic.Logger | ||
import com.intellij.openapi.progress.ProcessCanceledException | ||
import com.intellij.psi.tree.IElementType | ||
import gay.pizza.pork.parser.* | ||
import com.intellij.psi.TokenType as PsiTokenType | ||
|
||
class PorkLexer : LexerBase() { | ||
private val log: Logger = Logger.getInstance(PorkLexer::class.java) | ||
|
||
private lateinit var source: StringCharSource | ||
private lateinit var tokenizer: Tokenizer | ||
private var internalTokenStart: Int = 0 | ||
private var internalTokenEnd: Int = 0 | ||
private var internalState: Int = 0 | ||
private var currentTokenType: IElementType? = null | ||
|
||
override fun start(buffer: CharSequence, startOffset: Int, endOffset: Int, initialState: Int) { | ||
source = StringCharSource( | ||
input = buffer, | ||
startIndex = startOffset, | ||
endIndex = endOffset | ||
) | ||
tokenizer = Tokenizer(source) | ||
internalState = initialState | ||
internalTokenStart = startOffset | ||
internalTokenEnd = startOffset | ||
currentTokenType = null | ||
advance() | ||
} | ||
|
||
override fun getState(): Int { | ||
return internalState | ||
} | ||
|
||
override fun getTokenType(): IElementType? { | ||
return currentTokenType | ||
} | ||
|
||
override fun getTokenStart(): Int { | ||
return internalTokenStart | ||
} | ||
|
||
override fun getTokenEnd(): Int { | ||
return internalTokenEnd | ||
} | ||
|
||
override fun advance() { | ||
internalTokenStart = internalTokenEnd | ||
if (internalTokenStart == bufferEnd) { | ||
currentTokenType = null | ||
return | ||
} | ||
|
||
try { | ||
val currentToken = tokenizer.next() | ||
currentTokenType = tokenAsElement(currentToken) | ||
internalTokenStart = currentToken.start | ||
internalTokenEnd = currentToken.start + currentToken.text.length | ||
} catch (e: ProcessCanceledException) { | ||
throw e | ||
} catch (e: Throwable) { | ||
currentTokenType = PsiTokenType.BAD_CHARACTER | ||
internalTokenEnd = bufferEnd | ||
log.warn(Tokenizer::class.java.name, e) | ||
} | ||
} | ||
|
||
override fun getBufferSequence(): CharSequence { | ||
return source.input | ||
} | ||
|
||
override fun getBufferEnd(): Int { | ||
return source.endIndex | ||
} | ||
|
||
private fun tokenAsElement(token: Token): IElementType = when { | ||
token.type.family == TokenFamily.KeywordFamily -> | ||
PorkTokenTypes.Keyword | ||
token.type.family == TokenFamily.SymbolFamily -> | ||
PorkTokenTypes.Symbol | ||
token.type.family == TokenFamily.OperatorFamily -> | ||
PorkTokenTypes.Operator | ||
token.type.family == TokenFamily.StringLiteralFamily -> | ||
PorkTokenTypes.String | ||
token.type.family == TokenFamily.NumericLiteralFamily -> | ||
PorkTokenTypes.Number | ||
token.type == TokenType.Whitespace -> | ||
PorkTokenTypes.Whitespace | ||
else -> PsiTokenType.CODE_FRAGMENT | ||
} | ||
|
||
override fun toString(): String = "Lexer(start=$internalTokenStart, end=$internalTokenEnd)" | ||
} |
49 changes: 49 additions & 0 deletions
49
support/pork-idea/src/main/kotlin/gay/pizza/pork/intellij/PorkSyntaxHighlighter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package gay.pizza.pork.intellij | ||
|
||
import com.intellij.lexer.Lexer | ||
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors | ||
import com.intellij.openapi.editor.colors.TextAttributesKey | ||
import com.intellij.openapi.fileTypes.SyntaxHighlighter | ||
import com.intellij.openapi.fileTypes.SyntaxHighlighterBase | ||
import com.intellij.psi.tree.IElementType | ||
|
||
object PorkSyntaxHighlighter : SyntaxHighlighter { | ||
override fun getHighlightingLexer(): Lexer { | ||
return PorkLexer() | ||
} | ||
|
||
override fun getTokenHighlights(tokenType: IElementType?): Array<TextAttributesKey> { | ||
if (tokenType == null) return emptyArray() | ||
val attributes = when (tokenType) { | ||
PorkTokenTypes.Keyword -> | ||
TextAttributesKey.createTextAttributesKey( | ||
"PORK.KEYWORD", | ||
DefaultLanguageHighlighterColors.KEYWORD | ||
) | ||
PorkTokenTypes.Symbol -> | ||
TextAttributesKey.createTextAttributesKey( | ||
"PORK.SYMBOL", | ||
DefaultLanguageHighlighterColors.LOCAL_VARIABLE | ||
) | ||
PorkTokenTypes.Operator -> | ||
TextAttributesKey.createTextAttributesKey( | ||
"PORK.OPERATOR", | ||
DefaultLanguageHighlighterColors.OPERATION_SIGN | ||
) | ||
PorkTokenTypes.String -> | ||
TextAttributesKey.createTextAttributesKey( | ||
"PORK.STRING", | ||
DefaultLanguageHighlighterColors.STRING | ||
) | ||
PorkTokenTypes.Number -> | ||
TextAttributesKey.createTextAttributesKey( | ||
"PORK.NUMBER", | ||
DefaultLanguageHighlighterColors.NUMBER | ||
) | ||
else -> null | ||
} | ||
return if (attributes == null) | ||
emptyArray() | ||
else SyntaxHighlighterBase.pack(attributes) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
support/pork-idea/src/main/kotlin/gay/pizza/pork/intellij/PorkSyntaxHighlighterFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package gay.pizza.pork.intellij | ||
|
||
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 PorkSyntaxHighlighterFactory : SyntaxHighlighterFactory() { | ||
override fun getSyntaxHighlighter(project: Project?, virtualFile: VirtualFile?): SyntaxHighlighter { | ||
return PorkSyntaxHighlighter | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
support/pork-idea/src/main/kotlin/gay/pizza/pork/intellij/PorkTokenTypes.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package gay.pizza.pork.intellij | ||
|
||
import com.intellij.psi.TokenType | ||
import com.intellij.psi.tree.IElementType | ||
|
||
object PorkTokenTypes { | ||
val Whitespace = TokenType.WHITE_SPACE | ||
val Keyword = IElementType("keyword", PorkLanguage) | ||
val Symbol = IElementType("symbol", PorkLanguage) | ||
val Operator = IElementType("operator", PorkLanguage) | ||
val String = IElementType("string", PorkLanguage) | ||
val Number = IElementType("number", PorkLanguage) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!-- Plugin Configuration File. Read more: https://plugins.jetbrains.com/docs/intellij/plugin-configuration-file.html --> | ||
<idea-plugin> | ||
<id>gay.pizza.plugins.pork</id> | ||
<name>Pork</name> | ||
<category>Languages</category> | ||
<vendor>Gay Pizza Specifications</vendor> | ||
<depends>com.intellij.modules.platform</depends> | ||
<extensions defaultExtensionNs="com.intellij"> | ||
<fileType name="Pork File" language="Pork" extensions="pork" fieldName="INSTANCE" | ||
implementationClass="gay.pizza.pork.intellij.PorkFileType"/> | ||
<lang.syntaxHighlighterFactory | ||
language="Pork" | ||
implementationClass="gay.pizza.pork.intellij.PorkSyntaxHighlighterFactory"/> | ||
</extensions> | ||
|
||
<applicationListeners> | ||
</applicationListeners> | ||
</idea-plugin> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.