]> git.lizzy.rs Git - rust.git/commitdiff
Change macro to function
authorEvgenii P <eupn@protonmail.com>
Fri, 9 Aug 2019 08:04:13 +0000 (15:04 +0700)
committerEvgenii P <eupn@protonmail.com>
Fri, 9 Aug 2019 08:04:13 +0000 (15:04 +0700)
crates/ra_syntax/src/parsing/lexer.rs

index 7a9bc355d12016c9127fc1ac341ebdbd901eba7f..06822ea9175253cc10defc1338b99079d70a61a1 100644 (file)
@@ -12,19 +12,17 @@ pub struct Token {
     pub len: TextUnit,
 }
 
-macro_rules! match_literal_kind {
-    ($kind:expr) => {
-        match $kind {
-            ra_rustc_lexer::LiteralKind::Int { .. } => INT_NUMBER,
-            ra_rustc_lexer::LiteralKind::Float { .. } => FLOAT_NUMBER,
-            ra_rustc_lexer::LiteralKind::Char { .. } => CHAR,
-            ra_rustc_lexer::LiteralKind::Byte { .. } => BYTE,
-            ra_rustc_lexer::LiteralKind::Str { .. } => STRING,
-            ra_rustc_lexer::LiteralKind::ByteStr { .. } => BYTE_STRING,
-            ra_rustc_lexer::LiteralKind::RawStr { .. } => RAW_STRING,
-            ra_rustc_lexer::LiteralKind::RawByteStr { .. } => RAW_BYTE_STRING,
-        }
-    };
+fn match_literal_kind(kind: ra_rustc_lexer::LiteralKind) -> SyntaxKind {
+    match kind {
+        ra_rustc_lexer::LiteralKind::Int { .. } => INT_NUMBER,
+        ra_rustc_lexer::LiteralKind::Float { .. } => FLOAT_NUMBER,
+        ra_rustc_lexer::LiteralKind::Char { .. } => CHAR,
+        ra_rustc_lexer::LiteralKind::Byte { .. } => BYTE,
+        ra_rustc_lexer::LiteralKind::Str { .. } => STRING,
+        ra_rustc_lexer::LiteralKind::ByteStr { .. } => BYTE_STRING,
+        ra_rustc_lexer::LiteralKind::RawStr { .. } => RAW_STRING,
+        ra_rustc_lexer::LiteralKind::RawByteStr { .. } => RAW_BYTE_STRING,
+    }
 }
 
 /// Break a string up into its component tokens
@@ -68,7 +66,7 @@ macro_rules! decompose {
                 }
             }
             ra_rustc_lexer::TokenKind::RawIdent => IDENT,
-            ra_rustc_lexer::TokenKind::Literal { kind, .. } => match_literal_kind!(kind),
+            ra_rustc_lexer::TokenKind::Literal { kind, .. } => match_literal_kind(kind),
             ra_rustc_lexer::TokenKind::Lifetime { .. } => LIFETIME,
             ra_rustc_lexer::TokenKind::Semi => SEMI,
             ra_rustc_lexer::TokenKind::Comma => COMMA,
@@ -137,7 +135,7 @@ pub fn classify_literal(text: &str) -> Option<Token> {
         return None;
     }
     let kind = match t.kind {
-        ra_rustc_lexer::TokenKind::Literal { kind, .. } => match_literal_kind!(kind),
+        ra_rustc_lexer::TokenKind::Literal { kind, .. } => match_literal_kind(kind),
         _ => return None,
     };
     Some(Token { kind, len: TextUnit::from_usize(t.len) })