diff --git a/src/main/gen/dev/blachut/svelte/lang/parsing/html/_SvelteHtmlLexer.java b/src/main/gen/dev/blachut/svelte/lang/parsing/html/_SvelteHtmlLexer.java index 1d696290..06e2a2c9 100644 --- a/src/main/gen/dev/blachut/svelte/lang/parsing/html/_SvelteHtmlLexer.java +++ b/src/main/gen/dev/blachut/svelte/lang/parsing/html/_SvelteHtmlLexer.java @@ -4,6 +4,7 @@ package dev.blachut.svelte.lang.parsing.html; import com.intellij.lexer.FlexLexer; +import com.intellij.psi.TokenType; import com.intellij.psi.tree.IElementType; import com.intellij.psi.xml.XmlTokenType; import dev.blachut.svelte.lang.psi.SvelteTokenTypes; @@ -303,73 +304,74 @@ private static int zzUnpackRowMap(String packed, int offset, int [] result) { "\1\126\5\124\30\125\2\124\1\127\3\124\1\131\3\124"+ "\5\125\2\124\4\125\3\132\2\133\5\132\1\134\3\132"+ "\1\133\35\132\1\135\1\132\1\136\3\132\1\137\1\140"+ - "\41\132\1\141\1\132\1\142\4\132\1\143\13\132\1\144"+ - "\2\132\1\135\11\132\1\145\10\132\10\25\1\27\4\25"+ - "\2\0\1\25\1\0\33\25\1\0\4\25\2\0\17\25"+ - "\1\26\4\25\1\27\4\25\1\0\1\31\1\25\1\0"+ - "\33\25\1\0\4\25\2\0\24\25\1\27\4\25\2\0"+ - "\1\25\1\0\33\25\1\0\22\25\102\0\1\31\12\0"+ - "\1\31\61\0\1\146\7\0\2\146\6\0\1\147\30\146"+ - "\3\0\1\150\1\151\5\0\5\146\2\0\4\146\1\0"+ - "\1\152\7\0\2\152\7\0\21\152\1\153\6\152\10\0"+ - "\1\154\1\0\2\152\1\155\1\152\1\156\2\0\1\153"+ - "\1\157\2\152\3\0\1\36\12\0\1\36\60\0\5\160"+ - "\1\110\71\160\6\161\1\110\70\161\44\0\2\162\60\0"+ - "\2\163\62\0\1\164\103\0\1\165\56\0\2\54\6\0"+ - "\4\54\5\0\30\54\12\0\5\54\2\0\4\54\56\0"+ - "\1\166\23\0\1\60\12\0\1\60\132\0\1\167\24\0"+ - "\5\63\2\0\7\63\3\0\31\63\1\0\3\63\1\0"+ - "\23\63\1\64\1\63\2\0\7\63\1\36\2\0\31\63"+ - "\1\0\3\63\1\0\20\63\5\0\3\67\67\0\15\77"+ - "\1\170\1\0\33\77\1\0\3\77\1\171\23\77\1\100"+ - "\11\77\1\170\1\36\33\77\1\0\3\77\1\171\35\77"+ - "\1\170\1\0\33\77\1\167\3\77\1\171\20\77\5\105"+ - "\2\0\6\105\1\170\1\0\33\105\1\0\3\105\1\172"+ - "\23\105\1\106\1\105\2\0\6\105\1\170\1\60\33\105"+ - "\1\0\3\105\1\172\72\105\1\167\3\105\1\172\20\105"+ - "\61\0\1\110\15\0\52\116\1\0\2\116\1\173\73\116"+ - "\1\117\24\116\1\0\3\125\7\0\1\125\2\0\1\125"+ - "\2\0\31\125\1\0\2\125\7\0\5\125\2\0\4\125"+ - "\14\0\1\174\134\0\1\175\27\0\2\133\11\0\1\133"+ - "\146\0\1\176\47\0\1\177\102\0\1\200\22\0\1\201"+ - "\74\0\1\202\101\0\1\203\10\0\2\146\6\0\4\146"+ - "\5\0\30\146\12\0\5\146\2\0\4\146\14\0\1\204"+ - "\5\0\1\205\55\0\1\206\7\0\2\206\7\0\30\206"+ - "\12\0\5\206\2\0\4\206\1\0\2\152\6\0\4\152"+ - "\5\0\30\152\12\0\5\152\1\0\1\207\4\152\1\0"+ - "\2\152\6\0\4\152\5\0\6\152\1\210\21\152\12\0"+ - "\5\152\1\0\1\207\4\152\2\0\1\211\72\0\1\212"+ - "\2\0\2\152\6\0\4\152\5\0\11\152\1\213\5\152"+ - "\1\214\10\152\12\0\5\152\1\0\1\207\4\152\1\0"+ - "\2\152\6\0\4\152\5\0\25\152\1\215\2\152\12\0"+ - "\5\152\1\0\1\207\4\152\1\0\2\152\6\0\4\152"+ - "\5\0\23\152\1\216\4\152\12\0\5\152\1\0\1\207"+ - "\4\152\46\0\2\217\67\0\2\220\56\0\1\221\30\0"+ - "\1\222\40\0\1\223\42\0\1\224\17\0\52\77\1\0"+ - "\3\77\1\171\20\77\52\105\1\0\3\105\1\172\20\105"+ - "\52\116\1\0\24\116\52\0\1\222\54\0\1\225\103\0"+ - "\1\226\126\0\1\227\37\0\1\230\136\0\1\231\24\0"+ - "\1\232\105\0\2\233\53\0\2\206\6\0\4\206\5\0"+ - "\30\206\12\0\5\206\2\0\4\206\1\0\2\152\6\0"+ - "\4\152\5\0\30\152\12\0\5\152\1\0\1\234\4\152"+ - "\2\0\1\211\67\0\1\234\6\0\1\235\17\0\1\235"+ - "\2\0\2\235\5\0\2\235\10\0\2\235\14\0\1\235"+ - "\1\0\1\235\7\0\1\235\1\0\2\152\6\0\4\152"+ - "\5\0\2\152\1\236\25\152\12\0\5\152\1\0\1\207"+ - "\4\152\1\0\2\152\6\0\4\152\5\0\11\152\1\210"+ - "\16\152\12\0\5\152\1\0\1\207\4\152\1\0\2\152"+ - "\6\0\4\152\5\0\30\152\12\0\1\152\1\214\3\152"+ + "\16\132\2\133\11\132\1\133\7\132\1\141\1\132\1\142"+ + "\4\132\1\143\13\132\1\144\2\132\1\135\11\132\1\145"+ + "\10\132\10\25\1\27\4\25\2\0\1\25\1\0\33\25"+ + "\1\0\4\25\2\0\17\25\1\26\4\25\1\27\4\25"+ + "\1\0\1\31\1\25\1\0\33\25\1\0\4\25\2\0"+ + "\24\25\1\27\4\25\2\0\1\25\1\0\33\25\1\0"+ + "\22\25\102\0\1\31\12\0\1\31\61\0\1\146\7\0"+ + "\2\146\6\0\1\147\30\146\3\0\1\150\1\151\5\0"+ + "\5\146\2\0\4\146\1\0\1\152\7\0\2\152\7\0"+ + "\21\152\1\153\6\152\10\0\1\154\1\0\2\152\1\155"+ + "\1\152\1\156\2\0\1\153\1\157\2\152\3\0\1\36"+ + "\12\0\1\36\60\0\5\160\1\110\71\160\6\161\1\110"+ + "\70\161\44\0\2\162\60\0\2\163\62\0\1\164\103\0"+ + "\1\165\56\0\2\54\6\0\4\54\5\0\30\54\12\0"+ + "\5\54\2\0\4\54\56\0\1\166\23\0\1\60\12\0"+ + "\1\60\132\0\1\167\24\0\5\63\2\0\7\63\3\0"+ + "\31\63\1\0\3\63\1\0\23\63\1\64\1\63\2\0"+ + "\7\63\1\36\2\0\31\63\1\0\3\63\1\0\20\63"+ + "\5\0\3\67\67\0\15\77\1\170\1\0\33\77\1\0"+ + "\3\77\1\171\23\77\1\100\11\77\1\170\1\36\33\77"+ + "\1\0\3\77\1\171\35\77\1\170\1\0\33\77\1\167"+ + "\3\77\1\171\20\77\5\105\2\0\6\105\1\170\1\0"+ + "\33\105\1\0\3\105\1\172\23\105\1\106\1\105\2\0"+ + "\6\105\1\170\1\60\33\105\1\0\3\105\1\172\72\105"+ + "\1\167\3\105\1\172\20\105\61\0\1\110\15\0\52\116"+ + "\1\0\2\116\1\173\73\116\1\117\24\116\1\0\3\125"+ + "\7\0\1\125\2\0\1\125\2\0\31\125\1\0\2\125"+ + "\7\0\5\125\2\0\4\125\14\0\1\174\134\0\1\175"+ + "\27\0\2\133\11\0\1\133\146\0\1\176\47\0\1\177"+ + "\102\0\1\200\22\0\1\201\74\0\1\202\101\0\1\203"+ + "\10\0\2\146\6\0\4\146\5\0\30\146\12\0\5\146"+ + "\2\0\4\146\14\0\1\204\5\0\1\205\55\0\1\206"+ + "\7\0\2\206\7\0\30\206\12\0\5\206\2\0\4\206"+ + "\1\0\2\152\6\0\4\152\5\0\30\152\12\0\5\152"+ "\1\0\1\207\4\152\1\0\2\152\6\0\4\152\5\0"+ - "\2\152\1\153\25\152\12\0\5\152\1\0\1\207\4\152"+ - "\42\0\2\237\75\0\2\240\105\0\1\241\40\0\1\242"+ - "\110\0\1\243\140\0\1\244\43\0\1\245\100\0\1\246"+ - "\110\0\1\247\52\0\2\250\52\0\1\235\17\0\1\235"+ - "\2\0\2\235\5\0\2\235\10\0\2\235\14\0\1\235"+ - "\1\0\1\235\3\0\1\234\3\0\1\235\1\0\2\152"+ - "\6\0\4\152\5\0\30\152\12\0\1\152\1\210\3\152"+ - "\1\0\1\207\4\152\50\0\2\251\41\0\1\221\35\0"+ - "\1\222\63\0\1\252\67\0\1\253\75\0\2\254\73\0"+ - "\2\255\101\0\1\256\77\0\2\257\77\0\2\260\41\0"; + "\6\152\1\210\21\152\12\0\5\152\1\0\1\207\4\152"+ + "\2\0\1\211\72\0\1\212\2\0\2\152\6\0\4\152"+ + "\5\0\11\152\1\213\5\152\1\214\10\152\12\0\5\152"+ + "\1\0\1\207\4\152\1\0\2\152\6\0\4\152\5\0"+ + "\25\152\1\215\2\152\12\0\5\152\1\0\1\207\4\152"+ + "\1\0\2\152\6\0\4\152\5\0\23\152\1\216\4\152"+ + "\12\0\5\152\1\0\1\207\4\152\46\0\2\217\67\0"+ + "\2\220\56\0\1\221\30\0\1\222\40\0\1\223\42\0"+ + "\1\224\17\0\52\77\1\0\3\77\1\171\20\77\52\105"+ + "\1\0\3\105\1\172\20\105\52\116\1\0\24\116\52\0"+ + "\1\222\54\0\1\225\103\0\1\226\126\0\1\227\37\0"+ + "\1\230\136\0\1\231\24\0\1\232\105\0\2\233\53\0"+ + "\2\206\6\0\4\206\5\0\30\206\12\0\5\206\2\0"+ + "\4\206\1\0\2\152\6\0\4\152\5\0\30\152\12\0"+ + "\5\152\1\0\1\234\4\152\2\0\1\211\67\0\1\234"+ + "\6\0\1\235\17\0\1\235\2\0\2\235\5\0\2\235"+ + "\10\0\2\235\14\0\1\235\1\0\1\235\7\0\1\235"+ + "\1\0\2\152\6\0\4\152\5\0\2\152\1\236\25\152"+ + "\12\0\5\152\1\0\1\207\4\152\1\0\2\152\6\0"+ + "\4\152\5\0\11\152\1\210\16\152\12\0\5\152\1\0"+ + "\1\207\4\152\1\0\2\152\6\0\4\152\5\0\30\152"+ + "\12\0\1\152\1\214\3\152\1\0\1\207\4\152\1\0"+ + "\2\152\6\0\4\152\5\0\2\152\1\153\25\152\12\0"+ + "\5\152\1\0\1\207\4\152\42\0\2\237\75\0\2\240"+ + "\105\0\1\241\40\0\1\242\110\0\1\243\140\0\1\244"+ + "\43\0\1\245\100\0\1\246\110\0\1\247\52\0\2\250"+ + "\52\0\1\235\17\0\1\235\2\0\2\235\5\0\2\235"+ + "\10\0\2\235\14\0\1\235\1\0\1\235\3\0\1\234"+ + "\3\0\1\235\1\0\2\152\6\0\4\152\5\0\30\152"+ + "\12\0\1\152\1\210\3\152\1\0\1\207\4\152\50\0"+ + "\2\251\41\0\1\221\35\0\1\222\63\0\1\252\67\0"+ + "\1\253\75\0\2\254\73\0\2\255\101\0\1\256\77\0"+ + "\2\257\77\0\2\260\41\0"; private static int [] zzUnpackTrans() { int [] result = new int[7056]; @@ -967,7 +969,7 @@ else if (zzAtEOF) { // fall through case 100: break; case 38: - { return SvelteTokenTypes.TEMP_PREFIX; + { return TokenType.WHITE_SPACE; } // fall through case 101: break; diff --git a/src/main/java/dev/blachut/svelte/lang/parsing/html/SvelteHtmlLexer.flex b/src/main/java/dev/blachut/svelte/lang/parsing/html/SvelteHtmlLexer.flex index fe05e8cb..b2f90e22 100644 --- a/src/main/java/dev/blachut/svelte/lang/parsing/html/SvelteHtmlLexer.flex +++ b/src/main/java/dev/blachut/svelte/lang/parsing/html/SvelteHtmlLexer.flex @@ -4,6 +4,7 @@ package dev.blachut.svelte.lang.parsing.html; import com.intellij.lexer.FlexLexer; import com.intellij.psi.tree.IElementType; import com.intellij.psi.xml.*; +import com.intellij.psi.TokenType; import dev.blachut.svelte.lang.psi.SvelteTokenTypes; %% @@ -147,7 +148,7 @@ CONDITIONAL_COMMENT_CONDITION=({ALPHA})({ALPHA}|{WHITE_SPACE_CHARS}|{DIGIT}|"."| "{" { yybeginNestable(SVELTE_INTERPOLATION_START); return SvelteTokenTypes.START_MUSTACHE_TEMP; } { - {WHITE_SPACE} { return SvelteTokenTypes.TEMP_PREFIX; } + {WHITE_SPACE} { return TokenType.WHITE_SPACE; } "#" { yybegin(SVELTE_INTERPOLATION_KEYWORD); return SvelteTokenTypes.HASH; } ":" { yybegin(SVELTE_INTERPOLATION_KEYWORD); return SvelteTokenTypes.COLON; } "/" { yybegin(SVELTE_INTERPOLATION_KEYWORD); return SvelteTokenTypes.SLASH; } @@ -156,8 +157,7 @@ CONDITIONAL_COMMENT_CONDITION=({ALPHA})({ALPHA}|{WHITE_SPACE_CHARS}|{DIGIT}|"."| } { - // TODO Disallow whitespace - // {WHITE_SPACE} { return BAD_CHARACTER; } + {WHITE_SPACE} { return TokenType.WHITE_SPACE; } "if" { yybegin(SVELTE_INTERPOLATION); return SvelteTokenTypes.LAZY_IF; } "else" { yybegin(SVELTE_INTERPOLATION); return SvelteTokenTypes.LAZY_ELSE; } "each" { yybegin(SVELTE_INTERPOLATION); return SvelteTokenTypes.LAZY_EACH; } diff --git a/src/main/java/dev/blachut/svelte/lang/parsing/html/SvelteManualParsing.kt b/src/main/java/dev/blachut/svelte/lang/parsing/html/SvelteManualParsing.kt index 4c79a6bb..ae0566c3 100644 --- a/src/main/java/dev/blachut/svelte/lang/parsing/html/SvelteManualParsing.kt +++ b/src/main/java/dev/blachut/svelte/lang/parsing/html/SvelteManualParsing.kt @@ -2,24 +2,25 @@ package dev.blachut.svelte.lang.parsing.html import com.intellij.lang.PsiBuilder import com.intellij.lang.javascript.JSTokenTypes -import com.intellij.psi.TokenType import com.intellij.psi.tree.IElementType import com.intellij.psi.tree.ILazyParseableElementType +import dev.blachut.svelte.lang.isTokenAfterWhiteSpace import dev.blachut.svelte.lang.psi.SvelteBlockLazyElementTypes import dev.blachut.svelte.lang.psi.SvelteJSLazyElementTypes import dev.blachut.svelte.lang.psi.SvelteTokenTypes object SvelteManualParsing { + fun parseNotAllowedWhitespace(builder: PsiBuilder, precedingSymbol: String) { + if (builder.isTokenAfterWhiteSpace()) { + builder.error("whitespace is not allowed after $precedingSymbol") + } + } + fun parseLazyBlock(builder: PsiBuilder): Pair { val marker = builder.mark() builder.remapCurrentToken(JSTokenTypes.LBRACE) builder.advanceLexer() - if (builder.tokenType == SvelteTokenTypes.TEMP_PREFIX) { - builder.remapCurrentToken(TokenType.WHITE_SPACE) - builder.advanceLexer() - } - if (builder.tokenType == SvelteTokenTypes.HASH) { builder.advanceLexer() val token = when (builder.tokenType) { @@ -41,6 +42,8 @@ object SvelteManualParsing { } else if (builder.tokenType == SvelteTokenTypes.SLASH) { builder.remapCurrentToken(JSTokenTypes.DIV) builder.advanceLexer() + parseNotAllowedWhitespace(builder, "/") + val token = when (builder.tokenType) { SvelteTokenTypes.LAZY_IF -> { builder.remapCurrentToken(JSTokenTypes.IF_KEYWORD) diff --git a/src/main/java/dev/blachut/svelte/lang/psi/SvelteBlockLazyElementTypes.kt b/src/main/java/dev/blachut/svelte/lang/psi/SvelteBlockLazyElementTypes.kt index 7d8cf3f6..484554ce 100644 --- a/src/main/java/dev/blachut/svelte/lang/psi/SvelteBlockLazyElementTypes.kt +++ b/src/main/java/dev/blachut/svelte/lang/psi/SvelteBlockLazyElementTypes.kt @@ -3,6 +3,7 @@ package dev.blachut.svelte.lang.psi import com.intellij.lang.PsiBuilder import com.intellij.lang.javascript.JSTokenTypes import com.intellij.lang.javascript.parsing.JavaScriptParser +import dev.blachut.svelte.lang.parsing.html.SvelteManualParsing object SvelteBlockLazyElementTypes { val IF_START = object : SvelteBlockLazyElementType("IF_START") { @@ -10,6 +11,7 @@ object SvelteBlockLazyElementTypes { override fun parseTokens(builder: PsiBuilder, parser: JavaScriptParser<*, *, *, *>) { builder.advanceLexer() // JSTokenTypes.SHARP + SvelteManualParsing.parseNotAllowedWhitespace(builder, "#") builder.advanceLexer() // JSTokenTypes.IF_KEYWORD parser.expressionParser.parseExpression() @@ -21,6 +23,7 @@ object SvelteBlockLazyElementTypes { override fun parseTokens(builder: PsiBuilder, parser: JavaScriptParser<*, *, *, *>) { builder.advanceLexer() // JSTokenTypes.COLON + SvelteManualParsing.parseNotAllowedWhitespace(builder, ":") builder.advanceLexer() // JSTokenTypes.ELSE_KEYWORD if (builder.tokenType === JSTokenTypes.IF_KEYWORD) { @@ -39,6 +42,7 @@ object SvelteBlockLazyElementTypes { override fun parseTokens(builder: PsiBuilder, parser: JavaScriptParser<*, *, *, *>) { builder.advanceLexer() // JSTokenTypes.SHARP + SvelteManualParsing.parseNotAllowedWhitespace(builder, "#") builder.advanceLexer() // JSTokenTypes.IDENTIFIER -- fake EACH parser.expressionParser.parseExpression() @@ -76,6 +80,7 @@ object SvelteBlockLazyElementTypes { override fun parseTokens(builder: PsiBuilder, parser: JavaScriptParser<*, *, *, *>) { builder.advanceLexer() // JSTokenTypes.SHARP + SvelteManualParsing.parseNotAllowedWhitespace(builder, "#") builder.advanceLexer() // JSTokenTypes.AWAIT_KEYWORD parser.expressionParser.parseExpression() @@ -93,6 +98,7 @@ object SvelteBlockLazyElementTypes { override fun parseTokens(builder: PsiBuilder, parser: JavaScriptParser<*, *, *, *>) { builder.advanceLexer() // JSTokenTypes.COLON + SvelteManualParsing.parseNotAllowedWhitespace(builder, ":") builder.advanceLexer() // JSTokenTypes.IDENTIFIER -- fake THEN // TODO Check weird RBRACE placement @@ -105,6 +111,7 @@ object SvelteBlockLazyElementTypes { override fun parseTokens(builder: PsiBuilder, parser: JavaScriptParser<*, *, *, *>) { builder.advanceLexer() // JSTokenTypes.COLON + SvelteManualParsing.parseNotAllowedWhitespace(builder, ":") builder.advanceLexer() // JSTokenTypes.CATCH_KEYWORD parser.expressionParser.parseDestructuringElement(SvelteJSElementTypes.PARAMETER, false, false) diff --git a/src/main/java/dev/blachut/svelte/lang/psi/SvelteTokenTypes.kt b/src/main/java/dev/blachut/svelte/lang/psi/SvelteTokenTypes.kt index c99c9cfd..e0ebdc8b 100644 --- a/src/main/java/dev/blachut/svelte/lang/psi/SvelteTokenTypes.kt +++ b/src/main/java/dev/blachut/svelte/lang/psi/SvelteTokenTypes.kt @@ -13,8 +13,6 @@ object SvelteTokenTypes { @JvmField val END_MUSTACHE = SvelteElementType("END_MUSTACHE") - @JvmField - val TEMP_PREFIX = SvelteElementType("TEMP_PREFIX") @JvmField val LAZY_IF = SvelteElementType("LAZY_IF") @JvmField