From 338983c3382b369bb3ccaf187b48e44400cab90c Mon Sep 17 00:00:00 2001
From: stratact <stratact1@gmail.com>
Date: Thu, 21 Jun 2018 12:42:59 -0700
Subject: [PATCH] Support `-` and `+` in alias names and remove math
 functionality in alias code

---
 src/lib/builtins/variables.rs  | 50 +---------------------------------
 src/lib/shell/variables/mod.rs |  2 +-
 2 files changed, 2 insertions(+), 50 deletions(-)

diff --git a/src/lib/builtins/variables.rs b/src/lib/builtins/variables.rs
index eaf2ac9f..3ef89787 100644
--- a/src/lib/builtins/variables.rs
+++ b/src/lib/builtins/variables.rs
@@ -23,15 +23,6 @@ enum Binding {
     ListEntries,
     KeyOnly(Identifier),
     KeyValue(Identifier, Value),
-    Math(Identifier, Operator, f32),
-    MathInvalid(Value),
-}
-
-enum Operator {
-    Plus,
-    Minus,
-    Divide,
-    Multiply,
 }
 
 /// Parses alias as a `(key, value)` tuple.
@@ -42,7 +33,6 @@ fn parse_alias(args: &str) -> Binding {
     // Find the key and advance the iterator until the equals operator is found.
     let mut key = "".to_owned();
     let mut found_key = false;
-    let mut operator = None;
 
     // Scans through characters until the key is found, then continues to scan until
     // the equals operator is found.
@@ -50,34 +40,6 @@ fn parse_alias(args: &str) -> Binding {
         match character {
             ' ' if key.is_empty() => (),
             ' ' => found_key = true,
-            '+' => {
-                if char_iter.next() == Some('=') {
-                    operator = Some(Operator::Plus);
-                    found_key = true;
-                }
-                break;
-            }
-            '-' => {
-                if char_iter.next() == Some('=') {
-                    operator = Some(Operator::Minus);
-                    found_key = true;
-                }
-                break;
-            }
-            '*' => {
-                if char_iter.next() == Some('=') {
-                    operator = Some(Operator::Multiply);
-                    found_key = true;
-                }
-                break;
-            }
-            '/' => {
-                if char_iter.next() == Some('=') {
-                    operator = Some(Operator::Divide);
-                    found_key = true;
-                }
-                break;
-            }
             '=' => {
                 found_key = true;
                 break;
@@ -98,13 +60,7 @@ fn parse_alias(args: &str) -> Binding {
         } else if !Variables::is_valid_variable_name(&key) {
             Binding::InvalidKey(key)
         } else {
-            match operator {
-                Some(operator) => match value.parse::<f32>() {
-                    Ok(value) => Binding::Math(key, operator, value),
-                    Err(_) => Binding::MathInvalid(value),
-                },
-                None => Binding::KeyValue(key, value),
-            }
+            Binding::KeyValue(key, value)
         }
     }
 }
@@ -125,10 +81,6 @@ pub(crate) fn alias(vars: &mut Variables, args: &str) -> i32 {
             eprintln!("ion: please provide value for alias '{}'", key);
             return FAILURE;
         }
-        _ => {
-            eprintln!("ion: invalid alias syntax");
-            return FAILURE;
-        }
     }
     SUCCESS
 }
diff --git a/src/lib/shell/variables/mod.rs b/src/lib/shell/variables/mod.rs
index 07a84de6..8a5cc047 100644
--- a/src/lib/shell/variables/mod.rs
+++ b/src/lib/shell/variables/mod.rs
@@ -315,7 +315,7 @@ impl Variables {
     }
 
     pub(crate) fn is_valid_variable_character(c: char) -> bool {
-        c.is_alphanumeric() || c == '_' || c == '?' || c == '.'
+        c.is_alphanumeric() || c == '_' || c == '?' || c == '.' || c == '-' || c == '+'
     }
 
     pub fn variables(&self) -> impl Iterator<Item = (&SmallString, &Value)> {
-- 
GitLab