Sha256: ec5db4e4fd80858a088c7b2748e3fd960742ad9768479d54b060f12b4564eac3

Contents?: true

Size: 1.67 KB

Versions: 28

Compression:

Stored size: 1.67 KB

Contents

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

module Rouge
  module Lexers
    class LLVM < RegexLexer
      title "LLVM"
      desc 'The LLVM Compiler Infrastructure (http://llvm.org/)'
      tag 'llvm'

      filenames '*.ll'
      mimetypes 'text/x-llvm'

      string = /"[^"]*?"/
      identifier = /([-a-zA-Z$._][-a-zA-Z$._0-9]*|#{string})/

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

      def self.instructions
        Kernel::load File.join(Lexers::BASE_DIR, "llvm/keywords.rb")
        instructions
      end

      def self.types
        Kernel::load File.join(Lexers::BASE_DIR, "llvm/keywords.rb")
        types
      end

      state :basic do
        rule %r/;.*?$/, Comment::Single
        rule %r/\s+/, Text

        rule %r/#{identifier}\s*:/, Name::Label

        rule %r/@(#{identifier}|\d+)/, Name::Variable::Global
        rule %r/#\d+/, Name::Variable::Global
        rule %r/(%|!)#{identifier}/, Name::Variable
        rule %r/(%|!)\d+/, Name::Variable

        rule %r/c?#{string}/, Str

        rule %r/0[xX][a-fA-F0-9]+/, Num
        rule %r/-?\d+(?:[.]\d+)?(?:[eE][-+]?\d+(?:[.]\d+)?)?/, Num

        rule %r/[=<>{}\[\]()*.,!]|x/, Punctuation
      end

      state :root do
        mixin :basic

        rule %r/i[1-9]\d*/, Keyword::Type

        rule %r/\w+/ do |m|
          if self.class.types.include? m[0]
            token Keyword::Type
          elsif self.class.instructions.include? m[0]
            token Keyword
          elsif self.class.keywords.include? m[0]
            token Keyword
          else
            token Error
          end
        end
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 2 rubygems

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