Re: [Pyparsing] Newline-Sensitive Languages
Brought to you by:
ptmcg
From: Evan H. <eva...@gm...> - 2017-07-11 05:43:07
|
How about this: from pyparsing import ParserElement, Literal ParserElement.setDefaultWhitespaceChars(" \t\r\f\v") newline = Literal("\n") On Mon, Jul 10, 2017 at 2:40 PM, Eric Dilmore <eri...@gm...> wrote: > What is the best way to create a newline-sensitive language (like Python > itself)? I continually run into problems where the newlines are eaten by > the automated whitespace-grabber, and I've found what I believe to be two > working solutions: > > - Attach .setWhitespaceChars(' \t') to the end of all of the low-level > parsers so that, when combined, they don't gobble up newlines. > - Add White(' \t') between all low-level parsers, such that they eat > non-newline whitespace but not the newlines. > > Neither one of these is particularly elegant. It would be nice if > .setWhitespaceChars propagated down to children (like .ignore does), but I > don't expect it to be changed anytime soon because it would break backwards > compatibility pretty bad for anyone who was using either one of these > methods of producing newline-dependent languages. > > Which of these two is preferable? Or, alternatively, is there an even > better way that I haven't thought of yet? > > Thanks in advance! > > ------------------------------------------------------------ > ------------------ > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > _______________________________________________ > Pyparsing-users mailing list > Pyp...@li... > https://lists.sourceforge.net/lists/listinfo/pyparsing-users > -- “The true logic of this world is in the calculus of probabilities.” – James Clerk Maxwell |