Re: [Pyparsing] To parse any language character set
Brought to you by:
ptmcg
From: Eike W. <eik...@gm...> - 2008-10-29 16:18:14
|
Hello Ujjaval! On Tuesday 28 October 2008, you wrote: > Now to parse such sentence, I changed your parser code to the > following: Here, I want to parse this string as a string that > starts with 'ABC' followed by '|' and ends with '\r'. I need > everything in between with '|' as delimiter in a list including > 'XYZ' as last element in this case. Look at: LineEnd() Your parsers normally don't see '\n' because the whitespace is removed by the parsing machinery. If you want to use the end-of-line frequently as an element in your grammar, you could tell Pyparsing that '\n' should not be treated as whitespace: ParserElement.setDefaultWhitespaceChars('\t ') But you have to care for all the newlines youself then, which might become tedious. Look at indentedBlock(...) as an example how Paul (Pyparsing's author) does it. (I use indentedBlock myself.) Kind regards, Eike. |