Created
September 10, 2024 19:10
-
-
Save andy0130tw/c1f4e986165ed039d2478fdf7bb2d061 to your computer and use it in GitHub Desktop.
Lezer grammar definition for JSON diff syntax used by jd (https://github.com/josephburnett/jd). Built on top of JSON's grammar.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@top JSONDiff { section* } | |
value { True | False | Null | Number | String | Object | Array } | |
section { | |
Header | |
(Deletion+ Insertion* | Insertion+) | |
} | |
Header { "@" "[" list<path> "]" "\n" } | |
path { EmptyObject | PropertyName | Number } | |
EmptyObject { "{" "}" } | |
Insertion { "+" value "\n" } | |
Deletion { "-" value "\n" } | |
String { string } | |
Object { "{" list<Property>? "}" } | |
Array { "[" list<value>? "]" } | |
Property { PropertyName ":" value } | |
PropertyName { string } | |
@tokens { | |
True { "true" } | |
False { "false" } | |
Null { "null" } | |
Number { '-'? int frac? exp? } | |
int { '0' | $[1-9] @digit* } | |
frac { '.' @digit+ } | |
exp { $[eE] $[+\-]? @digit+ } | |
string { '"' char* '"' } | |
char { $[\u{20}\u{21}\u{23}-\u{5b}\u{5d}-\u{10ffff}] | "\\" esc } | |
esc { $["\\\/bfnrt] | "u" hex hex hex hex } | |
hex { $[0-9a-fA-F] } | |
whitespace { $[ \r\t] } | |
"{" "}" "[" "]" "@" "+" "-" | |
} | |
@skip { whitespace } | |
list<item> { item ("," item)* } | |
@external propSource jsonHighlighting from "./highlight" | |
@detectDelim |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
demo