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

UnityYAML does not seem to have comments #64

Open
rafzi opened this issue Nov 14, 2023 · 1 comment
Open

UnityYAML does not seem to have comments #64

rafzi opened this issue Nov 14, 2023 · 1 comment

Comments

@rafzi
Copy link

rafzi commented Nov 14, 2023

See: https://docs.unity3d.com/Manual/UnityYAML.html "UnityYAML does not support comments."

For example, GameObjects' names can contain #. In a scene file, it may look like this:

GameObject:
  ...
  m_Name: Hello # World

The Unity editor shows this in the UI as Hello # World, but unityparser will just extract Hello.

But I actually found this issue because of the following parsing error. An example scene file:

GameObject:
  ...
  m_Name: Really # really # really # really # really # really # really # long # long#
name#

Note how the name is split across two lines. The trailing # seems to cause the error:

  File "yaml/composer.py", line 127, in compose_mapping_node
    while not self.check_event(MappingEndEvent):
  File "yaml/parser.py", line 98, in check_event
    self.current_event = self.state()
  File "unityparser/parser.py", line 65, in parse_block_mapping_key
    raise ParserError("while parsing a block mapping", self.marks[-1],
yaml.parser.ParserError: while parsing a block mapping
  in "Example.unity", line 997, column 3
expected <block end>, but found '<scalar>'
  in "Example.unity", line 1015, column 5

Happy to submit a PR, but would appreciate some pointers.

@sp-ricard-valverde
Copy link
Collaborator

Hey, thanks for reporting !

Frankly, the scalar parsing logic comes from Pyyaml library(which does not preserve comments, but it does parse them out apparently) so it does not surprise me that the comment gets stripped out.

In order to try support this we'll probably need to overwrite the scanner logic that Pyyaml does, by allowing the # character for plain scalars:
https://github.com/yaml/pyyaml/blob/a98fd6088e81d7aca571220c966bbfe2ac43c335/lib/yaml/scanner.py#L735

Probably needs overriding the emitter too:
https://github.com/yaml/pyyaml/blob/a98fd6088e81d7aca571220c966bbfe2ac43c335/lib/yaml/emitter.py#L692

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

No branches or pull requests

2 participants