Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QuotedString, multiline=True and a newline in the quote sequence #492

Open
rowlesmr opened this issue Jul 5, 2023 · 2 comments
Open

QuotedString, multiline=True and a newline in the quote sequence #492

rowlesmr opened this issue Jul 5, 2023 · 2 comments

Comments

@rowlesmr
Copy link

rowlesmr commented Jul 5, 2023

I think I've found a bug in QuotedString where multiline=True and there is a newline in the quote sequence.

The newline is ignored.

ParserElement.set_default_whitespace_chars("")
newlinequote = QuotedString("\n;", multiline=True)
newlinequote.search_string("lsjdf \n;Hi \n mum!\n; sldjf")  # Receive [['Hi \nmum!\n']]. Expect [['Hi \n mum!']]
newlinequote.search_string("lsjdf \n;Hi \n m;um!\n; sldjf")  # Receive [['Hi \n m']]. Expect [['Hi \n m;um!']]
newlinequote.search_string("lsj;df \n;Hi \n m;um!\n; sldjf")  # Receive [['df \n'], ['um!\n']]. Expect [['Hi \n m;um!']]

Is this the desired behaviour?

@ptmcg
Copy link
Member

ptmcg commented Jul 5, 2023

This is interesting, using a newline as part of the quotes. Needs some further study.

@rowlesmr
Copy link
Author

rowlesmr commented Jul 5, 2023

https://www.iucr.org/__data/assets/text_file/0009/112131/CIF2-ENBF.txt

is the grammar I'm trying to implement. My question specifically applies to "text-field".

(* text block *) 
text-field = text-delim, text-content, text-delim ;
text-delim = line-term, ';' ;
text-content = { allchars } - ( { allchars }, text-delim, { allchars } ) ;

I would like to use QuotedString, as it returns the content; I had a devil of a time making that work in another parser I tried.

Edit: I think this is how to directly implement it with the existing grammar constructs you have. allchars comes from here

line_term = (Literal("\r") + Opt("\n")) | Literal("\n")
text_delim = Combine(line_term + Literal(";")) 
text_content = ~(ZeroOrMore(allchars) + text_delim + ZeroOrMore(allchars)) + ZeroOrMore(allchars)
text_field = text_delim + text_content + text_delim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants