Zulip Chat Archive

Stream: Is there code for X?

Topic: Expression printed as AST


Xavier Martinet (Sep 30 2021 at 08:16):

Hi everyone! I am pretty new to Lean, and I was wondering: is there any way to get the underlying ASTs behind the mathematical expression manipulated by Lean? For instance I saw there was a set_option pp.notation false I could parse, but maybe there was a better way to automatically extract the AST directly?

Scott Morrison (Sep 30 2021 at 08:27):

See if lean --make --ast foo.lean gives you something you like.

Scott Morrison (Sep 30 2021 at 08:28):

(This exists solely to support migrating mathlib to lean4, so if it's not what you're after the alternative answer is to switch to lean4.)

Mario Carneiro (Sep 30 2021 at 08:57):

lean --ast is good for if you want to manipulate the AST of a lean expression outside of lean. If you want the AST inside lean, you can just parse it into an expr and pattern match on it, print it using tactic.pp and other things

Xavier Martinet (Sep 30 2021 at 14:05):

Thanks! I will try that


Last updated: Dec 20 2023 at 11:08 UTC