Conversation
I implemented this in a second commit (and rebased after the now-merged #195). Can you have a look/test please? |
|
Thank you! I was looking into this, but will check what you've done. |
This largely restructures the code. Instead of compiling everything into one all-or-nothing regular expression it keeps all regular expressions for the format strings separately. To scan input, it iterates over these regexps until they no longer match.
|
With the new code, I get >>> fmt = "%s %s"
>>> scanf(fmt, "")
('', '')
>>> scanf(fmt, "x")
('x', '')
>>> scanf(fmt, "x ")
('x', '')
>>> scanf(fmt, "x y")
('x', 'y')resp. in PyRAF The i.e. the conversion is the same as in IRAF/ecl, but the return code (number of conversions) differs. This is something glued into PyRAF, because the API of the PyRAF scanf function (both C module and new Python code) returns the tuple of values that matched the format, and the calculation of the return code is done elsewhere. |
|
OK, I added another commit that modifies the stop condition. Now it resembles the original PyRAF behavior: |
|
Yes, so there are long-established usage patterns that rely on IRAF's return value behaviour (eg. |
|
I think this looks pretty good. I should probably try adding some more test cases to be sure! |
|
I'm not sure whether this would break our stuff, but I notice some odd treatment of spaces in IRAF. With CL & PyRAF 2.2.1, gives |
|
That means that any conversion (maybe except |
|
The many possible corner cases make me a bit nervous, but this seems to be working quite well. I'll try re-running our tests with it early next week. |
The output handling was changed by accident when the Python scanf code was introduced
This resembles the behavior of the original sscanf C module
|
I used my Copilot time to discuss a number of test cases and found the major cause for the problem we had: I accidentally changed the handling of the scanf module output in This behavior is now re-established, and the regular expressions are now adjusted to behave There are still a few differences between the C module and scanf.py (and IRAF's scanf implementation):
|
|
It's great to see all those tests! The only thing that might worry me in that table is |
|
I notice some inexact float values like |
|
For |
78c3543 to
9c4d85d
Compare
The test cases were generated in discussion with ChatGPT5o to examine the differences in the behavior of scanf.py and the earlier ssanfmodule.c. The fixes in scanf.py were then done to let all tests pass.
|
This is looking much better in my Gemini IRAF testing so far. I'm just running some extra tests... |
|
Hi @olebole, this passed all of our non-interactive testing (in some quick interactive testing, I ran into another display issue, but that's unrelated), so I think it's OK. Thanks for all your effort on this! |
|
Hi @jehturner that is great; I will merge! |
This re-establishes
Difference is however now
Closes: #196