Zulip Chat Archive

Stream: lean4

Topic: Get syntax range in pattern matching


Patrick Massot (Jan 12 2025 at 10:41):

When matching some syntax I know I can use %$tk to record one piece of syntax that was matched. Is there a way to do that with several consecutive pieces? Or am I meant to create a syntax category for the suggestion I want?

Sebastian Ullrich (Jan 12 2025 at 12:54):

Do you mean their lexical range? You can put the first and last token in a mkNullNode and get the range of that

Patrick Massot (Jan 12 2025 at 13:02):

Yes I want to get their lexical range. I don’t know what it means to “put the first and last token in a mkNullNode and get the range of that”.

Patrick Massot (Jan 12 2025 at 13:03):

And the context of this question is described at #lean4 > Show tactic state and widget in custom calc @ 💬

Patrick Massot (Jan 12 2025 at 13:04):

I just moved that thread because I just noticed I originally put it in the mathlib4 channel by accident.

Damiano Testa (Jan 12 2025 at 15:47):

Is something like this what you are looking for?

import Lean

elab tk:group("these" "are" "all" "together") "these" "are" "not" : command => do
  Lean.logInfoAt tk "Underlying them all"
  return

these are all together these are not

Patrick Massot (Jan 12 2025 at 15:48):

I’m looking for the analogue of that when doing pattern matching.

Sebastian Ullrich (Jan 12 2025 at 17:02):

mkNullNode #[firstTk, lastTk] is a Syntax spanning the two tokens. It's not a valid syntax to elaborate but likely it works for the widget and withTacticInfoContext, which is responsible for annotating a syntax range with the pre and post state of executing a tactic


Last updated: May 02 2025 at 03:31 UTC