Skip to content

Commit

Permalink
feat: improve comment handling during compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
zeldan committed Aug 29, 2024

Verified

This commit was signed with the committer’s verified signature.
battery-staple Rohen Giralt
1 parent 0ada288 commit 86ea0ff
Showing 2 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/exercises/exercise_06.rs
Original file line number Diff line number Diff line change
@@ -61,7 +61,7 @@ pub fn Component() -> impl IntoView {
</div>

<div class="flex flex-col gap-1">
<h3 class="text-xl font-bold">Step 3: Call Your Functions</h3>
<h3 class="text-xl font-bold">Step 3: Call Your Greet Functions</h3>
<pre
on:click={
let exercise_06 = exercise_06.clone();
@@ -81,7 +81,7 @@ pub fn Component() -> impl IntoView {
</div>

<div class="flex flex-col gap-1">
<h3 class="text-xl font-bold">Step 4: Call Your Greet Functions</h3>
<h3 class="text-xl font-bold">Step 4: Call Your Dice Functions</h3>
<pre
on:click={
let exercise_06 = exercise_06.clone();
18 changes: 12 additions & 6 deletions src/server/compile.rs
Original file line number Diff line number Diff line change
@@ -18,17 +18,23 @@ pub async fn compile(session_id: String, code: String) -> Result<String, ServerF
let sed_command = cfg!(target_os = "macos").then(|| "gsed").unwrap_or("sed");
let modified_code = format!("{};", code);
let commands = vec![
// Comment out all lines that start with `print`
format!(
"{} -i '/\\/\\//! s/print/\\/\\/print/g' {}",
"{} -i '/^ print/ s/^\\(.*\\)$/\\/\\/\\1/g' {}",
sed_command, file_path
),
format!("{} -i '$i\\{}' {}", sed_command, modified_code, file_path),
format!("rustfmt -- {}", file_path),
// Comment out all lines that end with `();`, which includes function calls
format!(
"cargo run --manifest-path ./sessions/{0}/Cargo.toml -- --name tryrust-{0}",
session_id
"{} -i '/();$/ s/^\\(.*\\)$/\\/\\/\\1/g' {}",
sed_command, file_path
),
];
format!("{} -i '$i\\{}' {}", sed_command, modified_code, file_path),
format!("rustfmt -- {}", file_path),
format!(
"cargo run --manifest-path ./sessions/{0}/Cargo.toml -- --name tryrust-{0}",
session_id
),
];
let command = commands.join(" && ");

let mut cmd = Command::new("sh");

0 comments on commit 86ea0ff

Please sign in to comment.