-
Notifications
You must be signed in to change notification settings - Fork 14
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
Behaviour of xparse
when encountering invalid delimiters
#93
Comments
This was referenced Oct 20, 2021
alternatively, perhaps the issue is the behaviour of julia> Parsers.codes(res.code)
"INVALID: OK | NEWLINE | INVALID_DELIMITER "
julia> Parsers.ok(res.code)
false i.e. why is this Line 66 in 6b560d4
not just x & OK == OK ?
Docs say: Line 30 in 6b560d4
So on reflection, i feel like the current |
This was referenced Oct 20, 2021
quinnj
added a commit
that referenced
this issue
Oct 21, 2021
As pointed out by @nickrobinson251, if calling `typeparser` succeeds (i.e. `(code & OK) == OK`), then we might as well set the correct value in the parsing `Result` object. Up till now, if there was any `INVALID` code invovled, `res.val` was undefined. With the proposed change in this PR, we introduce a `Parsers.valueok(code)` function that can be checked, and if true, then the user can know that a valid value was parsed and can be accessed via `res.val`. Closes #93.
quinnj
added a commit
that referenced
this issue
Oct 21, 2021
As pointed out by @nickrobinson251, if calling `typeparser` succeeds (i.e. `(code & OK) == OK`), then we might as well set the correct value in the parsing `Result` object. Up till now, if there was any `INVALID` code invovled, `res.val` was undefined. With the proposed change in this PR, we introduce a `Parsers.valueok(code)` function that can be checked, and if true, then the user can know that a valid value was parsed and can be accessed via `res.val`. Closes #93.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am trying to rely on
xparse
to correctly parse a value when i know the input contains invalid characters (i.e. an invalid delimiter). I am hoping/expecting to get the correct value and aINVALID_DELIMITER
return code.(I gather we do want it to be possible to rely on
xparse
in the presence of invalid delimiters, given #78).But
xparse
doesn't always return the correct value (using Parsers.jl v2.0.6).For example, when trying to parse a
Float64
when there are special characters like/
here
xparse
returned the expected code (INVALID_DELIMITER
), but not the correct value (expected isres.val === 1.0
)Looking at what might be happening
The internal
xparse2
gives the correct value, suggesting thetypeparser
actually does extract the correct value (and the "incorrect" code is due to simplifications inxparse2
and doesn't matter here)And calling
typeparser
directly, I see the correct value (as expected):This isn't specific to the
/
character or toFloat64
, e.g. parsingInt64
s:So i suspect, this isn't to do with the
typeparser
s, but to do with the logic for handlinginvalid
cases inxparse
.In particular, i think it's because
xparse
doesn't populate the value when the codes is notok
:typeparser
returns the correct valuexparse
correctly sets the code toINVALID_DELIMITER
and send us todonedone
Parsers.jl/src/Parsers.jl
Lines 532 to 540 in 6b560d4
donedone
check's ifok(code)
(which isfalse
) and then doesn't pass the value toResult
Parsers.jl/src/Parsers.jl
Lines 659 to 666 in 6b560d4
So we have everything we need... but we're not using it.
Possible solution?
I think
donedone
might be doing this to handle the cases where we get sent todonedone
before we've even calledtypeparser
(e.g. because we hit "end of file" before hitting non-whitespace characters)If this diagnosis is correct, i wonder if we should just handle that explicitly, rather than checking
ok(code)
e.g.via a different goto-label, e.g.
The text was updated successfully, but these errors were encountered: