diff --git a/examples/multiline-arrays.ion b/examples/multiline-arrays.ion new file mode 100644 index 0000000000000000000000000000000000000000..ce9174a379e2a911a35f4094401fb8898e1c4125 --- /dev/null +++ b/examples/multiline-arrays.ion @@ -0,0 +1,16 @@ +let x = [ + a # a comment + b # another comment + ab#cd #with a comment +] + +echo @x + +let y = [ + a + # a comment + #another comment +] + +echo @x + diff --git a/examples/multiline-arrays.out b/examples/multiline-arrays.out new file mode 100644 index 0000000000000000000000000000000000000000..ddf27e8e8d8185efacadd9c1865444da842aa78a --- /dev/null +++ b/examples/multiline-arrays.out @@ -0,0 +1,2 @@ +a b ab#cd +a b ab#cd diff --git a/src/shell/binary/terminate.rs b/src/shell/binary/terminate.rs index 2cb932d9b34e907f10806b579b1e02873992a8da..c288c206ab6d6b5a0369df894c1ec93522462457 100644 --- a/src/shell/binary/terminate.rs +++ b/src/shell/binary/terminate.rs @@ -11,8 +11,26 @@ pub(crate) fn terminate_script_quotes<I: Iterator<Item = String>>( while !buffer.is_terminated() { loop { if let Some(command) = lines.next() { - buffer.append(&command); - break; + if !command.starts_with('#') { + let mut start = 0; + let cmd: &str = loop { + if start >= command.len() { + break &command; + } + + match command[start..].find('#').map(|x| x + start) { + Some(pos) if command.as_bytes()[pos-1] != b' ' => { + start = pos + 1; + } + Some(pos) => { + break &command[..pos] + } + None => break &command + } + }; + buffer.append(cmd); + break; + } } else { eprintln!("ion: unterminated quote in script"); return FAILURE; @@ -40,7 +58,9 @@ pub(crate) fn terminate_quotes(shell: &mut Shell, command: String) -> Result<Str shell.flow_control.level += 1; while !buffer.is_terminated() { if let Some(command) = shell.readln() { - buffer.append(&command); + if !command.starts_with('#') { + buffer.append(&command); + } } else { return Err(()); }