1
+ """
2
+ Contains the main functionality of the JSONSchemaLexer.
3
+ """
4
+
5
+ from typing import Any , ClassVar
6
+
1
7
from pygments .lexer import RegexLexer , include
2
8
from pygments .token import Token
3
9
4
10
5
11
def _get_regex_from_options (options : list [str ]) -> str :
6
12
"""
7
- Constructs a regular expression pattern allowing any string from the options list.
13
+ Constructs regex allowing any string from the options list.
8
14
9
15
Args:
10
- options (list[str]): List of options to be included in the regex pattern.
16
+ options (list[str]): List of options to be included
17
+ in the regex pattern.
11
18
12
19
Returns:
13
20
str: Regular expression pattern constructed from the options.
14
21
15
22
"""
16
23
options = ['"' + option + '"' for option in options ]
17
- regex_str = "(" + "|" .join (options ) + ")"
18
- return regex_str
24
+ return "(" + "|" .join (options ) + ")"
19
25
20
26
21
27
class JSONSchemaLexer (RegexLexer ):
@@ -25,7 +31,7 @@ class JSONSchemaLexer(RegexLexer):
25
31
26
32
name = "JSON Schema Lexer"
27
33
28
- data_types = [
34
+ data_types : ClassVar [ list [ str ]] = [
29
35
"object" ,
30
36
"integer" ,
31
37
"string" ,
@@ -34,7 +40,7 @@ class JSONSchemaLexer(RegexLexer):
34
40
"boolean" ,
35
41
"null" ,
36
42
]
37
- core_keywords = [
43
+ core_keywords : ClassVar [ list [ str ]] = [
38
44
r"\$schema" ,
39
45
r"\$id" ,
40
46
r"\$ref" ,
@@ -45,7 +51,7 @@ class JSONSchemaLexer(RegexLexer):
45
51
r"\$anchor" ,
46
52
r"\$vocabulary" ,
47
53
]
48
- applicator_keywords = [
54
+ applicator_keywords : ClassVar [ list [ str ]] = [
49
55
"oneOf" ,
50
56
"allOf" ,
51
57
"anyOf" ,
@@ -62,7 +68,7 @@ class JSONSchemaLexer(RegexLexer):
62
68
"contains" ,
63
69
"items" ,
64
70
]
65
- meta_data_keywords = [
71
+ meta_data_keywords : ClassVar [ list [ str ]] = [
66
72
"title" ,
67
73
"description" ,
68
74
"default" ,
@@ -71,7 +77,7 @@ class JSONSchemaLexer(RegexLexer):
71
77
"readOnly" ,
72
78
"writeOnly" ,
73
79
]
74
- validation_keywords = [
80
+ validation_keywords : ClassVar [ list [ str ]] = [
75
81
"type" ,
76
82
"enum" ,
77
83
"const" ,
@@ -93,7 +99,7 @@ class JSONSchemaLexer(RegexLexer):
93
99
"maxContains" ,
94
100
"uniqueItems" ,
95
101
]
96
- other_keywords = [
102
+ other_keywords : ClassVar [ list [ str ]] = [
97
103
"format" ,
98
104
"unevaluatedItems" ,
99
105
"unevaluatedProperties" ,
@@ -103,12 +109,13 @@ class JSONSchemaLexer(RegexLexer):
103
109
"format_assertion" ,
104
110
]
105
111
106
- tokens = {
112
+ tokens : ClassVar [ dict [ str , list [ Any ]]] = {
107
113
"whitespace" : [
108
114
(r"\s+" , Token .Whitespace ),
109
115
],
110
116
"data_types" : [
111
- # Used Literal type here to differentiate the highlighted color of data types from other keywords
117
+ # Used Literal type here to differentiate the highlighted
118
+ # color of data types from other keywords
112
119
(_get_regex_from_options (data_types ), Token .Literal ),
113
120
],
114
121
"core_keywords" : [
@@ -186,7 +193,8 @@ class JSONSchemaLexer(RegexLexer):
186
193
(r"," , Token .Punctuation ),
187
194
(r"]" , Token .Punctuation , "#pop" ),
188
195
],
189
- # a json value - either a simple value or a complex value (object or array)
196
+ # a json value - either a simple value or a
197
+ # complex value (object or array)
190
198
"value" : [
191
199
include ("whitespace" ),
192
200
include ("simplevalue" ),
0 commit comments