ZigBrains/core/src/main/grammar/ZigString.flex

64 lines
2 KiB
Text
Raw Normal View History

2024-10-28 15:22:57 +01:00
/*
2024-10-30 16:43:33 +01:00
* This file is part of ZigBrains.
2024-10-28 15:22:57 +01:00
*
2024-10-30 16:43:33 +01:00
* Copyright (C) 2023-2024 FalsePattern
* All Rights Reserved
2024-10-28 15:22:57 +01:00
*
2024-10-30 16:43:33 +01:00
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
2024-10-28 15:22:57 +01:00
*
2024-10-30 16:43:33 +01:00
* 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/>.
2024-10-28 15:22:57 +01:00
*/
package com.falsepattern.zigbrains.zig.lexerstring;
2024-10-28 15:22:57 +01:00
import com.intellij.lexer.FlexLexer;
import com.intellij.psi.tree.IElementType;
import static com.intellij.psi.TokenType.WHITE_SPACE;
import static com.intellij.psi.TokenType.BAD_CHARACTER;
import static com.falsepattern.zigbrains.zig.psi.ZigTypes.*;
import static com.intellij.psi.StringEscapesTokenTypes.*;
%%
%public
%class ZigLexerString
2024-10-28 15:22:57 +01:00
%implements FlexLexer
%function advance
%type IElementType
hex=[0-9a-fA-F]
char_escape_unicode= "\\x" {hex} {hex} | "\\u{" {hex}+ "}"
char_escape_unicode_invalid= "\\x" | "\\u"
char_escape_single_valid= "\\" [nr\\t'\"]
char_escape_single_invalid= "\\" [^nr\\t'\"]
%state STR
%%
<YYINITIAL> {
"\"" { yybegin(STR); return STRING_LITERAL_SINGLE; }
[^] { return STRING_LITERAL_SINGLE; }
}
<STR> {
{char_escape_unicode} { return VALID_STRING_ESCAPE_TOKEN; }
{char_escape_unicode_invalid} { return INVALID_UNICODE_ESCAPE_TOKEN; }
{char_escape_single_valid} { return VALID_STRING_ESCAPE_TOKEN; }
{char_escape_single_invalid} { return INVALID_CHARACTER_ESCAPE_TOKEN; }
[^] { return STRING_LITERAL_SINGLE; }
}