lib/rouge/lexers/sass/common.rb in rouge-0.5.1 vs lib/rouge/lexers/sass/common.rb in rouge-0.5.2
- old
+ new
@@ -1,181 +1,172 @@
module Rouge
module Lexers
# shared states with SCSS
- # TODO: make this less nasty to do
- module SassCommon
- include Token::Tokens
+ class SassCommon < RegexLexer
+ id = /[\w-]+/
- def self.included(klass)
- klass.class_eval(&INCLUDED_PROC)
- end
+ state :content_common do
+ rule /@for\b/, Keyword, :for
+ rule /@(debug|warn|if|while)/, Keyword, :value
+ rule /(@mixin)(\s+)(#{id})/ do
+ group Keyword; group Text; group Name::Function
+ push :value
+ end
- INCLUDED_PROC = proc do
- id = /[\w-]+/
+ rule /@extend\b/, Keyword, :selector
- state :content_common do
- rule /@for\b/, Keyword, :for
- rule /@(debug|warn|if|while)/, Keyword, :value
- rule /(@mixin)(\s+)(#{id})/ do
- group Keyword; group Text; group Name::Function
- push :value
- end
+ rule /(@include)(\s+)(#{id})/ do
+ group Keyword; group Text; group Name::Decorator
+ push :value
+ end
- rule /@extend\b/, Keyword, :selector
+ rule /@#{id}/, Keyword, :selector
- rule /(@include)(\s+)(#{id})/ do
- group Keyword; group Text; group Name::Decorator
- push :value
- end
-
- rule /@#{id}/, Keyword, :selector
-
- # $variable: assignment
- rule /([$]#{id})([ \t]*)(:)/ do
- group Name::Variable; group Text; group Punctuation
- push :value
- end
+ # $variable: assignment
+ rule /([$]#{id})([ \t]*)(:)/ do
+ group Name::Variable; group Text; group Punctuation
+ push :value
end
+ end
- state :value do
- mixin :end_section
- rule /[ \t]+/, Text
- rule /[$]#{id}/, Name::Variable
- rule /url[(]/, Str::Other, :string_url
- rule /#{id}(?=\s*[(])/, Name::Function
- rule /%#{id}/, Name::Decorator
+ state :value do
+ mixin :end_section
+ rule /[ \t]+/, Text
+ rule /[$]#{id}/, Name::Variable
+ rule /url[(]/, Str::Other, :string_url
+ rule /#{id}(?=\s*[(])/, Name::Function
+ rule /%#{id}/, Name::Decorator
- # named literals
- rule /(true|false)\b/, Name::Builtin::Pseudo
- rule /(and|or|not)\b/, Operator::Word
+ # named literals
+ rule /(true|false)\b/, Name::Builtin::Pseudo
+ rule /(and|or|not)\b/, Operator::Word
- # colors and numbers
- rule /#[a-z0-9]{1,6}/i, Num::Hex
- rule /-?\d+(%|[a-z]+)?/, Num
- rule /-?\d*\.\d+(%|[a-z]+)?/, Num::Integer
+ # colors and numbers
+ rule /#[a-z0-9]{1,6}/i, Num::Hex
+ rule /-?\d+(%|[a-z]+)?/, Num
+ rule /-?\d*\.\d+(%|[a-z]+)?/, Num::Integer
- mixin :has_strings
- mixin :has_interp
+ mixin :has_strings
+ mixin :has_interp
- rule /[~^*!&%<>\|+=@:,.\/?-]+/, Operator
- rule /[\[\]()]+/, Punctuation
- rule %r(/[*]), Comment::Multiline, :inline_comment
- rule %r(//[^\n]*), Comment::Single
+ rule /[~^*!&%<>\|+=@:,.\/?-]+/, Operator
+ rule /[\[\]()]+/, Punctuation
+ rule %r(/[*]), Comment::Multiline, :inline_comment
+ rule %r(//[^\n]*), Comment::Single
- # identifiers
- rule(id) do |m|
- if CSS.builtins.include? m[0]
- token Name::Builtin
- elsif CSS.constants.include? m[0]
- token Name::Constant
- else
- token Name
- end
+ # identifiers
+ rule(id) do |m|
+ if CSS.builtins.include? m[0]
+ token Name::Builtin
+ elsif CSS.constants.include? m[0]
+ token Name::Constant
+ else
+ token Name
end
end
+ end
- state :has_interp do
- rule /[#][{]/, Str::Interpol, :interpolation
- end
+ state :has_interp do
+ rule /[#][{]/, Str::Interpol, :interpolation
+ end
- state :has_strings do
- rule /"/, Str::Double, :dq
- rule /'/, Str::Single, :sq
- end
+ state :has_strings do
+ rule /"/, Str::Double, :dq
+ rule /'/, Str::Single, :sq
+ end
- state :interpolation do
- rule /}/, Str::Interpol, :pop!
- mixin :value
- end
+ state :interpolation do
+ rule /}/, Str::Interpol, :pop!
+ mixin :value
+ end
- state :selector do
- mixin :end_section
+ state :selector do
+ mixin :end_section
- mixin :has_strings
- mixin :has_interp
- rule /[ \t]+/, Text
- rule /:/, Name::Decorator, :pseudo_class
- rule /[.]/, Name::Class, :class
- rule /#/, Name::Namespace, :id
- rule /%/, Name::Variable, :placeholder
- rule id, Name::Tag
- rule /&/, Keyword
- rule /[~^*!&\[\]()<>\|+=@:;,.\/?-]/, Operator
- end
+ mixin :has_strings
+ mixin :has_interp
+ rule /[ \t]+/, Text
+ rule /:/, Name::Decorator, :pseudo_class
+ rule /[.]/, Name::Class, :class
+ rule /#/, Name::Namespace, :id
+ rule /%/, Name::Variable, :placeholder
+ rule id, Name::Tag
+ rule /&/, Keyword
+ rule /[~^*!&\[\]()<>\|+=@:;,.\/?-]/, Operator
+ end
- state :dq do
- rule /"/, Str::Double, :pop!
- mixin :has_interp
- rule /(\\.|#(?![{])|[^\n"#])+/, Str::Double
- end
+ state :dq do
+ rule /"/, Str::Double, :pop!
+ mixin :has_interp
+ rule /(\\.|#(?![{])|[^\n"#])+/, Str::Double
+ end
- state :sq do
- rule /'/, Str::Single, :pop!
- mixin :has_interp
- rule /(\\.|#(?![{])|[^\n'#])+/, Str::Single
- end
+ state :sq do
+ rule /'/, Str::Single, :pop!
+ mixin :has_interp
+ rule /(\\.|#(?![{])|[^\n'#])+/, Str::Single
+ end
- state :string_url do
- rule /[)]/, Str::Other, :pop!
- rule /(\\.|#(?![{])|[^\n)#])+/, Str::Other
- mixin :has_interp
- end
+ state :string_url do
+ rule /[)]/, Str::Other, :pop!
+ rule /(\\.|#(?![{])|[^\n)#])+/, Str::Other
+ mixin :has_interp
+ end
- state :selector_piece do
- mixin :has_interp
- rule(//) { pop! }
- end
+ state :selector_piece do
+ mixin :has_interp
+ rule(//) { pop! }
+ end
- state :pseudo_class do
- rule id, Name::Decorator
- mixin :selector_piece
- end
+ state :pseudo_class do
+ rule id, Name::Decorator
+ mixin :selector_piece
+ end
- state :class do
- rule id, Name::Class
- mixin :selector_piece
- end
+ state :class do
+ rule id, Name::Class
+ mixin :selector_piece
+ end
- state :id do
- rule id, Name::Namespace
- mixin :selector_piece
- end
+ state :id do
+ rule id, Name::Namespace
+ mixin :selector_piece
+ end
- state :placeholder do
- rule id, Name::Variable
- mixin :selector_piece
- end
+ state :placeholder do
+ rule id, Name::Variable
+ mixin :selector_piece
+ end
- state :for do
- rule /(from|to|through)/, Operator::Word
- mixin :value
- end
+ state :for do
+ rule /(from|to|through)/, Operator::Word
+ mixin :value
+ end
- state :attr_common do
- mixin :has_interp
- rule id do |m|
- if CSS.attributes.include? m[0]
- token Name::Label
- else
- token Name::Attribute
- end
+ state :attr_common do
+ mixin :has_interp
+ rule id do |m|
+ if CSS.attributes.include? m[0]
+ token Name::Label
+ else
+ token Name::Attribute
end
end
+ end
- state :attribute do
- mixin :attr_common
+ state :attribute do
+ mixin :attr_common
- rule /([ \t]*)(:)/ do
- group Text; group Punctuation
- push :value
- end
+ rule /([ \t]*)(:)/ do
+ group Text; group Punctuation
+ push :value
end
+ end
- state :inline_comment do
- rule /(\\#|#(?=[^\n{])|\*(?=[^\n\/])|[^\n#*])+/, Comment::Multiline
- mixin :has_interp
- rule %r([*]/), Comment::Multiline, :pop!
- end
+ state :inline_comment do
+ rule /(\\#|#(?=[^\n{])|\*(?=[^\n\/])|[^\n#*])+/, Comment::Multiline
+ mixin :has_interp
+ rule %r([*]/), Comment::Multiline, :pop!
end
end
end
end