parser pythonic parsing with pyparsing playlist data parsing |in the previous section' second subsection we created handcrafted regexbased parser for files in this subsection we will create parser to do the same thingbut this time using the pyparsing module an extract from file is shown in figure ( )and the bnf is shown in figure ( as we did when reviewing the previous subsection' pls parserwe will review the parser in three partsfirst the creation of the parserthen the helper functionand finally the call to the parser just as with the pls parserwe are ignoring the parser' return value and instead populating our data structure as the parsing progresses (in the following two subsections we will create parsers whose return values are used songs [title restofline("title"filename restofline("filename"seconds combine(optional("-"word(nums)setparseactionlambda tokensint(tokens[ ]))("seconds"info suppress("#extinf:"seconds suppress(","title entry info lineend(filename lineend(entry setparseaction(add_songparser suppress("#extm "oneormore(entrysong named tuple we begin by creating an empty list that will hold the song named tuples although the bnf is quite simplesome of the parser elements are more complex than those we have seen so far notice also that we create the parser elements in reverse order to the order used in the bnf this is because in python we can only refer to things that already existso for examplewe cannot create parser element for an entry before we have created one for an info since the former refers to the latter the title and filename parser elements are ones that match every character from the parse position where they are tried until the end of the line this means that they can match any charactersincluding whitespace--but not including newline which is where they stop we also give these parser elements namesfor example"title"--this allows us to conveniently access them by name as an attribute of the tokens object that is given to parse action functions the seconds parser element matches an optional minus sign followed by digits(nums is predefined pyparsing string that contains the digitswe use combine(to ensure that the sign (if presentand digits are returned as single string (it is possible to specify separator for combine()but there is no need in this casesince the default of an empty string is exactly what we want the ply parser