lib/rouge/lexers/tulip.rb in rouge-2.0.2 vs lib/rouge/lexers/tulip.rb in rouge-2.0.3
- old
+ new
@@ -1,74 +1,76 @@
module Rouge
module Lexers
class Tulip < RegexLexer
+ desc 'the tulip programming language (twitter.com/tuliplang)'
tag 'tulip'
- aliases 'tlp'
+ aliases 'tulip'
+
filenames '*.tlp'
- desc 'The tulip programming language http://github.com/jneen/tulip'
- id = /\w[\w-]*/
+ mimetypes 'text/x-tulip', 'application/x-tulip'
def self.analyze_text(text)
- return 1 if text.shebang?('tulip')
+ return 1 if text.shebang? 'tulip'
+ return 0
end
- state :root do
+ id = /[a-z][\w-]*/i
+ upper_id = /[A-Z][\w-]*/
+
+ state :comments_and_whitespace do
rule /\s+/, Text
- rule /#.*?\n/, Comment
- rule /%#{id}/, Keyword::Type
+ rule /#.*?$/, Comment
+ end
+
+ state :root do
+ mixin :comments_and_whitespace
+
rule /@#{id}/, Keyword
- rule /[.][.]?#{id}/, Name::Label
- rule /-#{id}[?]?/, Str::Symbol
- rule /\d+/, Num
- rule %r(/#{id}?), Name::Decorator
- rule %r((#{id}/)(#{id})) do
- groups Name::Namespace, Name::Variable
+
+
+ rule /[>,!\[\]:{}()=;\/]/, Punctuation
+
+ rule /(\\#{id})([{])/ do
+ groups Name::Variable, Str
+ push :nested_string
end
- rule /"{/, Str, :string_interp
- rule /'?{/, Str, :string
- rule /['"][^\s)\]]+/, Str
+ rule /\\#{id}/, Name::Function
- rule /[$]/, Name::Variable
+ rule /"/, Str, :dq
- rule /[-+:;~!()\[\]=?>|_%,]/, Punctuation
- rule /[.][.][.]/, Punctuation
- rule id, Name
- end
+ rule /'{/, Str, :nested_string
- state :string_base do
- rule /{/ do
- token Str; push
- end
+ rule /[.]#{id}/, Name::Tag
+ rule /[$]#{id}/, Name::Variable
- rule /}/, Str, :pop!
- rule /[$]/, Str
- rule /[^${}\\]+/, Str
- end
+ rule /[0-9]+([.][0-9]+)?/, Num
- state :string do
- mixin :string_base
- rule /\\/, Str
- end
+ rule /#{id}/, Name
- state :interp do
- rule(/[(]/) { token Punctuation; push }
- rule /[)]/, Punctuation, :pop!
- mixin :root
+ rule /</, Comment::Preproc, :angle_brackets
end
- state :interp_root do
- rule /[(]/, Str::Interpol, :interp
- rule /[)]/, Str::Interpol, :pop!
- mixin :root
+ state :dq do
+ rule /[^\\"]+/, Str
+ rule /"/, Str, :pop!
+ rule /\\./, Str::Escape
end
- state :string_interp do
+ state :nested_string do
rule /\\./, Str::Escape
- rule /[$][(]/, Str::Interpol, :interp_root
- rule /[$]#{id}?/, Name::Variable
- mixin :string_base
+ rule(/{/) { token Str; push :nested_string }
+ rule(/}/) { token Str; pop! }
+ rule(/[^{}\\]+/) { token Str }
+ end
+
+ state :angle_brackets do
+ mixin :comments_and_whitespace
+ rule />/, Comment::Preproc, :pop!
+ rule /[*:]/, Punctuation
+ rule /#{upper_id}/, Keyword::Type
+ rule /#{id}/, Name::Variable
end
end
end
end