Paul McGuire wrote: > Sorry about your coffee cup! Would you be interested in a pyparsing > rendition? > > -- Paul > > > from pyparsing import * > > def defineGrammar(): > ParserElement.setDefaultWhitespaceChars(" \t") > > ident = Word(alphanums+"_") > LT,GT = map(Suppress,"<>") > NL = LineEnd().suppress() > > real = Word(nums,nums+".") > integer = Word(nums) > quotedString = QuotedString('"') > > dataValue = real | integer | Word(alphas,alphanums) | quotedString > dataDef = ident + ZeroOrMore(dataValue) + NL > tagDef = Forward() > tagDef << LT + ident + ZeroOrMore(dataValue) + NL + \ > Dict(ZeroOrMore(Group(dataDef) | Group(tagDef))) + GT + NL > tagData = Dict(OneOrMore(Group(tagDef))) > return tagData > > results = defineGrammar().parseString(TESTTXT) > print( results.dump() ) > print results.REAPER_PROJECT.TRACK.keys() > print results.REAPER_PROJECT.TRACK.PANENV2 > print results.REAPER_PROJECT.TRACK.PANENV2.ACT > > > prints out: > > [['REAPER_PROJECT', '0.1', ['METRONOME', '6', '2.000000', ['SAMPLES', > '', '']], ['TRACK', ['MAINSEND', '1'], ['VOLENV2', ['ACT', '1']], > ['PANENV2', ['ACT', '1']]]]] > - REAPER_PROJECT: ['0.1', ['METRONOME', '6', '2.000000', ['SAMPLES', > '', '']], ['TRACK', ['MAINSEND', '1'], ['VOLENV2', ['ACT', '1']], > ['PANENV2', ['ACT', '1']]]] > - METRONOME: ['6', '2.000000', ['SAMPLES', '', '']] > - SAMPLES: ['', ''] > - TRACK: [['MAINSEND', '1'], ['VOLENV2', ['ACT', '1']], ['PANENV2', > ['ACT', '1']]] > - MAINSEND: 1 > - PANENV2: [['ACT', '1']] > - ACT: 1 > - VOLENV2: [['ACT', '1']] > - ACT: 1 > ['PANENV2', 'MAINSEND', 'VOLENV2'] > [['ACT', '1']] > 1
Thank You Paul - I am very interested. In between drinking coffee and smashing coffee cups, I actually visited your site and my impression was: wow, If I could only take the time instead of struggling with this 'almost there' re thing! I am not that good at it actually, but working hard, not worrying about the cups to much... I will now revisit pyparsing and learn! I cheated a bit on you and read this: http://www.oreillynet.com/pub/au/2557. I live in a little danish town, Svendborg, nice by the sea and all. I learned steel construction in the 80's at the local shipyard, (now closed), much later (96-98) I received a very short education in IT-skills on a business school in Odense, the nearest city. I spent the years 98-05 working for Maersk Data, later IBM. From 05 and onwards independent. Struggling hard to keep orders at a bare minimum, I spend some of my spare time working with the elderly, and some of it programming python for different purposes at home, and some of it playing in the band: http://myspace.com/dementedk, and some of it combining the two. So now You know more or less the same about me as I know about You. Jorgen -- http://mail.python.org/mailman/listinfo/python-list