Skip to content

Commit

Permalink
(GRAM): Recognize assert!, assert_eq! and assert_ne! macros
Browse files Browse the repository at this point in the history
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);

For assert! and debug_assert! format arguments are supported:
assert!(a == b, "Some text");
assert!(a == b, "Text {} {} syntax", "with", "format");

Different parenthesis are supported:
assert!(a == b);
assert![a == b];
assert!{a == b};

Fixes intellij-rust#636

assert_ne! is stable since Rust 1.12.
rust-lang/rust#35074
  • Loading branch information
kumbayo committed Oct 7, 2016
1 parent 938f195 commit e6c1aff
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/main/kotlin/org/rust/lang/core/grammar/rust.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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 ::= <<macro_args_delim token_trees>>

Expand All @@ -1051,6 +1063,12 @@ item_macro_arg ::= '(' token_trees ')' ';'

try_macro_args ::= <<macro_args_delim any_expr>>

private zz_assert_macro_args ::= any_expr [ ',' <<comma_separated_list format_macro_arg>> ]
assert_macro_args ::= <<macro_args_delim zz_assert_macro_args>>

private zz_assert_eq_macro_args ::= any_expr ',' any_expr
assert_eq_macro_args ::= <<macro_args_delim zz_assert_eq_macro_args>>

format_macro_args ::= <<macro_args_delim [ <<comma_separated_list format_macro_arg>> ] >>
format_macro_arg ::= [ IDENTIFIER '=' ] any_expr

Expand Down

0 comments on commit e6c1aff

Please sign in to comment.