sectionthe fourth parser is new and much more complexand is shown in this sectionand in lex/yacc form in the following section simple key-value data parsing |handcrafted keyvalue parser in the previous section' first subsection we created handcrafted regex-based key-value parser that was used by the playlists py program to read pls files in this subsection we will create parser to do the same jobbut this time using the pyparsing module as beforethe purpose of our parser is to populate dictionary with key-value items matching those in the filebut with lowercase keys an extract from pls file is shown in figure ( )and the bnf is shown in figure ( since pyparsing skips whitespace by defaultwe can ignore the bnf' blank nonterminal and optional whitespace (\ *we will look at the code in three partsfirstthe creation of the parser itselfseconda helper function used by the parserand thirdthe call to the parser to parse pls file all the code is quoted from the readkeyvalue py module file that is imported by the playlists py program key_values {left_bracketright_bracketequals map(suppress"[]="ini_header left_bracket charsnotin("]"right_bracket key_value word(alphanumsequals restofline key_value setparseaction(accumulatecomment "#restofline parser oneormore(ini_header key_valueparser ignore(commentfor this particular parserinstead of reading the results at the end we will accumulate results as we gopopulating the key_values dictionary with each key=value we encounter functionalstyle programming the left and right brackets and the equals signs are important elements of the grammarbut are of no interest in themselves so for each of them we create suppress(parser element--this will match the appropriate characterbut won' include the character in the results (we could have written each of them individuallyfor exampleas left_bracket suppress("[")and so onbut using the built-in map(function is more convenient the definition of the ini_header parser element follows quite naturally from the bnfa left bracketthen any characters except right bracketand then right bracket we haven' defined parse action for this parser elementso although the parser will match any occurrences that it encountersnothing will be done with themwhich is what we want ply keyvalue parser