Advertisement
Guest User

Untitled

a guest
Apr 10th, 2023
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6 0.73 KB | None | 0 0
  1. grammar JSON {
  2.     token TOP { ^ <object> $ }
  3.     rule object { '{' <pairlist> { {} } '}' { {} } }
  4.     rule pairlist { <pair> { {} } [',' <pair> { {} }]* }
  5.     rule pair { <string> { {~$/[0]} => $<value>.made } ':' <value> { {} } }
  6.     rule array { '[' <valuelist> { [] } ']' { [] } }
  7.     rule valuelist { <value> { [~] $/.list } [',' <value> { [~] $/.list }]* }
  8.     rule value { <string> {~$<string>} | <number> {+$/} | <object> {$<object>} | <array> {$<array>} | 'true' {True} | 'false' {False} | 'null' {Any} }
  9.     token string { '"' <strcontent>* '"' { make ~$/ } }
  10.     token strcontent { \\ <strchar> | <!before '"' > . }
  11.     token strchar { <-[\\\"\n]> }
  12.    token number { '-'? \d+ [ '.' \d+ ]? [ <[eE]> [ <[+\-]>? \d+ ] ]? }
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement