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

Comment shebang line before passing to tokenizer #437

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use crate::{rules, Cli};
use chrono::prelude::*;
use colored::Colorize;
use heraclitus_compiler::prelude::*;
use itertools::Itertools;
use std::env;
use std::fs;
use std::fs::File;
Expand All @@ -35,12 +34,12 @@ impl AmberCompiler {
path,
cli_opts,
}
.load_code(AmberCompiler::strip_off_shebang(code))
.load_code(AmberCompiler::comment_shebang(code))
}

fn strip_off_shebang(code: String) -> String {
fn comment_shebang(code: String) -> String {
if code.starts_with("#!") {
code.split('\n').skip(1).collect_vec().join("\n")
String::from("// ") + &code
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually... can we replace shebang with an empty line? The comments can now persist in the generated bash file: #403

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could, but wouldn't it be better to show that there was a shebang in the input file, for debugging purposes?

Copy link
Member

@Ph0enixKM Ph0enixKM Sep 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay let's leave it as a comment then

} else {
code
}
Expand Down