lib/rouge/lexers/coffeescript.rb in rouge-0.2.5 vs lib/rouge/lexers/coffeescript.rb in rouge-0.2.6
- old
+ new
@@ -34,20 +34,23 @@
parseInt document window
)
end
id = /[$a-zA-Z_][a-zA-Z0-9_]*/
- lval = /@?#{id}([.]#{id})*/
state :comments_and_whitespace do
rule /\s+/m, 'Text'
rule /###.*?###/m, 'Comment.Multiline'
rule /#.*?\n/, 'Comment.Single'
end
state :multiline_regex do
+ # this order is important, so that #{ isn't interpreted
+ # as a comment
+ mixin :has_interpolation
mixin :comments_and_whitespace
+
rule %r(///([gim]+\b|\B)), 'Literal.String.Regex', :pop!
rule %r(/), 'Literal.String.Regex'
rule %r([^/#]+), 'Literal.String.Regex'
end
@@ -88,12 +91,24 @@
push :slash_starts_regex
end
rule /#{id}(?=\s*:)/, 'Name.Attribute', :slash_starts_regex
- rule /#{id}/, 'Name.Other', :slash_starts_regex
+ rule /#{id}/ do |m|
+ if self.class.keywords.include? m[0]
+ token 'Keyword'
+ elsif self.class.constants.include? m[0]
+ token 'Name.Constant'
+ elsif self.class.builtins.include? m[0]
+ token 'Name.Builtin'
+ else
+ token 'Name.Other'
+ end
+ push :slash_starts_regex
+ end
+
rule /[{(\[;,]/, 'Punctuation', :slash_starts_regex
rule /[})\].]/, 'Punctuation'
rule /\d+[.]\d+([eE]\d+)?[fd]?/, 'Literal.Number.Float'
rule /0x[0-9a-fA-F]+/, 'Literal.Number.Hex'
@@ -150,27 +165,9 @@
state :tsqs do
rule /'''/, 'Literal.String', :pop!
rule /'/, 'Literal.String'
mixin :single_strings
- end
-
- postprocess 'Name' do |tok, val|
- if tok.name == 'Name.Attribute'
- if self.class.keywords.include? val
- tok = 'Error' # keywords as attributes = nono
- else
- # pass. leave attributes alone.
- end
- elsif self.class.keywords.include? val
- tok = 'Keyword'
- elsif self.class.constants.include? val
- tok = 'Name.Constant'
- elsif self.class.builtins.include? val
- tok = 'Name.Builtin'
- end
-
- token tok, val
end
end
end
end