lib/rouge/lexers/cpp.rb in rouge-0.3.4 vs lib/rouge/lexers/cpp.rb in rouge-0.3.5
- old
+ new
@@ -46,21 +46,45 @@
# optional comments or whitespace
ws = %r((?:\s|//.*?\n|/[*].*?[*]/)+)
id = /[a-zA-Z_][a-zA-Z0-9]*/
- state :whitespace do
- rule /^#if\s+0/, 'Comment.Preproc', :if_0
- rule /^#/, 'Comment.Preproc', :macro
- rule /^#{ws}#if\s+0\b/, 'Comment.Preproc', :if_0
- rule /^#{ws}#/, 'Comment.Preproc', :macro
- rule /\s+/m, 'Text'
+ start { push :bol }
+
+ state :bol do
+ mixin :inline_whitespace
+ rule /#if\s+0/ do
+ token 'Comment.Preproc'
+ pop!; push :if_0
+ end
+
+ rule /#/ do
+ token 'Comment.Preproc'
+ pop!; push :macro
+ end
+
+ rule(//) { pop! }
+ end
+
+ state :inline_whitespace do
+ rule /[ \t\r]+/, 'Text'
rule /\\\n/, 'Text'
- rule %r(/(\\\n)?/(\n|(.|\n)*?[^\\]\n)), 'Comment.Single'
- rule %r(/(\\\n)?[*](.|\n)*?[*](\\\n)?/), 'Comment.Multiline'
+ rule %r(/(\\\n)?[*].*?[*](\\\n)?/)m, 'Comment.Multiline'
end
+ state :whitespace do
+ mixin :inline_whitespace
+ rule %r(/(\\\n)?/(\n|(.|\n)*?[^\\]\n)), 'Comment.Single', :bol
+ rule /\n/, 'Text', :bol
+ end
+
+ state :multiline_comment do
+ rule %r([*](\\\n)?/), 'Comment.Multiline', :pop!
+ rule %r([*]), 'Comment.Multiline'
+ rule %r([^*]+), 'Comment.Multiline'
+ end
+
state :root do
mixin :whitespace
rule /L?"/, 'Literal.String', :string
rule %r(L?'(\\.|\\[0-7]{1,3}|\\x[a-f0-9]{1,2}|[^\\'\n])')i, 'Literal.String.Char'
@@ -115,10 +139,13 @@
rule %r([^/\n]+), 'Comment.Preproc'
rule %r(/[*].*?[*]/)m, 'Comment.Multiliine'
rule %r(//.*$), 'Comment.Single'
rule %r(/), 'Comment.Preproc'
rule /(?<=\\)\n/, 'Comment.Preproc'
- rule /\n/, 'Comment.Preproc', :pop!
+ rule /\n/ do
+ token 'Comment.Preproc'
+ pop!; push :bol
+ end
end
state :if_0 do
rule /^\s*#if.*?(?<!\\)\n/, 'Comment.Preproc', :if_0
rule /^\s*#el(?:se|if).*\n/, 'Comment.Preproc', :pop!