/
json.bnf
139 lines (118 loc) · 3.71 KB
/
json.bnf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
{
parserClass = 'com.intellij.json.JsonParser'
parserUtilClass = "com.intellij.json.psi.JsonParserUtil"
psiPackage = 'com.intellij.json.psi'
psiImplPackage = 'com.intellij.json.psi.impl'
elementTypeHolderClass = 'com.intellij.json.JsonElementTypes'
elementTypeClass = 'com.intellij.json.JsonElementType'
psiClassPrefix = "Json"
psiVisitorName = "JsonElementVisitor"
psiImplUtilClass = 'com.intellij.json.psi.impl.JsonPsiImplUtils'
tokenTypeClass = 'com.intellij.json.JsonTokenType'
implements("value") = "com.intellij.json.psi.JsonElement"
extends("value") = "com.intellij.json.psi.impl.JsonElementImpl"
tokens = [
L_CURLY='{'
R_CURLY='}'
L_BRACKET='['
R_BRACKET=']'
COMMA=','
COLON=':'
LINE_COMMENT='regexp://.*'
// "/*" ([^*]|\*+[^*/])* (\*+"/")?
BLOCK_COMMENT='regexp:/\*([^*]|\*+[^*/])*(\*+/)?'
// else /\*(?:[^*]|\*[^/])*\*+/
// unclosed string literal matches till the line's end
// any escape sequences included, illegal escapes are indicated by SyntaxHighlighter
// and JsonStringLiteralAnnotator
DOUBLE_QUOTED_STRING="regexp:\"([^\\\"\r\n]|\\[^\r\n])*\"?"
SINGLE_QUOTED_STRING="regexp:'([^\\\'\r\n]|\\[^\r\n])*'?"
// STRING='regexp:"([^\\"\r\n]|\\([\\"/bfnrt]|u[a-fA-F0-9]{4}))*"?'
NUMBER='regexp:-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d*)?'
TRUE='true'
FALSE='false'
NULL='null'
// Actually not defined in RFC 4627, but may be used for JSON5 and helps with
// auto completion of keywords.
INDENTIFIER='regexp:[:jletter:] [:jletterdigit:]*'
]
extends("container|literal|reference_expression")=value
extends("array|object")=container
extends("string_literal|number_literal|boolean_literal|null_literal")=literal
implements("property")=[
"com.intellij.json.psi.JsonElement"
"com.intellij.psi.PsiNamedElement"
]
}
// For compatibility we allow any value at root level (see JsonStandardComplianceAnnotator)
json ::= value+
object ::= '{' object_element* '}' {
pin=1
methods=[
findProperty
getPresentation
]
mixin="com.intellij.json.psi.impl.JsonObjectMixin"
}
// Hackity-hack to parse array elements and properties even if separating commas are missing,
// TODO: Find out if there is any simpler way to do so in GrammarKit
private object_element ::= property (','|&'}') {
recoverWhile = not_brace_or_next_value
pin = 1
}
property ::= property_name (':' value) {
methods=[
getName
getNameElement
getValue
// suppress getValueList() accessor
value=""
getPresentation
]
mixin="com.intellij.json.psi.impl.JsonPropertyMixin"
pin(".*")=1
}
private property_name ::= literal | reference_expression
array ::= '[' array_element* ']' {
methods=[
getPresentation
]
pin=1
}
private array_element ::= value (','|&']') {
recoverWhile = not_bracket_or_next_value
pin=1
}
string_literal ::= SINGLE_QUOTED_STRING | DOUBLE_QUOTED_STRING {
methods=[
getTextFragments
getValue
SINGLE_QUOTED_STRING=""
DOUBLE_QUOTED_STRING=""
]
mixin="com.intellij.json.psi.impl.JsonStringLiteralMixin"
}
number_literal ::= NUMBER {
methods=[
NUMBER=""
getValue
]
}
boolean_literal ::= TRUE | FALSE {
methods=[
getValue
]
}
null_literal ::= NULL
literal ::= string_literal | number_literal | boolean_literal | null_literal {
methods=[
isQuotedString
]
mixin="com.intellij.json.psi.impl.JsonLiteralMixin"
}
fake container ::= object | literal
reference_expression ::= INDENTIFIER
value ::= object | array | literal | reference_expression
// Recoveries
private not_bracket_or_next_value ::= !(']'|value)
private not_brace_or_next_value ::= !('}'|value)