Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String parsing with new lines is broken #780

Closed
Necr0x0Der opened this issue Oct 11, 2024 · 3 comments · Fixed by #783
Closed

String parsing with new lines is broken #780

Necr0x0Der opened this issue Oct 11, 2024 · 3 comments · Fixed by #783

Comments

@Necr0x0Der
Copy link
Collaborator

Describe the bug
After this PR:
#777
unit tests in metta-motto became broken.

To Reproduce
Run the test in metta-motto:

!(assertEqual
   ((echo-agent)
    (system "Ping") (user "Pong"))
"system Ping
user Pong")

While echo-agent returns

"system Ping
user Pong"

which is composed as '\n'.join("system Ping", "user Pong"), it cannot be matched with the string formed by parsing in Metta

"system Ping
user Pong"

This:

!(assertEqual
   ((echo-agent)
    (system "Ping") (user "Pong"))
"system Ping\nuser Pong")

also doesn't work.

Expected behavior
There should be a way to specify multi-line strings in metta scripts, which could be matched against corresponding strings formed in Python.

@Necr0x0Der
Copy link
Collaborator Author

The issue seems that

"system Ping
user Pong"

is not converted into Python String by

r"^\".*\"$": lambda token: ValueAtom(str(token[1:-1]), 'String'),

and is parsed as Rust string.
An attempt to write:

m = MeTTa()
x = m.run('''
! "A
B"
''')
print(x[0][0].get_object().content == '''A
B''')

results in

Cannot get_object of unsupported non-C "A
B"

Basically, the corresponding regex in Python is not invoked in this case. While if we return the old one

"\"[^\"]*\"": lambda token: ValueAtom(str(token[1:-1]), 'String')

it works here.

@vsbogd
Copy link
Collaborator

vsbogd commented Oct 11, 2024

Interesting, probably, because $ matches end of line.

@vsbogd vsbogd mentioned this issue Oct 14, 2024
@vsbogd
Copy link
Collaborator

vsbogd commented Oct 14, 2024

First guess was correct: . inside regex doesn't recognize \n and because of this te\nst is parsed as a symbol atom. Fixed in #783

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants