Skip to content

Commit

Permalink
Add support for lean, and fixed single comment regression (#70)
Browse files Browse the repository at this point in the history
* Add Lean

* Handle single-line comments inside multi-line ones.
  • Loading branch information
gebner authored and Aaronepower committed Sep 29, 2016
1 parent 5ced28a commit 9faa8d4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ Julia
JSON
JSX
Kotlin
Lean
LESS
LD Script
LISP
Expand Down
5 changes: 5 additions & 0 deletions src/lib/language/language_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ pub enum LanguageType {
Jsx,
/// Kotlin
Kotlin,
/// Lean
Lean,
/// Less
Less,
/// LinkerScript
Expand Down Expand Up @@ -236,6 +238,7 @@ impl LanguageType {
Jsx => "JSX",
Julia => "Julia",
Kotlin => "Kotlin",
Lean => "Lean",
Less => "LESS",
LinkerScript => "LD Script",
Lisp => "LISP",
Expand Down Expand Up @@ -335,6 +338,7 @@ impl LanguageType {
"jsx" => Some(Jsx),
"kt" | "kts" => Some(Kotlin),
"lds" => Some(LinkerScript),
"lean" | "hlean" => Some(Lean),
"less" => Some(Less),
"lua" => Some(Lua),
"m" => Some(ObjectiveC),
Expand Down Expand Up @@ -439,6 +443,7 @@ impl<'a> From<&'a str> for LanguageType {
"Json" => Json,
"Jsx" => Jsx,
"Kotlin" => Kotlin,
"Lean" => Lean,
"Less" => Less,
"LinkerScript" => LinkerScript,
"Lisp" => Lisp,
Expand Down
1 change: 1 addition & 0 deletions src/lib/language/languages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ impl Languages {
.set_quotes(vec![("\"", "\""), ("\"\"\"", "\"\"\"")]),
Kotlin => Language::new_c().nested()
.set_quotes(vec![("\"", "\""), ("\"\"\"", "\"\"\"")]),
Lean => Language::new(vec!["--"], vec![("/-", "-/")]).nested(),
Less => Language::new_c(),
LinkerScript => Language::new_c(),
Lisp => Language::new(vec![";"], vec![("#|", "|#")]).nested(),
Expand Down
17 changes: 14 additions & 3 deletions src/lib/utils/multi_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ pub fn handle_multi_line(line: &str,
}


for comment in &language.line_comment {
if window.starts_with(comment) {
break 'window;
if stack.is_empty() {
for comment in &language.line_comment {
if window.starts_with(comment) {
break 'window;
}
}
}

Expand Down Expand Up @@ -117,6 +119,15 @@ mod tests {
assert_eq!(stack.len(), 0);
}

#[test]
fn single_comment_in_multi() {
let mut stack = vec![];
let mut quote = None;
let language = Language::new_c();
handle_multi_line("Hello /* // */ world", &language, &mut stack, &mut quote);
assert_eq!(stack.len(), 0);
}

#[test]
fn comment_start() {
let mut stack = vec![];
Expand Down

0 comments on commit 9faa8d4

Please sign in to comment.