-
Notifications
You must be signed in to change notification settings - Fork 39
Add: "include" keyword, allowing to include files without external tools #358
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
base: master
Are you sure you want to change the base?
Conversation
|
Tested simplest case with FIRS, works as expected. |
|
Tested locally as working with params.
|
|
Is there anything us NewGRF authors can do to help test this? It would be nice to get it out of draft status! |
|
The character to concat identifiers is Do we block pontential future "member access" by using "." for concatenation? |
|
Well it's still very hacky, and needs more work. |
|
I wholeheartedly approve of the idea, because more code reusability is always welcomed, but I stand against token concatenation and identifier mutation capabilities being included. One of my main arguments against it is, if user chooses to use this feature to create templated names a. e. purchase spriteset names with common prefix, then he will still need to write (and remember) full prefix in the place of its usage. I am currently developing a language server for NML and ability to join identifiers makes a lot of things ambiguous and error-prone, just like complex defines in C do. IMHO, we should fix boilerplate-y sections instead of providing generic macros support. |
|
Also, we should consider incomplete code inside included file: is the intended behavior to allow users to use includes inside other AST nodes or parse file separately and include received statements to the resulting unit at the top level? |
|
I am still strongly in favour of this, but I'm unsure how to help move it forward. I am not convinced that we need parameterised includes. Simplicity is the goal for an include feature IMO. That said, I wonder if we could target, not a file, but a script with params, returning nml as a string? Then the author could template the output of |
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#definefrom C preprocessor).Include syntax is
include(<filename>[, <ID> = <expression>[, ...]]);.Added identifier concatenation support using
<identifier>##<identifier>.--nmloutput for042_include.nml: