trueagi-io / hyperon-experimental

MeTTa programming language implementation
https://metta-lang.dev
MIT License
133 stars 44 forks source link

How should MeTTa handle escaped characters such as new line? #619

Closed ngeiswei closed 5 months ago

ngeiswei commented 5 months ago

What is the problem?

Escaped characters are mishandled, for instance \ disappears from the string.

How to reproduce the problem?

Try the following

! "1\n2"

What should be normally expected?

I suppose the escaped character should either be left untouched, like

["1\n2"]

or parsed and displayed like

["1
2"]

What do you get instead?

["1n2"]

What else do you have to say?

The same problem occurs with other escaped characters like \t. The misbehavior is also observed when using println!.

luketpeterson commented 5 months ago

I assume you're talking about the S-expression parser, since a symbol atom created programmatically should be fine.

Currently the MeTTa parser doesn't do anything with escape sequences inside string literals except ensure a \" doesn't terminate the quote block.

There's a todo in the code to do escaping properly. Albeit buried. https://github.com/trueagi-io/hyperon-experimental/blob/3af6c9089b3c9b4a9bfc82661f5967d307686bac/repl/src/repl.default.metta#L5C1-L6C1

vsbogd commented 5 months ago

@ngeiswei , I believe we can close it?