YarnSpinnerTool / YarnSpinner

Yarn Spinner is a tool for building interactive dialogue in games!
https://yarnspinner.dev
MIT License
2.3k stars 201 forks source link

Inconsistent parsing error with unterminated commands #351

Closed dogboydog closed 1 year ago

dogboydog commented 1 year ago

What is the current behavior?

This will cause an error:

title: Hello
tags: 
---
<<my_command .
Man: Hello
===

Line 4: Unexpected "" while reading a command statement

But this won't

title: Hello
tags: 
---
<<my_command .
Man: Hello
===

title: Hello2
tags:
---
<<wait 1>>
Normal node
===

Please provide the steps to reproduce, and if possible a minimal demo of the problem: Run this project https://github.com/dogboydog/YarnSpinnerUnterminatedCommand

What is the expected behavior?

These two should probably be treated the same way (I would think an error for both?)

Please tell us about your environment:

McJones commented 1 year ago

There is a bit more going on here than it first appears, these notes are as much for me to remember so I don't forget as they are to try and explain what is going on.

The missing >> is actually cascading out and it just keeps gobbling up text until it finds one. The first example throws a strange error because it never finds the closing >> and is complaining about that. The second example "works" purely because the <<wait 1>> has a >> that the earlier <<my_command can use. So the command on line four spans eight lines and has a lot of parameters which probably isn't desirable.

At this stage I think unfortunately the fix will be to make it so that command text cannot contain newlines and we'll have to capture any rogue new lines/unterminated commands at the parser level instead of just the lexer.

dogboydog commented 1 year ago

Hopefully not too many people use commands with newlines in them. Never occured to me that would work since you can't split dialogue lines. Thanks for looking into it.

desplesda commented 1 year ago

Fixed in 6df2d19be3b38518f4aec25aa572ef7d79e6cc72 by making the lexer detect newlines inside commands. The parser will now emit parse errors when this is detected.