Skip to content

remove lastNoSuccessVar #108

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

Merged
merged 1 commit into from
Jul 10, 2018

Conversation

svalaskevicius
Copy link
Contributor

@svalaskevicius svalaskevicius commented Mar 10, 2017

lastNoSuccessVar is introducing a non referentially transparent, hard to debug source
of errors where parsing Failures are remembered and, even if they are covered by subsequent
combinators, such as |, still replaces correct Failures at the end of phrase parsing with them.

This is confusing from two perspectives:

  • how is that error that should have been covered not fixed by the |?
  • what is the real parsing error that I should focus to fix in my input?

a small example:

let's assume we are creating a parser to parse (IF condition THEN 1 END)*.
let condition be TRUE|FALSE.

when given input IF FALSE THEN 1 IF TRUE THEN 1 END (note the missing END), the parser would have returned:
TRUE expected, FALSE given.

Which is obviously not correct, as FALSE is a valid option described in the parser, and the correct error is that the END token is missing.

This PR replaces issue #107 .

@SethTisue
Copy link
Member

perhaps of interest to @mrerrormessage, since this might change some NetLogo error messages

@mrerrormessage
Copy link

Thanks for the heads-up @SethTisue. It looks like we only use phrase in one place, which contains a note saying that we use it to find the longest possible parse to report errors on. This change looks like it would probably break that capability, so we'll hold off on upgrading until we have a solution in place.

@svalaskevicius
Copy link
Contributor Author

svalaskevicius commented Mar 10, 2017

@mrerrormessage unless I misunderstood your comment - the parsed length should not be affected by this change, only the error it gives on failure to parse (instead of remembering the non-error errors, like in the TRUE|FALSE scenario above, it would fail with either the last parser failure or the "not all input consumed" if the given parser reports success but there is some input left)

@mrerrormessage
Copy link

mrerrormessage commented Mar 10, 2017

@svalaskevicius , thanks for the clarification - I misunderstood the change. I wouldn't expect this change to affect us in that case.

@gourlaysama gourlaysama closed this Feb 6, 2018
@svalaskevicius
Copy link
Contributor Author

@gourlaysama why?

@gourlaysama gourlaysama changed the base branch from master to 1.1.x February 6, 2018 17:47
@gourlaysama gourlaysama reopened this Feb 6, 2018
@gourlaysama
Copy link
Contributor

@svalaskevicius sorry, GitHub automatically closed the PR when the base branch was renamed (master to 1.1.x).

I've reopened it (and this should make it into 1.1.1)

@svalaskevicius
Copy link
Contributor Author

ah, thanks :) was just surprised a bit as there was no explanation

would be good though if anyone could review it, and decide whether it's worth to merge it or better to close - as it has been hanging here for a while now :)

I do remember having some frustrations when debugging the issues caused by this :D

@SethTisue
Copy link
Member

needs a rebase now

@SethTisue
Copy link
Member

@svalaskevicius you still around...?

@svalaskevicius
Copy link
Contributor Author

Hi. I am, will this get merged once rebased? :)

@SethTisue
Copy link
Member

@svalaskevicius I'm in favor of merging it, and from @gourlaysama's last comment, it sounds like he is too

@svalaskevicius
Copy link
Contributor Author

Awesome, I'll rebase it when I have a minute (hopefully not too many conflicts) and will ping here again :)

`lastNoSuccessVar` is introducing a non referrentially transparent, hard to debug source
of errors where parsing Failures are remembered and, even if they are covered by subsequent
combinators, such as `|`, still replaces correct Failures at the end of phrase parsing with them.

This is confusing from two perspectives:
 - how is that error that should have been covered not fixed by the `|`?
 - what is the real parsing error that I should focus to fix in my input?

a small example:

let's assume we are creating a parser to parse `(IF condition THEN 1 END)*`.
let `condition` be `TRUE|FALSE`.

when given input `IF FALSE THEN 1 IF TRUE THEN 1 END` (note the missing `END`), the parser would
have returned:
 `TRUE expected, FALSE given`.

Which is obviously not correct, as FALSE is a valid option described in the parser.
@svalaskevicius svalaskevicius force-pushed the remove-lastNoSuccessVar branch from f5757ff to df4b17b Compare June 30, 2018 13:00
@svalaskevicius
Copy link
Contributor Author

@SethTisue it's rebased now :)

@SethTisue SethTisue merged commit be861c7 into scala:1.1.x Jul 10, 2018
@svalaskevicius svalaskevicius deleted the remove-lastNoSuccessVar branch July 10, 2018 08:22
ru.typeOf[Parsers].decl(ru.TermName("lastNoSuccessVar")).asTerm.accessed.asTerm
mirror.reflect(p).reflectField(lastNoSuccessVarField).get.
asInstanceOf[DynamicVariable[Option[_]]]
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can remove the entire test file now. Its only purpose was testing that lastNoSuccessVar doesn't leak a circular reference. See #69

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, want to PR it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately not, it's been a few years since I last used this. Life has taken me away from Scala... I hoped the PR's author (@svalaskevicius) might wish to drop it.

Philippus added a commit to Philippus/scala-parser-combinators that referenced this pull request Apr 10, 2019
Soya-Onishi pushed a commit to Soya-Onishi/scala-parser-combinators that referenced this pull request Aug 5, 2019
This change means revival of lastNoSuccessVar(deleted by scala#108).
However, in this time, a new variable(`lastFailure` in `Success` class) is
immutable(i.e. this variable does not means revival of side effects).
That is why, probably, this change does not break referentially transparent.
Soya-Onishi pushed a commit to Soya-Onishi/scala-parser-combinators that referenced this pull request Aug 5, 2019
This change means revival of lastNoSuccessVar(deleted by scala#108).
However, in this time, a new variable(`lastFailure` in `Success` class) is
immutable(i.e. this variable does not means revival of side effects).
That is why, probably, this change does not break referentially transparent.
Soya-Onishi pushed a commit to Soya-Onishi/scala-parser-combinators that referenced this pull request Aug 5, 2019
This change means revival of lastNoSuccessVar(deleted by scala#108).
However, in this time, a new variable(`lastFailure` in `Success` class) is
immutable(i.e. this variable does not means revival of side effects).
That is why, probably, this change does not break referentially transparent.
Philippus pushed a commit to Soya-Onishi/scala-parser-combinators that referenced this pull request Nov 16, 2020
This change means revival of lastNoSuccessVar(deleted by scala#108).
However, in this time, a new variable(`lastFailure` in `Success` class) is
immutable(i.e. this variable does not means revival of side effects).
That is why, probably, this change does not break referentially transparent.
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.

5 participants