1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# -*- 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
|