Zulip Chat Archive
Stream: mathlib4
Topic: Mathlib.Tactic.Lift steals the token `to`
Kim Morrison (May 10 2025 at 09:17):
import Mathlib.Tactic.Lift
structure Foo where
to : Unit
produces
unexpected token 'to'; expected command
Is someone able to fix this for us? Or have we just decided that to is not an acceptable field name if using Mathlib?
Andrew Yang (May 10 2025 at 09:29):
syntax (name := lift) "lift " term " to " term (" using " term)?
(" with " ident (ppSpace colGt ident)? (ppSpace colGt ident)?)? : tactic
structure Foo where
to : Unit
This is the culprit but why does a syntax in the tactic category trigger here?
Edward van de Meent (May 10 2025 at 09:30):
Personally I think both. imo to seem very non-descriptive as a name, but I imagine that downstream projects should have freedom to do whatever they want, so the tactic shouldn't reserve it
Alex Meiburg (May 10 2025 at 14:27):
It would be a very reasonable name in a pair ti / to, i.e. a collection of "t in" and "t out" - $t_{i}$ and $t_{o}$ are definitely something I've seen in plenty of papers. (Granted they could be tᵢ and tₒ.)
Edward van de Meent (May 10 2025 at 14:30):
(did you mean to post this somewhere else?)
Ruben Van de Velde (May 10 2025 at 14:33):
No, it's relevant to naming things to (or t\_o)
Eric Wieser (May 10 2025 at 14:34):
&" to " fixes this
Damiano Testa (May 11 2025 at 18:46):
I am in favour of adding &. In general, forbidding two letter identifiers seems like it should be avoided.
Yury G. Kudryashov (May 12 2025 at 00:32):
What does & do?
Aaron Liu (May 12 2025 at 00:33):
It makes the token not reserved
Aaron Liu (May 12 2025 at 00:34):
@loogle "nonreserved"
loogle (May 12 2025 at 00:34):
:search: Lean.ParserDescr.nonReservedSymbol, Lean.ParserDescr.nonReservedSymbol.sizeOf_spec, and 13 more
Kim Morrison (May 12 2025 at 06:22):
Eric Wieser said:
&" to "fixes this
Sorry, I should have said in my original message that this doesn't work: we get lots of "unexpected token" errors when setting up the elab_rules. (I didn't diagnose any further.)
Eric Wieser (May 12 2025 at 07:30):
I tried it with Andrew's mwe and it seemed to work
Robin Arnez (May 12 2025 at 07:41):
It doesn't work:
syntax (name := lift) "lift " term &" to " term (" using " term)?
(" with " ident (ppSpace colGt ident)? (ppSpace colGt ident)?)? : tactic
example : True := by
lift 3 to 3 -- parses `to` as a name instead of a keyword
Eric Wieser (May 12 2025 at 07:43):
syntax (name := lift) "lift " term:arg &" to " term (" using " term)? works
Eric Wieser (May 12 2025 at 07:44):
But I guess breaks lift f a to
Robin Arnez (May 12 2025 at 07:44):
Yeah but it comes at a cost:
syntax (name := lift) "lift " term:arg &" to " term (" using " term)?
(" with " ident (ppSpace colGt ident)? (ppSpace colGt ident)?)? : tactic
example : True := by
lift 1 + 5 to 3 -- invalid token "+", expected "to"
Robin Arnez (May 12 2025 at 07:44):
Yeah right
Robin Arnez (May 12 2025 at 07:48):
Yeah, right so is it possible to have
structure Foo where
to : Unit
example : True := by
lift f a to 3
Hmm...
Robin Arnez (May 12 2025 at 08:06):
Okay this seems to work:
import Lean.Parser
open Lean Parser
@[inline]
def Lean.Parser.ParserContext.mk (core : ParserContextCore) : ParserContext := by
constructor
assumption
def withKeyword (tk : String) : Parser → Parser := withFn fun f c s =>
let c' : ParserContext := .mk { c with tokens := c.tokens.insert tk tk }
f c' s
def termWithTo : Parser := leading_parser withKeyword "to" (categoryParser `term 0)
syntax (name := lift) "lift " termWithTo &" to " term (" using " term)?
(" with " ident (ppSpace colGt ident)? (ppSpace colGt ident)?)? : tactic
structure Foo where
to : Unit
example : True := by
lift f a to 3
Eric Wieser (May 12 2025 at 08:40):
That fails on lift (fun to => to) a to 3
Eric Wieser (May 12 2025 at 08:44):
But that's better than the status quo!
Kevin Buzzard (May 12 2025 at 08:47):
Eric Wieser said:
That fails on
lift (fun to => to) a to 3
Anyone who tries that deserves pain anyway :-)
Mario Carneiro (May 12 2025 at 10:00):
Kim Morrison said:
import Mathlib.Tactic.Lift structure Foo where to : Unitproduces
unexpected token 'to'; expected commandIs someone able to fix this for us? Or have we just decided that
tois not an acceptable field name if using Mathlib?
I recall this being a major point of discussion when lift was first added with this keyword. Yes, this is making to into a keyword and this means it can't be used in field names unless you use guillemets, just as you can't use with and as as variable names
Mario Carneiro (May 12 2025 at 10:00):
Because of the way it is used, you can't use &"to" here
Mario Carneiro (May 12 2025 at 10:01):
that trick doesn't always work or else there would be no need for keywords in the first place
Mario Carneiro (May 12 2025 at 10:03):
(certainly I have wanted to use as as a name on many occasions, e.g. in list functions with a and as)
Ruben Van de Velde (May 12 2025 at 10:09):
Can we do lift x → X?
Mario Carneiro (May 12 2025 at 10:10):
no, -> is already valid in expression position, it means a function type
Eric Wieser (May 12 2025 at 10:14):
lift x : X could work?
Edward van de Meent (May 12 2025 at 10:14):
we could do lift X from x, i think?
Mario Carneiro (May 12 2025 at 10:24):
I'm just not sure why we are resurrecting this conversation
Mario Carneiro (May 12 2025 at 10:25):
we had a poll and everything IIRC, we decided at the time to go with making this into a keyword
Mario Carneiro (May 12 2025 at 10:25):
it's a very short english preposition, arguably not that different from as, from, with, using
Mario Carneiro (May 12 2025 at 10:26):
and it is nice to not have to contort grammar in tactics using an extremely short lexicon of prepositions
Aaron Liu (May 12 2025 at 12:08):
The nonReservedSymbol parser seems to take an additional includeIdent argument, would setting that to true help here?
Robin Arnez (May 12 2025 at 12:48):
The problem is not the "to" but the term before it parsing more than it should, so that shouldn't help.
Robin Arnez (May 12 2025 at 12:48):
Also, as is not a keyword I don't think..?
Mario Carneiro (May 12 2025 at 14:07):
you're right, maybe I got confused with ML where as is a keyword. at is also a keyword in lean
Last updated: Dec 20 2025 at 21:32 UTC