Zulip Chat Archive

Stream: metaprogramming / tactics

Topic: location of current decl


Alex J. Best (Jun 27 2023 at 11:39):

Is it possible from within TacticM to get the file location of the current declaration (or say the Syntax of the leading def theorem etc?).

Alex J. Best (Jun 27 2023 at 11:41):

I.e. imagine I wanted to write a tactic blah that prints the location of the example

...
stuff
...
example : False := by
  blah -- current declaration is at line 7 column 1

Scott Morrison (Jun 27 2023 at 11:55):

This isn't a complete answer, but maybe

def getSourceUpTo (s : Syntax) : CoreM (String × String) := do
  let fileMap := ( readThe Core.Context).fileMap
  let ({ line := line, column := _ }, _) := stxRange fileMap s
  ...

from branch#sagredo-widget is useful.


Last updated: Dec 20 2023 at 11:08 UTC