Zulip Chat Archive

Stream: general

Topic: Creating a wrapper for a Term quotiation


Codegoblin (Apr 30 2025 at 08:13):

Hello Lean Community,

I am trying to add comments to all of my syntax declarations via wrappers to both syntax declarations and the matching of said syntax.

I have already created a wrapper for syntax creation, which adds a syntax parser (for comments) between every element of the syntax defined by the user.

Syntax with comment

This transforms the following syntax

declare_syntax_cat example_stx_cat
#syntax_with_comments  "example_stx"  : example_stx_cat

to a syntax declaration of

syntax (comment)? "example_stx" (comment)? : example_stx_cat

Now I want to 'ignore' the comments in all matches, for this purpose I would like to wrap quotations to add an optional match like

$[$_:comment]?

between every element.

E.g. I would like to create the following function

def canMatch (i : TSyntax `example_stx_cat) : Bool :=
  match i with
    | `(example_stx_cat | $[$_:comment]? example_stx $[$_:comment]?) => true
    | _ => false

more like this

def canMatch (i : TSyntax `example_stx_cat) : Bool :=
  match i with
    | syntax_match_with_comments `(example_stx_cat |  example_stx ) => true
    | _ => false

Now I do not know how I can add the comment matches to the quotation. So far I have the following:

quote match

But if I try to deconstruct the dynamic quote or construct one like

match syntax_match_quote with
          | `(Parser.Term.dynamicQuot | `($id:ident | $s:stx)) => ...

I get the error

failed to determine parser using syntax stack, the specified element on the stack is not an identifier

Is this because I try to de/construct a quotation with a quotation? Is there a way to add the empty match ($[$_:comment]?) to the syntax of a quotation?


Last updated: May 02 2025 at 03:31 UTC