icsharpcode / AvalonEdit

The WPF-based text editor component used in SharpDevelop
http://avalonedit.net/
MIT License
1.85k stars 469 forks source link

Fix JSON highlighting #418

Open ltrzesniewski opened 9 months ago

ltrzesniewski commented 9 months ago

While doing https://github.com/icsharpcode/ILSpy/pull/3138 I noticed the JSON highlighting was wrong (see the last 2 lines in the screenshot), so this PR fixes that.

EDIT: I noticed there's an issue for this, so this fixes #410.

Here's the difference for the following example:

{
    "String": "Value",
    "Bool": true,
    "Null": null,
    "Number:": -42e10,
    "Object": {
        "Foo:": "Bar",
        "Multiline Key"
            :
            "Value"
    },
    "Array": ["Foo", "Bar", "Baz"]
}

Before:

image

After:

image

The rule for numbers adds support for - and reformats the regex.

I also kept the existing single-quoted strings and hex numbers which are not part of the JSON spec.