Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty Define breaks subsequent macros #4017

Open
AnthonyMuscio opened this issue Jun 25, 2019 · 11 comments
Open

Empty Define breaks subsequent macros #4017

AnthonyMuscio opened this issue Jun 25, 2019 · 11 comments

Comments

@AnthonyMuscio
Copy link
Contributor

AnthonyMuscio commented Jun 25, 2019

If in a tiddler one does this

\define empty-macro()
\define valid-macro() any content
\define multi-line-macro()
Content of valid macro
\end

The empty-macro will cause the remainder of the tiddlers macro definitions not be recognised.

This is hard to debug, so could we fix the "fault" caused by empty macros?

Thanks Tony

@pmario
Copy link
Member

pmario commented Jun 25, 2019

You are right. The empty-macro() is not recognized in the right way. The parse-tree looks like this:

[
    {
        "type": "set",
        "attributes": {
            "name": {
                "type": "string",
                "value": "empty-macro"
            },
            "value": {
                "type": "string",
                "value": "\\define valid-macro() any content\n\n\\define multi-line-macro()\nContent of valid macro"
            }
        },

@pmario
Copy link
Member

pmario commented Jun 25, 2019

If you add a character "." to the empty-macro it works as expected.

\define empty-macro() . 
\define valid-macro() any content
\define multi-line-macro()
Content of valid macro
\end
[
    {
        "type": "set",
        "attributes": {
            "name": {
                "type": "string",
                "value": "empty-macro"
            },
            "value": {
                "type": "string",
                "value": "."
            }
        },

@pmario
Copy link
Member

pmario commented Jun 25, 2019

What's the purpose of the empty-macro?

@AnthonyMuscio
Copy link
Contributor Author

The empty macro is never something I intended to do but it has happened a few times as I have tried to build more complex macros. When macros are used as variables I try and define them so they can be referenced inside another macro but sometimes I slip up.

It would never be a problem if it was not so easy to overlook and the symptoms quite odd.

It would just be nice if it failed more gracefully if not with a message.

Regards
Tony

@twMat
Copy link
Contributor

twMat commented Jun 25, 2019

The empty macro is never something I intended to do but it has happened a few times as I have tried to build more complex macros.

Yes, this happens to me too. I think it is a matter of personality (scattered multi-tasking vs focussed).

@pmario
Copy link
Member

pmario commented Dec 9, 2023

duplicate of: Bug: empty macro definitions don't parse as expected #3460

@AnthonyMuscio
Copy link
Contributor Author

Close in favour of the duplicate #3460 but I hope it is addressed. Another use case is coding with the output preview displayed. In some cases this can give invalid values and generate list of all tiddlers and other time consuming artifacts.

@btheado
Copy link
Contributor

btheado commented Dec 27, 2023

This seems like a different issue than #3460. I created a PR for it at #7911 and it does not address this issue.

To me, the OP looks like a set of valid nested macros:

\define empty-macro()
\define valid-macro() any content
\define multi-line-macro()
Content of valid macro
\end

How can the above be distinguished from nested macros (empty-macro is the outer macro terminated by the \end)?

@AnthonyMuscio
Copy link
Contributor Author

I believe the rule is to nest "macros" you need to name the outer macros in the \end

Your example does not use this suggested approach, but still works. but possibly not in all cases.

  • You don't have an empty macro, you have a parent macro.
\define empty-macro()
\define valid-macro() any content
\define multi-line-macro()
Content of valid macro
\end multi-line-macro
this is not empty it is a parent.
\end empty-macro

<<empty-macro>>
  • In fact you must close the parent macro or and multiline inner macros otherwise it is ambiguous.

However I would also point out you are using the deprecated \define macro not the current \procedure or very useful \function or the new custom \widgets.

Note that this Issue was raised in AnthonyMuscio opened this issue on Jun 25, 2019

  • A few years now.

But the problem remains is still not resolved in two cases;

\define empty-macro()

\end

\define empty-macro()
\end

The above will "break" subsequent macros.

And the same happens with the new \procedures as well.

@AnthonyMuscio
Copy link
Contributor Author

The rule is to nest "macros" you need to name the outer macros in the \end

Your example does not use this suggested approach, but still works. but possibly not in all cases.

  • You don't have an empty macro, you have a parent macro.
\define empty-macro()
\define valid-macro() any content
\define multi-line-macro()
Content of valid macro
\end multi-line-macro
this is not empty it is a parent.
\end empty-macro

<<empty-macro>>
  • In fact you must close the parent macro or and multipline inner macros otherwise it is ambiguous.

However I would also point out you are using the deprecated \define macro not the current \procedure or very useful \function or the new custom \widgets.

Note that this Issue was raised in AnthonyMuscio opened this issue on Jun 25, 2019

  • A few years now.

But the reason is still not resolved in two cases;

\define empty-macro()

\end

\define empty-macro()
\end

The above will "break" subsequent macros. including for \procedures

@AnthonyMuscio AnthonyMuscio reopened this Dec 27, 2023
@Jermolene
Copy link
Member

Hi @btheado as @AnthonyMuscio says, I think the example in the OP is missing an \end. As far as I can tell it is processed exactly as expected.

But the reason is still not resolved in two cases;

@AnthonyMuscio that's the issue in #3460 which remains unfixed at the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants