From 90de7d61d991b17d88e051ec1152f773052614ca Mon Sep 17 00:00:00 2001 From: Peter Oberndorfer Date: Tue, 20 Sep 2016 21:21:45 +0200 Subject: [PATCH] (GRAM): Recognize assert!, assert_eq! and assert_ne! macros This improves navigation and code highlighting inside the following macros: assert!(a == b); debug_assert!(a == b); assert_eq!(a, b); debug_assert_eq!(a, b); assert_ne!(a, b); debug_assert_ne!(a, b); Format arguments are supported: assert!(a == b, "Text {} {} syntax", "with", "format"); assert!(a == b, "Some text"); assert_eq!(a, b, "Some text"); assert_ne!(a, b, "Some text"); Different parenthesis are supported: assert!(a == b); assert![a == b]; assert!{a == b}; Fixes #636 assert_ne! is stable since Rust 1.12. rust-lang/rust#35074 --- .../org/rust/lang/core/grammar/rust.bnf | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/org/rust/lang/core/grammar/rust.bnf b/src/main/kotlin/org/rust/lang/core/grammar/rust.bnf index a02a5778e5c..4b9a19da192 100644 --- a/src/main/kotlin/org/rust/lang/core/grammar/rust.bnf +++ b/src/main/kotlin/org/rust/lang/core/grammar/rust.bnf @@ -173,7 +173,7 @@ extends (".*_attr") = attr elementType ("expr_like_macro|item_like_macro") = macro - extends ("(try|format_like)_macro") = macro + extends ("(try|format_like|assert|assert_eq)_macro") = macro elementType (".*_macro_invocation|macro_rules_invocation") = macro_invocation generateTokens=false @@ -1004,6 +1004,8 @@ item_like_macro ::= macro_invocation item_macro_arg try_macro ::= try_macro_invocation try_macro_args { pin = 1 } format_like_macro ::= format_like_macro_invocation format_macro_args { pin = 1 } +assert_macro ::= assert_macro_invocation assert_macro_args { pin = 1 } +assert_eq_macro ::= assert_eq_macro_invocation assert_eq_macro_args { pin = 1 } macro_definition ::= macro_rules_invocation IDENTIFIER item_macro_arg { pin = 1 @@ -1012,6 +1014,8 @@ macro_definition ::= macro_rules_invocation IDENTIFIER item_macro_arg { private build_in_macro ::= try_macro | format_like_macro + | assert_macro + | assert_eq_macro private zz_macro_call ::= build_in_macro | expr_like_macro { pin(".*") = macro_invocation } private zz_macro_item ::= macro_definition | item_like_macro { @@ -1039,6 +1043,14 @@ format_like_macro_invocation ::= ( "format" | "trace" | "warn" ) '!' +assert_macro_invocation ::= ( "assert" + | "debug_assert") '!' + +assert_eq_macro_invocation ::= ( "assert_eq" + | "assert_ne" + | "debug_assert_eq" + | "debug_assert_ne") '!' + // Arguments macro_arg ::= <> @@ -1051,6 +1063,12 @@ item_macro_arg ::= '(' token_trees ')' ';' try_macro_args ::= <> +private zz_assert_macro_args ::= any_expr [ ',' <> ] +assert_macro_args ::= <> + +private zz_assert_eq_macro_args ::= any_expr ',' any_expr [ ',' <> ] +assert_eq_macro_args ::= <> + format_macro_args ::= <> ] >> format_macro_arg ::= [ IDENTIFIER '=' ] any_expr