Skip to content

Commit

Permalink
Ignore keyword order for keyword-based grammars
Browse files Browse the repository at this point in the history
The order of the input list affected the final grammar, which is
unintuitive behavior. The keywords are now sorted to prevent unnecessary
differences between grammars.

In addition, I removed the documentation that `keywords` could be a list
of `DAIDEObject`s because the code itself does not support that.
  • Loading branch information
aphedges committed Jun 4, 2023
1 parent 2d987ea commit 4eccbf1
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/daidepp/grammar/grammar_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,7 @@ def create_grammar_from_press_keywords(
Parameters
----------
keywords : List[PressKeywords]
List of press keywords. Although the type hint says List[PressKeywords],
this can be a list of string literals or DAIDEObjects (to avoid circular imports).
List of press keywords.
allow_just_arrangement : bool, optional
if set to True, the parser accepts strings that are only arrangements, in
addition to press messages. So, for example, the parser could parse, by default False
Expand All @@ -247,6 +246,9 @@ def create_grammar_from_press_keywords(
if allow_just_arrangement and string_type == "message":
string_type = "arrangement"

# The input order or any duplicate elements should not affect the generated grammar
keywords = sorted(set(keywords))

full_grammar = create_daide_grammar(
level=MAX_DAIDE_LEVEL,
string_type=string_type,
Expand Down

0 comments on commit 4eccbf1

Please sign in to comment.