/usr/lib/ruby/vendor_ruby/rugments/lexers/matlab.rb is in ruby-rugments 1.0.0~beta8-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | module Rugments
module Lexers
class Matlab < RegexLexer
title 'MATLAB'
desc 'Matlab'
tag 'matlab'
aliases 'm'
filenames '*.m'
mimetypes 'text/x-matlab', 'application/x-matlab'
def self.analyze_text(text)
return 0.4 if text.match(/^\s*% /) # % comments are a dead giveaway
end
def self.keywords
@keywords = Set.new %w(
break case catch classdef continue else elseif end for function
global if otherwise parfor persistent return spmd switch try while
)
end
def self.builtins
load Pathname.new(__FILE__).dirname.join('matlab/builtins.rb')
builtins
end
state :root do
rule /\s+/m, Text # Whitespace
rule %r([{]%.*?%[}])m, Comment::Multiline
rule /%.*$/, Comment::Single
rule /([.][.][.])(.*?)$/ do
groups(Keyword, Comment)
end
rule /^(!)(.*?)(?=%|$)/ do |m|
token Keyword, m[1]
delegate Shell, m[2]
end
rule /[a-zA-Z][_a-zA-Z0-9]*/m do |m|
match = m[0]
if self.class.keywords.include? match
token Keyword
elsif self.class.builtins.include? match
token Name::Builtin
else
token Name
end
end
rule %r{[(){};:,\/\\\]\[]}, Punctuation
rule /~=|==|<<|>>|[-~+\/*%=<>&^|.]/, Operator
rule /(\d+\.\d*|\d*\.\d+)(e[+-]?[0-9]+)?/i, Num::Float
rule /\d+e[+-]?[0-9]+/i, Num::Float
rule /\d+L/, Num::Integer::Long
rule /\d+/, Num::Integer
rule /'/, Str::Single, :string
end
state :string do
rule /[^']+/, Str::Single
rule /''/, Str::Escape
rule /'/, Str::Single, :pop!
end
end
end
end
|