json: allow empty .jsonl files (WEB-49403)

Also, allow empty .json files to make creating a new JSON file more pleasant.

GitOrigin-RevId: 707361a11b025917c06758f5c058c144f18eee4f
This commit is contained in:
Sergey Simonchik
2021-02-08 23:30:38 +03:00
committed by intellij-monorepo-bot
parent 626db253dc
commit ec5f02f021
5 changed files with 15 additions and 8 deletions

View File

@@ -115,19 +115,15 @@ public class JsonParser implements PsiParser, LightPsiParser {
}
/* ********************************************************** */
// value+
// value*
static boolean json(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "json")) return false;
boolean r;
Marker m = enter_section_(b);
r = value(b, l + 1);
while (r) {
while (true) {
int c = current_position_(b);
if (!value(b, l + 1)) break;
if (!empty_element_parsed_guard_(b, "json", c)) break;
}
exit_section_(b, m, null, r);
return r;
return true;
}
/* ********************************************************** */

View File

@@ -59,7 +59,8 @@
}
// For compatibility we allow any value at root level (see JsonStandardComplianceAnnotator)
json ::= value+
// Empty file is also allowed
json ::= value*
object ::= '{' object_element* '}' {
pin=1

View File

@@ -45,6 +45,16 @@ public class JsonHighlightingTest extends JsonHighlightingTestBase {
doTestHighlightingForJsonLines(false, true, true);
}
public void testJsonLinesEmptyFile() {
enableStandardComplianceInspection(true, true);
doTestHighlightingForJsonLines(false, true, true);
}
public void testEmptyFile() {
enableStandardComplianceInspection(true, true);
doTestHighlighting(false, true, true);
}
public void testDuplicatePropertyKeys() {
myFixture.enableInspections(JsonDuplicatePropertyKeysInspection.class);
doTestHighlighting(false, true, true);