s-expression parser in python

James Stroud nospamjstroudmapson at mbi.ucla.edu
Tue Apr 6 20:02:59 EDT 2010


Hello All,

I want to use an s-expression based configuration file format for a 
python program I'm writing. Does anyone have a favorite parser?

I'm currently using sexpy.parse() (http://pypi.python.org/pypi/sexpy) 
which works very well but I don't know how secure it is. Does anyone 
have experience with sexpy or another parser? I'm mostly concerned with 
  safety when the parser evaluates scalar data types. Sexpy is not well 
documented in this regard.

Also, I don't want a lisp/scheme interpreter, just the parser.

For example,

    """
    (and
      (or (> uid 1000)
          (!= gid 20)
      )
      (> quota 5.0e+03)
    )
    """

Should be parsed to

    ["and",
      ["or", ["=", "uid", 1405],
             ["!=", "gid", 20]],
      [">", "quota", 5000.0]
    ]

Note proper parsing of ints, floats, etc.

I've already wrote the evaluator for the parsed lists, so I'm not 
interested in alternatives to S-expressions. Also, I'm really not 
interested in json, yaml, etc., for the configuration format because I'm 
quite fond of the brevity and clarity of S-expressions (your opinion may 
vary).

Thanks in advance for any insight.

James



More information about the Python-list mailing list