Skip to content

Commit

Permalink
Update docs for escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
klntsky committed Nov 23, 2024
1 parent e1eeeb2 commit 836defb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
12 changes: 1 addition & 11 deletions docs/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,7 @@ Chat IDs are actually variables that contain an entire chat history [(example us

# Escaping

Normally, you would not need escaping, e.g. `[:foo` will evaluate to `[:foo` as text. But if you want to specify a MetaPrompt expression literally, use `\` before the `[` character: `\[:foo]` will evaluate to `[:foo]` as text, without special meaning. You can escape `\` with another `\`, but only if it is positioned before a `[`:

`\foo` → (text `\foo`)

`\\` → (text `\\`)

`\[:foo]` → (text `[:foo]`)

`\\[:foo]` → (text `\\`) (variable `foo`)

`\[some text` -> (text `[some text`) - note that in this case the `\` character disappears, although escaping does not happen because `[some text` is not a special MetaPrompt construct.
`[` and `]` must be escaped using `\\`.

# Modules

Expand Down
6 changes: 6 additions & 0 deletions python/tests/test_parser.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# TODO: add negative tests
from parse_metaprompt import (
parse_metaprompt,
extract_tokens,
Expand Down Expand Up @@ -160,6 +161,11 @@ def test_absence_of_comment():
assert result == [t("# asd")]


def test_bslash():
result = parse("\\")
assert result == [t("\\")]


def test_kw_EQ_KW():
result = parse("==")
assert result == [t("==")]
Expand Down

0 comments on commit 836defb

Please sign in to comment.