Fix var underscores

This commit is contained in:
Gregory Schier
2025-01-13 07:41:13 -08:00
parent 34c0449a40
commit d37cfad862

View File

@@ -271,7 +271,7 @@ impl Parser {
let is_valid = if start_pos == self.pos {
ch.is_alphabetic() // First char has to be alphabetic
} else {
ch.is_alphanumeric() || ch == '-' || ch == '-'
ch.is_alphanumeric() || ch == '-' || ch == '_'
};
if is_valid {
text.push(ch);
@@ -441,6 +441,20 @@ mod tests {
);
}
#[test]
fn var_underscores() {
let mut p = Parser::new("${[ a_b ]}");
assert_eq!(
p.parse().tokens,
vec![
Token::Tag {
val: Val::Var { name: "a_b".into() }
},
Token::Eof
]
);
}
#[test]
fn var_prefixes() {
let mut p = Parser::new("${[ -a ]}${[ _a ]}${[ 0a ]}");