Sha256: db290919cfbb18e30780f53d35a07ba631df3bc196f48771739012ece2ea8c4a

Contents?: true

Size: 1.9 KB

Versions: 28

Compression:

Stored size: 1.9 KB

Contents

# -*- coding: utf-8 -*- #
# frozen_string_literal: true

module Rouge
  module Lexers
    class VimL < RegexLexer
      title "VimL"
      desc "VimL, the scripting language for the Vim editor (vim.org)"
      tag 'viml'
      aliases 'vim', 'vimscript', 'ex'
      filenames '*.vim', '*.vba', '.vimrc', '.exrc', '.gvimrc',
                '_vimrc', '_exrc', '_gvimrc' # _ names for windows

      mimetypes 'text/x-vim'

      def self.keywords
        Kernel::load File.join(Lexers::BASE_DIR, 'viml/keywords.rb')
        self.keywords
      end

      state :root do
        rule %r/^(\s*)(".*?)$/ do
          groups Text, Comment
        end

        rule %r/^\s*\\/, Str::Escape

        rule %r/[ \t]+/, Text

        # TODO: regexes can have other delimiters
        rule %r(/(\\\\|\\/|[^\n/])*/), Str::Regex
        rule %r("(\\\\|\\"|[^\n"])*"), Str::Double
        rule %r('(\\\\|\\'|[^\n'])*'), Str::Single

        # if it's not a string, it's a comment.
        rule %r/(?<=\s)"[^-:.%#=*].*?$/, Comment

        rule %r/-?\d+/, Num
        rule %r/#[0-9a-f]{6}/i, Num::Hex
        rule %r/^:/, Punctuation
        rule %r/[():<>+=!\[\]{}\|,~.-]/, Punctuation
        rule %r/\b(let|if|else|endif|elseif|fun|function|endfunction)\b/,
          Keyword

        rule %r/\b(NONE|bold|italic|underline|dark|light)\b/, Name::Builtin

        rule %r/[absg]:\w+\b/, Name::Variable
        rule %r/\b\w+\b/ do |m|
          name = m[0]
          keywords = self.class.keywords

          if keywords[:command].include? name
            token Keyword
          elsif keywords[:function].include? name
            token Name::Builtin
          elsif keywords[:option].include? name
            token Name::Builtin
          elsif keywords[:auto].include? name
            token Name::Builtin
          else
            token Text
          end
        end

        # no errors in VimL!
        rule %r/./m, Text
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
rouge-4.5.1 lib/rouge/lexers/viml.rb
rouge-4.5.0 lib/rouge/lexers/viml.rb
rouge-4.4.0 lib/rouge/lexers/viml.rb
rouge-4.3.0 lib/rouge/lexers/viml.rb
rouge-4.2.1 lib/rouge/lexers/viml.rb
rouge-4.2.0 lib/rouge/lexers/viml.rb
rouge-4.1.3 lib/rouge/lexers/viml.rb
rouge-4.1.2 lib/rouge/lexers/viml.rb
rouge-4.1.1 lib/rouge/lexers/viml.rb
mumukit-content-type-1.12.1 vendor/bundle/ruby/2.7.0/gems/rouge-3.30.0/lib/rouge/lexers/viml.rb
mumukit-content-type-1.12.0 vendor/bundle/ruby/2.7.0/gems/rouge-3.30.0/lib/rouge/lexers/viml.rb
rouge-4.1.0 lib/rouge/lexers/viml.rb
rouge-4.0.1 lib/rouge/lexers/viml.rb
rouge-4.0.0 lib/rouge/lexers/viml.rb
rouge-3.30.0 lib/rouge/lexers/viml.rb
rouge-3.29.0 lib/rouge/lexers/viml.rb
rouge-3.28.0 lib/rouge/lexers/viml.rb
rouge-3.27.0 lib/rouge/lexers/viml.rb
rouge-3.26.1 lib/rouge/lexers/viml.rb
mumukit-content-type-1.11.1 vendor/bundle/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexers/viml.rb