From d3de2ab656c325975c665d81440aad3dd6296b0f Mon Sep 17 00:00:00 2001 From: David Hewson Date: Sun, 29 Oct 2017 13:42:35 +0000 Subject: [PATCH 1/2] handle comments around parameters and types in general --- RustEnhanced.sublime-syntax | 1 + syntax_test_rust.rs | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/RustEnhanced.sublime-syntax b/RustEnhanced.sublime-syntax index 96db8f4f..dcf0f934 100644 --- a/RustEnhanced.sublime-syntax +++ b/RustEnhanced.sublime-syntax @@ -446,6 +446,7 @@ contexts: pop: true type-any-identifier: + - include: comments - include: support-type - include: return-type - match: '&' diff --git a/syntax_test_rust.rs b/syntax_test_rust.rs index 538ad41f..3056aa30 100644 --- a/syntax_test_rust.rs +++ b/syntax_test_rust.rs @@ -1097,4 +1097,11 @@ where T: AsRef; //^^^^^^^^^^^^^^^ meta.struct // ^^^ meta.struct meta.where storage.type -// ^ punctuation.terminator \ No newline at end of file +// ^ punctuation.terminator + +fn foo i32>(f: F) { +// ^^^^^^^ meta.generic comment + let lam = |time: i32 /* comment */, other: i32| { +// ^^^^^^^^^^^^^ meta.function.parameters comment + }; +} From 3e6ebe5cd2effd68357f2e1bc8a4c44803ccad16 Mon Sep 17 00:00:00 2001 From: David Hewson Date: Fri, 27 Oct 2017 00:14:55 +0100 Subject: [PATCH 2/2] replace after-operator with check for type declaration syntax the after-operator was to deal with type declarations of the style used in `forward_ref_binop` which contains `type Output = <$t as $imp<$u>>::Output;` there is a more precise way to deal with this and it fixes other macro syntax highlighting such as in mdo (although it uses a custom operator so all bets are off) --- RustEnhanced.sublime-syntax | 11 ++++++----- syntax_test_rust.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/RustEnhanced.sublime-syntax b/RustEnhanced.sublime-syntax index dcf0f934..f7ddbe29 100644 --- a/RustEnhanced.sublime-syntax +++ b/RustEnhanced.sublime-syntax @@ -71,6 +71,12 @@ contexts: 1: storage.modifier.rust 2: storage.type.type.rust 3: entity.name.type.rust + push: + - match: '=(?!=)' + scope: keyword.operator.rust + push: after-operator + - match: '(?=\S)' + pop: true - match: '\b(?:(pub)\s+)?(trait)\s+({{identifier}})\b' captures: @@ -129,7 +135,6 @@ contexts: - match: \breturn\b scope: keyword.control.rust - push: after-operator - match: \b(as|in|box)\b scope: keyword.operator.rust @@ -213,18 +218,14 @@ contexts: # match blocks containing just enums - match: '=>' scope: keyword.operator.rust - push: after-operator - match: '=(?!=)' scope: keyword.operator.rust - push: after-operator - match: '[;,]' - push: after-operator - match: ':' scope: punctuation.separator.rust - push: after-operator - match: '\.\.\.' scope: keyword.operator.rust diff --git a/syntax_test_rust.rs b/syntax_test_rust.rs index 3056aa30..1d852c4b 100644 --- a/syntax_test_rust.rs +++ b/syntax_test_rust.rs @@ -1105,3 +1105,31 @@ fn foo i32>(f: F) { // ^^^^^^^^^^^^^ meta.function.parameters comment }; } + +// mdo example +fn main() { + // exporting the monadic functions for the Iterator monad (similar + // to list comprehension) + use mdo::iter::{bind, ret, mzero}; + + let l = bind(1i32..11, move |z| + bind(1..z, move |x| + bind(x..z, move |y| + bind(if x * x + y * y == z * z { ret(()) } + else { mzero() }, + move |_| + ret((x, y, z)) + )))).collect::>(); + println!("{:?}", l); + + // the same thing, using the mdo! macro + let l = mdo! { + z =<< 1i32..11; + x =<< 1..z; +// ^^^ keyword.operator + y =<< x..z; + when x * x + y * y == z * z; + ret ret((x, y, z)) + }.collect::>(); + println!("{:?}", l); +}