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

[Merged by Bors] - feat(ast,scanner): add end-pos support #612

Closed
wants to merge 4 commits into from

Conversation

ericrbg
Copy link
Contributor

@ericrbg ericrbg commented Sep 1, 2021

This adds end position support to the scanner and therefore the AST nodes. There's actually "two different" proposals in this PR for how this is implemented outside the scanner (in the two separate commits); the first is very light and definitely works, but is only implemented for tactics, <|> and ; (my usecase in Alectryon).

The second commit hijacks set_ast_pexpr to also set the AST's position m_end, but I'm not sure in what variety of ways this method is used and so it may give (and as far as I can see, somewhat does) give some false results, but it's at least correct in the above 3 settings.

I also modified check_break_before to use this new end-pos; this means that, for example, something like this:

example : 0 = 1 :=
begin
  symmetry           ,
  sorry

  --some comment
end

if you have the cursor anywhere between the symmetry and the comma, the tactic state will show the state the symmetry, and similarly after the sorry token ends (although the "goals accomplished!" text can sometimes not show up). I think that I should do something similar for check_break_at_pos, but I left it for now as I don't wanna accidentally break too much.

src/frontends/lean/parser.cpp Outdated Show resolved Hide resolved
@digama0
Copy link
Member

digama0 commented Sep 9, 2021

bors r+

bors bot pushed a commit that referenced this pull request Sep 9, 2021
This adds end position support to the scanner and therefore the AST nodes. There's actually "two different" proposals in this PR for how this is implemented outside the scanner (in the two separate commits); the first is very light and definitely works, but is only implemented for `tactic`s, `<|>` and `;` (my usecase in Alectryon).

The second commit hijacks `set_ast_pexpr` to also set the AST's position `m_end`, but I'm not sure in what variety of ways this method is used and so it may give (and as far as I can see, somewhat does) give some false results, but it's at least correct in the above 3 settings.

I also modified `check_break_before` to use this new end-pos; this means that, for example, something like this:

```lean
example : 0 = 1 :=
begin
  symmetry           ,
  sorry

  --some comment
end
```

if you have the cursor anywhere between the `symmetry` and the comma, the tactic state will show the state <after> the symmetry, and similarly after the `sorry` token ends (although the "goals accomplished!" text can sometimes not show up). I think that I should do something similar for `check_break_at_pos`, but I left it for now as I don't wanna accidentally break too much.
@bors
Copy link

bors bot commented Sep 9, 2021

Pull request successfully merged into master.

Build succeeded:

@bors bors bot changed the title feat(ast,scanner): add end-pos support [Merged by Bors] - feat(ast,scanner): add end-pos support Sep 9, 2021
@bors bors bot closed this Sep 9, 2021
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.

None yet

2 participants