mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 22:09:09 +00:00
Merge remote-tracking branch 'origin/main' into remove-nat
This commit is contained in:
commit
24a38c4a26
99 changed files with 2636 additions and 938 deletions
|
@ -3838,6 +3838,35 @@ struct HeaderOutput<'a> {
|
|||
opt_platform_shorthand: Option<&'a str>,
|
||||
}
|
||||
|
||||
fn ensure_roc_file<'a>(filename: &Path, src_bytes: &[u8]) -> Result<(), LoadingProblem<'a>> {
|
||||
match filename.extension() {
|
||||
Some(ext) => {
|
||||
if ext != ROC_FILE_EXTENSION {
|
||||
return Err(LoadingProblem::FileProblem {
|
||||
filename: filename.to_path_buf(),
|
||||
error: io::ErrorKind::Unsupported,
|
||||
});
|
||||
}
|
||||
}
|
||||
None => {
|
||||
let index = src_bytes
|
||||
.iter()
|
||||
.position(|a| *a == b'\n')
|
||||
.unwrap_or(src_bytes.len());
|
||||
let frist_line_bytes = src_bytes[0..index].to_vec();
|
||||
if let Ok(first_line) = String::from_utf8(frist_line_bytes) {
|
||||
if !(first_line.starts_with("#!") && first_line.contains("roc")) {
|
||||
return Err(LoadingProblem::FileProblem {
|
||||
filename: filename.to_path_buf(),
|
||||
error: std::io::ErrorKind::Unsupported,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn parse_header<'a>(
|
||||
arena: &'a Bump,
|
||||
read_file_duration: Duration,
|
||||
|
@ -3856,6 +3885,8 @@ fn parse_header<'a>(
|
|||
let parsed = roc_parse::module::parse_header(arena, parse_state.clone());
|
||||
let parse_header_duration = parse_start.elapsed();
|
||||
|
||||
ensure_roc_file(&filename, src_bytes)?;
|
||||
|
||||
// Insert the first entries for this module's timings
|
||||
let mut module_timing = ModuleTiming::new(start_time);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue