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

14 parsing single character variables fails #15

Merged
merged 7 commits into from
Jan 9, 2024

Conversation

ClaasRostock
Copy link
Collaborator

@ClaasRostock ClaasRostock commented Jan 9, 2024

Single character references were not correctly extracted from block_content.
Reason was the regex used to find them.

  • replaced all occurences of \$\w[\w\[\]]+ with \$\w[\w\[\]]* (i.e. using * instead of + )
  • added unit tests to check that single character references get correctly identified, extracted and resolved.

…cter expressions and -references from block_content
…ct with single single character expressions and -references
… of '\$\w[\w\[\]]+' with '\$\w[\w\[\]]*' (-> using * in regex instead of + -> That was the problem)
@ClaasRostock ClaasRostock linked an issue Jan 9, 2024 that may be closed by this pull request
@ClaasRostock ClaasRostock self-assigned this Jan 9, 2024
@ClaasRostock ClaasRostock requested a review from frl000 January 9, 2024 12:12
@frl000
Copy link
Member

frl000 commented Jan 9, 2024

I tried to adapt for single character keyword vectors. For single component it worked, so I think the issue is fixed.
I have no clue why and when this "$\w[\w[]]+" was introduced, but probably "someone" had no single char. keywords in mind. And it is surely a bad manner.
I marked an issue that I found with mixed string lists in test_dictReader.py:594, any idea what I missed there?

…gle_character_references() in test_dictReader.py fail on line 594, the test with multiple string references concatenated.

("AliceandBobfailtheparagliding contest")
@frl000
Copy link
Member

frl000 commented Jan 9, 2024

oops. No python string concatenation. This is simply substitution.

@ClaasRostock
Copy link
Collaborator Author

ClaasRostock commented Jan 9, 2024

oops. No python string concatenation. This is simply substitution.

Hi Frank, @frl000

great test that you added with the reference lists, I like it :-)
The problem was the format of how you declared the "concatenated" string expression in test_single_characters_vars_dict.
a) You used single quotes around the expression. However, expressions by definition must be enclosed in double quotes, otherwise they will not be identified as expression (but as string literal instead).
b) the + operator fails to concatenate the strings because, once the individual strings in the expression are resolved, they are put back into the expression without quotes. evaluation of "Alice + and + Bob" then has no effect. The quoting in the expression after resolving the referenced strings would need to look like "'Alice' + 'and' + 'Bob'" in order to have evalution turn that into "AliceandBob". However, I have no idea currently how we could accomplish that behaviour without unwanted side effects. Nested quoting in the dict I quickly tried, but that does not yield the intended result. I resolved this particluar problem then by changing "$m[0] + $m[1] + $m[2] + $m[3] + $m[4] + $m[5]" to simply "$m[0]$m[1]$m[2]$m[3]$m[4]$m[5]". With that, result is what you probably intended, and the test passes.

@ClaasRostock ClaasRostock merged commit b903cbd into main Jan 9, 2024
11 checks passed
@ClaasRostock ClaasRostock deleted the 14-parsing-single-character-variables-fails branch January 9, 2024 16:46
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

Successfully merging this pull request may close these issues.

parsing single-character variables fails
2 participants