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

Make tokens in <|> relevant to syntax match #1744

Merged
merged 6 commits into from
Oct 28, 2022
Merged

Make tokens in <|> relevant to syntax match #1744

merged 6 commits into from
Oct 28, 2022

Conversation

Kha
Copy link
Member

@Kha Kha commented Oct 17, 2022

Implements #1275 (comment)

Fixes #1275

@Kha Kha changed the title fix: syntax match should not ignore tokens in <|> Make tokens in <|> relevant to syntax match Oct 17, 2022
@Kha Kha added the changelog label Oct 17, 2022
@Kha Kha force-pushed the 1275 branch 2 times, most recently from 4f05083 to 6cab36f Compare October 17, 2022 11:55
@Kha
Copy link
Member Author

Kha commented Oct 17, 2022

I suppose &"foo" <|> ... should trigger a token match just as well. Which begs the question of how to handle

syntax discharger := atomic(" (" (&"discharger" <|> &"disch")) " := " tacticSeq ")"

@Kha
Copy link
Member Author

Kha commented Oct 17, 2022

The simplest solution would be to define

syntax dischTk := &"discharger" <|> &"disch"

and then use $_:dischTk. It would basically be the reverse of the previous situation: introduce intermediary syntax when you do not want to match the token.

@gebner
Copy link
Member

gebner commented Oct 17, 2022

I think for discharger, we can just remove the disch variant. Generally, adding an extra syntax node sounds good.

@Kha
Copy link
Member Author

Kha commented Oct 18, 2022

I'm still unsure what to do about something like

syntax unifConstraint := term (" =?= " <|> " ≟ ") term

In built-in syntax this would be unicodeSymbol, but we can't make that a parser alias as it takes two strings, not parsers. By the above we could do

syntax unifTk := " =?= " <|> " ≟ "

but then we would have to write $_:unifTk in patterns instead. Do we want to keep the pattern irrelevance in these cases? Then we could also introduce a generic parser combinator, as I think was proposed before, like

syntax unifTk := nomatch (" =?= " <|> " ≟ ")

except maybe with a better name.

@gebner
Copy link
Member

gebner commented Oct 18, 2022

The one-size-fits-all solution for when ParserDescr is not expressive enough is to make a parser alias. I think this also depends on (y)our long-term plans: do we want to get rid of ParserDescr or get rid of Parser? As it stands, we're running into ParserDescr limitations left and right (e.g. we can't expose sepByIndent either because it takes a string and a parser, and I'm not even getting into optional arguments).

We've discussed the nomatch before, such a feature would also be great for sepByIndent, etc. Here the nomatch should be outside of the unifTk though, we don't want to check the kind of the unifTk node.

@Kha
Copy link
Member Author

Kha commented Oct 18, 2022

do we want to get rid of ParserDescr

I do!

Here the nomatch should be outside of the unifTk though, we don't want to check the kind of the unifTk node.

Ah, you're right. Unless someone can think of a better name, I'd probably go with that.

@@ -337,14 +337,15 @@ macro_rules

section
open Lean.Parser.Tactic
syntax cdotTk := patternIgnore("·" <|> ".")
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the only case where I had to introduce a new syntax abbrev, since a token quotation inside patternIgnore obviously can't work anymore. And yes, I went with a less "cute" name than nomatch after all.

@leodemoura leodemoura added the awaiting-author Waiting for PR author to address issues label Oct 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-author Waiting for PR author to address issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Antiquotation types silently ignore tokens
3 participants