Skip to content

Commit d3c5761

Browse files
Merge pull request #40 from augmentable-dev/add-rust
a bit of restructuring, and add support for rust
2 parents 00d6555 + 6f8ea54 commit d3c5761

File tree

4 files changed

+113
-59
lines changed

4 files changed

+113
-59
lines changed

pkg/comments/comments.go

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -13,65 +13,6 @@ import (
1313
"gopkg.in/src-d/go-git.v4/plumbing/object"
1414
)
1515

16-
// CStyleCommentOptions ...
17-
var CStyleCommentOptions *lege.ParseOptions = &lege.ParseOptions{
18-
Boundaries: []lege.Boundary{
19-
{
20-
Start: "//",
21-
End: "\n",
22-
},
23-
{
24-
Start: "/*",
25-
End: "*/",
26-
},
27-
},
28-
}
29-
30-
// HashStyleCommentOptions ...
31-
var HashStyleCommentOptions *lege.ParseOptions = &lege.ParseOptions{
32-
Boundaries: []lege.Boundary{
33-
{
34-
Start: "#",
35-
End: "\n",
36-
},
37-
},
38-
}
39-
40-
// LispStyleCommentOptions ..
41-
var LispStyleCommentOptions *lege.ParseOptions = &lege.ParseOptions{
42-
Boundaries: []lege.Boundary{
43-
{
44-
Start: ";",
45-
End: "\n",
46-
},
47-
},
48-
}
49-
50-
// Language is a source language (i.e. "Go")
51-
type Language string
52-
53-
// LanguageParseOptions keeps track of source languages and their corresponding comment options
54-
var LanguageParseOptions map[Language]*lege.ParseOptions = map[Language]*lege.ParseOptions{
55-
"Go": CStyleCommentOptions,
56-
"Java": CStyleCommentOptions,
57-
"C": CStyleCommentOptions,
58-
"C++": CStyleCommentOptions,
59-
"C#": CStyleCommentOptions,
60-
"JavaScript": CStyleCommentOptions,
61-
"Python": HashStyleCommentOptions,
62-
"Ruby": HashStyleCommentOptions,
63-
"PHP": CStyleCommentOptions,
64-
"Shell": HashStyleCommentOptions,
65-
"Visual Basic": {Boundaries: []lege.Boundary{{Start: "'", End: "\n"}}},
66-
"TypeScript": CStyleCommentOptions,
67-
"Objective-C": CStyleCommentOptions,
68-
"Groovy": CStyleCommentOptions,
69-
"Swift": CStyleCommentOptions,
70-
"Common Lisp": LispStyleCommentOptions,
71-
"Emacs Lisp": LispStyleCommentOptions,
72-
"R": HashStyleCommentOptions,
73-
}
74-
7516
// Comments is a list of comments
7617
type Comments []*Comment
7718

pkg/comments/comments_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,19 @@ func TestLispFiles(t *testing.T) {
3131
t.Fail()
3232
}
3333
}
34+
35+
func TestRustFiles(t *testing.T) {
36+
var comments Comments
37+
err := SearchDir("testdata/rust", func(comment *Comment) {
38+
comments = append(comments, comment)
39+
})
40+
if err != nil {
41+
t.Fatal(err)
42+
}
43+
44+
// TODO: break the different comment types out into separate files?
45+
// once the issue with lege is worked out for handling the different comment types
46+
if len(comments) != 21 {
47+
t.Fail()
48+
}
49+
}

pkg/comments/languages.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package comments
2+
3+
import "github.com/augmentable-dev/lege"
4+
5+
// CStyleCommentOptions ...
6+
var CStyleCommentOptions *lege.ParseOptions = &lege.ParseOptions{
7+
Boundaries: []lege.Boundary{
8+
{
9+
Start: "//",
10+
End: "\n",
11+
},
12+
{
13+
Start: "/*",
14+
End: "*/",
15+
},
16+
},
17+
}
18+
19+
// HashStyleCommentOptions ...
20+
var HashStyleCommentOptions *lege.ParseOptions = &lege.ParseOptions{
21+
Boundaries: []lege.Boundary{
22+
{
23+
Start: "#",
24+
End: "\n",
25+
},
26+
},
27+
}
28+
29+
// LispStyleCommentOptions ..
30+
var LispStyleCommentOptions *lege.ParseOptions = &lege.ParseOptions{
31+
Boundaries: []lege.Boundary{
32+
{
33+
Start: ";",
34+
End: "\n",
35+
},
36+
},
37+
}
38+
39+
// Language is a source language (i.e. "Go")
40+
type Language string
41+
42+
// LanguageParseOptions keeps track of source languages and their corresponding comment options
43+
var LanguageParseOptions map[Language]*lege.ParseOptions = map[Language]*lege.ParseOptions{
44+
"Go": CStyleCommentOptions,
45+
"Java": CStyleCommentOptions,
46+
"C": CStyleCommentOptions,
47+
"C++": CStyleCommentOptions,
48+
"C#": CStyleCommentOptions,
49+
"JavaScript": CStyleCommentOptions,
50+
"Python": HashStyleCommentOptions,
51+
"Ruby": HashStyleCommentOptions,
52+
"PHP": CStyleCommentOptions,
53+
"Shell": HashStyleCommentOptions,
54+
"Visual Basic": {Boundaries: []lege.Boundary{{Start: "'", End: "\n"}}},
55+
"TypeScript": CStyleCommentOptions,
56+
"Objective-C": CStyleCommentOptions,
57+
"Groovy": CStyleCommentOptions,
58+
"Swift": CStyleCommentOptions,
59+
"Common Lisp": LispStyleCommentOptions,
60+
"Emacs Lisp": LispStyleCommentOptions,
61+
"R": HashStyleCommentOptions,
62+
63+
// TODO Currently, the underlying pkg that does the parsing/plucking (lege) doesn't properly support precedance
64+
// so lines beginning with /// or //! will be picked up by this start // and include a / or ! preceding the comment
65+
"Rust": {Boundaries: []lege.Boundary{{Start: "///", End: "\n"}, {Start: "//!", End: "\n"}, {Start: "//", End: "\n"}}},
66+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Line comments are anything after ‘//’ and extend to the end of the line.
2+
3+
let x = 5; // This is also a line comment.
4+
5+
// If you have a long explanation for something, you can put line comments next
6+
// to each other. Put a space between the // and your comment so that it’s
7+
// more readable.
8+
9+
10+
/// Adds one to the number given.
11+
///
12+
/// # Examples
13+
///
14+
/// ```
15+
/// let five = 5;
16+
///
17+
/// assert_eq!(6, add_one(5));
18+
/// # fn add_one(x: i32) -> i32 {
19+
/// # x + 1
20+
/// # }
21+
/// ```
22+
fn add_one(x: i32) -> i32 {
23+
x + 1
24+
}
25+
26+
27+
//! # The Rust Standard Library
28+
//!
29+
//! The Rust Standard Library provides the essential runtime
30+
//! functionality for building portable Rust software.
31+

0 commit comments

Comments
 (0)