martin-helmich / typo3-typoscript-parser

Library containing a simple parser for the TypoScript configuration language.
32 stars 10 forks source link

Rewritten core TypoScript parser #83

Open lolli42 opened 1 year ago

lolli42 commented 1 year ago

I'm creating this issue to leave some information about current TYPO3 core development that happened in the last month for version 12 and raise awareness in this area. I guess it's fine to close the issue again, but I hope it's ok to outline a bit.

TYPO3 v12 comes with a rewritten TypoScript parser, deprecating the old approach.

First, I want to give a huge "Thank You!" to Martin for this repository: I know this parser is used by various people to parse TypoScript a-like syntax as a standalone solution for various use cases. It also inspired the new core solution and gave me another source to look up details. As such, the new core parser follows similar principles: A tokenizer, a solution to parse "@import" statements into a tree, an AST builder, together with tree traversers and visitors.

While the new parser is currently fully marked @internal in the core, with only the consuming code (TypoScript, pageTsConfig, userTsConfig) being public API, the core parser could still be used to achieve similar things this repository provides, in case people don't hesitate to access internally marked core classes. The parser "library" is part of the "core" extension, it can be composer-required directly, to then use the classes. The core extension has no direct dependency to other core extensions like "backend" and similar, so requiring "core" still loads various dependencies, but does not end up in a fully working TYPO3. Eventually, when dust settles, it would be possible to extract the TypoScript parser to a standalone library as well. Details like DB queries are already relatively well contained and are only a semi-hard dependency at the moment, possibly with further extraction.

A couple of details have not yet been implement in the core approach - for instance a "PrettyPrinter" is missing. This may be added later though, improving the tstemplate extension with features.

The new parser also streamlines some TypoScript syntax details. For instance using a 'constant' within an identifier is no longer allowed: foo.{$bar}.baz = something. This will apply to all TYPO3 projects with v12 and above.

I'm writing this since I see various options to continue with this repository. I'm fine with all of them and I'm absolutely not saying this approach is obsolete in any way:

Martin, please feel free to contact me (eg. via TYPO3 slack) in case you're worried and interested, I'm open for everything. Feel free to continue as is if that fits your needs and wishes, too: Your work on this parser is great and I totally don't want to destroy anything of it.

martin-helmich commented 1 year ago

Hey Christian,

thanks for reaching out. I'll respond here instead of Slack, so that others may read along and chime in. Apart from that, it might also be easier to have a quick chat about some things, so I might also give you a poke on Slack shortly. 🙂

This project originally started as a programming excercise many moons ago; It was fun to build, but I don't have any emotional attachment to it and only maintain it out of necessity for the typo3-typoscript-lint^1 project.

Actually, keeping the parser in sync with the "actual" implementation in the TYPO3 core has always been a hassle that I would not mind getting rid of. So, replacing this library with an "official" parser that offers the same capabilities does -- in general -- seem favourable to me (with some caveats being listed below).

Keeping this in mind:

The parser "library" is part of the "core" extension, it can be composer-required directly, to then use the classes.

THAT, on the other hand, does not sound particularly appealing to me. I would prefer not depending on any internal APIs that might break without any notice. Also, the typo3-typoscript-lint project is often composer-(dev)-required into many TYPO3 projects, so it might be a potential issue if the linter requires its own version of the TYPO3 core as a dependency. Although, the PHAR installation is the recommended mode of installation anyway, so that second argument might be a non-issue.

A couple of details have not yet been implement in the core approach - for instance a "PrettyPrinter" is missing.

That doesn't sound too bad for me. Once could argue that printing code is actually a separate concern from parsing it, in any case. So, maintaining a separate library with printers and other "add-on" features, might actually be preferable.

Some additional caveats that I could think of stem from the usage of this parser library for the Typoscript Linter:


So, regarding to the suggested alternatives:

I would prefer not depending on the TYPO3 core itself. I would prefer having a separate library without any (unrelated) dependencies and with a stable API contract that I could either depend on directly in typo3-typoscript-lint, or to shim in a new version of the typo3-typoscript-parser library.

TL;DR: My make-a-wish solution would consist of us joining forces and creating a unified standalone library that both the TYPO3 core and the linter could require as a dependency. My time to work on this project has been limited in the recent past, but I'd be happy to join forces and help as my spare time allows.

Maybe we can schedule a quick call on Slack to hash out some more details. I'll leave this issue open (and pin it) for a while, in case anyone else wants to chime in.

sabbelasichon commented 5 months ago

@lolli42 @martin-helmich Thanks for all your work and starting this discussion here. As we are creating a new tool to modify also TypoScript files to ease the upgrade of TYPO3 (https://github.com/andreaswolf/fractor), i would also like to see a dedicated composer package for the TypoScript part instead of relying on the core package itself. What has to be done to move forward? I would be happy to help and join forces.

lolli42 commented 4 months ago

Hey.

Thanks for feedback so far.

I understand having the core parser as standalone library would be a good thing to have. Simon Schaufelberger pinged me on this recently as well. I essentially answered this. Note: Opinions below!

sabbelasichon commented 4 months ago

@lolli42 Thanks for your detail explanation. I am not against requiring typo3/cms-core in Fractor by no means. The only concern for now is that we would like to support a great range of TYPO3 versions in the same branch. That is not easily doable if we would require typo3/cms-core as far as i understand. Let us have a direct conversation so we can see what we can achieve in the current situation. Thank you very much for your passion and work.