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
declare_syntax_catsyntax_with_comments_elementsyntaxstr:syntax_with_comments_elementsyntaxident:syntax_with_comments_element/-- A call to syntax_with_comments is like a call to syntax, except between every element of the syntax the comment syntax_category is added -/syntax(name:=syntax_with_comments_stx)("#")?"syntax_with_comments"(syntax_with_comments_element)*":"ident:commandprivatedefevaluate_syntax_creation(elements:TSyntaxArray`syntax_with_comments_element)(stx_cat:Ident):Command:=Unhygienic.rundoletcomment_stx←`(stx|($(mkIdent`comment):ident)?)letmutelements_as_stx:Array(TSyntax`stx):=#[comment_stx]forelementinelementsdomatchelementwith|`(syntax_with_comments_element|$str_element:str)=>letstr_element_stx←`(stx|$(str_element):str)elements_as_stx:=elements_as_stx.pushstr_element_stxelements_as_stx:=elements_as_stx.pushcomment_stx|`(syntax_with_comments_element|$ident_element:ident)=>letident_element_stx←`(stx|$(ident_element):ident)elements_as_stx:=elements_as_stx.pushident_element_stxelements_as_stx:=elements_as_stx.pushcomment_stx|_=>unreachable!return←`(command|syntax$[$elements_as_stx]*:$stx_cat)@[command_elabsyntax_with_comments_stx]privatedefsyntax_with_comments_implementation:CommandElab:=funstx=>dotrymatchstxwith|`(#syntax_with_comments$elements:syntax_with_comments_element*:$stx_cat:ident)=>lets:=(evaluate_syntax_creationelementsstx_cat)logInfoselabCommands|`(syntax_with_comments$elements:syntax_with_comments_element*:$stx_cat:ident)=>lets:=(evaluate_syntax_creationelementsstx_cat)elabCommands|_=>returncatch|x=>throwErrorx.toMessageData
Now I do not know how I can add the comment matches to the quotation. So far I have the following:
quote match
syntax(name:=syntax_match_with_comments_stx)("#")?"syntax_match_with_comments"Parser.Term.dynamicQuot:term@[term_elabsyntax_match_with_comments_stx]privatedefsyntax_match_with_comments_implementation:TermElab:=funstxexpectedType?=>domatchstxwith|`(#syntax_match_with_comments$syntax_match_quote:dynamicQuot)=>logInfosyntax_match_quoteelabTermsyntax_match_quoteexpectedType?|`(syntax_match_with_comments$syntax_match_quote:dynamicQuot)=>elabTermsyntax_match_quoteexpectedType?|syntx=>throwErrors!"Could not create Syntax match for syntax '{syntx}'"
But if I try to deconstruct the dynamic quote or construct one like
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?