diff --git a/setup/install.ab b/setup/install.ab index 0425fdf9..5f1ad551 100644 --- a/setup/install.ab +++ b/setup/install.ab @@ -1,6 +1,8 @@ +import { hasFailed } from "std" + let name = "AmberNative" let target = "amber" -let tag = "0.3.0-alpha" +let tag = "0.3.1-alpha" let place = "/opt/amber" unsafe { @@ -29,34 +31,26 @@ unsafe { } echo "Installing Amber" - let isDone = false - - silent $ruby -v$ - if status == 0 { - let code = "require \"open-uri\"; open(\"{target}\", \"wb\") do |file|; file << open(\"{url}\").read; end" - echo "Using ruby as a download method..." - $sudo ruby -e "{code}"$ - isDone = true - } - - silent $curl -v$ - if status == 0 { - echo "Using curl as a download method..." - $curl -o "{target}" "{url}"$ - isDone = true - } - - silent $wget -v$ - if status == 0 { - echo "Using wget as a download method..." - $wget -O "{target}" "{url}"$ - isDone = true - } - if not isDone { - echo "Neither ruby, curl or wget are installed on your system." - echo "Please install one of them and try again." - $exit 1$ + if { + not hasFailed("ruby -v") { + let code = "require \"open-uri\"; open(\"{target}\", \"wb\") do |file|; file << open(\"{url}\").read; end" + echo "Using ruby as a download method..." + $sudo ruby -e "{code}"$ + } + not hasFailed("curl -v") { + echo "Using curl as a download method..." + $curl -o "{target}" "{url}"$ + } + not hasFailed("wget -V") { + echo "Using wget as a download method..." + $wget -O "{target}" "{url}"$ + } + else { + echo "Neither ruby, curl or wget are installed on your system." + echo "Please install one of them and try again." + $exit 1$ + } } // Create directory for amber @@ -69,4 +63,4 @@ unsafe { $sudo ln -s "{place}/{target}" "/usr/local/bin/{target}"$ // Send success message echo "Amber has been installed successfully. 🎉" -} \ No newline at end of file +} diff --git a/setup/install.sh b/setup/install.sh index df6a9eec..3e4d82dd 100755 --- a/setup/install.sh +++ b/setup/install.sh @@ -1,6 +1,17 @@ +function hasFailed__18_v0 { + local command=$1 + ${command} > /dev/null 2>&1 +__AMBER_STATUS=$?; +if [ $__AMBER_STATUS != 0 ]; then +$(exit $__AMBER_STATUS) +: +fi; + __AMBER_FUN_hasFailed18_v0=$(echo $__AMBER_STATUS '!=' 0 | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//'); + return 0 +} __0_name="AmberNative"; __1_target="amber"; -__2_tag="0.3.0-alpha"; +__2_tag="0.3.1-alpha"; __3_place="/opt/amber"; __AMBER_VAL_0=$(uname -s); __AMBER_STATUS=$?; @@ -36,57 +47,35 @@ $(exit $__AMBER_STATUS) fi fi; echo "Installing Amber"; - isDone=0; - ruby -v > /dev/null 2>&1 -__AMBER_STATUS=$?; -if [ $__AMBER_STATUS != 0 ]; then -$(exit $__AMBER_STATUS) -: -fi; - if [ $(echo $__AMBER_STATUS '==' 0 | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//') != 0 ]; then + hasFailed__18_v0 "ruby -v"; + hasFailed__18_v0 "curl -v"; + hasFailed__18_v0 "wget -V"; + if [ $(echo '!' ${__AMBER_FUN_hasFailed18_v0} | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//') != 0 ]; then code="require \"open-uri\"; open(\"${__1_target}\", \"wb\") do |file|; file << open(\"${url}\").read; end"; echo "Using ruby as a download method..."; - ruby -e "${code}" -__AMBER_STATUS=$?; -if [ $__AMBER_STATUS != 0 ]; then -$(exit $__AMBER_STATUS) -: -fi; - isDone=1 -fi; - curl -v > /dev/null 2>&1 + sudo ruby -e "${code}" __AMBER_STATUS=$?; if [ $__AMBER_STATUS != 0 ]; then $(exit $__AMBER_STATUS) : -fi; - if [ $(echo $__AMBER_STATUS '==' 0 | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//') != 0 ]; then +fi +elif [ $(echo '!' ${__AMBER_FUN_hasFailed18_v0} | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//') != 0 ]; then echo "Using curl as a download method..."; curl -o "${__1_target}" "${url}" __AMBER_STATUS=$?; if [ $__AMBER_STATUS != 0 ]; then $(exit $__AMBER_STATUS) : -fi; - isDone=1 -fi; - wget -v > /dev/null 2>&1 -__AMBER_STATUS=$?; -if [ $__AMBER_STATUS != 0 ]; then -$(exit $__AMBER_STATUS) -: -fi; - if [ $(echo $__AMBER_STATUS '==' 0 | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//') != 0 ]; then +fi +elif [ $(echo '!' ${__AMBER_FUN_hasFailed18_v0} | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//') != 0 ]; then echo "Using wget as a download method..."; wget -O "${__1_target}" "${url}" __AMBER_STATUS=$?; if [ $__AMBER_STATUS != 0 ]; then $(exit $__AMBER_STATUS) : -fi; - isDone=1 -fi; - if [ $(echo '!' ${isDone} | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//') != 0 ]; then +fi +else echo "Neither ruby, curl or wget are installed on your system."; echo "Please install one of them and try again."; exit 1 diff --git a/src/modules/condition/ifchain.rs b/src/modules/condition/ifchain.rs index a20b6a4a..cf6d699f 100644 --- a/src/modules/condition/ifchain.rs +++ b/src/modules/condition/ifchain.rs @@ -38,10 +38,13 @@ impl SyntaxModule for IfChain { is_else = true; break } - // Handle end of the if chain - if syntax(meta, &mut cond).is_err() { + if token(meta, "}").is_ok() { break } + // Handle end of the if chain + if let Err(err) = syntax(meta, &mut cond) { + return Err(err) + } match token(meta, "{") { Ok(_) => { syntax(meta, &mut block)?; diff --git a/src/modules/expression/binop/mod.rs b/src/modules/expression/binop/mod.rs index eff5f43f..e153de1c 100644 --- a/src/modules/expression/binop/mod.rs +++ b/src/modules/expression/binop/mod.rs @@ -1,5 +1,5 @@ use heraclitus_compiler::prelude::*; -use crate::{utils::{metadata::ParserMetadata}, modules::types::{Type, Typed}}; +use crate::{utils::metadata::ParserMetadata, modules::types::{Type, Typed}}; use super::super::expression::expr::Expr; pub mod add; diff --git a/src/modules/function/declaration.rs b/src/modules/function/declaration.rs index 9ce64721..f4a58f54 100644 --- a/src/modules/function/declaration.rs +++ b/src/modules/function/declaration.rs @@ -110,6 +110,10 @@ impl SyntaxModule for FunctionDeclaration { self.arg_types.push(Type::Generic); } } + let tok = meta.get_current_token(); + if token(meta, "=").is_ok() { + return error!(meta, tok, "Default values for function arguments are not yet supported") + } match token(meta, ")") { Ok(_) => break, Err(_) => token(meta, ",")? diff --git a/src/modules/function/invocation_utils.rs b/src/modules/function/invocation_utils.rs index e314253b..03182b09 100644 --- a/src/modules/function/invocation_utils.rs +++ b/src/modules/function/invocation_utils.rs @@ -46,8 +46,11 @@ fn run_function_with_args(meta: &mut ParserMetadata, mut fun: FunctionDecl, args } let mut ctx = meta.fun_cache.get_context(fun.id).unwrap().clone(); let mut block = Block::new(); + let mut binop_border = None; // Swap the contexts to use the function context swap(&mut ctx, &mut meta.context); + // Swap the binop border to clear it + swap(&mut binop_border, &mut meta.binop_border); // Create a sub context for new variables meta.push_scope(); for (kind, name, is_ref) in izip!(args, &fun.arg_names, &fun.arg_refs) { @@ -63,6 +66,8 @@ fn run_function_with_args(meta: &mut ParserMetadata, mut fun: FunctionDecl, args meta.pop_scope(); // Restore old context swap(&mut ctx, &mut meta.context); + // Restore old binop border + swap(&mut binop_border, &mut meta.binop_border); // Set the new return type or null if nothing was returned if let Type::Generic = fun.returns { fun.returns = ctx.fun_ret_type.clone().unwrap_or_else(|| Type::Null); diff --git a/src/modules/statement/stmt.rs b/src/modules/statement/stmt.rs index 9c9ada33..e2d8651c 100644 --- a/src/modules/statement/stmt.rs +++ b/src/modules/statement/stmt.rs @@ -151,7 +151,7 @@ impl TranslateModule for Statement { // Translate the statement let translated = self.translate_match(meta, self.value.as_ref().unwrap()); // This is a workaround that handles $(...) which cannot be used as a statement - let translated = (matches!(self.value, Some(StatementType::Expr(_))) || translated.starts_with('$') || translated.starts_with("\"$")) + let translated = (matches!(self.value, Some(StatementType::Expr(_))) || translated.starts_with("$(") || translated.starts_with("\"$(")) .then(|| format!("echo {} > /dev/null 2>&1", translated)) .unwrap_or_else(|| translated); // Get all the required supplemental statements diff --git a/src/std/main.ab b/src/std/main.ab index 12e28b4d..1c4beeb6 100644 --- a/src/std/main.ab +++ b/src/std/main.ab @@ -73,7 +73,6 @@ pub fun parse(text: Text): Num { return text as Num } -#[allow_absurd_cast] pub fun chars(text: Text): [Text] { let chars = [Text] unsafe $for ((i=0; i<\$\{#{nameof text}}; i++)); do @@ -86,3 +85,12 @@ pub fun chars(text: Text): [Text] { pub fun sum(list: [Num]): Num { return unsafe $echo "{list}" | awk '\{s=0; for (i=1; i<=NF; i++) s+=\$i; print s}'$ as Num } + +pub fun hasFailed(command: Text): Bool { + unsafe silent ${command}$ + return status != 0 +} + +pub fun exit(code: Num): Null { + unsafe $exit "{code}"$ +} diff --git a/src/tests/validity.rs b/src/tests/validity.rs index c8f3b66a..df45db6b 100644 --- a/src/tests/validity.rs +++ b/src/tests/validity.rs @@ -725,7 +725,7 @@ fn status() { echo status } "; - test_amber!(code, "127\n0"); + test_amber!(code, "127\n127"); } #[test]