Created
June 16, 2021 12:39
-
-
Save rzymek/0b29f9d35e063330c2ac9b0c5cb9d3f6 to your computer and use it in GitHub Desktop.
parse ToString output to JSON for formatting
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
QuotedObject | |
= Object | |
/ "'" v:Object "'" { return v } | |
/ '"' v:Object '"' { return v } | |
Object = UnnamedObject / NamedObject | |
UnnamedObject = "{" fieldValues:FieldValues "}" { return fieldValues.reduce((r,v)=>({...r, ...v})) } | |
NamedObject = name:Name value:UnnamedObject { return {[name]: value } } | |
Name = [a-zA-Z_0-9-]+ { return text() } | |
FieldValues = values:(', '? FieldValue)* { return values.map(it=>it[1]) } | |
FieldValue | |
= field:Name '=' value:Value { return {[field]:value} } | |
Value = Array / QuotedObject / String / Boolean / Null / Unquoted | |
Array = "[" values:([,]?[ ]* Value)* "]" { return values.map(it=>it[2]) } | |
String = "'" chars:[^']* "'" { return chars.join('') } | |
Boolean = "true" / "false" { return Boolean(text()) } | |
Null = "null" { return null } | |
Unquoted = [A-Za-z0-9-:/\\._?=&]+ { return text() } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment