@@ -119,7 +119,7 @@ def p_attrib(self, p):
119
119
"pkg_license_concluded : PKG_LICENSE_CONCLUDED error\n source_info : PKG_SOURCE_INFO error\n "
120
120
"homepage : PKG_HOMEPAGE error\n pkg_checksum : PKG_CHECKSUM error\n "
121
121
"verification_code : PKG_VERIFICATION_CODE error\n originator : PKG_ORIGINATOR error\n "
122
- "download_location : PKG_DOWWNLOAD_LOCATION error\n files_analyzed : PKG_FILES_ANALYZED error\n "
122
+ "download_location : PKG_DOWNLOAD_LOCATION error\n files_analyzed : PKG_FILES_ANALYZED error\n "
123
123
"supplier : PKG_SUPPLIER error\n pkg_file_name : PKG_FILE_NAME error\n "
124
124
"package_version : PKG_VERSION error\n primary_package_purpose : PRIMARY_PACKAGE_PURPOSE error\n "
125
125
"built_date : BUILT_DATE error\n release_date : RELEASE_DATE error\n "
@@ -150,7 +150,7 @@ def p_current_element_error(self, p):
150
150
"package_name : PKG_NAME LINE\n description : PKG_DESCRIPTION text_or_line\n "
151
151
"summary : PKG_SUMMARY text_or_line\n source_info : PKG_SOURCE_INFO text_or_line\n "
152
152
"homepage : PKG_HOMEPAGE line_or_no_assertion_or_none\n "
153
- "download_location : PKG_DOWWNLOAD_LOCATION line_or_no_assertion_or_none\n "
153
+ "download_location : PKG_DOWNLOAD_LOCATION line_or_no_assertion_or_none\n "
154
154
"originator : PKG_ORIGINATOR actor_or_no_assertion\n supplier : PKG_SUPPLIER actor_or_no_assertion\n "
155
155
"pkg_comment : PKG_COMMENT text_or_line\n "
156
156
"pkg_copyright_text : PKG_COPYRIGHT_TEXT line_or_no_assertion_or_none\n "
@@ -165,9 +165,7 @@ def p_current_element_error(self, p):
165
165
"file_spdx_id : SNIPPET_FILE_SPDXID LINE\n "
166
166
"snippet_license_concluded : SNIPPET_LICENSE_CONCLUDED license_or_no_assertion_or_none\n "
167
167
"annotation_spdx_id : ANNOTATION_SPDX_ID LINE\n "
168
- "annotation_comment : ANNOTATION_COMMENT text_or_line\n "
169
-
170
- )
168
+ "annotation_comment : ANNOTATION_COMMENT text_or_line" )
171
169
def p_generic_value (self , p ):
172
170
if p [1 ] in EXPECTED_START_TAG_ELEMENT .keys ():
173
171
self .initialize_new_current_element (EXPECTED_START_TAG_ELEMENT [p [1 ]])
@@ -206,8 +204,9 @@ def p_actor_values(self, p):
206
204
207
205
@grammar_rule ("spdx_id : SPDX_ID LINE" )
208
206
def p_spdx_id (self , p ):
209
- # We assume that the documents spdx_id is defined first in the SPDXDocument, before any package or file
210
- # information. If this is not the case the parser will behave unexpectedly as the spdx_ids are assigned falsy.
207
+ # As all SPDX Ids share the same tag, there is no knowing which spdx_id belongs to the document.
208
+ # We assume that to be the first spdx_id we encounter. As the specification does not explicitly require this,
209
+ # our approach might lead to unwanted behavior when the document's SPDX Id is defined later in the document.
211
210
if "spdx_id" in self .creation_info :
212
211
self .current_element ["spdx_id" ] = p [2 ]
213
212
else :
@@ -302,7 +301,8 @@ def p_pkg_attribution_text(self, p):
302
301
self .check_that_current_element_matches_class_for_value (Package , p .lineno (1 ))
303
302
self .current_element .setdefault ("attribution_texts" , []).append (p [2 ])
304
303
305
- @grammar_rule ("pkg_external_ref : PKG_EXTERNAL_REF LINE PKG_EXTERNAL_REF_COMMENT text_or_line\n | PKG_EXTERNAL_REF LINE" )
304
+ @grammar_rule (
305
+ "pkg_external_ref : PKG_EXTERNAL_REF LINE PKG_EXTERNAL_REF_COMMENT text_or_line\n | PKG_EXTERNAL_REF LINE" )
306
306
def p_pkg_external_refs (self , p ):
307
307
if not self .check_that_current_element_matches_class_for_value (Package , p .lineno (1 )):
308
308
return
@@ -516,9 +516,8 @@ def check_that_current_element_matches_class_for_value(self, expected_class, lin
516
516
517
517
def construct_current_element (self ):
518
518
if "class" not in self .current_element :
519
- # When the first element of the document is instantiated we don't have a current element in scope
520
- # and the key "class" doesn't exist. Additionally, if the first element doesn't have the expected start
521
- # value the key "class" wouldn't exist. To prevent a KeyError we use early return.
519
+ # This happens when the first element is initialized via initialize_new_current_element() or if the first
520
+ # element is missing its expected starting tag. In both cases we are unable to construct an element.
522
521
return
523
522
524
523
clazz = self .current_element .pop ("class" )
0 commit comments