EBNF - How to define a string that has to start and end with specific character and contains any character?

178 Views Asked by At

I'm currently trying to write my own programming language and I start with the syntax definition in EBNF (Extended Backus–Naur form). I have the problem that I don't know how to define the syntax for a string. I know how to do that in RegEx ('[^']*' for single-quoted and "[^"]*" for double-quoted strings) but have no clue how to match every character in EBNF. Is there a way to do this or something equivalent without explicitly mentioning each and every of the hundreds of thousands of characters that Unicode has?

Update

I've found an interesting solution in the tester I use which allows me to use RegEx within the EBNF by prepending a string with #.
I still can't get it to work properly (because the RegEx is applied to every single character, not the whole string) and I don't know if that syntax is standard EBNF.

My question seems to be similar to EBNF ESCAPE CHARACTERS but not the exact same.

Update 2

I found a solution that seems to work as intended in the tester I use (I can't be sure if it's universally correct):

escape_sequence = "\\", ( '"' | "'" | "\\" ) ;
string          = ( '"', { escape_sequence | #'[^"]' }, '"' ) | ( "'", { escape_sequence | #"[^']" }, "'" ) ;
0

There are 0 best solutions below