feat: zig quote matching
This commit is contained in:
parent
c652e1f05c
commit
8a988d5bfe
5 changed files with 53 additions and 5 deletions
|
@ -17,6 +17,11 @@ Changelog structure reference:
|
|||
|
||||
## [Unreleased]
|
||||
|
||||
### Added
|
||||
|
||||
- Zig
|
||||
- String, character literal, and `@"identifier"` quote matching
|
||||
|
||||
### Fixed
|
||||
|
||||
- Zon
|
||||
|
|
|
@ -165,6 +165,8 @@
|
|||
|
||||
STRING_LITERAL_SINGLE='quoted string literal'
|
||||
STRING_LITERAL_MULTI='multiline string literal'
|
||||
BAD_SQUOT='unterminated character literal'
|
||||
BAD_DQUOT='unterminated string'
|
||||
|
||||
IDENTIFIER='identifier'
|
||||
BUILTINIDENTIFIER='builtin identifier'
|
||||
|
|
|
@ -80,7 +80,8 @@ BUILTINIDENTIFIER="@"[A-Za-z_][A-Za-z0-9_]*
|
|||
%state CHAR_LIT
|
||||
|
||||
%state ID_QUOT
|
||||
%state UNT_QUOT
|
||||
%state UNT_SQUOT
|
||||
%state UNT_DQUOT
|
||||
|
||||
%state CDOC_CMT
|
||||
%state DOC_CMT
|
||||
|
@ -221,14 +222,14 @@ BUILTINIDENTIFIER="@"[A-Za-z_][A-Za-z0-9_]*
|
|||
|
||||
<YYINITIAL> "'" { yybegin(CHAR_LIT); }
|
||||
<CHAR_LIT> {char_char}*"'" { yybegin(YYINITIAL); return CHAR_LITERAL; }
|
||||
<CHAR_LIT> [^] { yypushback(1); yybegin(UNT_QUOT); }
|
||||
<CHAR_LIT> [^] { yypushback(1); yybegin(UNT_SQUOT); }
|
||||
|
||||
<YYINITIAL> {FLOAT} { return FLOAT; }
|
||||
<YYINITIAL> {INTEGER} { return INTEGER; }
|
||||
|
||||
<YYINITIAL> "\"" { yybegin(STR_LIT); }
|
||||
<STR_LIT> {string_char}*"\"" { yybegin(YYINITIAL); return STRING_LITERAL_SINGLE; }
|
||||
<STR_LIT> [^] { yypushback(1); yybegin(UNT_QUOT); }
|
||||
<STR_LIT> [^] { yypushback(1); yybegin(UNT_DQUOT); }
|
||||
<YYINITIAL> "\\\\" { yybegin(STR_MULT_LINE); }
|
||||
<STR_MULT_LINE> {all_nl_wrap} "\\\\" { }
|
||||
<STR_MULT_LINE> {all_nl_nowrap} { yybegin(YYINITIAL); return STRING_LITERAL_MULTI; }
|
||||
|
@ -236,11 +237,12 @@ BUILTINIDENTIFIER="@"[A-Za-z_][A-Za-z0-9_]*
|
|||
<YYINITIAL> {IDENTIFIER_PLAIN} { return IDENTIFIER; }
|
||||
<YYINITIAL> "@\"" { yybegin(ID_QUOT); }
|
||||
<ID_QUOT> {string_char}*"\"" { yybegin(YYINITIAL); return IDENTIFIER; }
|
||||
<ID_QUOT> [^] { yypushback(1); yybegin(UNT_QUOT); }
|
||||
<ID_QUOT> [^] { yypushback(1); yybegin(UNT_DQUOT); }
|
||||
|
||||
<YYINITIAL> {BUILTINIDENTIFIER} { return BUILTINIDENTIFIER; }
|
||||
|
||||
<UNT_QUOT> [^\n]*{CRLF} { yybegin(YYINITIAL); return BAD_CHARACTER; }
|
||||
<UNT_SQUOT> [^\n]*{CRLF} { yybegin(YYINITIAL); return BAD_SQUOT; }
|
||||
<UNT_DQUOT> [^\n]*{CRLF} { yybegin(YYINITIAL); return BAD_DQUOT; }
|
||||
|
||||
<YYINITIAL> {WHITE_SPACE} { return WHITE_SPACE; }
|
||||
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* This file is part of ZigBrains.
|
||||
*
|
||||
* Copyright (C) 2023-2024 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.zig.pairing
|
||||
|
||||
import com.falsepattern.zigbrains.zig.psi.ZigTypes
|
||||
import com.intellij.codeInsight.editorActions.MultiCharQuoteHandler
|
||||
import com.intellij.codeInsight.editorActions.SimpleTokenSetQuoteHandler
|
||||
import com.intellij.openapi.editor.highlighter.HighlighterIterator
|
||||
|
||||
class ZigQuoteHandler: SimpleTokenSetQuoteHandler(ZigTypes.STRING_LITERAL_SINGLE, ZigTypes.IDENTIFIER, ZigTypes.BAD_DQUOT, ZigTypes.CHAR_LITERAL, ZigTypes.BAD_SQUOT), MultiCharQuoteHandler {
|
||||
override fun getClosingQuote(iterator: HighlighterIterator, offset: Int) = when(iterator.tokenType) {
|
||||
ZigTypes.STRING_LITERAL_SINGLE, ZigTypes.IDENTIFIER, ZigTypes.BAD_DQUOT -> "\""
|
||||
ZigTypes.CHAR_LITERAL, ZigTypes.BAD_SQUOT -> "'"
|
||||
else -> null
|
||||
}
|
||||
}
|
|
@ -22,6 +22,9 @@
|
|||
<lang.parserDefinition
|
||||
language="Zig"
|
||||
implementationClass="com.falsepattern.zigbrains.zig.parser.ZigParserDefinition"/>
|
||||
<lang.quoteHandler
|
||||
language="Zig"
|
||||
implementationClass="com.falsepattern.zigbrains.zig.pairing.ZigQuoteHandler"/>
|
||||
<lang.syntaxHighlighterFactory
|
||||
language="Zig"
|
||||
implementationClass="com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighterFactory"/>
|
||||
|
|
Loading…
Add table
Reference in a new issue