Repository navigation
Description
Context
Born from this discussion on Slack: https://robotframework.slack.com/archives/C015KB1QSDN/p1775116818448659
Robot includes the Parser API:
Robot Framework supports external parsers that can handle custom data formats or even override Robot Framework's own parser.
Recently, I tried to use this API to centrally replace the import to a library. In doing so, I found out that the parser API only works for suite files (.robot files with tests/tasks) and init files (__init__.robot files). Any other filetype is unsupported by the Parser API. This includes:
- Resource files (
.robot/.resourcefiles without tests/tasks) - Variable files (
.json/.py/.yaml, ...) - Library files (
.py)
Goal
Extend the parser API to also allow control over the following filetypes:
- Resource files
Variable filesAlready controllable through Python logic using a.pyfile withget_variablesfunction. Because of this, I see no need right now to add support for this to the Parser API. If someone disagrees, please open a separate issue for this.Library filesAlready controllable through Python logic because these are Python files by definition. Because of this, I see no need right now to add support for this to the Parser API. If someone disagrees, please open a separate issue for this.
Possible design
The current parser API is implemented with a parse and parse_init method/function. See user guide for details. The parse function allows you to change suite files. The parse_init function allows you to change __init__.robot files.
Add a new function/method to the Parser API: parse_resource. Example:
from robot.running.resourcemodel import ResourceFile
class RobotPreParser:
def parse_resource(self, source: Path) -> ResourceFile:
resource = ResourceFile.from_file_system(source)
# Do something interesting
return resourceThis would allow full control over both the raw and the parsed resource file before Robot does anything else with it. This approach builds out the existing parser API. This should be a non-breaking change.
Optionally, parse can be renamed to parse_suite. This would make it clear what the function applies to. This is a breaking change. A soft deprecation is possible here: Rename to parse_suite, make parse an alias for parse_suite, deprecate parse in subsequent major version(s). Renaming the parse function can be a separate issue.
Activity
pekkaklarck commentedon May 5, 2026
Enhancing custom parsers so that they can parse resource files is certainly a good idea. That was left out originally because there were no reported use cases and because it would have increased complexity of the custom parser implementation. Now we have a concrete request for this functionality and based on quick prototyping this isn't overly complicated to implement either.
When the custom parser API was originally implemented, a big part of the work was designing the API. Now that the API exists, it is logical to extend it with new, optional
parse_resource(source: Path) -> ResourceFilemethod as the description already explained. I don't see big enough benefits in renaming the existingparsemethod toparse_suite, though.pekkaklarck commentedon May 5, 2026
As I hinted above, I did little prototyping and got the basic functionality working. My main motivation was to see is it feasible to implement this in RF 7.5 scope and based on the prototype the answer is yes. The code needs cleanup, lacks error handling, doesn't have tests or documentation, probably breaks some existing functionality and is in general very much in prototype level. I don't have time to finish it in the near future, so I'll paste the code here in case @Lakitna or someone else is interested to continue the work. That would also be the best way to make sure this actually gets implemented in RF 7.5. There are other issues that I consider more important and/or that need my expertise more, and I will concentrate on them first.
[-]Make preparser work for resource files[/-][+]Add resource file support to custom parser API[/+]Lakitna commentedon May 10, 2026
I gave it a look. Your implementation seems to to require the parser to include
resourceas an extension:Doing this will make it call the
parsefunction for all.resourcefiles. Because it's in the list of extensions. It will then try to parse the resource file as a suite file which is problematic.Do you think that
parseshould never call.resource, or that a second list of extensions is better? Something like:Or do you have another approach that'd work better?
pekkaklarck commentedon May 12, 2026
Good catch. It's probably best to add separate
resource_extension. Special casing.resourcewould fix that particular case, but the same problem would occur with other extensions.Other things that came to my mind:
parse_resource. Currentlyparseis required, but we could make it optional. We could then validate that at least one ofparse,parse_initandparse_resourceexists, but I don't think that's necessary. We don't, for example, validate that a listener has any listener methods (but that could be a good idea now that I think about it).TestSuite.custom_parsersduring parsing time. That feels a bit like a hack and storing this information to some context object would be much better. We unfortunately don't have such a context object available and adding one as part of this enhancement isn't worth the effort. Probably storing the information inTestSuiteis fine, but perhaps we should useTestSuite._custom_parsersto indicate this isn't part of the public API.Lakitna commentedon May 15, 2026
For the parser, this seems easy enough. Making all parser methods optional (but 1 required) sounds like a good idea.
I did see that it should be part of
TestSuite, but so far I've only gotten custom resource parsers working on directory suites and not yet on file suites. I've been trying to trace whereTestSuiteis created, but this seems to be in quite a few places. And all those places need to get a list of custom resource parsers. It's been quite the puzzle, probably because I'm also familiarizing myself with the codebase at the same time :)pekkaklarck commentedon May 15, 2026
It's certainly a puzzle. Some of the stuff is fairly complicated and some of the old code is just bad. Getting familiar with the code base certainly helps if if are interested to contribute!
Lakitna commentedon May 17, 2026
I've got a working version! 🎉🎉
It's still pretty rough. It still needs at least:
robot.api)ParserinterfaceThat being said, initial comments are much appreciated :)
#5678
pekkaklarck commentedon May 17, 2026
Awesome! I'm currently at our cottage fixing things and have only limited time for my real work until I'm home. It may thus take several days until I can look at this properly.
Lakitna commentedon May 17, 2026
No problem! In the meantime, I'll keep chipping away at it. There are 30 atests to fix and 2 utests to fix and I also have to familiarize myself with the testing setup. That should give you plenty of time to check it out when you have more time :)
pekkaklarck commentedon Sep 1, 2026
Unfortunately I have been busy with other RF 7.5 features and haven't had time to look at this. Now RF 7.5 is getting ready, but it's been delayed so much (the target was to get it out in early July) that I want to get it released ASAP. I looked at the PR implementing this quickly and noticed that the PR is still draft, there are some TODOs in the code and that there are some conflicts to be fixed. In this situation I believe it's best to move this issue to RF 7.6 and look at it again a bit later when we have more time.