Skip to content

Instantly share code, notes, and snippets.

@Skrylar
Forked from dockimbel/JSON.red
Last active October 20, 2015 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Skrylar/f5d8e7f4ca93ac50bfec to your computer and use it in GitHub Desktop.
Save Skrylar/f5d8e7f4ca93ac50bfec to your computer and use it in GitHub Desktop.
JSON toy parser for Red
Red []
digit-nz: charset "123456789"
digit: append copy digit-nz #"0"
hex: append copy digit "abcdefABCDEF"
sign: charset "+-"
exponent-e: charset "eE"
dquot: #"^""
exponent: [ exponent-e opt sign some digit ]
decimal: [ #"." some digit ]
number: [ opt #"-" [ "0" | digit-nz any digit ] opt decimal opt exponent ]
array: [ opt [ value any ["," value] ] ]
value: [ string | number | array | "true" | "false" | "null" ]
str-escape: [ dquot | #"\" | #"/" | "b" | "f" | "n" | "r" | "t" | "u" 4 hex ]
string: [ dquot any [#"\" str-escape | not dquot skip ] dquot ]
print parse "[^"Fish bone^"]" value
comment [
Memory error: allocate memory > 2MB (--NOT_IMPLEMENTED--)
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment