BNF parsing in Python

Michael Ströder michael at stroeder.com
Mon Oct 29 14:11:20 EST 2001


HI!

Disclaimer: I'm not good in compiler/parser methods.

I'd like to parse strings describing LDAPv3 schema elements which
seem to be declared as BNF (one example, not complete):

      AttributeTypeDescription = "(" whsp
            numericoid whsp              ; AttributeType identifier
          [ "NAME" qdescrs ]             ; name used in
AttributeType
          [ "DESC" qdstring ]            ; description
          [ "OBSOLETE" whsp ]
          [ "SUP" woid ]                 ; derived from this other
                                         ; AttributeType
          [ "EQUALITY" woid              ; Matching Rule name
          [ "ORDERING" woid              ; Matching Rule name
          [ "SUBSTR" woid ]              ; Matching Rule name
          [ "SYNTAX" whsp noidlen whsp ] ; see section 4.3
          [ "SINGLE-VALUE" whsp ]        ; default multi-valued
          [ "COLLECTIVE" whsp ]          ; default not collective
          [ "NO-USER-MODIFICATION" whsp ]; default user modifiable
          [ "USAGE" whsp AttributeUsage ]; default userApplications
          whsp ")"

      AttributeUsage =
          "userApplications"     /
          "directoryOperation"   /
          "distributedOperation" / ; DSA-shared
          "dSAOperation"          ; DSA-specific, value depends on
server

Here are some examples of strings to parse (not only the BNF above):

( 2.5.13.20 NAME 'telephoneNumberMatch' SYNTAX
1.3.6.1.4.1.1466.115.121.1.50 )

( 0.9.2342.19200300.100.1.39 NAME 'homePostalAddress' 
  EQUALITY caseIgnoreListMatch SUBSTR caseIgnoreListSubstringsMatch
  SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )

( 2.5.6.6 NAME 'person' SUP top STRUCTURAL
  MUST ( sn $ cn )
  MAY ( userPassword $ telephoneNumber $ seeAlso $ description ) )

Any clues on where to start? Should be pure Python and
license-compatible to be included into an open source project
(probably BSD style license).

Ciao, Michael.



More information about the Python-list mailing list