rouge 3.5.1 → 3.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/lib/rouge.rb +1 -0
- data/lib/rouge/cli.rb +19 -11
- data/lib/rouge/demos/ada +26 -0
- data/lib/rouge/demos/armasm +12 -0
- data/lib/rouge/demos/batchfile +3 -0
- data/lib/rouge/demos/bbcbasic +6 -0
- data/lib/rouge/demos/clean +6 -0
- data/lib/rouge/demos/cmhg +8 -0
- data/lib/rouge/demos/cuda +11 -0
- data/lib/rouge/demos/cython +6 -0
- data/lib/rouge/demos/eex +1 -0
- data/lib/rouge/demos/epp +4 -0
- data/lib/rouge/demos/gdscript +18 -0
- data/lib/rouge/demos/haxe +5 -0
- data/lib/rouge/demos/hocon +8 -0
- data/lib/rouge/demos/hql +5 -0
- data/lib/rouge/demos/jsl +3 -0
- data/lib/rouge/demos/lustre +6 -0
- data/lib/rouge/demos/lutin +18 -0
- data/lib/rouge/demos/mason +22 -0
- data/lib/rouge/demos/msgtrans +4 -0
- data/lib/rouge/demos/openedge +4 -0
- data/lib/rouge/demos/opentype_feature_file +6 -0
- data/lib/rouge/demos/plist +1 -132
- data/lib/rouge/demos/powershell +12 -48
- data/lib/rouge/demos/reasonml +12 -0
- data/lib/rouge/demos/sas +13 -0
- data/lib/rouge/demos/sparql +6 -0
- data/lib/rouge/demos/terraform +0 -15
- data/lib/rouge/demos/xojo +2 -1
- data/lib/rouge/demos/xpath +2 -0
- data/lib/rouge/demos/xquery +22 -0
- data/lib/rouge/formatters/html.rb +18 -2
- data/lib/rouge/formatters/html_line_table.rb +53 -0
- data/lib/rouge/formatters/tex.rb +14 -12
- data/lib/rouge/guessers/disambiguation.rb +12 -0
- data/lib/rouge/guessers/modeline.rb +1 -1
- data/lib/rouge/lexers/ada.rb +162 -0
- data/lib/rouge/lexers/apache.rb +1 -1
- data/lib/rouge/lexers/armasm.rb +145 -0
- data/lib/rouge/lexers/batchfile.rb +164 -0
- data/lib/rouge/lexers/bbcbasic.rb +112 -0
- data/lib/rouge/lexers/bpf.rb +12 -12
- data/lib/rouge/lexers/ceylon.rb +5 -5
- data/lib/rouge/lexers/clean.rb +156 -0
- data/lib/rouge/lexers/cmhg.rb +34 -0
- data/lib/rouge/lexers/common_lisp.rb +1 -1
- data/lib/rouge/lexers/console.rb +1 -1
- data/lib/rouge/lexers/cpp.rb +4 -1
- data/lib/rouge/lexers/cuda.rb +35 -0
- data/lib/rouge/lexers/cython.rb +151 -0
- data/lib/rouge/lexers/docker.rb +2 -2
- data/lib/rouge/lexers/eex.rb +51 -0
- data/lib/rouge/lexers/elixir.rb +25 -11
- data/lib/rouge/lexers/elm.rb +1 -1
- data/lib/rouge/lexers/epp.rb +51 -0
- data/lib/rouge/lexers/escape.rb +3 -0
- data/lib/rouge/lexers/fsharp.rb +4 -4
- data/lib/rouge/lexers/gdscript.rb +171 -0
- data/lib/rouge/lexers/gherkin.rb +4 -2
- data/lib/rouge/lexers/glsl.rb +1 -1
- data/lib/rouge/lexers/graphql.rb +10 -3
- data/lib/rouge/lexers/handlebars.rb +14 -3
- data/lib/rouge/lexers/haxe.rb +246 -0
- data/lib/rouge/lexers/hocon.rb +86 -0
- data/lib/rouge/lexers/hql.rb +139 -0
- data/lib/rouge/lexers/html.rb +2 -2
- data/lib/rouge/lexers/http.rb +6 -6
- data/lib/rouge/lexers/idlang.rb +1 -1
- data/lib/rouge/lexers/igorpro.rb +1 -1
- data/lib/rouge/lexers/javascript.rb +1 -1
- data/lib/rouge/lexers/jsl.rb +55 -0
- data/lib/rouge/lexers/json.rb +44 -6
- data/lib/rouge/lexers/jsp.rb +3 -3
- data/lib/rouge/lexers/julia.rb +1 -1
- data/lib/rouge/lexers/liquid.rb +23 -0
- data/lib/rouge/lexers/lustre.rb +79 -0
- data/lib/rouge/lexers/lutin.rb +33 -0
- data/lib/rouge/lexers/magik.rb +2 -1
- data/lib/rouge/lexers/make.rb +44 -16
- data/lib/rouge/lexers/mason.rb +115 -0
- data/lib/rouge/lexers/matlab.rb +4 -2
- data/lib/rouge/lexers/matlab/builtins.yml +3515 -0
- data/lib/rouge/lexers/mosel.rb +43 -43
- data/lib/rouge/lexers/msgtrans.rb +26 -0
- data/lib/rouge/lexers/nim.rb +2 -1
- data/lib/rouge/lexers/nix.rb +1 -1
- data/lib/rouge/lexers/ocaml.rb +12 -48
- data/lib/rouge/lexers/ocaml/common.rb +53 -0
- data/lib/rouge/lexers/openedge.rb +429 -0
- data/lib/rouge/lexers/opentype_feature_file.rb +113 -0
- data/lib/rouge/lexers/perl.rb +12 -14
- data/lib/rouge/lexers/php.rb +31 -9
- data/lib/rouge/lexers/php/builtins.rb +181 -174
- data/lib/rouge/lexers/plain_text.rb +1 -1
- data/lib/rouge/lexers/powershell.rb +181 -635
- data/lib/rouge/lexers/puppet.rb +2 -2
- data/lib/rouge/lexers/q.rb +1 -1
- data/lib/rouge/lexers/r.rb +2 -3
- data/lib/rouge/lexers/reasonml.rb +65 -0
- data/lib/rouge/lexers/ruby.rb +2 -2
- data/lib/rouge/lexers/rust.rb +12 -9
- data/lib/rouge/lexers/sas.rb +563 -0
- data/lib/rouge/lexers/scala.rb +1 -1
- data/lib/rouge/lexers/sed.rb +1 -1
- data/lib/rouge/lexers/shell.rb +1 -1
- data/lib/rouge/lexers/smarty.rb +10 -10
- data/lib/rouge/lexers/sparql.rb +129 -0
- data/lib/rouge/lexers/sql.rb +26 -6
- data/lib/rouge/lexers/swift.rb +4 -4
- data/lib/rouge/lexers/terraform.rb +8 -0
- data/lib/rouge/lexers/tex.rb +1 -1
- data/lib/rouge/lexers/toml.rb +1 -1
- data/lib/rouge/lexers/vala.rb +1 -1
- data/lib/rouge/lexers/vhdl.rb +1 -1
- data/lib/rouge/lexers/wollok.rb +1 -1
- data/lib/rouge/lexers/xml.rb +1 -1
- data/lib/rouge/lexers/xojo.rb +4 -4
- data/lib/rouge/lexers/xpath.rb +332 -0
- data/lib/rouge/lexers/xquery.rb +145 -0
- data/lib/rouge/lexers/yaml.rb +5 -3
- data/lib/rouge/regex_lexer.rb +14 -13
- data/lib/rouge/tex_theme_renderer.rb +7 -3
- data/lib/rouge/themes/magritte.rb +3 -3
- data/lib/rouge/themes/monokai_sublime.rb +2 -1
- data/lib/rouge/themes/pastie.rb +1 -1
- data/lib/rouge/themes/thankful_eyes.rb +1 -1
- data/lib/rouge/themes/tulip.rb +1 -1
- data/lib/rouge/util.rb +2 -2
- data/lib/rouge/version.rb +1 -1
- data/rouge.gemspec +4 -3
- metadata +61 -5
- data/lib/rouge/lexers/matlab/builtins.rb +0 -13
data/lib/rouge/lexers/ceylon.rb
CHANGED
@@ -31,14 +31,14 @@ module Rouge
|
|
31
31
|
rule %r((abstracts|extends|satisfies|super|given|of|out|assign)\b), Keyword::Declaration
|
32
32
|
|
33
33
|
rule %r((function|value|void|new)\b), Keyword::Type
|
34
|
-
|
34
|
+
|
35
35
|
rule %r((assembly|module|package)(\s+)) do
|
36
36
|
groups Keyword::Namespace, Text
|
37
37
|
push :import
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
rule %r((true|false|null)\b), Keyword::Constant
|
41
|
-
|
41
|
+
|
42
42
|
rule %r((class|interface|object|alias)(\s+)) do
|
43
43
|
groups Keyword::Declaration, Text
|
44
44
|
push :class
|
@@ -48,7 +48,7 @@ module Rouge
|
|
48
48
|
groups Keyword::Namespace, Text
|
49
49
|
push :import
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
rule %r("(\\\\|\\"|[^"])*"), Literal::String
|
53
53
|
rule %r('\\.'|'[^\\]'|'\\\{#[0-9a-fA-F]{4}\}'), Literal::String::Char
|
54
54
|
rule %r(".*``.*``.*"', String::Interpol
|
@@ -84,7 +84,7 @@ module Rouge
|
|
84
84
|
rule %r([a-z][\w.]*), Name::Namespace, :pop!
|
85
85
|
rule %r("(\\\\|\\"|[^"])*"), Literal::String, :pop!
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
state :comment do
|
89
89
|
rule %r([^*/]), Comment.Multiline
|
90
90
|
rule %r(/\*), Comment::Multiline, :push!
|
@@ -0,0 +1,156 @@
|
|
1
|
+
# -*- coding: utf-8 -*- #
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Rouge
|
5
|
+
module Lexers
|
6
|
+
class Clean < RegexLexer
|
7
|
+
title "Clean"
|
8
|
+
desc "The Clean programming language (clean.cs.ru.nl)"
|
9
|
+
|
10
|
+
tag 'clean'
|
11
|
+
filenames '*.dcl', '*.icl'
|
12
|
+
|
13
|
+
def self.keywords
|
14
|
+
@keywords ||= Set.new %w(
|
15
|
+
if otherwise
|
16
|
+
let in
|
17
|
+
with where
|
18
|
+
case of
|
19
|
+
infix infixl infixr
|
20
|
+
class instance
|
21
|
+
generic derive
|
22
|
+
special
|
23
|
+
implementation definition system module
|
24
|
+
from import qualified as
|
25
|
+
dynamic
|
26
|
+
code inline foreign export ccall stdcall
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
# These are literal patterns common to the ABC intermediate language and
|
31
|
+
# Clean. Clean has more extensive literal patterns (see :basic below).
|
32
|
+
state :common_literals do
|
33
|
+
rule %r/'(?:[^'\\]|\\(?:x[0-9a-fA-F]+|\d+|.))'/, Str::Char
|
34
|
+
|
35
|
+
rule %r/[+~-]?\d+\.\d+(?:E[+-]?\d+)?\b/, Num::Float
|
36
|
+
rule %r/[+~-]?\d+E[+-]?\d+\b/, Num::Float
|
37
|
+
rule %r/[+~-]?\d+/, Num::Integer
|
38
|
+
|
39
|
+
rule %r/"/, Str::Double, :string
|
40
|
+
end
|
41
|
+
|
42
|
+
state :basic do
|
43
|
+
rule %r/\s+/m, Text::Whitespace
|
44
|
+
|
45
|
+
rule %r/\/\/\*.*/, Comment::Doc
|
46
|
+
rule %r/\/\/.*/, Comment::Single
|
47
|
+
rule %r/\/\*\*/, Comment::Doc, :comment_doc
|
48
|
+
rule %r/\/\*/, Comment::Multiline, :comment
|
49
|
+
|
50
|
+
rule %r/[+~-]?0[0-7]+/, Num::Oct
|
51
|
+
rule %r/[+~-]?0x[0-9a-fA-F]+/, Num::Hex
|
52
|
+
mixin :common_literals
|
53
|
+
rule %r/(\[)(\s*)(')(?=.*?'\])/ do
|
54
|
+
groups Punctuation, Text::Whitespace, Str::Single, Punctuation
|
55
|
+
push :charlist
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# nested commenting
|
60
|
+
state :comment_doc do
|
61
|
+
rule %r/\*\//, Comment::Doc, :pop!
|
62
|
+
rule %r/\/\/.*/, Comment::Doc # Singleline comments in multiline comments are skipped
|
63
|
+
rule %r/\/\*/, Comment::Doc, :comment
|
64
|
+
rule %r/[^*\/]+/, Comment::Doc
|
65
|
+
rule %r/[*\/]/, Comment::Doc
|
66
|
+
end
|
67
|
+
|
68
|
+
# This is the same as the above, but with Multiline instead of Doc
|
69
|
+
state :comment do
|
70
|
+
rule %r/\*\//, Comment::Multiline, :pop!
|
71
|
+
rule %r/\/\/.*/, Comment::Multiline # Singleline comments in multiline comments are skipped
|
72
|
+
rule %r/\/\*/, Comment::Multiline, :comment
|
73
|
+
rule %r/[^*\/]+/, Comment::Multiline
|
74
|
+
rule %r/[*\/]/, Comment::Multiline
|
75
|
+
end
|
76
|
+
|
77
|
+
state :root do
|
78
|
+
mixin :basic
|
79
|
+
|
80
|
+
rule %r/code(\s+inline)?\s*{/, Comment::Preproc, :abc
|
81
|
+
|
82
|
+
rule %r/_*[a-z][\w_`]*/ do |m|
|
83
|
+
if self.class.keywords.include?(m[0])
|
84
|
+
token Keyword
|
85
|
+
else
|
86
|
+
token Name
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
rule %r/_*[A-Z][\w_`]*/ do |m|
|
91
|
+
if m[0]=='True' || m[0]=='False'
|
92
|
+
token Keyword::Constant
|
93
|
+
else
|
94
|
+
token Keyword::Type
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
rule %r/[^\w_\s`]/, Punctuation
|
99
|
+
rule %r/_\b/, Punctuation
|
100
|
+
end
|
101
|
+
|
102
|
+
state :escapes do
|
103
|
+
rule %r/\\x[0-9a-fA-F]{1,2}/i, Str::Escape
|
104
|
+
rule %r/\\d\d{0,3}/i, Str::Escape
|
105
|
+
rule %r/\\0[0-7]{0,3}/, Str::Escape
|
106
|
+
rule %r/\\[0-7]{1,3}/, Str::Escape
|
107
|
+
rule %r/\\[nrfbtv\\"']/, Str::Escape
|
108
|
+
end
|
109
|
+
|
110
|
+
state :string do
|
111
|
+
rule %r/"/, Str::Double, :pop!
|
112
|
+
mixin :escapes
|
113
|
+
rule %r/[^\\"]+/, Str::Double
|
114
|
+
end
|
115
|
+
|
116
|
+
state :charlist do
|
117
|
+
rule %r/(')(\])/ do
|
118
|
+
groups Str::Single, Punctuation
|
119
|
+
pop!
|
120
|
+
end
|
121
|
+
mixin :escapes
|
122
|
+
rule %r/[^\\']/, Str::Single
|
123
|
+
end
|
124
|
+
|
125
|
+
state :abc_basic do
|
126
|
+
rule %r/\s+/, Text::Whitespace
|
127
|
+
rule %r/\|.*/, Comment::Single
|
128
|
+
mixin :common_literals
|
129
|
+
end
|
130
|
+
|
131
|
+
# The ABC intermediate language can be included, similar to C's inline
|
132
|
+
# assembly. For some information about ABC, see:
|
133
|
+
# https://en.wikipedia.org/wiki/Clean_(programming_language)#The_ABC-Machine
|
134
|
+
state :abc do
|
135
|
+
mixin :abc_basic
|
136
|
+
|
137
|
+
rule %r/}/, Comment::Preproc, :pop!
|
138
|
+
rule %r/\.\w*/, Keyword, :abc_rest_of_line
|
139
|
+
rule %r/[\w_]+/, Name::Builtin, :abc_rest_of_line
|
140
|
+
end
|
141
|
+
|
142
|
+
state :abc_rest_of_line do
|
143
|
+
rule %r/\n/, Text::Whitespace, :pop!
|
144
|
+
rule %r/}/ do
|
145
|
+
token Comment::Preproc
|
146
|
+
pop!
|
147
|
+
pop!
|
148
|
+
end
|
149
|
+
|
150
|
+
mixin :abc_basic
|
151
|
+
|
152
|
+
rule %r/\S+/, Name
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# -*- coding: utf-8 -*- #
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Rouge
|
5
|
+
module Lexers
|
6
|
+
class CMHG < RegexLexer
|
7
|
+
title "CMHG"
|
8
|
+
desc "RISC OS C module header generator source file"
|
9
|
+
tag 'cmhg'
|
10
|
+
filenames '*.cmhg'
|
11
|
+
|
12
|
+
def self.preproc_keyword
|
13
|
+
@preproc_keyword ||= %w(
|
14
|
+
define elif else endif error if ifdef ifndef include line pragma undef warning
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
state :root do
|
19
|
+
rule %r/;[^\n]*/, Comment
|
20
|
+
rule %r/^([ \t]*)(#[ \t]*(?:(?:#{CMHG.preproc_keyword.join('|')})(?:[ \t].*)?)?)(?=\n)/ do
|
21
|
+
groups Text, Comment::Preproc
|
22
|
+
end
|
23
|
+
rule %r/[-a-z]+:/, Keyword::Declaration
|
24
|
+
rule %r/[a-z_]\w+/i, Name::Entity
|
25
|
+
rule %r/"[^"]*"/, Literal::String
|
26
|
+
rule %r/(?:&|0x)\h+/, Literal::Number::Hex
|
27
|
+
rule %r/\d+/, Literal::Number
|
28
|
+
rule %r/[,\/()]/, Punctuation
|
29
|
+
rule %r/[ \t]+/, Text
|
30
|
+
rule %r/\n+/, Text
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -7,7 +7,7 @@ module Rouge
|
|
7
7
|
title "Common Lisp"
|
8
8
|
desc "The Common Lisp variant of Lisp (common-lisp.net)"
|
9
9
|
tag 'common_lisp'
|
10
|
-
aliases 'cl', 'common-lisp', 'elisp', 'emacs-lisp'
|
10
|
+
aliases 'cl', 'common-lisp', 'elisp', 'emacs-lisp', 'lisp'
|
11
11
|
|
12
12
|
filenames '*.cl', '*.lisp', '*.asd', '*.el' # used for Elisp too
|
13
13
|
mimetypes 'text/x-common-lisp'
|
data/lib/rouge/lexers/console.rb
CHANGED
@@ -116,7 +116,7 @@ module Rouge
|
|
116
116
|
# before we pass to the lang lexer so it can determine where
|
117
117
|
# the "real" beginning of the line is
|
118
118
|
$' =~ /\A\s*/
|
119
|
-
yield Text, $& unless $&.empty?
|
119
|
+
yield Text::Whitespace, $& unless $&.empty?
|
120
120
|
|
121
121
|
lang_lexer.continue_lex($', &output)
|
122
122
|
elsif comment_regex =~ input[0].strip
|
data/lib/rouge/lexers/cpp.rb
CHANGED
@@ -17,7 +17,7 @@ module Rouge
|
|
17
17
|
'*.cc', '*.hh',
|
18
18
|
'*.cxx', '*.hxx',
|
19
19
|
'*.pde', '*.ino',
|
20
|
-
'*.tpp'
|
20
|
+
'*.tpp', '*.h'
|
21
21
|
mimetypes 'text/x-c++hdr', 'text/x-c++src'
|
22
22
|
|
23
23
|
def self.keywords
|
@@ -58,9 +58,11 @@ module Rouge
|
|
58
58
|
|
59
59
|
prepend :statements do
|
60
60
|
rule %r/class\b/, Keyword, :classname
|
61
|
+
rule %r/\d+(\.\d+)?(?:h|(?:min)|s|(?:ms)|(?:us)|(?:ns))/, Num::Other
|
61
62
|
rule %r((#{dq}[.]#{dq}?|[.]#{dq})(e[+-]?#{dq}[lu]*)?)i, Num::Float
|
62
63
|
rule %r(#{dq}e[+-]?#{dq}[lu]*)i, Num::Float
|
63
64
|
rule %r/0x\h('?\h)*[lu]*/i, Num::Hex
|
65
|
+
rule %r/0b[01]+(?:_[01]+)*/, Num::Bin
|
64
66
|
rule %r/0[0-7]('?[0-7])*[lu]*/i, Num::Oct
|
65
67
|
rule %r/#{dq}[lu]*/i, Num::Integer
|
66
68
|
rule %r/\bnullptr\b/, Name::Builtin
|
@@ -72,6 +74,7 @@ module Rouge
|
|
72
74
|
|
73
75
|
# template specification
|
74
76
|
rule %r/\s*(?=>)/m, Text, :pop!
|
77
|
+
rule %r/[.]{3}/, Operator
|
75
78
|
mixin :whitespace
|
76
79
|
end
|
77
80
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# -*- coding: utf-8 -*- #
|
2
|
+
|
3
|
+
module Rouge
|
4
|
+
module Lexers
|
5
|
+
load_lexer 'cpp.rb'
|
6
|
+
|
7
|
+
class CUDA < Cpp
|
8
|
+
title "CUDA"
|
9
|
+
desc "Compute Unified Device Architecture, used for programming with NVIDIA GPU"
|
10
|
+
|
11
|
+
tag 'cuda'
|
12
|
+
filenames '*.cu', '*.cuh'
|
13
|
+
|
14
|
+
def self.keywords
|
15
|
+
@keywords ||= super + Set.new(%w(
|
16
|
+
__global__ __device__ __host__ __noinline__ __forceinline__
|
17
|
+
__constant__ __shared__ __managed__ __restrict__
|
18
|
+
))
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.keywords_type
|
22
|
+
@keywords_type ||= super + Set.new(%w(
|
23
|
+
char1 char2 char3 char4 uchar1 uchar2 uchar3 uchar4
|
24
|
+
short1 short2 short3 short4 ushort1 ushort2 ushort3 ushort4
|
25
|
+
int1 int2 int3 int4 uint1 uint2 uint3 uint4
|
26
|
+
long1 long2 long3 long4 ulong1 ulong2 ulong3 ulong4
|
27
|
+
longlong1 longlong2 longlong3 longlong4
|
28
|
+
ulonglong1 ulonglong2 ulonglong3 ulonglong4
|
29
|
+
float1 float2 float3 float4 double1 double2 double3 double4
|
30
|
+
dim3
|
31
|
+
))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,151 @@
|
|
1
|
+
# -*- coding: utf-8 -*- #
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Rouge
|
5
|
+
module Lexers
|
6
|
+
load_lexer 'python.rb'
|
7
|
+
|
8
|
+
class Cython < Python
|
9
|
+
title "Cython"
|
10
|
+
desc "Cython and Pyrex source code (cython.org)"
|
11
|
+
tag 'cython'
|
12
|
+
aliases 'pyx', 'pyrex'
|
13
|
+
filenames '*.pyx', '*.pxd', '*.pxi'
|
14
|
+
mimetypes 'text/x-cython', 'application/x-cython'
|
15
|
+
|
16
|
+
def initialize(opts = {})
|
17
|
+
super opts
|
18
|
+
@indentation = nil
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.keywords
|
22
|
+
@keywords ||= super + %w(
|
23
|
+
by except? fused gil nogil
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.c_keywords
|
28
|
+
@ckeywords ||= %w(
|
29
|
+
public readonly extern api inline enum union
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
identifier = /[a-z_]\w*/i
|
34
|
+
dotted_identifier = /[a-z_.][\w.]*/i
|
35
|
+
|
36
|
+
prepend :root do
|
37
|
+
rule %r/cp?def|ctypedef/ do
|
38
|
+
token Keyword
|
39
|
+
push :c_definitions
|
40
|
+
push :c_start
|
41
|
+
end
|
42
|
+
|
43
|
+
rule %r/(from)((?:\\\s|\s)+)(#{dotted_identifier})((?:\\\s|\s)+)(cimport)/ do
|
44
|
+
groups Keyword::Namespace,
|
45
|
+
Text,
|
46
|
+
Name::Namespace,
|
47
|
+
Text,
|
48
|
+
Keyword::Namespace
|
49
|
+
end
|
50
|
+
|
51
|
+
rule %r/(cimport)(\s+)(#{dotted_identifier})/ do
|
52
|
+
groups Keyword::Namespace, Text, Name::Namespace
|
53
|
+
end
|
54
|
+
|
55
|
+
rule %r/(struct)((?:\\\s|\s)+)/ do
|
56
|
+
groups Keyword, Text
|
57
|
+
push :classname
|
58
|
+
end
|
59
|
+
|
60
|
+
mixin :func_call_fix
|
61
|
+
|
62
|
+
rule %r/[(,]/, Punctuation, :c_start
|
63
|
+
end
|
64
|
+
|
65
|
+
prepend :classname do
|
66
|
+
rule %r/(?:\\\s|\s)+/, Text
|
67
|
+
end
|
68
|
+
|
69
|
+
prepend :funcname do
|
70
|
+
rule %r/(?:\\\s|\s)+/, Text
|
71
|
+
end
|
72
|
+
# This is a fix for the way that function calls are lexed in the Python
|
73
|
+
# lexer. This should be moved to the Python lexer once confirmed that it
|
74
|
+
# does not cause any regressions.
|
75
|
+
state :func_call_fix do
|
76
|
+
rule %r/#{identifier}(?=\()/ do |m|
|
77
|
+
if self.class.keywords.include? m[0]
|
78
|
+
token Keyword
|
79
|
+
elsif self.class.exceptions.include? m[0]
|
80
|
+
token Name::Builtin
|
81
|
+
elsif self.class.builtins.include? m[0]
|
82
|
+
token Name::Builtin
|
83
|
+
elsif self.class.builtins_pseudo.include? m[0]
|
84
|
+
token Name::Builtin::Pseudo
|
85
|
+
else
|
86
|
+
token Name::Function
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
# The Cython lexer adds three states to those already in the Python lexer.
|
92
|
+
# Calls to `cdef`, `cpdef` and `ctypedef` move the lexer into the :c_start
|
93
|
+
# state. The primary purpose of this state is to highlight datatypes. Once
|
94
|
+
# this has been done, the lexer moves to the :c_definitions state where
|
95
|
+
# the majority of text in a definition is lexed. Finally, newlines cause
|
96
|
+
# the lexer to move to :c_indent. This state is used to check whether we
|
97
|
+
# have moved out of a C block.
|
98
|
+
|
99
|
+
state :c_start do
|
100
|
+
rule %r/[^\S\n]+/, Text
|
101
|
+
|
102
|
+
rule %r/cp?def|ctypedef/, Keyword
|
103
|
+
|
104
|
+
rule %r/(?:un)?signed/, Keyword::Type
|
105
|
+
|
106
|
+
# This rule matches identifiers that could be type declarations. The
|
107
|
+
# lookahead matches (1) pointers, (2) arrays and (3) variable names.
|
108
|
+
rule %r/#{identifier}(?=(?:\*+)|(?:[ \t]*\[)|(?:[ \t]+\w))/ do |m|
|
109
|
+
if self.class.keywords.include? m[0]
|
110
|
+
token Keyword
|
111
|
+
pop!
|
112
|
+
elsif %w(def).include? m[0]
|
113
|
+
token Keyword
|
114
|
+
goto :funcname
|
115
|
+
elsif %w(struct class).include? m[0]
|
116
|
+
token Keyword::Reserved
|
117
|
+
goto :classname
|
118
|
+
elsif self.class.c_keywords.include? m[0]
|
119
|
+
token Keyword::Reserved
|
120
|
+
else
|
121
|
+
token Keyword::Type
|
122
|
+
pop!
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
rule(//) { pop! }
|
127
|
+
end
|
128
|
+
|
129
|
+
state :c_definitions do
|
130
|
+
rule %r/\n/, Text, :c_indent
|
131
|
+
mixin :root
|
132
|
+
end
|
133
|
+
|
134
|
+
state :c_indent do
|
135
|
+
rule %r/[ \t]+/ do |m|
|
136
|
+
token Text
|
137
|
+
goto :c_start
|
138
|
+
|
139
|
+
if @indentation.nil?
|
140
|
+
@indentation = m[0]
|
141
|
+
elsif @indentation.length > m[0].length
|
142
|
+
@indentation = nil
|
143
|
+
pop! 2 # Pop :c_start and :c_definitions
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
rule(//) { @indentation = nil; reset_stack }
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|