Closed LordAro closed 1 year ago
Playing on the playground I came with this:
OBJECT <- 'OBJECT' COLON ALPHANUM MULTILINE_STRING_HEAD MULTILINE_STRING
ALPHANUM <- < [A-Za-z][A-Za-z0-9]* >
~MULTILINE_STRING_HEAD <- < $eq<EQ+> >
MULTILINE_STRING <- <MULTILINE_STRING_DATA> $eq
MULTILINE_STRING_DATA <- (!$eq .)*
EQ <- '='
COLON <- ':'
%whitespace <- [ \t\r\n]*
Output:
+ OBJECT
- COLON (:)
- ALPHANUM (flibble)
- MULTILINE_STRING (foobar
)
Nice, thanks! That seems to work great, even when combined with
STRING <- MULTILINE_STRING_HEAD MULTILINE_STRING / SINGLE_STR / DOUBLE_STR
SINGLE_STR <- "'" < [^']* > "'"
DOUBLE_STR <- '"' < [^"]* > '"'
I'm trying to construct a grammar that matches the following:
Where "foobar" is a multiline string containing anything, deliminated by an arbitrary (but matching) number of equals symbols.
This is the best I've come up with, but this requires putting
< >
around the entire string, so the AST ends up containing the deliminators as well as the string body. If I remove the<>
fromMULTILINE_STRING
, it doesn't match anymore.Is there something better I can do?