Sha256: f4924fda10f61a4d66c70e3a6893c14d9734d5c10f3fabc244d4cc3cfab28afa

Contents?: true

Size: 1.68 KB

Versions: 9

Compression:

Stored size: 1.68 KB

Contents

module Rouge
  module Lexers
    class Tulip < RegexLexer
      tag 'tulip'
      aliases 'tlp'
      filenames '*.tlp'
      desc 'The tulip programming language http://github.com/jneen/tulip'

      id = /\w[\w-]*/

      def self.analyze_text(text)
        return 1 if text.shebang?('tulip')
      end

      state :root do
        rule /\s+/, Text
        rule /#.*?\n/, Comment
        rule /%#{id}/, Keyword::Type
        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
        end

        rule /"{/, Str, :string_interp
        rule /'?{/, Str, :string
        rule /['"][^\s)\]]+/, Str

        rule /[$]/, Name::Variable

        rule /[-+:;~!()\[\]=?>|_%,]/, Punctuation
        rule /[.][.][.]/, Punctuation
        rule id, Name
      end

      state :string_base do
        rule /{/ do
          token Str; push
        end

        rule /}/, Str, :pop!
        rule /[$]/, Str
        rule /[^${}\\]+/, Str
      end

      state :string do
        mixin :string_base
        rule /\\/, Str
      end

      state :interp do
        rule(/[(]/) { token Punctuation; push }
        rule /[)]/, Punctuation, :pop!
        mixin :root
      end

      state :interp_root do
        rule /[(]/, Str::Interpol, :interp
        rule /[)]/, Str::Interpol, :pop!
        mixin :root
      end

      state :string_interp do
        rule /\\./, Str::Escape
        rule /[$][(]/, Str::Interpol, :interp_root
        rule /[$]#{id}?/, Name::Variable
        mixin :string_base
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
rouge-2.0.2 lib/rouge/lexers/tulip.rb
rouge-2.0.1 lib/rouge/lexers/tulip.rb
rouge-2.0.0 lib/rouge/lexers/tulip.rb
rouge-1.11.1 lib/rouge/lexers/tulip.rb
rouge-1.11.0 lib/rouge/lexers/tulip.rb
rouge-1.10.1 lib/rouge/lexers/tulip.rb
rouge-1.10.0 lib/rouge/lexers/tulip.rb
gitlab-rouge-1.9.2 lib/rouge/lexers/tulip.rb
rouge-1.9.1 lib/rouge/lexers/tulip.rb