all I'm learning Parsley by writing parser that parse vCard format. My problem is that some lines in vCard format may be split over several lines. Multiple-line representation using the RFC 822 “folding” technique. That is, wherever there may be linear white space a CRLF immediately followed by at least one LWSP-char. My solution is first parse raw text, there I can find newline followed by space and join that lines. However I can't get it to work: there is my latest try: The code returns errors there is last: TypeError: unsupported operand type(s) for +: 'bool' and 'str
import parsley
my_newline = "\n"
space = " "
def isLogicalLine(txt=""): #Function called from Parsley, just search for newline followed by space
result = True
if txt[:-2] == my_newline+space:
result = False
return result
tst_line2 = parsley.makeGrammar("""
CRLF = '\n'
line = (~(CRLF) anything+:x ?(isLogicalLine(x))):first_part -> first_part+ ' test '
""", {"isLogicalLine":isLogicalLine})
# ~(CRLF) = NOT CRLF
# ?(isLogicalLine(x)) = python expression that is true or false
# -> first_part+ ' test ' == modify result by Python express
test_string = "BEGIN:VCARD"+my_newline+"VERSION:2.1"+my_newline+\
"N;CHARSET=UTF-8;ENCODING=8BIT:Bab"+my_newline+\
"TEL;PREF;VOICE;ENCODING=8BIT:123456789"+my_newline+"END:VCARD"+\
my_newline+" END:VCARD"
print(tst_line2(test_string).line())