lib/rouge/lexers/javascript.rb in rouge-2.0.1 vs lib/rouge/lexers/javascript.rb in rouge-2.0.2
- old
+ new
@@ -137,10 +137,15 @@
rule %r([-<>+*%&|\^/!=]=?), Operator, :expr_start
rule /[(\[,]/, Punctuation, :expr_start
rule /;/, Punctuation, :statement
rule /[)\].]/, Punctuation
+ rule /`/ do
+ token Str::Double
+ push :template_string
+ end
+
rule /[?]/ do
token Punctuation
push :ternary
push :expr_start
end
@@ -168,14 +173,20 @@
rule /[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?/, Num::Float
rule /0x[0-9a-fA-F]+/, Num::Hex
rule /[0-9]+/, Num::Integer
rule /"(\\\\|\\"|[^"])*"/, Str::Double
rule /'(\\\\|\\'|[^'])*'/, Str::Single
+ rule /:/, Punctuation
end
# braced parts that aren't object literals
state :statement do
+ rule /case\b/ do
+ token Keyword
+ goto :expr_start
+ end
+
rule /(#{id})(\s*)(:)/ do
groups Name::Label, Text, Punctuation
end
rule /[{}]/, Punctuation
@@ -211,9 +222,21 @@
rule /:/ do
token Punctuation
goto :expr_start
end
+ mixin :root
+ end
+
+ # template strings
+ state :template_string do
+ rule /\${/, Punctuation, :template_string_expr
+ rule /`/, Str::Double, :pop!
+ rule /(\\\\|\\[\$`]|[^\$`]|\$[^{])*/, Str::Double
+ end
+
+ state :template_string_expr do
+ rule /}/, Punctuation, :pop!
mixin :root
end
end
class JSON < RegexLexer