backport: 21.1.0

This commit is contained in:
FalsePattern 2025-03-11 02:01:56 +01:00
parent 97d22f3054
commit ae08287d7e
Signed by: falsepattern
GPG key ID: E930CDEC50C50E23
20 changed files with 256 additions and 513 deletions

View file

@ -17,6 +17,18 @@ Changelog structure reference:
## [Unreleased] ## [Unreleased]
## [21.1.0]
### Added
- Zon
- ZLS integration
### Changed
- Zon
- Fully refactored the parser for parity with the zig parser
## [21.0.0] ## [21.0.0]
### Added ### Added

View file

@ -34,6 +34,7 @@ import static com.falsepattern.zigbrains.zig.psi.ZigTypes.*;
%implements FlexLexer %implements FlexLexer
%function advance %function advance
%type IElementType %type IElementType
%unicode
CRLF=\R CRLF=\R
WHITE_SPACE=[\s]+ WHITE_SPACE=[\s]+

View file

@ -34,46 +34,57 @@
elementTypeClass="com.falsepattern.zigbrains.zon.parser.ZonElementType" elementTypeClass="com.falsepattern.zigbrains.zon.parser.ZonElementType"
tokenTypeClass="com.falsepattern.zigbrains.zon.parser.ZonTokenType" tokenTypeClass="com.falsepattern.zigbrains.zon.parser.ZonTokenType"
tokens=[ tokens=[
LINE_COMMENT='comment'
DOT='.' DOT='.'
EQUAL='='
LBRACE='{' LBRACE='{'
RBRACE='}' RBRACE='}'
EQ='='
COMMA=',' COMMA=','
COMMENT='comment' KEYWORD_FALSE='false'
ID='identifier' KEYWORD_TRUE='true'
STRING_LITERAL_SINGLE='string' KEYWORD_NULL='null'
LINE_STRING='multiline string' NUM_NAN='nan'
BAD_STRING='unterminated string' NUM_INF='inf'
BOOL_TRUE='true' CHAR_LITERAL='char literal'
BOOL_FALSE='false' STRING_LITERAL_SINGLE='string literal'
STRING_LITERAL_MULTI='multiline string literal'
FLOAT='float'
INTEGER='integer'
IDENTIFIER='identifier'
BAD_SQUOT='unterminated quote'
BAD_DQUOT='unterminated double quote'
] ]
//Mixins
mixin("entry")="com.falsepattern.zigbrains.zon.psi.impl.mixins.ZonEntryMixinImpl"
implements("entry")="com.falsepattern.zigbrains.zon.psi.mixins.ZonEntryMixin"
mixin("identifier")="com.falsepattern.zigbrains.zon.psi.impl.mixins.ZonIdentifierMixinImpl"
implements("identifier")="com.falsepattern.zigbrains.zon.psi.mixins.ZonIdentifierMixin"
} }
zonFile ::= entry Root ::= Expr
entry ::= DOT LBRACE (list | struct | ()) RBRACE Expr
::= CHAR_LITERAL
| StringLiteral
| DOT IDENTIFIER
| DOT InitList
| Bool
| Number
| KEYWORD_NULL
struct ::= (property | property_placeholder) (COMMA (property_placeholder? property property_placeholder? | property_placeholder))* COMMA?
list ::= value (COMMA value)* COMMA? InitList
::= LBRACE ZB_InitList_Body RBRACE {pin=1}
property ::= DOT identifier EQ value private ZB_InitList_Body
::= FieldInit (COMMA ZB_InitList_FieldInit)* COMMA?
| Expr (COMMA ZB_InitList_Expr)* COMMA?
| ()
identifier ::= ID private ZB_InitList_FieldInit ::= FieldInit {recoverWhile="ZB_InitList_Recover"}
private ZB_InitList_Expr ::= Expr {recoverWhile="ZB_InitList_Recover"}
property_placeholder ::= DOT? INTELLIJ_COMPLETION_DUMMY private ZB_InitList_Recover ::= !(COMMA | RBRACE)
private value ::= entry | boolean | STRING_LITERAL | value_placeholder FieldInit ::= DOT IDENTIFIER EQUAL Expr
value_placeholder ::= INTELLIJ_COMPLETION_DUMMY Bool ::= KEYWORD_TRUE | KEYWORD_FALSE
boolean ::= BOOL_TRUE | BOOL_FALSE Number ::= FLOAT | INTEGER | NUM_NAN | NUM_INF
STRING_LITERAL ::= STRING_LITERAL_SINGLE | LINE_STRING+ StringLiteral ::= STRING_LITERAL_SINGLE | STRING_LITERAL_MULTI

View file

@ -38,52 +38,120 @@ import static com.falsepattern.zigbrains.zon.psi.ZonTypes.*;
CRLF=\R CRLF=\R
WHITE_SPACE=[\s]+ WHITE_SPACE=[\s]+
LINE_COMMENT="//" [^\n]* | "////" [^\n]*
COMMENT="///".*
ID=[A-Za-z_][A-Za-z0-9_]*
bin=[01]
bin_="_"? {bin}
oct=[0-7]
oct_="_"? {oct}
hex=[0-9a-fA-F] hex=[0-9a-fA-F]
char_escape hex_="_"? {hex}
= "\\x" {hex} {hex} dec=[0-9]
| "\\u{" {hex}+ "}" dec_="_"? {dec}
| "\\" [nr\\t'\"]
string_char bin_int={bin} {bin_}*
= {char_escape} oct_int={oct} {oct_}*
| [^\\\"\n] dec_int={dec} {dec_}*
hex_int={hex} {hex_}*
LINE_STRING=("\\\\" [^\n]* [ \n]*)+ char_char= \\ .
| [^\'\n]
%state STRING_LITERAL string_char= \\ .
%state ID_STRING | [^\"\n]
%state UNCLOSED_STRING
all_nl_wrap=[^\n]* [ \n]*
all_no_nl=[^\n]+
FLOAT= "0x" {hex_int} "." {hex_int} ([pP] [-+]? {dec_int})?
| {dec_int} "." {dec_int} ([eE] [-+]? {dec_int})?
| "0x" {hex_int} [pP] [-+]? {dec_int}
| {dec_int} [eE] [-+]? {dec_int}
INTEGER= "0b" {bin_int}
| "0o" {oct_int}
| "0x" {hex_int}
| {dec_int}
IDENTIFIER_PLAIN=[A-Za-z_][A-Za-z0-9_]*
%state STR_LIT
%state STR_MULT_LINE
%state CHAR_LIT
%state ID_QUOT
%state UNT_SQUOT
%state UNT_DQUOT
%state LINE_CMT
%% %%
//Comments
<YYINITIAL> "//" { yybegin(LINE_CMT); }
<LINE_CMT> {all_nl_wrap} "//" { }
<LINE_CMT> {all_no_nl} { }
<LINE_CMT> \n { yybegin(YYINITIAL); return LINE_COMMENT; }
<LINE_CMT> <<EOF>> { yybegin(YYINITIAL); return LINE_COMMENT; }
//Symbols
<YYINITIAL> {WHITE_SPACE} { return WHITE_SPACE; }
<YYINITIAL> "." { return DOT; } <YYINITIAL> "." { return DOT; }
<YYINITIAL> "IntellijIdeaRulezzz" { return INTELLIJ_COMPLETION_DUMMY; } <YYINITIAL> "=" { return EQUAL; }
<YYINITIAL> "{" { return LBRACE; } <YYINITIAL> "{" { return LBRACE; }
<YYINITIAL> "}" { return RBRACE; } <YYINITIAL> "}" { return RBRACE; }
<YYINITIAL> "=" { return EQ; }
<YYINITIAL> "," { return COMMA; } <YYINITIAL> "," { return COMMA; }
<YYINITIAL> "true" { return BOOL_TRUE; }
<YYINITIAL> "false" { return BOOL_FALSE; }
<YYINITIAL> {COMMENT} { return COMMENT; }
<YYINITIAL> {LINE_COMMENT} { return COMMENT; }
<YYINITIAL> {ID} { return ID; } //Keywords
<YYINITIAL> "@\"" { yybegin(ID_STRING); }
<ID_STRING> {string_char}*"\"" { yybegin(YYINITIAL); return ID; }
<ID_STRING> [^] { yypushback(1); yybegin(UNCLOSED_STRING); }
<YYINITIAL> "\"" { yybegin(STRING_LITERAL); } <YYINITIAL> "false" { return KEYWORD_FALSE; }
<STRING_LITERAL> {string_char}*"\"" { yybegin(YYINITIAL); return STRING_LITERAL_SINGLE; } <YYINITIAL> "true" { return KEYWORD_TRUE; }
<STRING_LITERAL> [^] { yypushback(1); yybegin(UNCLOSED_STRING); } <YYINITIAL> "null" { return KEYWORD_NULL; }
<YYINITIAL> "nan" { return NUM_NAN; }
<YYINITIAL> "inf" { return NUM_INF; }
<UNCLOSED_STRING>[^\n]*{CRLF} { yybegin(YYINITIAL); return BAD_STRING; } //Strings
<YYINITIAL> {LINE_STRING} { return LINE_STRING; } <YYINITIAL> "'" { yybegin(CHAR_LIT); }
<CHAR_LIT> {char_char}*"'" { yybegin(YYINITIAL); return CHAR_LITERAL; }
<CHAR_LIT> <<EOF>> { yybegin(YYINITIAL); return BAD_SQUOT; }
<CHAR_LIT> [^] { yypushback(1); yybegin(UNT_SQUOT); }
<YYINITIAL> "\"" { yybegin(STR_LIT); }
<STR_LIT> {string_char}*"\"" { yybegin(YYINITIAL); return STRING_LITERAL_SINGLE; }
<STR_LIT> <<EOF>> { yybegin(YYINITIAL); return BAD_DQUOT; }
<STR_LIT> [^] { yypushback(1); yybegin(UNT_DQUOT); }
<YYINITIAL> "\\\\" { yybegin(STR_MULT_LINE); }
<STR_MULT_LINE> {all_nl_wrap} "\\\\" { }
<STR_MULT_LINE> {all_no_nl} { }
<STR_MULT_LINE> \n { yybegin(YYINITIAL); return STRING_LITERAL_MULTI; }
<STR_MULT_LINE> <<EOF>> { yybegin(YYINITIAL); return STRING_LITERAL_MULTI; }
//Numbers
<YYINITIAL> {FLOAT} { return FLOAT; }
<YYINITIAL> {INTEGER} { return INTEGER; }
//Identifiers
<YYINITIAL> {IDENTIFIER_PLAIN} { return IDENTIFIER; }
<YYINITIAL> "@\"" { yybegin(ID_QUOT); }
<ID_QUOT> {string_char}*"\"" { yybegin(YYINITIAL); return IDENTIFIER; }
<ID_QUOT> <<EOF>> { yybegin(YYINITIAL); return BAD_DQUOT; }
<ID_QUOT> [^] { yypushback(1); yybegin(UNT_DQUOT); }
//Error handling
<UNT_SQUOT> <<EOF>> { yybegin(YYINITIAL); return BAD_SQUOT; }
<UNT_SQUOT> {CRLF} { yybegin(YYINITIAL); return BAD_SQUOT; }
<UNT_SQUOT> {all_no_nl} { }
<UNT_DQUOT> <<EOF>> { yybegin(YYINITIAL); return BAD_DQUOT; }
<UNT_DQUOT> {CRLF} { yybegin(YYINITIAL); return BAD_DQUOT; }
<UNT_DQUOT> {all_no_nl} { }
//Misc
<YYINITIAL> {WHITE_SPACE} { return WHITE_SPACE; }
[^] { return BAD_CHARACTER; } [^] { return BAD_CHARACTER; }

View file

@ -41,7 +41,7 @@ class ZonCommenter: CodeDocumentationAwareCommenter, IndentedCommenter {
override fun forceIndentedLineComment() = true override fun forceIndentedLineComment() = true
override fun getLineCommentTokenType(): IElementType = ZonTypes.COMMENT override fun getLineCommentTokenType(): IElementType = ZonTypes.LINE_COMMENT
override fun getBlockCommentTokenType() = null override fun getBlockCommentTokenType() = null

View file

@ -1,146 +0,0 @@
/*
* This file is part of ZigBrains.
*
* Copyright (C) 2023-2025 FalsePattern
* All Rights Reserved
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* ZigBrains is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, only version 3 of the License.
*
* ZigBrains is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with ZigBrains. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.zigbrains.zon.completion
import com.falsepattern.zigbrains.zon.psi.*
import com.intellij.codeInsight.completion.*
import com.intellij.codeInsight.lookup.LookupElementBuilder
import com.intellij.patterns.ElementPattern
import com.intellij.patterns.PlatformPatterns.psiElement
import com.intellij.patterns.PsiElementPattern
import com.intellij.psi.PsiElement
import com.intellij.psi.util.parentOfType
import com.intellij.util.ProcessingContext
import org.jetbrains.annotations.NonNls
class ZonCompletionContributor : CompletionContributor() {
init {
extend(
CompletionType.BASIC,
psiElement()
.withParent(psiElement(ZonTypes.PROPERTY_PLACEHOLDER))
.withSuperParent(4, psiOfType<ZonFile>())
) { parameters, _, result ->
val placeholder = parameters.position.parentOfType<ZonPropertyPlaceholder>() ?: return@extend
val zonEntry = placeholder.parentOfType<ZonEntry>() ?: return@extend
val keys = zonEntry.keys
doAddCompletions(placeholder.text.startsWith('.'), keys, ZON_ROOT_KEYS, result)
}
extend(
CompletionType.BASIC,
psiElement()
.withParent(psiElement(ZonTypes.VALUE_PLACEHOLDER))
.withSuperParent(2, psiElement(ZonTypes.LIST))
.withSuperParent(4, psiOfType<ZonFile>())
) { _, _, result ->
doAddCompletions(false, emptySet(), ZON_ROOT_KEYS, result)
}
extend(
CompletionType.BASIC,
psiElement()
.withParent(psiElement(ZonTypes.PROPERTY_PLACEHOLDER))
.withSuperParent(4, psiElement(ZonTypes.PROPERTY))
.withSuperParent(7, psiElement(ZonTypes.PROPERTY))
.withSuperParent(10, psiOfType<ZonFile>())
) { parameters, _, result ->
val placeholder = parameters.position.parentOfType<ZonPropertyPlaceholder>() ?: return@extend
val depEntry = placeholder.parentOfType<ZonEntry>() ?: return@extend
if (depEntry.isDependency) {
doAddCompletions(placeholder.text.startsWith('.'), emptySet(), ZON_DEP_KEYS, result)
}
}
extend(
CompletionType.BASIC,
psiElement()
.withParent(psiElement(ZonTypes.VALUE_PLACEHOLDER))
.withSuperParent(2, psiElement(ZonTypes.LIST))
.withSuperParent(4, psiElement(ZonTypes.PROPERTY))
.withSuperParent(7, psiElement(ZonTypes.PROPERTY))
.withSuperParent(10, psiOfType<ZonFile>())
) {parameters, _, result ->
val placeholder = parameters.position.parentOfType<ZonValuePlaceholder>() ?: return@extend
val depEntry = placeholder.parentOfType<ZonEntry>() ?: return@extend
if (depEntry.isDependency) {
doAddCompletions(false, emptySet(), ZON_DEP_KEYS, result)
}
}
extend(
CompletionType.BASIC,
psiElement()
.withParent(psiElement(ZonTypes.VALUE_PLACEHOLDER))
.withSuperParent(5, psiElement(ZonTypes.PROPERTY))
.withSuperParent(8, psiElement(ZonTypes.PROPERTY))
.withSuperParent(11, psiOfType<ZonFile>())
) { parameters, _, result ->
val placeholder = parameters.position.parentOfType<ZonValuePlaceholder>() ?: return@extend
val valueProperty = placeholder.parentOfType<ZonProperty>() ?: return@extend
if (valueProperty.isDependency && valueProperty.identifier.value == "lazy") {
result.addElement(LookupElementBuilder.create("true"))
result.addElement(LookupElementBuilder.create("false"))
}
}
}
private inline fun extend(type: CompletionType, place: ElementPattern<PsiElement>, crossinline action: Processor) {
extend(type, place, object : CompletionProvider<CompletionParameters>() {
override fun addCompletions(
parameters: CompletionParameters, context: ProcessingContext, result: CompletionResultSet
) = action(parameters, context, result)
})
}
}
private typealias Processor = (
parameters: CompletionParameters, context: ProcessingContext, result: CompletionResultSet
) -> Unit
@NonNls
private val ZON_ROOT_KEYS: List<String> =
listOf("name", "version", "minimum_zig_version", "dependencies", "paths")
@NonNls
private val ZON_DEP_KEYS: List<String> = listOf("url", "hash", "path", "lazy")
private fun doAddCompletions(
hasDot: Boolean, current: Set<String>, expected: List<String>, result: CompletionResultSet
) {
for (key in expected) {
if (current.contains(key)) {
continue
}
result.addElement(LookupElementBuilder.create(if (hasDot) key else ".$key"))
}
}
private val ZonProperty.isDependency: Boolean
get() {
return parentOfType<ZonEntry>()?.isDependency == true
}
private val ZonEntry.isDependency: Boolean
get() {
val parentProperty = parentOfType<ZonProperty>()?.parentOfType<ZonProperty>() ?: return false
return parentProperty.identifier.value == "dependencies"
}
private inline fun <reified T : PsiElement> psiOfType(): PsiElementPattern.Capture<T> =
psiElement(T::class.java)

View file

@ -1,58 +0,0 @@
/*
* This file is part of ZigBrains.
*
* Copyright (C) 2023-2025 FalsePattern
* All Rights Reserved
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* ZigBrains is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, only version 3 of the License.
*
* ZigBrains is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with ZigBrains. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.zigbrains.zon.folding
import com.falsepattern.zigbrains.zon.psi.ZonStruct
import com.falsepattern.zigbrains.zon.psi.ZonVisitor
import com.intellij.lang.ASTNode
import com.intellij.lang.folding.CustomFoldingBuilder
import com.intellij.lang.folding.FoldingDescriptor
import com.intellij.openapi.editor.Document
import com.intellij.openapi.project.DumbAware
import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiElement
class ZonFoldingBuilder: CustomFoldingBuilder(), DumbAware {
override fun buildLanguageFoldRegions(
descriptors: MutableList<FoldingDescriptor>,
root: PsiElement,
document: Document,
quick: Boolean
) {
root.accept(object: ZonVisitor() {
override fun visitElement(element: PsiElement) {
super.visitElement(element)
element.acceptChildren(this)
}
override fun visitStruct(o: ZonStruct) {
super.visitStruct(o)
descriptors.add(FoldingDescriptor(o, o.textRange))
}
})
}
override fun getLanguagePlaceholderText(node: ASTNode, range: TextRange) = ".{...}"
override fun isRegionCollapsedByDefault(node: ASTNode) = false
}

View file

@ -27,14 +27,19 @@ import com.intellij.formatting.*
import com.intellij.lang.ASTNode import com.intellij.lang.ASTNode
import com.intellij.psi.TokenType import com.intellij.psi.TokenType
import com.intellij.psi.formatter.common.AbstractBlock import com.intellij.psi.formatter.common.AbstractBlock
import com.intellij.psi.tree.IElementType
class ZonBlock( class ZonBlock(
node: ASTNode, node: ASTNode,
wrap: Wrap?, wrap: Wrap?,
alignment: Alignment?, alignment: Alignment?,
private val spacingBuilder: SpacingBuilder val spacingBuilder: SpacingBuilder
) : AbstractBlock(node, wrap, alignment) { ) : AbstractBlock(node, wrap, alignment) {
override fun getSpacing(child1: Block?, child2: Block) = null
override fun isLeaf() = myNode.firstChildNode == null
override fun buildChildren(): MutableList<Block> { override fun buildChildren(): MutableList<Block> {
val blocks = ArrayList<Block>() val blocks = ArrayList<Block>()
var child = myNode.firstChildNode var child = myNode.firstChildNode
@ -44,33 +49,41 @@ class ZonBlock(
} }
child = child.treeNext child = child.treeNext
} }
return blocks return blocks
} }
override fun getIndent(): Indent {
val parent = myNode.treeParent ?: return Indent.getNoneIndent()
val elementType = myNode.elementType
return if (parent.elementType == ZonTypes.ENTRY &&
elementType != ZonTypes.DOT &&
elementType != ZonTypes.LBRACE &&
elementType != ZonTypes.RBRACE
) {
Indent.getNormalIndent()
} else {
Indent.getNoneIndent()
}
}
override fun getSpacing(child1: Block?, child2: Block) = null
override fun isLeaf(): Boolean = myNode.firstChildNode == null
override fun getChildIndent(): Indent { override fun getChildIndent(): Indent {
return if (myNode.elementType == ZonTypes.ENTRY) { val node = this.node
Indent.getNormalIndent() return getIndentBasedOnParentType(node, null, node.elementType, PLACEHOLDER)
} else {
Indent.getNoneIndent()
}
} }
override fun getIndent(): Indent {
val node = this.node
val parent = node.treeParent ?: return noneIndent
return getIndentBasedOnParentType(parent, node, parent.elementType, node.elementType)
}
} }
private fun getIndentBasedOnParentType(
parent: ASTNode,
child: ASTNode?,
parentType: IElementType,
childType: IElementType
): Indent {
//Struct/tuple initializers
if (parentType == ZonTypes.INIT_LIST && !childType.isBrace)
return normalIndent
return noneIndent
}
private val normalIndent: Indent get() = Indent.getNormalIndent()
private val noneIndent: Indent get() = Indent.getNoneIndent()
private val IElementType?.isBrace: Boolean
get() {
return this == ZonTypes.LBRACE || this == ZonTypes.RBRACE
}
private val PLACEHOLDER = IElementType("placeholder", null)

View file

@ -1,80 +0,0 @@
/*
* This file is part of ZigBrains.
*
* Copyright (C) 2023-2025 FalsePattern
* All Rights Reserved
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* ZigBrains is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, only version 3 of the License.
*
* ZigBrains is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with ZigBrains. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.zigbrains.zon.highlighting
import com.falsepattern.zigbrains.Icons
import com.falsepattern.zigbrains.ZigBrainsBundle
import com.intellij.openapi.options.colors.AttributesDescriptor
import com.intellij.openapi.options.colors.ColorDescriptor
import com.intellij.openapi.options.colors.ColorSettingsPage
class ZonColorSettingsPage: ColorSettingsPage {
override fun getAttributeDescriptors() = DESCRIPTORS
override fun getColorDescriptors(): Array<ColorDescriptor> = ColorDescriptor.EMPTY_ARRAY
override fun getDisplayName() = ZigBrainsBundle.message("configurable.name.zon-color-settings-page")
override fun getIcon() = Icons.Zon
override fun getHighlighter() = ZonSyntaxHighlighter()
override fun getDemoText() = """
.{
//This is an example file with some random data
.name = "zls",
.version = "0.11.0",
.dependencies = .{
.known_folders = .{
.url = "https://github.com/ziglibs/known-folders/archive/fa75e1bc672952efa0cf06160bbd942b47f6d59b.tar.gz",
.hash = "122048992ca58a78318b6eba4f65c692564be5af3b30fbef50cd4abeda981b2e7fa5",
.lazy = true,
},
.diffz = .{
.url = "https://github.com/ziglibs/diffz/archive/90353d401c59e2ca5ed0abe5444c29ad3d7489aa.tar.gz",
.hash = "122089a8247a693cad53beb161bde6c30f71376cd4298798d45b32740c3581405864",
},
.binned_allocator = .{
.url = "https://gist.github.com/antlilja/8372900fcc09e38d7b0b6bbaddad3904/archive/6c3321e0969ff2463f8335da5601986cf2108690.tar.gz",
.hash = "1220363c7e27b2d3f39de6ff6e90f9537a0634199860fea237a55ddb1e1717f5d6a5",
},
},
.paths = .{""},
}
""".trimIndent()
override fun getAdditionalHighlightingTagToDescriptorMap() = null
}
val DESCRIPTORS = arrayOf(
AttributesDescriptor(ZigBrainsBundle.message("zon.color-settings.eq"), ZonSyntaxHighlighter.EQ),
AttributesDescriptor(ZigBrainsBundle.message("zon.color-settings.id"), ZonSyntaxHighlighter.ID),
AttributesDescriptor(ZigBrainsBundle.message("zon.color-settings.comment"), ZonSyntaxHighlighter.COMMENT),
AttributesDescriptor(ZigBrainsBundle.message("zon.color-settings.bad_char"), ZonSyntaxHighlighter.BAD_CHAR),
AttributesDescriptor(ZigBrainsBundle.message("zon.color-settings.string"), ZonSyntaxHighlighter.STRING),
AttributesDescriptor(ZigBrainsBundle.message("zon.color-settings.comma"), ZonSyntaxHighlighter.COMMA),
AttributesDescriptor(ZigBrainsBundle.message("zon.color-settings.dot"), ZonSyntaxHighlighter.DOT),
AttributesDescriptor(ZigBrainsBundle.message("zon.color-settings.boolean"), ZonSyntaxHighlighter.BOOLEAN),
AttributesDescriptor(ZigBrainsBundle.message("zon.color-settings.brace"), ZonSyntaxHighlighter.BRACE)
)

View file

@ -22,54 +22,62 @@
package com.falsepattern.zigbrains.zon.highlighting package com.falsepattern.zigbrains.zon.highlighting
import com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter
import com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.Companion
import com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.Companion.BAD_CHAR
import com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.Companion.CHAR
import com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.Companion.COMMENT
import com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.Companion.KEYWORD
import com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.Companion.NUMBER
import com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.Companion.STRING
import com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.Companion.STRING_ESC_I_C
import com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.Companion.STRING_ESC_I_U
import com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter.Companion.STRING_ESC_V
import com.falsepattern.zigbrains.zig.psi.ZigTypes
import com.falsepattern.zigbrains.zon.lexer.ZonHighlightingLexer
import com.falsepattern.zigbrains.zon.lexer.ZonLexerAdapter import com.falsepattern.zigbrains.zon.lexer.ZonLexerAdapter
import com.falsepattern.zigbrains.zon.psi.ZonTypes import com.falsepattern.zigbrains.zon.psi.ZonTypes
import com.intellij.openapi.editor.HighlighterColors import com.intellij.openapi.editor.HighlighterColors
import com.intellij.openapi.editor.colors.TextAttributesKey import com.intellij.openapi.editor.colors.TextAttributesKey
import com.intellij.openapi.fileTypes.SyntaxHighlighterBase import com.intellij.openapi.fileTypes.SyntaxHighlighterBase
import com.intellij.psi.StringEscapesTokenTypes
import com.intellij.psi.TokenType import com.intellij.psi.TokenType
import com.intellij.psi.tree.IElementType import com.intellij.psi.tree.IElementType
import org.jetbrains.annotations.NonNls import org.jetbrains.annotations.NonNls
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors as DefaultColors import com.intellij.openapi.editor.DefaultLanguageHighlighterColors as DefaultColors
class ZonSyntaxHighlighter : SyntaxHighlighterBase() { class ZonSyntaxHighlighter : SyntaxHighlighterBase() {
override fun getHighlightingLexer() = ZonLexerAdapter() override fun getHighlightingLexer() = ZonHighlightingLexer()
override fun getTokenHighlights(tokenType: IElementType?) = KEYMAP.getOrDefault(tokenType, EMPTY_KEYS) override fun getTokenHighlights(tokenType: IElementType?) = KEYMAP.getOrDefault(tokenType, EMPTY_KEYS)
companion object { companion object {
// @formatter:off
val EQ = createKey("EQ" , DefaultColors.OPERATION_SIGN )
val ID = createKey("ID" , DefaultColors.INSTANCE_FIELD )
val COMMENT = createKey("COMMENT" , DefaultColors.LINE_COMMENT )
val BAD_CHAR = createKey("BAD_CHARACTER", HighlighterColors.BAD_CHARACTER)
val STRING = createKey("STRING" , DefaultColors.STRING )
val COMMA = createKey("COMMA" , DefaultColors.COMMA )
val BOOLEAN = createKey("BOOLEAN" , DefaultColors.KEYWORD )
val DOT = createKey("DOT" , DefaultColors.DOT )
val BRACE = createKey("BRACE" , DefaultColors.BRACES )
// @formatter:on
private val EMPTY_KEYS = emptyArray<TextAttributesKey>() private val EMPTY_KEYS = emptyArray<TextAttributesKey>()
private val KEYMAP = HashMap<IElementType, Array<TextAttributesKey>>() private val KEYMAP = HashMap<IElementType, Array<TextAttributesKey>>()
private fun createKey(name: @NonNls String, fallback: TextAttributesKey) =
TextAttributesKey.createTextAttributesKey("ZON_$name", fallback)
private fun addMapping(key: TextAttributesKey, vararg types: IElementType) = types.forEach { KEYMAP[it] = arrayOf(key) } private fun addMapping(key: TextAttributesKey, vararg types: IElementType) = types.forEach { KEYMAP[it] = arrayOf(key) }
init { init {
// @formatter:off // @formatter:off
addMapping(DOT , ZonTypes.DOT) addMapping(COMMENT, ZonTypes.LINE_COMMENT)
addMapping(COMMA , ZonTypes.COMMA) addMapping(
addMapping(BRACE , ZonTypes.LBRACE) KEYWORD,
addMapping(BRACE , ZonTypes.RBRACE) *ZonTypes::class.java
addMapping(STRING , ZonTypes.LINE_STRING, ZonTypes.STRING_LITERAL_SINGLE) .fields
.filter {
it.name.startsWith("KEYWORD_")
}
.map { it.get(null) as IElementType }
.toTypedArray()
)
addMapping(STRING, ZonTypes.STRING_LITERAL_SINGLE, ZonTypes.STRING_LITERAL_MULTI, ZigTypes.STRING_LITERAL_SINGLE, ZigTypes.STRING_LITERAL_MULTI)
addMapping(STRING_ESC_V, StringEscapesTokenTypes.VALID_STRING_ESCAPE_TOKEN)
addMapping(STRING_ESC_I_C, StringEscapesTokenTypes.INVALID_CHARACTER_ESCAPE_TOKEN)
addMapping(STRING_ESC_I_U, StringEscapesTokenTypes.INVALID_UNICODE_ESCAPE_TOKEN)
addMapping(BAD_CHAR, TokenType.BAD_CHARACTER) addMapping(BAD_CHAR, TokenType.BAD_CHARACTER)
addMapping(COMMENT , ZonTypes.COMMENT) addMapping(NUMBER, ZonTypes.INTEGER, ZonTypes.FLOAT, ZonTypes.NUM_NAN, ZonTypes.NUM_INF)
addMapping(ID , ZonTypes.ID) addMapping(CHAR, ZonTypes.CHAR_LITERAL, ZigTypes.CHAR_LITERAL)
addMapping(EQ , ZonTypes.EQ)
addMapping(BOOLEAN , ZonTypes.BOOL_FALSE, ZonTypes.BOOL_TRUE)
// @formatter:on // @formatter:on
} }
} }

View file

@ -20,15 +20,25 @@
* along with ZigBrains. If not, see <https://www.gnu.org/licenses/>. * along with ZigBrains. If not, see <https://www.gnu.org/licenses/>.
*/ */
package com.falsepattern.zigbrains.zon.psi.impl.mixins package com.falsepattern.zigbrains.zon.lexer
import com.falsepattern.zigbrains.zon.psi.ZonEntry import com.falsepattern.zigbrains.zig.lexerstring.ZigLexerStringAdapter
import com.intellij.extapi.psi.ASTWrapperPsiElement import com.falsepattern.zigbrains.zig.psi.ZigTypes
import com.intellij.lang.ASTNode import com.falsepattern.zigbrains.zon.psi.ZonTypes
import com.intellij.lexer.LayeredLexer
import com.intellij.lexer.MergingLexerAdapter
import com.intellij.psi.tree.IElementType
import com.intellij.psi.tree.TokenSet
abstract class ZonEntryMixinImpl(node: ASTNode): ASTWrapperPsiElement(node), ZonEntry { class ZonHighlightingLexer: LayeredLexer(ZonLexerAdapter()) {
override val keys: Set<String> get() { init {
val struct = this.struct ?: return emptySet() registerSelfStoppingLayer(
return struct.propertyList.map { it.identifier.value }.toSet() MergingLexerAdapter(
ZigLexerStringAdapter(),
TokenSet.create(ZigTypes.STRING_LITERAL_SINGLE, ZigTypes.CHAR_LITERAL)
),
arrayOf(ZonTypes.STRING_LITERAL_SINGLE, ZonTypes.CHAR_LITERAL),
IElementType.EMPTY_ARRAY
)
} }
} }

View file

@ -28,7 +28,7 @@ import com.intellij.lang.PairedBraceMatcher
import com.intellij.psi.PsiFile import com.intellij.psi.PsiFile
import com.intellij.psi.tree.IElementType import com.intellij.psi.tree.IElementType
class ZonBraceMatcher : PairedBraceMatcher { class ZonBraceMatcher: PairedBraceMatcher {
override fun getPairs() = override fun getPairs() =
PAIRS PAIRS
@ -39,5 +39,5 @@ class ZonBraceMatcher : PairedBraceMatcher {
file?.findElementAt(openingBraceOffset)?.parent?.textOffset ?: openingBraceOffset file?.findElementAt(openingBraceOffset)?.parent?.textOffset ?: openingBraceOffset
} }
private val PAIR = BracePair(ZonTypes.LBRACE, ZonTypes.RBRACE, true) private val BRACE_PAIR = BracePair(ZonTypes.LBRACE, ZonTypes.RBRACE, true)
private val PAIRS = arrayOf(PAIR) private val PAIRS = arrayOf(BRACE_PAIR)

View file

@ -27,7 +27,10 @@ import com.intellij.codeInsight.editorActions.MultiCharQuoteHandler
import com.intellij.codeInsight.editorActions.SimpleTokenSetQuoteHandler import com.intellij.codeInsight.editorActions.SimpleTokenSetQuoteHandler
import com.intellij.openapi.editor.highlighter.HighlighterIterator import com.intellij.openapi.editor.highlighter.HighlighterIterator
class ZonQuoteHandler: SimpleTokenSetQuoteHandler(ZonTypes.STRING_LITERAL_SINGLE, ZonTypes.BAD_STRING), MultiCharQuoteHandler { class ZonQuoteHandler: SimpleTokenSetQuoteHandler(ZonTypes.STRING_LITERAL_SINGLE, ZonTypes.IDENTIFIER, ZonTypes.BAD_DQUOT, ZonTypes.CHAR_LITERAL, ZonTypes.BAD_SQUOT), MultiCharQuoteHandler {
override fun getClosingQuote(iterator: HighlighterIterator, offset: Int) = override fun getClosingQuote(iterator: HighlighterIterator, offset: Int) = when(iterator.tokenType) {
"\"" ZonTypes.STRING_LITERAL_SINGLE, ZonTypes.IDENTIFIER, ZonTypes.BAD_DQUOT -> "\""
ZonTypes.CHAR_LITERAL, ZonTypes.BAD_SQUOT -> "'"
else -> null
}
} }

View file

@ -26,6 +26,6 @@ import com.falsepattern.zigbrains.zon.psi.ZonTypes
import com.intellij.psi.tree.TokenSet import com.intellij.psi.tree.TokenSet
object ZonTokenSets { object ZonTokenSets {
val COMMENTS = TokenSet.create(ZonTypes.COMMENT) val COMMENTS = TokenSet.create(ZonTypes.LINE_COMMENT)
val STRINGS = TokenSet.create(ZonTypes.LINE_STRING, ZonTypes.STRING_LITERAL_SINGLE) val STRINGS = TokenSet.create(ZonTypes.STRING_LITERAL_SINGLE, ZonTypes.STRING_LITERAL_MULTI)
} }

View file

@ -1,37 +0,0 @@
/*
* This file is part of ZigBrains.
*
* Copyright (C) 2023-2025 FalsePattern
* All Rights Reserved
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* ZigBrains is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, only version 3 of the License.
*
* ZigBrains is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with ZigBrains. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.zigbrains.zon.psi.impl.mixins
import com.falsepattern.zigbrains.zon.psi.ZonIdentifier
import com.intellij.extapi.psi.ASTWrapperPsiElement
import com.intellij.lang.ASTNode
abstract class ZonIdentifierMixinImpl(node: ASTNode): ASTWrapperPsiElement(node), ZonIdentifier {
override val value: String get() {
val text = this.text!!
return if (text.startsWith('@'))
text.substring(2, text.length - 1)
else
text
}
}

View file

@ -1,29 +0,0 @@
/*
* This file is part of ZigBrains.
*
* Copyright (C) 2023-2025 FalsePattern
* All Rights Reserved
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* ZigBrains is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, only version 3 of the License.
*
* ZigBrains is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with ZigBrains. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.zigbrains.zon.psi.mixins
import com.intellij.psi.PsiElement
interface ZonEntryMixin: PsiElement {
val keys: Set<String>
}

View file

@ -1,30 +0,0 @@
/*
* This file is part of ZigBrains.
*
* Copyright (C) 2023-2025 FalsePattern
* All Rights Reserved
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* ZigBrains is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, only version 3 of the License.
*
* ZigBrains is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with ZigBrains. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.zigbrains.zon.psi.mixins
import com.intellij.psi.PsiElement
import org.jetbrains.annotations.NonNls
interface ZonIdentifierMixin: PsiElement {
val value: @NonNls String
}

View file

@ -64,11 +64,6 @@
<!-- region Zon --> <!-- region Zon -->
<extensions defaultExtensionNs="com.intellij"> <extensions defaultExtensionNs="com.intellij">
<colorSettingsPage
implementation="com.falsepattern.zigbrains.zon.highlighting.ZonColorSettingsPage"/>
<completion.contributor
language="Zon"
implementationClass="com.falsepattern.zigbrains.zon.completion.ZonCompletionContributor"/>
<fileType <fileType
name="Zon File" name="Zon File"
implementationClass="com.falsepattern.zigbrains.zon.ZonFileType" implementationClass="com.falsepattern.zigbrains.zon.ZonFileType"
@ -81,9 +76,6 @@
<lang.commenter <lang.commenter
language="Zon" language="Zon"
implementationClass="com.falsepattern.zigbrains.zon.comments.ZonCommenter"/> implementationClass="com.falsepattern.zigbrains.zon.comments.ZonCommenter"/>
<lang.foldingBuilder
language="Zon"
implementationClass="com.falsepattern.zigbrains.zon.folding.ZonFoldingBuilder"/>
<lang.formatter <lang.formatter
language="Zon" language="Zon"
implementationClass="com.falsepattern.zigbrains.zon.formatter.ZonFormattingModelBuilder"/> implementationClass="com.falsepattern.zigbrains.zon.formatter.ZonFormattingModelBuilder"/>

View file

@ -1,7 +1,7 @@
pluginName=ZigBrains pluginName=ZigBrains
pluginRepositoryUrl=https://github.com/FalsePattern/ZigBrains pluginRepositoryUrl=https://github.com/FalsePattern/ZigBrains
pluginVersion=21.0.0 pluginVersion=21.1.0
pluginSinceBuild=242 pluginSinceBuild=242
pluginUntilBuild=242.* pluginUntilBuild=242.*

View file

@ -73,6 +73,11 @@
serverId="ZigBrains" serverId="ZigBrains"
languageId="zig" languageId="zig"
/> />
<languageMapping
language="Zon"
serverId="ZigBrains"
languageId="zon"
/>
<semanticTokensColorsProvider <semanticTokensColorsProvider
serverId="ZigBrains" serverId="ZigBrains"
class="com.falsepattern.zigbrains.lsp.highlighting.ZLSSemanticTokenColorsProvider" class="com.falsepattern.zigbrains.lsp.highlighting.ZLSSemanticTokenColorsProvider"