-
Notifications
You must be signed in to change notification settings - Fork 95
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
Explicit imports: import 'Raw "sample.html"
#2036
Conversation
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.
The approach looks reasonable to me. I guess we might want to bikeshed the syntax a little...
core/src/term/mod.rs
Outdated
@@ -207,7 +207,7 @@ pub enum Term { | |||
|
|||
/// An unresolved import. | |||
#[serde(skip)] | |||
Import(OsString), | |||
Import{path: OsString, typ: Option<LocIdent>}, |
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.
I'd suggest having typ: InputFormat
here, and handling the supported types (including the auto-detection from the filename) while constructing the Term
.
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.
- How would it interact with optionally present format like
Nix
? Ideally it should recognize it and preserve during round-tripping and only fail when actually trying to import the file. Maybe#[cfg]
fromInputFormat::Nix
should be removed? - Does it move complexity to the
grammar.lalrpop
? (It's the first time I edit such a file)
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.
- Good question. I think since
InputFormat::Nix
is experimental, it's ok to error if it isn't supported. - I'd suggest adding the actual logic in
core/src/parser/utils.rs
, so that the changes togrammar.lalrpop
will be very simple.
What do you think about fallback to Falling back from passive format to code format may affect security if there is untrusted data near filename, if |
Bencher Report
Click to view all benchmark results
|
Bencher
Click to view all benchmark results
Bencher - Continuous Benchmarking View Public Perf Page Docs | Repo | Chat | Help |
Done. Some questions:
|
I think for backwards-compatibility we should fall back to the default when the extension is unknown. (But because the tag is a new feature, it's fine to error for an unknown tag.)
I think any of those options is ok; maybe @yannham has some input. The important thing for the pretty-printer is that it round-trips when doing (pretty-print -> parse). It doesn't need to round-trip when doing (parse -> pretty-print).
You mean
My preference is to not have unnecessary aliases, but maybe other people feel differently... |
I agree.
Same. We can always special-case later (like never showing when the format is Nickel, or/and when the extension agrees), but in general pretty-printing is used for error and result reporting, and isn't guaranteed to be stable (formatting doesn't use the pretty-printer).
I agree as well. We have a We discussed the syntax in today's weekly meeting. I'll make a separate issue soon, but this doesn't need to block this PR - we can change the syntax in a second PR. |
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.
Thanks for tackling this! Beside the syntax bikeshedding (which can be done later), and the type
-> format
question, this PR looks good.
core/src/error/mod.rs
Outdated
/// Attempt to specify an import, type of which is not known at the moment of compilation. | ||
/// `explicit` determines whether explicit import type annotation was used |
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.
Once again, I fear type
is a bit ambiguous here (because imports can have a type as well). I suggest we use format
consistently in the documentation and error reporting instead.
By the way, the CI is failing because some code in the |
The pull request is currently marked as draft because of not everything is implemented yet and it should not be merged yet. Other missing things (besides
|
Shall a warning be issued instead of a parse error in that case? (Does/should Nickel in general have warnings?) |
No, it doesn't. Something we've wanted to add for some time - this could be a good excuse, but it's a separate work. For now I would say let's stick to the previous behaviour (import anything unknown as Nickel, and it fails to parse, we show the parse error). |
* Rename typ to format * Bring back the fallback * Implement pretty-printer part * Fix compilation of NLP
Implemented additional changes:
Not implemented:
|
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.
Looks good! It's just missing some tests. You can take inspiration from nickel/core/tests/integration/inputs/imports
, where the test files for imports are located, and nickel/core/tests/integration/inputs/imports/imported
, which hosts the files imported by the former tests. If you put a .ncl
file in imported
which isn't a stand-alone test but just designed to be imported by another a test, as most of them are in imported
, you'll need to add a heading annotation # test.type = 'skip'
.
If you're not confident or can't devote more time to this, feel free to let us know and we can also take it from here.
Co-authored-by: Yann Hamdaoui <[email protected]>
Added some tests (without exhaustive tests for each possible input format). Note that when the same file is imported twice with different formats, the cache remembers the first import and ignores the tag on further ones. Shall we address this potential confusion source? I see two main ways:
|
I prefer the second option. I can imagine some use-case where you want to import something as a structured format and as raw text. |
Shall I include the implementation (vi@cfc46aa) into this branch? This is a more invasive change compared to just some explicit tag support. |
@vi Yes, I think it's fine to join both here. Splitting is good usually but the second change is really motivated by the current PR and has a ~ +30/-30 diff, which IMHO is entirely reasonable (and the current PR isn't too big either). |
Something's failed on Windows, it is not very clear from CI logs. Does Windows mangle |
Mh, that's very likely, yeah. One possibility is to remove the newlines at the end of the files and call it a day. Another possibility is to do a regexp match, for example to just check the We should probably have something like an OS-dependent |
Is there anything more to be done here (e.g. a syntax change for #2039) ? |
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.
Nope, we can handle this in a second step. Thanks a lot for carrying this through @vi !
Noticed possible regression:
|
I guess the pretty printer is at fault, for not inserting a space between |
Resolves #2033.
Resolves #1000.
Shall I continue this (i.e. try to make tests, error handling, docs, etc.) or it should be done some other way?
Shall it be based on master or e.g. on #2022?