Python’s simpleparse module


I’m working on a project that required a bit more from the JSON parser than the stock JSON parser with Python allowed for. After doing some hunting around, I came to the unfortunate conclusion that I’d probably need to write my own.

Thankfully, Python’s simpleparse module lived up to its billing (thanks in large part to JSON having such trivial syntax) Here’s the working BNF suitable for passing to simpleparse:

<ws> := [ tnr]*

>string_json< := string_single_quote / string_double_quote
key := string_json
array := "[", ws, ( value, (ws, ",", ws, value)* )?, ws, "]"

member := key, ws, ":", ws, value
object := "{", ws, ( member, ( ws, ",", ws, member )* )?, ws, "}"

true := "true"
false := "false"
null := "null"
>value< := false / null / true / object / array / float / int / string_json
>document< := ws, value, ws

This is also available in source code form here: jsonorder.py. jsonorder.py is part of a larger project, but it also works as a standalone library (albeit not a terribly useful one for most uses)

Advertisements

One thought on “Python’s simpleparse module

  1. Sacramento is the capital city of the U.S. state of California, and the county seat of Sacramento County. It is located at the confluence of the Sacramento River and the American River in the northern portion of California’s expansive Central Valley. With a 2009 estimated population of 489,676, it is the sixth-largest city in California.[1] Sacramento is the core cultural and economic center of the Sacramento metropolitan area which includes seven counties; with an estimated population of 2,927,123.[2] Its metropolitan area is the fourth largest in California after the Greater Los Angeles Area, San Francisco Bay Area, and the San Diego metropolitan area as well as the 25th largest in the United States. A city attaining global status, Sacramento was cited by Time magazine as America’s most ethnically and racially integrated city in 2002

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s