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

Add: "include" keyword, allowing to include files without external tools #358

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

glx22
Copy link
Contributor

@glx22 glx22 commented Jan 17, 2025

Many GRF workflows use tools to combine multiple files into a single NML (C preprocessor, python, ...).

So I though it would be nice to be able to do that natively in NML. It's done during parsing by switching lexer data.

I also added optional <ID> = <expression> as include parameters, allowing to replace some parts inside the included file during parsing (very basic equivalent of #define from C preprocessor).

Include syntax is include(<filename>[, <ID> = <expression>[, ...]]);.

Added identifier concatenation support using <identifier>.<identifier>.

--nml output for 042_include.nml:

param[0] = 0;

param[0] = (param[0] + 1);

const _NAMExy = 1;
param[0] = (param[0] + _NAMExy);


param[0] = (param[0] + 2);

const _testxy = 2;
param[0] = (param[0] + _testxy);


param[0] = (param[0] + 3);

const _test2xy = 3;
param[0] = (param[0] + _test2xy);


@andythenorth
Copy link
Contributor

Tested simplest case with FIRS, works as expected.

andythenorth/firs@0beca16

@andythenorth
Copy link
Contributor

Tested locally as working with params.

include("src/polar_fox/cargo_classes/cargo_class_constants.nml", cabbage=2, ham=1);

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

Successfully merging this pull request may close these issues.

2 participants