Skip to content

Commit

Permalink
Extend rust support (#58)
Browse files Browse the repository at this point in the history
* Extend Rust support

Adds support for macro definitions and modules in Rust.

* Add tuple support for Rust
  • Loading branch information
meqif authored and jacktasia committed Jul 6, 2016
1 parent 384d0ac commit d75ae09
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions dumb-jump.el
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,15 @@

;; rust
(:type "variable" :supports ("ag" "grep") :language "rust"
:regex "\\blet\\s+(mut\\s+)?JJJ(:\\s*[^=\\n]+)?\\s*=\\s*[^=\\n]+"
:regex "\\blet\\s+(\\\([^=\\n]*)?(mut\s+)?JJJ([^=\\n]*\\\))?(:\\s*[^=\\n]+)?\\s*=\\s*[^=\\n]+"
:tests ("let test = 1234;"
"let test: u32 = 1234;"
"let test: Vec<u32> = Vec::new();"
"let mut test = 1234;"
"let mut test: Vec<u32> = Vec::new();"))
"let mut test: Vec<u32> = Vec::new();"
"let (a, test, b) = (1, 2, 3);"
"let (a, mut test, mut b) = (1, 2, 3);"
"let (mut a, mut test): (u32, usize) = (1, 2);"))

(:type "variable" :supports ("ag" "grep") :language "rust"
:regex "\\bconst\\s+JJJ:\\s*[^=\\n]+\\s*=[^=\\n]+"
Expand All @@ -359,25 +362,34 @@
(:type "variable" :supports ("ag" "grep") :language "rust"
:regex "\\bfn\\s+.+\\s*\\\((.+,\\s+)?JJJ:\\s*[^=\\n]+\\s*(,\\s*.+)*\\\)"
:tests ("fn abc(test: u32) -> u32 {"
"fn abc(x: u32, y: u32, test: Vec<u32>, z: Vec<Foo>)"))
"fn abc(x: u32, y: u32, test: Vec<u32>, z: Vec<Foo>)"
"fn abc(x: u32, y: u32, test: &mut Vec<u32>, z: Vec<Foo>)"))

;; "if let" and "while let" desugaring
(:type "variable" :supports ("ag" "grep") :language "rust"
:regex "(if|while)\\s+let\\s+\\w+\\\((mut\\s+)?JJJ\\\)\\s*=\\s*[^=\\n]+\\s*{"
:regex "(if|while)\\s+let\\s+([^=\\n]+)?(mut\\s+)?JJJ([^=\\n\\\(]+)?\\s*=\\s*[^=\\n]+"
:tests ("if let Some(test) = abc() {"
"if let Some(mut test) = abc() {"
"if let Ok(test) = abc() {"
"if let Ok(mut test) = abc() {"
"if let Foo(mut test) = foo {"
"if let test = abc() {"
"if let Some(test) = abc()"
"if let Some((a, test, b)) = abc()"
"while let Some(test) = abc() {"
"while let Some(mut test) = abc() {"
"while let Ok(test) = abc() {"
"while let Ok(mut test) = abc() {"
"while let Foo(mut test) = foo {"))
"while let Ok(mut test) = abc() {")
:not ("while let test(foo) = abc() {"))

(:type "function" :supports ("ag" "grep") :language "rust"
:regex "\\bfn\\s+JJJ\\s*\\\("
:tests ("fn test(asdf: u32)" "fn test()" "pub fn test()"))

(:type "function" :supports ("ag" "grep") :language "rust"
:regex "\\bmacro_rules!\\s+JJJ"
:tests ("macro_rules! test"))

(:type "type" :supports ("ag" "grep") :language "rust"
:regex "struct\\s+JJJ\\s*[{\\\(]?"
:tests ("struct test(u32, u32)"
Expand All @@ -398,7 +410,11 @@
:tests ("impl test {"
"impl abc::test {"
"impl std::io::Read for test {"
"impl std::io::Read for abc::test {")))
"impl std::io::Read for abc::test {"))

(:type "type" :supports ("ag" "grep") :language "rust"
:regex "mod\\s+JJJ\\s*{?"
:tests ("mod test;" "pub mod test {")))

"List of regex patttern templates organized by language
and type to use for generating the grep command"
Expand Down

0 comments on commit d75ae09

Please sign in to comment.