mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
RUBY-21351 Added highlighting for invalid symbols in scalar headers
This commit is contained in:
@@ -83,11 +83,11 @@ public class _YAMLLexer implements FlexLexer, YAMLTokenTypes {
|
||||
"\1\21\7\0\1\1\1\0\1\22\1\0\2\23\2\24"+
|
||||
"\1\11\5\0\1\25\2\0\1\26\1\0\2\27\4\0"+
|
||||
"\1\15\1\1\1\0\1\22\3\0\1\1\4\0\1\25"+
|
||||
"\1\26\1\1\3\0\1\30\1\2\13\0\1\31\1\0"+
|
||||
"\1\1\2\0\1\32\3\0\1\33\1\0\1\1\5\0"+
|
||||
"\1\1\2\0\2\1\2\0\2\1\2\0\1\1\2\0"+
|
||||
"\1\1\1\0\1\1\4\0\2\1\1\0\4\1\1\0"+
|
||||
"\1\1\2\0\1\1";
|
||||
"\1\26\1\1\3\0\1\30\14\0\1\31\1\0\1\1"+
|
||||
"\2\0\1\32\3\0\1\33\1\0\1\1\5\0\1\1"+
|
||||
"\2\0\2\1\2\0\2\1\2\0\1\1\2\0\1\1"+
|
||||
"\1\0\1\1\4\0\2\1\1\0\4\1\1\0\1\1"+
|
||||
"\2\0\1\1";
|
||||
|
||||
private static int [] zzUnpackAction() {
|
||||
int [] result = new int[165];
|
||||
@@ -375,12 +375,12 @@ public class _YAMLLexer implements FlexLexer, YAMLTokenTypes {
|
||||
"\1\11\1\1\4\0\1\1\1\0\1\1\1\0\1\11"+
|
||||
"\1\1\1\11\1\1\1\11\5\0\1\1\2\0\1\1"+
|
||||
"\1\0\1\11\1\1\4\0\1\11\1\1\1\0\1\1"+
|
||||
"\3\0\1\1\4\0\1\11\2\1\3\0\1\11\3\1"+
|
||||
"\5\0\1\1\2\0\1\1\1\11\1\0\1\1\2\0"+
|
||||
"\1\11\3\0\1\11\1\0\1\1\5\0\1\1\2\0"+
|
||||
"\2\1\2\0\2\1\2\0\1\1\2\0\1\1\1\0"+
|
||||
"\1\1\2\0\1\11\1\0\2\1\1\0\4\1\1\0"+
|
||||
"\1\1\2\0\1\1";
|
||||
"\3\0\1\1\4\0\1\11\2\1\3\0\1\11\1\0"+
|
||||
"\2\1\5\0\1\1\2\0\1\1\1\11\1\0\1\1"+
|
||||
"\2\0\1\11\3\0\1\11\1\0\1\1\5\0\1\1"+
|
||||
"\2\0\2\1\2\0\2\1\2\0\1\1\2\0\1\1"+
|
||||
"\1\0\1\1\2\0\1\11\1\0\2\1\1\0\4\1"+
|
||||
"\1\0\1\1\2\0\1\1";
|
||||
|
||||
private static int [] zzUnpackAttribute() {
|
||||
int [] result = new int[165];
|
||||
|
||||
@@ -37,3 +37,5 @@ YamlMetaClass.error.scalar.value=Scalar value is not allowed here
|
||||
YamlScalarType.error.scalar.value=Scalar value expected
|
||||
YamlIntegerType.error.integer.value=Integer value expected
|
||||
YamlNumberType.error.numeric.value=Numeric value expected
|
||||
|
||||
YAMLParser.invalid.header.symbols=Invalid block scalar header
|
||||
|
||||
@@ -165,14 +165,14 @@ SCALAR_BLOCK_ERR_WORD = [^ \t#\n] [^ \t\n]*
|
||||
///////////////////////////// STATES DECLARATIONS //////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
%xstate BRACES, VALUE, VALUE_OR_KEY, VALUE_BRACE, INDENT_VALUE, SB_HEADER_TAIL
|
||||
%xstate BRACES, VALUE, VALUE_OR_KEY, VALUE_BRACE, INDENT_VALUE, BS_HEADER_TAIL
|
||||
|
||||
%%
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//////// RULES declarations ////////////////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
<YYINITIAL, BRACES, VALUE, VALUE_BRACE, VALUE_OR_KEY, SB_HEADER_TAIL> {
|
||||
<YYINITIAL, BRACES, VALUE, VALUE_BRACE, VALUE_OR_KEY, BS_HEADER_TAIL> {
|
||||
{COMMENT} {
|
||||
// YAML spec: when a comment follows another syntax element,
|
||||
// it must be separated from it by space characters.
|
||||
@@ -252,7 +252,7 @@ SCALAR_BLOCK_ERR_WORD = [^ \t#\n] [^ \t\n]*
|
||||
}
|
||||
}
|
||||
|
||||
<YYINITIAL, BRACES, VALUE, VALUE_BRACE, VALUE_OR_KEY, SB_HEADER_TAIL> {
|
||||
<YYINITIAL, BRACES, VALUE, VALUE_BRACE, VALUE_OR_KEY, BS_HEADER_TAIL> {
|
||||
|
||||
{WHITE_SPACE} { return getWhitespaceTypeAndUpdateIndent(); }
|
||||
|
||||
@@ -289,20 +289,21 @@ SCALAR_BLOCK_ERR_WORD = [^ \t#\n] [^ \t\n]*
|
||||
|
||||
<YYINITIAL, VALUE, VALUE_BRACE, VALUE_OR_KEY>{
|
||||
|
||||
">"("-"|"+")? { yyBegin(SB_HEADER_TAIL);
|
||||
">"("-"|"+")? { yyBegin(BS_HEADER_TAIL);
|
||||
valueTokenType = SCALAR_TEXT;
|
||||
return valueTokenType;
|
||||
}
|
||||
|
||||
"|"("-"|"+")? { yyBegin(SB_HEADER_TAIL);
|
||||
"|"("-"|"+")? { yyBegin(BS_HEADER_TAIL);
|
||||
valueTokenType = SCALAR_LIST;
|
||||
return valueTokenType;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
<SB_HEADER_TAIL>{
|
||||
([^ \t#\n] [^ \t\n]* [ \t]* )+ { return TEXT; }
|
||||
<BS_HEADER_TAIL>{
|
||||
{BS_HEADER_ERR_WORD} ([ \t]* {BS_HEADER_ERR_WORD})*
|
||||
{ return TEXT; }
|
||||
|
||||
{EOL} { yyBegin(INDENT_VALUE);
|
||||
valueIndent = currentLineIndent;
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.intellij.psi.tree.TokenSet;
|
||||
import com.intellij.util.containers.Stack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.yaml.YAMLBundle;
|
||||
import org.jetbrains.yaml.YAMLElementTypes;
|
||||
import org.jetbrains.yaml.YAMLTokenTypes;
|
||||
|
||||
@@ -222,8 +223,9 @@ public class YAMLParser implements PsiParser, YAMLTokenTypes {
|
||||
|
||||
// Parse header tail: TEXT is used as placeholder for invalid symbols in this context
|
||||
if (getTokenType() == TEXT) {
|
||||
PsiBuilder.Marker err = myBuilder.mark();
|
||||
advanceLexer();
|
||||
|
||||
err.error(YAMLBundle.message("YAMLParser.invalid.header.symbols"));
|
||||
}
|
||||
PsiBuilder.Marker endOfValue = myBuilder.mark();
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.jetbrains.yaml.highlighting;
|
||||
|
||||
import com.intellij.openapi.application.ex.PathManagerEx;
|
||||
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase;
|
||||
|
||||
public class YAMLHighlightingTest extends LightPlatformCodeInsightFixtureTestCase {
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return PathManagerEx.getCommunityHomePath() + "/plugins/yaml/testSrc/org/jetbrains/yaml/highlighting/data/";
|
||||
}
|
||||
|
||||
public void testBlockScalarHeaderError() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
myFixture.testHighlighting(true, false, false, getTestName(true) + ".yml");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
| <error descr="Invalid block scalar header">invalid w#ords in this context</error> #comments starts here
|
||||
hello
|
||||
world
|
||||
@@ -232,4 +232,8 @@ public class YAMLParserTest extends ParsingTestCase {
|
||||
public void testCommentInBlockScalarHeader() {
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
public void testErrorInBlockScalarHeader() {
|
||||
doTest(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
YAML file
|
||||
YAML document
|
||||
YAML sequence
|
||||
YAML sequence item
|
||||
PsiElement(-)('-')
|
||||
PsiWhiteSpace(' ')
|
||||
YAML scalar text
|
||||
PsiElement(scalar text)('>')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiErrorElement:Invalid block scalar header
|
||||
PsiElement(text)('some invalid symbols')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiComment(comment)('# comment')
|
||||
PsiElement(Eol)('\n')
|
||||
PsiElement(indent)(' ')
|
||||
PsiElement(scalar text)('hello')
|
||||
PsiElement(Eol)('\n')
|
||||
PsiElement(indent)(' ')
|
||||
PsiElement(scalar text)('world')
|
||||
PsiElement(Eol)('\n')
|
||||
YAML sequence item
|
||||
PsiElement(-)('-')
|
||||
PsiWhiteSpace(' ')
|
||||
YAML scalar list
|
||||
PsiElement(scalar list)('|')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiErrorElement:Invalid block scalar header
|
||||
PsiElement(text)('some invalid symbols')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiComment(comment)('# comment')
|
||||
PsiElement(Eol)('\n')
|
||||
PsiElement(indent)(' ')
|
||||
PsiElement(scalar list)('forever')
|
||||
PsiElement(Eol)('\n')
|
||||
PsiElement(indent)(' ')
|
||||
PsiElement(scalar list)('young')
|
||||
@@ -0,0 +1,6 @@
|
||||
- > some invalid symbols # comment
|
||||
hello
|
||||
world
|
||||
- | some invalid symbols # comment
|
||||
forever
|
||||
young
|
||||
Reference in New Issue
Block a user