Skip to content

Commit

Permalink
Fix bugs in JSON language
Browse files Browse the repository at this point in the history
* Fix numbers to include negative numbers.
* Remove hexidecimal from numbers it is not a valid value.
* Remove ) and ; from punctuation they are not valid punctuation.
* Include missing tests for punctuation and operators.
  • Loading branch information
vizjerai authored and mAAdhaTTah committed Jul 21, 2018
1 parent 12a827e commit 74fe81c
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 6 deletions.
4 changes: 2 additions & 2 deletions components/prism-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Prism.languages.json = {
pattern: /"(?:\\.|[^\\"\r\n])*"(?!\s*:)/,
greedy: true
},
'number': /\b0x[\dA-Fa-f]+\b|(?:\b\d+\.?\d*|\B\.\d+)(?:[Ee][+-]?\d+)?/,
'punctuation': /[{}[\]);,]/,
'number': /-?\d+\.?\d*([Ee][+-]?\d+)?/,
'punctuation': /[{}[\],]/,
'operator': /:/g,
'boolean': /\b(?:true|false)\b/i,
'null': /\bnull\b/i
Expand Down
2 changes: 1 addition & 1 deletion components/prism-json.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions tests/languages/json/number_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
5.0e8
0.2E+2
47e-5
-1.23
-2.34E33
-4.34E-33

----------------------------------------------------

Expand All @@ -13,9 +16,12 @@
["number", "3.14159"],
["number", "5.0e8"],
["number", "0.2E+2"],
["number", "47e-5"]
["number", "47e-5"],
["number", "-1.23"],
["number", "-2.34E33"],
["number", "-4.34E-33"]
]

----------------------------------------------------

Checks for numbers.
Checks for numbers.
11 changes: 11 additions & 0 deletions tests/languages/json/operator_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
:

----------------------------------------------------

[
["operator", ":"]
]

----------------------------------------------------

Checks for all operators.
20 changes: 20 additions & 0 deletions tests/languages/json/punctuation_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{}
{ }
[]
],
},
,

----------------------------------------------------

[
["punctuation", "{"], ["punctuation", "}"],
["punctuation", "{"], ["punctuation", "}"],
["punctuation", "["], ["punctuation", "]"],
["punctuation", "]"], ["punctuation", ","],
["punctuation", "}"], ["punctuation", ","],
["punctuation", ","]
]
----------------------------------------------------

Checks for punctuation.
2 changes: 1 addition & 1 deletion tests/languages/json/string_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@

----------------------------------------------------

Checks for strings.
Checks for strings.

0 comments on commit 74fe81c

Please sign in to comment.