-
Notifications
You must be signed in to change notification settings - Fork 454
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
an include feature for justfiles #1420
Conversation
src/loader.rs
Outdated
// Parse include directives. | ||
// Include directives are lines that look like: | ||
// #include "relative/path/to/file" | ||
let include_regexp = Regex::new(r#"^#include "([^"]+)"$"#).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your PR description uses the syntax "@include". Here you use "#include", also in the comment. Let's unify.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo from the implementation we used at my work which was #include
. I'll fix it up here in a minute.
buf.push('\n'); | ||
} | ||
|
||
Ok(self.arena.alloc(buf)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file currently adds functionality and requires manual validation.
It is missing a minimal automatic test, can you please add one?
src/loader.rs
Outdated
// Parse include directives. | ||
// Include directives are lines that look like: | ||
// #include "relative/path/to/file" | ||
let include_regexp = Regex::new(r#"^#include "([^"]+)"$"#).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's extract this logic to a separate, testable function which we call from here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work, needs a bit of improvement.
@mihaigalos This is just a draft, no need to review. I'll probably just use it as a starting point. I'd like to integrate include into the parser, instead of as a preprocessor step. |
That's fine. I would really like this feature. |
* Proof of concept: an include feature for justfiles. A fast proof that it's straightforward to do a no-fancy-parsing include feature. This design takes all lines that look like this: `@include "relative/path/to/file"` and replaces them with the contents of the pointed-to file. The resulting buffer is passed along to be parsed and executed as before. That's it: no attempt to look at the file or do anything with the contents. This is pure concatenation. * Satisfy clippy. Co-Authored-By: kevin@seaplane.io
Co-authored-by: Mihai Galos <mihaigalos@gmail.com>
Rebased on the latest |
Okay! I hoped to use this as a basis for a version that would parse included justfiles, and then include the token stream, instead of doing literal text inclusion, but I've been swamped and I know that this has been a long requested feature, so instead of delaying it, let's get this in. Some comments:
|
Why have any characters before the Good idea on dropping the quotes, they only add noise. |
Without the
|
I'm very biased since no ':' in Linux paths afaik, but can imagine |
Ultimately, linux paths are arbitrary strings, and can include any byte except nulls. |
This design takes all lines that look like this:
@include "relative/path/to/file"
and replaces them with the contents of the pointed-to file. The resulting buffer is passed along to be parsed and executed as before. That's it: no attempt to look at the file or do anything with the contents. This is pure concatenation.
Feel free to tweak as needed!
Implements #1407