Repository: spdx/tools-python

Issue:
Failed to convert spdx to xml with Annotation
I'm trying to convert a `.spdx` file to a `.xml` file.
This is my Code (it's basically the exact same code as in [spdx2_convert_format example](https://github.com/spdx/tools-python/blob/main/examples/spdx2_convert_format.py)):
```text
#  SPDX-FileCopyrightText: 2023 spdx contributors
#
#  SPDX-License-Identifier: Apache-2.0
from os import path

from spdx_tools.spdx.model import Document
from spdx_tools.spdx.writer.write_anything import write_file
from spdx_tools.spdx.parser.parse_anything import parse_file

# This example demonstrates how to load an existing SPDX2 file and convert it to a different SPDX2 format

# Provide a path to the input file in the originating format
input_path = path.join(path.dirname(__file__), "annotation_convert_fail.spdx")
# Parse the original input file (format is deduced automatically from the file extension)
document: Document = parse_file(input_path)
# Write to a different file format (e.g. XML, format is deduced automatically from the file extension)
write_file(document, "annotation_convert_fail.xml")
```

My `.spdx` file (example is in the .txt file) contains an Annotation and I wasn't able to make it work. I always got this error message:
```text
Traceback (most recent call last):
  File "C:\Users\lugmair\PycharmProjects\spdx_to_xml\venv\SPDX_Parsing-Converting.py", line 16, in <module>
    document: Document = parse_file(input_path)
                         ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lugmair\PycharmProjects\spdx_to_xml\venv\Lib\site-packages\spdx_tools\spdx\parser\parse_anything.py", line 32, in parse_file
    return tagvalue_parser.parse_from_file(file_name, encoding)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lugmair\PycharmProjects\spdx_to_xml\venv\Lib\site-packages\spdx_tools\spdx\parser\tagvalue\tagvalue_parser.py", line 12, in parse_from_file
    document: Document = parser.parse(data)
                         ^^^^^^^^^^^^^^^^^^
  File "C:\Users\lugmair\PycharmProjects\spdx_to_xml\venv\Lib\site-packages\spdx_tools\spdx\parser\tagvalue\parser.py", line 537, in parse
    self.yacc.parse(text, lexer=self.lex)
  File "C:\Users\lugmair\PycharmProjects\spdx_to_xml\venv\Lib\site-packages\ply\yacc.py", line 333, in parse
    return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lugmair\PycharmProjects\spdx_to_xml\venv\Lib\site-packages\ply\yacc.py", line 1120, in parseopt_notrack
    p.callable(pslice)
  File "C:\Users\lugmair\PycharmProjects\spdx_to_xml\venv\Lib\site-packages\spdx_tools\spdx\parser\tagvalue\parser.py", line 494, in p_annotator
    set_value(p, self.current_element, method_to_apply=ActorParser.parse_actor)
  File "C:\Users\lugmair\PycharmProjects\spdx_to_xml\venv\Lib\site-packages\spdx_tools\spdx\parser\tagvalue\helper_methods.py", line 65, in set_value
    dict_to_fill[argument_name] = method_to_apply(parsed_value[2])
                                                  ~~~~~~~~~~~~^^^
  File "C:\Users\lugmair\PycharmProjects\spdx_to_xml\venv\Lib\site-packages\ply\yacc.py", line 243, in __getitem__
    return self.slice[n].value
           ~~~~~~~~~~^^^
IndexError: list index out of range

Process finished with exit code 1

```

But as soon as I comment out the Annotation the conversion works. I think the Parser is crashing somewhere when the Annotation is commented in.



[annotation_convert_fail.txt](https://github.com/spdx/tools-python/files/14370188/annotation_convert_fail.txt)


Discussion:

Patch:
diff --git a/src/spdx_tools/spdx/parser/tagvalue/parser.py b/src/spdx_tools/spdx/parser/tagvalue/parser.py
index 32be114..a190dd7 100644
--- a/src/spdx_tools/spdx/parser/tagvalue/parser.py
+++ b/src/spdx_tools/spdx/parser/tagvalue/parser.py
@@ -488,7 +488,7 @@ class Parser:
 
     # parsing methods for annotation
 
-    @grammar_rule("annotator : ANNOTATOR PERSON_VALUE\n| TOOL_VALUE\n| ORGANIZATION_VALUE")
+    @grammar_rule("annotator : ANNOTATOR PERSON_VALUE\n| ANNOTATOR TOOL_VALUE\n| ANNOTATOR ORGANIZATION_VALUE")
     def p_annotator(self, p):
         self.initialize_new_current_element(Annotation)
         set_value(p, self.current_element, method_to_apply=ActorParser.parse_actor)


Test patch:
diff --git a/tests/spdx/parser/tagvalue/test_annotation_parser.py b/tests/spdx/parser/tagvalue/test_annotation_parser.py
index 629fe72..f10ebe8 100644
--- a/tests/spdx/parser/tagvalue/test_annotation_parser.py
+++ b/tests/spdx/parser/tagvalue/test_annotation_parser.py
@@ -34,6 +34,28 @@ def test_parse_annotation():
     assert annotation.spdx_id == DOCUMENT_SPDX_ID
 
 
+def test_parse_annotation_with_organization_as_annotator():
+    parser = Parser()
+    annotation_str = "\n".join(
+        [
+            "Annotator: Organization: some-organization",
+            "AnnotationDate: 2010-01-29T18:30:22Z",
+            "AnnotationComment: <text>Document level annotation</text>",
+            "AnnotationType: OTHER",
+            f"SPDXREF: {DOCUMENT_SPDX_ID}",
+        ]
+    )
+    document = parser.parse("\n".join([DOCUMENT_STR, annotation_str]))
+    assert document is not None
+    assert len(document.annotations) == 1
+    annotation = document.annotations[0]
+    assert annotation.annotator.name == "some-organization"
+    assert annotation.annotation_date == datetime(2010, 1, 29, 18, 30, 22)
+    assert annotation.annotation_comment == "Document level annotation"
+    assert annotation.annotation_type == AnnotationType.OTHER
+    assert annotation.spdx_id == DOCUMENT_SPDX_ID
+
+
 @pytest.mark.parametrize(
     "annotation_str, expected_message",
     [