Skip to content

Commit

Permalink
Implement reading SyntaxKind from strings
Browse files Browse the repository at this point in the history
  • Loading branch information
abhillman committed May 8, 2024
1 parent 01e6582 commit 6e4480c
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 8 deletions.
58 changes: 51 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ name = "all-packages"

[dependencies]
rowan = "0.15.0"
strum = "0.26.2"
strum_macros = "0.26.2"

[dev-dependencies]
criterion = "0.3.0"
Expand Down
15 changes: 14 additions & 1 deletion src/kinds.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
use strum_macros::EnumString;

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, EnumString)]
#[repr(u16)]
#[allow(non_camel_case_types)]
pub enum SyntaxKind {
Expand Down Expand Up @@ -134,3 +136,14 @@ impl SyntaxKind {
matches!(self, TOKEN_COMMENT | TOKEN_ERROR | TOKEN_WHITESPACE)
}
}

#[cfg(test)]
mod tests {
use crate::SyntaxKind;

#[test]
fn try_from() {
let kind = SyntaxKind::try_from("TOKEN_COMMENT").unwrap();
assert_eq!(kind, SyntaxKind::TOKEN_COMMENT);
}
}

0 comments on commit 6e4480c

Please sign in to comment.