Pyparsing help

Francesco Bochicchio bockman at virgilio.it
Mon Mar 24 07:49:19 EDT 2008


Il Sat, 22 Mar 2008 14:11:16 -0700, rh0dium ha scritto:

> Hi all,
> 
> I am struggling with parsing the following data:
> 
> test1 = """
> Technology      {
>                 name                            = "gtc" dielectric      
>                                = 2.75e-05 unitTimeName                  
>                  = "ns" timePrecision                   = 1000
>                 unitLengthName                  = "micron"
>                 lengthPrecision                 = 1000 gridResolution   
>                               = 5
>                 unitVoltageName                 = "v" voltagePrecision  
>                              = 1000000 unitCurrentName                 =
>                 "ma" currentPrecision                = 1000
>                 unitPowerName                   = "pw" powerPrecision   
>                               = 1000 unitResistanceName              =
>                 "kohm" resistancePrecision             = 10000000
>                 unitCapacitanceName             = "pf"
>                 capacitancePrecision            = 10000000
>                 unitInductanceName              = "nh"
>                 inductancePrecision             = 100
> }
> 
> Tile            "unit" {
>                 width                           = 0.22 height           
>                               = 1.69
> }
> 
>

Did you think of using something a bit more sofisticated than pyparsing?
I have had a good experience to using ply, a pure-python implementation
of yacc/lex tools, which I used to extract significant data from C 
programs to automatize documentation.

I never used before yacc or similar tools, but having a bit of experience 
with BNF notation, I found ply easy enough. In my case, the major problem 
was to cope with yacc limitation in describing C syntax (which I solved 
by "oelaxing" the rules a bit, since I was going to process only already-
compiled C code). In your much simpler case, I'd say that a few 
production rules should be enough.

P.S : there are others, faster and maybe more complete python parser, but 
as I said ply is pure python: no external libraries and runs everywhere.

Ciao
-------
FB    



More information about the Python-list mailing list