diff --git a/examples/unicode.out b/examples/unicode.out index 783109950dc036c92dcbd7b356480f1e6513b98a..5831cf275bc8634b076de527dbfcc6dce478a5af 100644 --- a/examples/unicode.out +++ b/examples/unicode.out @@ -3,5 +3,5 @@ ӌ ion: assignment error: invalid variable name Variable names may only be (unicode) alphanumeric or `_` -The first character must be alphabetic +The first character must be alphabetic or `_` diff --git a/examples/variables.ion b/examples/variables.ion new file mode 100644 index 0000000000000000000000000000000000000000..d0db286c9b851a9449a65cef6319373a61bb3593 --- /dev/null +++ b/examples/variables.ion @@ -0,0 +1,5 @@ +let alpha_numeric_name0 = hello +let _name_with_1_leading_underscore = leading +let __2 = underscores +let ___ = ! +echo $alpha_numeric_name0 $_name_with_1_leading_underscore $__2 $___ \ No newline at end of file diff --git a/examples/variables.out b/examples/variables.out new file mode 100644 index 0000000000000000000000000000000000000000..8fff7bb59a0d11f656389cbeffe670378719482b --- /dev/null +++ b/examples/variables.out @@ -0,0 +1 @@ +hello leading underscores ! diff --git a/src/lib/parser/statement/parse.rs b/src/lib/parser/statement/parse.rs index f53642cf5213ca5df889d5bf2df49b40d034c3ff..88db1c16c4745794bc03202d4af9bf98e6d5b37b 100644 --- a/src/lib/parser/statement/parse.rs +++ b/src/lib/parser/statement/parse.rs @@ -16,7 +16,7 @@ use std::char; pub fn is_valid_name(name: &str) -> bool { let mut chars = name.chars(); - chars.next().map_or(false, char::is_alphabetic) + chars.next().map_or(false, |b| char::is_alphabetic(b) || b == '_') && chars.all(|b| b.is_alphanumeric() || b == '_') } diff --git a/src/lib/shell/assignments.rs b/src/lib/shell/assignments.rs index f762e1f5a57a8e02b868040242380151022729e5..2107dcab9fb0ec2c94514b05904e5a8f3f592efb 100644 --- a/src/lib/shell/assignments.rs +++ b/src/lib/shell/assignments.rs @@ -99,7 +99,7 @@ impl<'b> Shell<'b> { } } - /// Collect all updates to perform on variables for a given assignement action + /// Collect all updates to perform on variables for a given assignment action pub(crate) fn calculate<'a>( &mut self, actions: AssignmentActions<'a>, @@ -115,7 +115,7 @@ impl<'b> Shell<'b> { if !is_valid_name(key.name) { return Err("invalid variable name\nVariable names may only be (unicode) \ - alphanumeric or `_`\nThe first character must be alphabetic" + alphanumeric or `_`\nThe first character must be alphabetic or `_`" .to_string()); }