Write me a gbnf grammar. When a paragraph starts with " it should end at the next…
- User
Write me a gbnf grammar. When a paragraph starts with " it should end at the next occurance of ", so after that only a newline or <|end_of_sentence|> are allowed. When a paragraph starts with ( it should end at the next occurance of ), so after that only a newline or <|end_of_sentence|> are allowed. Should a paragraph start without " or (, it should not be allowed to contain " and (). Paragraph is any text that ends with either new line or <|end_of_sentence|>
Assistant
Here's a GBNF grammar that implements your paragraph rules:
root ::= paragraph* paragraph ::= quoted_paragraph | parenthetical_paragraph | regular_paragraph quoted_paragraph ::= "\"" quoted_content "\"" paragraph_end parenthetical_paragraph ::= "(" parenthetical_content ")" paragraph_end regular_paragraph ::= regular_content paragraph_end quoted_content ::= quoted_char* parenthetical_content ::= parenthetical_char* regular_content ::= regular_char+ quoted_char ::= [^"\n] | "\\" ["] parenthetical_char ::= [^)\n] | "\\" [)] regular_char ::= [^"()\n] paragraph_end ::= "\n" | "<|end_of_sentence|>"This grammar defines:
- quoted_paragraph: Starts with
", contains any characters except unescaped quotes and newlines, ends with"followed by a paragraph terminator - parenthetical_paragraph: Starts with
(, contains any characters except unescaped parentheses and newlines, ends with)followed by a paragraph terminator - regular_paragraph: Contains any characters except quotes, parentheses, and newlines, and must have at least one character
- paragraph_end: Either a newline
\nor the special token<|end_of_sentence|>
The grammar allows for escaped quotes within quoted content and escaped parentheses within parenthetical content using backslash escaping. Regular paragraphs cannot contain quotes or parentheses at all, as specified in your requirements.
- quoted_paragraph: Starts with
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.