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 ", () are not allowed. When a paragraph starts with ( it should end at the next occurance of ), " is not 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|> So this is an example text that's allowed: Hi there! <3
"Hello! <>" (silence is deep) And this is an example of text that's not allowed: "Hi there" He said. "Hello" (she answered) Nothing ever happens(silence.)
Assistant
Here's a GBNF grammar that implements your paragraph rules:
root ::= paragraph* paragraph ::= quoted-paragraph | paren-paragraph | regular-paragraph quoted-paragraph ::= "\"" quoted-content "\"" paragraph-end paren-paragraph ::= "(" paren-content ")" paragraph-end regular-paragraph ::= regular-content paragraph-end paragraph-end ::= "\n" | "<|end▁of▁sentence|>" # Content rules for each paragraph type quoted-content ::= quoted-char* paren-content ::= paren-char* regular-content ::= regular-char+ # Character definitions quoted-char ::= [^"()\n<] | "<" [^|] paren-char ::= [^"\n<] | "<" [^|] regular-char ::= [^"()\n<] | "<" [^|]This grammar ensures:
- Quoted paragraphs start with
", end with", and cannot contain()inside - Parenthetical paragraphs start with
(, end with), and cannot contain"inside - Regular paragraphs cannot contain any
",(, or) - All paragraphs end with either a newline or
<|end▁of▁sentence|>
The character classes handle the special case of
<which is allowed unless it's the start of the end-of-sentence marker. This prevents false matches while still allowing characters like<3in your example.- Quoted paragraphs start with
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.