Skip to content

Commit

Permalink
chore: allow common ascii punctuation in attributes (#3733)
Browse files Browse the repository at this point in the history
# Description

spotted an issue with punctuation inside a `#[test(should_fail_with =
"")]` block ([comment on original
issue](#3372 (comment)))

## Problem\*

Resolves #3372 (an extension of this original issue)

## Summary\*

I built off of the original work done over here #3374 but simplified
things down to just cover all common punctuation

## Documentation\*

Check one:
- [x] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[Exceptional Case]** Documentation to be submitted in a separate
PR.

# PR Checklist\*

- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.

---------

Co-authored-by: kevaundray <kevtheappdev@gmail.com>
  • Loading branch information
sambarnes and kevaundray authored Dec 9, 2023
1 parent ee31cba commit 506b0c1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
9 changes: 6 additions & 3 deletions compiler/noirc_frontend/src/lexer/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,15 +633,18 @@ mod tests {
}

#[test]
fn test_attribute_with_apostrophe() {
let input = r#"#[test(should_fail_with = "the eagle's feathers")]"#;
fn test_attribute_with_common_punctuation() {
let input =
r#"#[test(should_fail_with = "stmt. q? exclaim! & symbols, 1% shouldn't fail")]"#;
let mut lexer = Lexer::new(input);

let token = lexer.next_token().unwrap().token().clone();
assert_eq!(
token,
Token::Attribute(Attribute::Function(FunctionAttribute::Test(
TestScope::ShouldFailWith { reason: "the eagle's feathers".to_owned().into() }
TestScope::ShouldFailWith {
reason: "stmt. q? exclaim! & symbols, 1% shouldn't fail".to_owned().into()
}
)))
);
}
Expand Down
7 changes: 1 addition & 6 deletions compiler/noirc_frontend/src/lexer/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,13 +468,8 @@ impl Attribute {
.all(|ch| {
ch.is_ascii_alphabetic()
|| ch.is_numeric()
|| ch == '_'
|| ch == '('
|| ch == ')'
|| ch == '='
|| ch == '"'
|| ch.is_ascii_punctuation()
|| ch == ' '
|| ch == '\''
})
.then_some(());

Expand Down

0 comments on commit 506b0c1

Please sign in to comment.