Permalink
Browse files

Process multi-line comment symbols first

Avoids matching single-line comment symbols in multi-line blocks.
Fixes failing test.
  • Loading branch information...
1 parent 8e01ed9 commit 00cce9b40f20a8c5d142025b19bf9f992d489a29 @jacobrask committed Apr 1, 2012
Showing with 16 additions and 11 deletions.
  1. +7 −5 lib/languages.js
  2. +9 −6 src/languages.coffee
View
@@ -16,17 +16,19 @@
if (this.symbols.single) {
this.regexs.single = new RegExp('^' + this.symbols.single);
}
- this.regexs.multi_start = new RegExp('^\\' + this.symbols.multi[0].split('').join('\\'));
- this.regexs.multi_end = new RegExp('\\' + this.symbols.multi[1].split('').join('\\'));
+ this.regexs.multiStart = new RegExp('^\\' + this.symbols.multi[0].split('').join('\\'));
+ this.regexs.multiEnd = new RegExp('\\' + this.symbols.multi[1].split('').join('\\'));
}
Language.prototype.checkType = function(str) {
- if (str.match(this.regexs.multi_start) && str.match(this.regexs.multi_end) || (this.regexs.single != null) && str.match(this.regexs.single)) {
+ if (str.match(this.regexs.multiStart) && str.match(this.regexs.multiEnd)) {
return 'single';
- } else if (str.match(this.regexs.multi_start)) {
+ } else if (str.match(this.regexs.multiStart)) {
return 'multistart';
- } else if (str.match(this.regexs.multi_end)) {
+ } else if (str.match(this.regexs.multiEnd)) {
return 'multiend';
+ } else if ((this.regexs.single != null) && str.match(this.regexs.single)) {
+ return 'single';
} else {
return 'code';
}
View
@@ -12,18 +12,21 @@ class Language
# We match only comments without any code on the same line.
@regexs.single = new RegExp('^' + @symbols.single) if @symbols.single
# Build regex's by splitting string and then joining with escape chars.
- @regexs.multi_start = new RegExp '^\\' + @symbols.multi[0].split('').join('\\')
- @regexs.multi_end = new RegExp '\\' + @symbols.multi[1].split('').join('\\')
+ @regexs.multiStart = new RegExp '^\\' + @symbols.multi[0].split('').join('\\')
+ @regexs.multiEnd = new RegExp '\\' + @symbols.multi[1].split('').join('\\')
# Check type of string.
checkType: (str) ->
- if str.match(@regexs.multi_start) and str.match(@regexs.multi_end) \
- or @regexs.single? and str.match @regexs.single
+ # Check for multi-line comment symbols first to avoid matching single-line
+ # comment symbols in multi-line blocks.
+ if str.match(@regexs.multiStart) and str.match(@regexs.multiEnd)
'single'
- else if str.match @regexs.multi_start
+ else if str.match @regexs.multiStart
'multistart'
- else if str.match @regexs.multi_end
+ else if str.match @regexs.multiEnd
'multiend'
+ else if @regexs.single? and str.match @regexs.single
+ 'single'
else
'code'

0 comments on commit 00cce9b

Please sign in to comment.