rouge 3.9.0 → 3.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rouge/demos/apex +9 -0
- data/lib/rouge/demos/clean +6 -0
- data/lib/rouge/demos/csvs +8 -0
- data/lib/rouge/demos/jsl +3 -0
- data/lib/rouge/demos/liquid +0 -1
- data/lib/rouge/demos/lustre +6 -0
- data/lib/rouge/demos/lutin +18 -0
- data/lib/rouge/demos/minizinc +23 -0
- data/lib/rouge/demos/q +6 -0
- data/lib/rouge/demos/robot_framework +27 -0
- data/lib/rouge/demos/sparql +6 -0
- data/lib/rouge/demos/ttcn3 +6 -0
- data/lib/rouge/guessers/disambiguation.rb +5 -0
- data/lib/rouge/lexer.rb +3 -0
- data/lib/rouge/lexers/apex.rb +126 -0
- data/lib/rouge/lexers/bpf.rb +20 -6
- data/lib/rouge/lexers/clean.rb +156 -0
- data/lib/rouge/lexers/common_lisp.rb +1 -1
- data/lib/rouge/lexers/coq.rb +12 -9
- data/lib/rouge/lexers/csvs.rb +44 -0
- data/lib/rouge/lexers/eex.rb +2 -1
- data/lib/rouge/lexers/http.rb +1 -1
- data/lib/rouge/lexers/jsl.rb +55 -0
- data/lib/rouge/lexers/json.rb +1 -1
- data/lib/rouge/lexers/kotlin.rb +21 -28
- data/lib/rouge/lexers/liquid.rb +82 -108
- data/lib/rouge/lexers/lustre.rb +79 -0
- data/lib/rouge/lexers/lutin.rb +33 -0
- data/lib/rouge/lexers/markdown.rb +7 -1
- data/lib/rouge/lexers/mason.rb +0 -5
- data/lib/rouge/lexers/minizinc.rb +87 -0
- data/lib/rouge/lexers/perl.rb +1 -1
- data/lib/rouge/lexers/q.rb +2 -1
- data/lib/rouge/lexers/robot_framework.rb +249 -0
- data/lib/rouge/lexers/shell.rb +5 -3
- data/lib/rouge/lexers/sparql.rb +129 -0
- data/lib/rouge/lexers/swift.rb +1 -1
- data/lib/rouge/lexers/ttcn3.rb +119 -0
- data/lib/rouge/plugins/redcarpet.rb +7 -1
- data/lib/rouge/version.rb +1 -1
- metadata +22 -2
@@ -0,0 +1,79 @@
|
|
1
|
+
# -*- coding: utf-8 -*- #
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Rouge
|
5
|
+
module Lexers
|
6
|
+
class Lustre < RegexLexer
|
7
|
+
title "Lustre"
|
8
|
+
desc 'The Lustre programming language (Verimag)'
|
9
|
+
tag 'lustre'
|
10
|
+
filenames '*.lus'
|
11
|
+
mimetypes 'text/x-lustre'
|
12
|
+
|
13
|
+
def self.keywords
|
14
|
+
@keywords ||= Set.new %w(
|
15
|
+
extern unsafe assert const current enum function let node operator
|
16
|
+
returns step struct tel type var model package needs provides uses is
|
17
|
+
body end include merge
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.word_operators
|
22
|
+
@word_operators ||= Set.new %w(
|
23
|
+
div and xor mod or not nor if then else fby pre when with
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.primitives
|
28
|
+
@primitives ||= Set.new %w(int real bool)
|
29
|
+
end
|
30
|
+
|
31
|
+
operator = %r([,!$%&*+./:<=>?@^|~#-]+)
|
32
|
+
id = /[a-z_][\w']*/i
|
33
|
+
|
34
|
+
state :root do
|
35
|
+
rule %r/\s+/m, Text
|
36
|
+
rule %r/false|true/, Keyword::Constant
|
37
|
+
rule %r(\-\-.*), Comment::Single
|
38
|
+
rule %r(/\*.*?\*/)m, Comment::Multiline
|
39
|
+
rule %r(\(\*.*?\*\))m, Comment::Multiline
|
40
|
+
rule id do |m|
|
41
|
+
match = m[0]
|
42
|
+
if self.class.keywords.include? match
|
43
|
+
token Keyword
|
44
|
+
elsif self.class.word_operators.include? match
|
45
|
+
token Operator::Word
|
46
|
+
elsif self.class.primitives.include? match
|
47
|
+
token Keyword::Type
|
48
|
+
else
|
49
|
+
token Name
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
rule %r/[(){}\[\];]+/, Punctuation
|
54
|
+
rule operator, Operator
|
55
|
+
|
56
|
+
rule %r/-?\d[\d_]*(.[\d_]*)?(e[+-]?\d[\d_]*)/i, Num::Float
|
57
|
+
rule %r/\d[\d_]*/, Num::Integer
|
58
|
+
|
59
|
+
rule %r/'(?:(\\[\\"'ntbr ])|(\\[0-9]{3})|(\\x\h{2}))'/, Str::Char
|
60
|
+
rule %r/'[.]'/, Str::Char
|
61
|
+
rule %r/"/, Str::Double, :string
|
62
|
+
rule %r/[~?]#{id}/, Name::Variable
|
63
|
+
end
|
64
|
+
|
65
|
+
state :string do
|
66
|
+
rule %r/[^\\"]+/, Str::Double
|
67
|
+
mixin :escape_sequence
|
68
|
+
rule %r/\\\n/, Str::Double
|
69
|
+
rule %r/"/, Str::Double, :pop!
|
70
|
+
end
|
71
|
+
|
72
|
+
state :escape_sequence do
|
73
|
+
rule %r/\\[\\"'ntbr]/, Str::Escape
|
74
|
+
rule %r/\\\d{3}/, Str::Escape
|
75
|
+
rule %r/\\x\h{2}/, Str::Escape
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# -*- coding: utf-8 -*- #
|
2
|
+
# frozen_string_literal: true
|
3
|
+
#
|
4
|
+
# adapted from lustre.rf (adapted from ocaml.rb), hence some ocaml-ism migth remains
|
5
|
+
module Rouge
|
6
|
+
module Lexers
|
7
|
+
load_lexer 'lustre.rb'
|
8
|
+
|
9
|
+
class Lutin < Lustre
|
10
|
+
title "Lutin"
|
11
|
+
desc 'The Lutin programming language (Verimag)'
|
12
|
+
tag 'lutin'
|
13
|
+
filenames '*.lut'
|
14
|
+
mimetypes 'text/x-lutin'
|
15
|
+
|
16
|
+
def self.keywords
|
17
|
+
@keywords ||= Set.new %w(
|
18
|
+
let in node extern system returns weak strong assert raise try catch
|
19
|
+
trap do exist erun run type ref exception include false true
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.word_operators
|
24
|
+
@word_operators ||= Set.new %w(
|
25
|
+
div and xor mod or not nor if then else pre)
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.primitives
|
29
|
+
@primitives ||= Set.new %w(int real bool trace loop fby)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -34,7 +34,13 @@ module Rouge
|
|
34
34
|
|
35
35
|
rule %r/^([ \t]*)(```|~~~)([^\n]*\n)((.*?)(\2))?/m do |m|
|
36
36
|
name = m[3].strip
|
37
|
-
sublexer =
|
37
|
+
sublexer =
|
38
|
+
begin
|
39
|
+
Lexer.find_fancy(name.empty? ? "guess" : name, m[5], @options)
|
40
|
+
rescue Guesser::Ambiguous => e
|
41
|
+
e.alternatives.first.new(@options)
|
42
|
+
end
|
43
|
+
|
38
44
|
sublexer ||= PlainText.new(@options.merge(:token => Str::Backtick))
|
39
45
|
sublexer.reset!
|
40
46
|
|
data/lib/rouge/lexers/mason.rb
CHANGED
@@ -15,11 +15,6 @@ module Rouge
|
|
15
15
|
@perl = Perl.new
|
16
16
|
end
|
17
17
|
|
18
|
-
def self.detect?(text)
|
19
|
-
return false if text.doctype?(/((?:ht|x)ml)/)
|
20
|
-
return true if text.doctype?
|
21
|
-
end
|
22
|
-
|
23
18
|
# Note: If you add a tag in the lines below, you also need to modify "disambiguate '*.m'" in file disambiguation.rb
|
24
19
|
TEXT_BLOCKS = %w(text doc)
|
25
20
|
PERL_BLOCKS = %w(args flags attr init once shared perl cleanup filter)
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# -*- coding: utf-8 -*- #
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# Based on Chroma's MiniZinc lexer:
|
5
|
+
# https://github.com/alecthomas/chroma/blob/5152194c717b394686d3d7a7e1946a360ec0728f/lexers/m/minizinc.go
|
6
|
+
|
7
|
+
module Rouge
|
8
|
+
module Lexers
|
9
|
+
class MiniZinc < RegexLexer
|
10
|
+
title "MiniZinc"
|
11
|
+
desc "MiniZinc is a free and open-source constraint modeling language (minizinc.org)"
|
12
|
+
tag 'minizinc'
|
13
|
+
filenames '*.mzn', '*.fzn', '*.dzn'
|
14
|
+
mimetypes 'text/minizinc'
|
15
|
+
|
16
|
+
def self.builtins
|
17
|
+
@builtins = Set.new %w[
|
18
|
+
abort abs acosh array_intersect array_union array1d array2d array3d
|
19
|
+
array4d array5d array6d asin assert atan bool2int card ceil concat
|
20
|
+
cos cosh dom dom_array dom_size fix exp floor index_set
|
21
|
+
index_set_1of2 index_set_2of2 index_set_1of3 index_set_2of3
|
22
|
+
index_set_3of3 int2float is_fixed join lb lb_array length ln log log2
|
23
|
+
log10 min max pow product round set2array show show_int show_float
|
24
|
+
sin sinh sqrt sum tan tanh trace ub ub_array
|
25
|
+
]
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.keywords
|
29
|
+
@keywords = Set.new %w[
|
30
|
+
ann annotation any constraint else endif function for forall if
|
31
|
+
include list of op output minimize maximize par predicate record
|
32
|
+
satisfy solve test then type var where
|
33
|
+
]
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.keywords_type
|
37
|
+
@keywords_type ||= Set.new %w(
|
38
|
+
array set bool enum float int string tuple
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.operators
|
43
|
+
@operators ||= Set.new %w(
|
44
|
+
in subset superset union diff symdiff intersect
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
id = /[$a-zA-Z_]\w*/
|
49
|
+
|
50
|
+
state :root do
|
51
|
+
rule %r(\s+)m, Text::Whitespace
|
52
|
+
rule %r(\\\n)m, Text::Whitespace
|
53
|
+
rule %r(%.*), Comment::Single
|
54
|
+
rule %r(/(\\\n)?[*](.|\n)*?[*](\\\n)?/)m, Comment::Multiline
|
55
|
+
rule %r/"(\\\\|\\"|[^"])*"/, Literal::String
|
56
|
+
|
57
|
+
rule %r(not|<->|->|<-|\\/|xor|/\\), Operator
|
58
|
+
rule %r(<|>|<=|>=|==|=|!=), Operator
|
59
|
+
rule %r(\+|-|\*|/|div|mod), Operator
|
60
|
+
rule %r(\\|\.\.|\+\+), Operator
|
61
|
+
rule %r([|()\[\]{},:;]), Punctuation
|
62
|
+
rule %r((true|false)\b), Keyword::Constant
|
63
|
+
rule %r(([+-]?)\d+(\.(?!\.)\d*)?([eE][-+]?\d+)?), Literal::Number
|
64
|
+
|
65
|
+
rule id do |m|
|
66
|
+
if self.class.keywords.include? m[0]
|
67
|
+
token Keyword
|
68
|
+
elsif self.class.keywords_type.include? m[0]
|
69
|
+
token Keyword::Type
|
70
|
+
elsif self.class.builtins.include? m[0]
|
71
|
+
token Name::Builtin
|
72
|
+
elsif self.class.operators.include? m[0]
|
73
|
+
token Operator
|
74
|
+
else
|
75
|
+
token Name::Other
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
rule %r(::\s*([^\W\d]\w*)(\s*\([^\)]*\))?), Name::Decorator
|
80
|
+
rule %r(\b([^\W\d]\w*)\b(\()) do
|
81
|
+
groups Name::Function, Punctuation
|
82
|
+
end
|
83
|
+
rule %r([^\W\d]\w*), Name::Other
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
data/lib/rouge/lexers/perl.rb
CHANGED
@@ -127,7 +127,7 @@ module Rouge
|
|
127
127
|
rule %r/(q|qq|qw|qr|qx)\(/, Str::Other, :rb_string
|
128
128
|
rule %r/(q|qq|qw|qr|qx)\[/, Str::Other, :sb_string
|
129
129
|
rule %r/(q|qq|qw|qr|qx)</, Str::Other, :lt_string
|
130
|
-
rule %r/(q|qq|qw|qr|qx)(
|
130
|
+
rule %r/(q|qq|qw|qr|qx)(\W)(.|\n)*?\2/, Str::Other
|
131
131
|
|
132
132
|
rule %r/package\s+/, Keyword, :modulename
|
133
133
|
rule %r/sub\s+/, Keyword, :funcname
|
data/lib/rouge/lexers/q.rb
CHANGED
@@ -0,0 +1,249 @@
|
|
1
|
+
# -*- coding: utf-8 -*- #
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Rouge
|
5
|
+
module Lexers
|
6
|
+
class RobotFramework < RegexLexer
|
7
|
+
tag 'robot_framework'
|
8
|
+
aliases 'robot', 'robot-framework'
|
9
|
+
|
10
|
+
title "Robot Framework"
|
11
|
+
desc 'Robot Framework is a generic open source automation testing framework (robotframework.org)'
|
12
|
+
|
13
|
+
filenames '*.robot'
|
14
|
+
mimetypes 'text/x-robot'
|
15
|
+
|
16
|
+
def initialize(opts = {})
|
17
|
+
super(opts)
|
18
|
+
@col = 0
|
19
|
+
@next = nil
|
20
|
+
@is_template = false
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.settings_with_keywords
|
24
|
+
@settings_with_keywords ||= Set.new [
|
25
|
+
"library", "resource", "setup", "teardown", "template", "suite setup",
|
26
|
+
"suite teardown", "task setup", "task teardown", "task template",
|
27
|
+
"test setup", "test teardown", "test template", "variables"
|
28
|
+
]
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.settings_with_args
|
32
|
+
@settings_with_args ||= Set.new [
|
33
|
+
"arguments", "default tags", "documentation", "force tags",
|
34
|
+
"metadata", "return", "tags", "timeout", "task timeout",
|
35
|
+
"test timeout"
|
36
|
+
]
|
37
|
+
end
|
38
|
+
|
39
|
+
id = %r/(?:\\|[^|$@&% \t\n])+(?: (?:\\.|[^|$@&% \t\n])+)*/
|
40
|
+
bdd = %r/(?:Given|When|Then|And|But) /i
|
41
|
+
sep = %r/ +\| +|[ ]{2,}|\t+/
|
42
|
+
|
43
|
+
start do
|
44
|
+
push :prior_text
|
45
|
+
end
|
46
|
+
|
47
|
+
state :prior_text do
|
48
|
+
rule %r/^[^*].*/, Text
|
49
|
+
rule(//) { pop! }
|
50
|
+
end
|
51
|
+
|
52
|
+
# Mixins
|
53
|
+
|
54
|
+
state :whitespace do
|
55
|
+
rule %r/\s+/, Text::Whitespace
|
56
|
+
end
|
57
|
+
|
58
|
+
state :section_include do
|
59
|
+
mixin :end_section
|
60
|
+
mixin :sep
|
61
|
+
mixin :newline
|
62
|
+
end
|
63
|
+
|
64
|
+
state :end_section do
|
65
|
+
rule(/(?=^(?:\| )?\*)/) { pop! }
|
66
|
+
end
|
67
|
+
|
68
|
+
state :return do
|
69
|
+
rule(//) { pop! }
|
70
|
+
end
|
71
|
+
|
72
|
+
state :sep do
|
73
|
+
rule %r/\| /, Text::Whitespace
|
74
|
+
|
75
|
+
rule sep do
|
76
|
+
token Text::Whitespace
|
77
|
+
@col = @col + 1
|
78
|
+
if @next
|
79
|
+
push @next
|
80
|
+
elsif @is_template
|
81
|
+
push :args
|
82
|
+
elsif @col == 1
|
83
|
+
@next = :keyword
|
84
|
+
push :keyword
|
85
|
+
else
|
86
|
+
push :args
|
87
|
+
end
|
88
|
+
push :cell_start
|
89
|
+
end
|
90
|
+
|
91
|
+
rule %r/\.\.\. */ do
|
92
|
+
token Text::Whitespace
|
93
|
+
@col = @col + 1
|
94
|
+
push :args
|
95
|
+
end
|
96
|
+
|
97
|
+
rule %r/ ?\|/, Text::Whitespace
|
98
|
+
end
|
99
|
+
|
100
|
+
state :newline do
|
101
|
+
rule %r/\n/ do
|
102
|
+
token Text::Whitespace
|
103
|
+
@col = 0
|
104
|
+
@next = nil
|
105
|
+
push :cell_start
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# States
|
110
|
+
|
111
|
+
state :root do
|
112
|
+
mixin :whitespace
|
113
|
+
|
114
|
+
rule %r/^(?:\| )?\*[* ]*([A-Z]+(?: [A-Z]+)?).*/i do |m|
|
115
|
+
token Generic::Heading, m[0]
|
116
|
+
case m[1].chomp("s").downcase
|
117
|
+
when "setting" then push :section_settings
|
118
|
+
when "test case" then push :section_tests
|
119
|
+
when "task" then push :section_tasks
|
120
|
+
when "keyword" then push :section_keywords
|
121
|
+
when "variable" then push :section_variables
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
state :section_settings do
|
127
|
+
mixin :section_include
|
128
|
+
|
129
|
+
rule %r/([A-Z]+(?: [A-Z]+)?)(:?)/i do |m|
|
130
|
+
match = m[1].downcase
|
131
|
+
@next = if self.class.settings_with_keywords.include? match
|
132
|
+
:keyword
|
133
|
+
elsif self.class.settings_with_args.include? match
|
134
|
+
:args
|
135
|
+
end
|
136
|
+
groups Name::Builtin::Pseudo, Punctuation
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
state :section_tests do
|
141
|
+
mixin :section_include
|
142
|
+
|
143
|
+
rule %r/[$@&%{}]+/, Name::Label
|
144
|
+
rule %r/( )(?![ |])/, Name::Label
|
145
|
+
|
146
|
+
rule id do
|
147
|
+
@is_template = false
|
148
|
+
token Name::Label
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
state :section_tasks do
|
153
|
+
mixin :section_tests
|
154
|
+
end
|
155
|
+
|
156
|
+
state :section_keywords do
|
157
|
+
mixin :section_include
|
158
|
+
|
159
|
+
rule %r/[$@&%]\{/ do
|
160
|
+
token Name::Variable
|
161
|
+
push :var
|
162
|
+
end
|
163
|
+
|
164
|
+
rule %r/[$@&%{}]+/, Name::Label
|
165
|
+
rule %r/( )(?![ |])/, Name::Label
|
166
|
+
|
167
|
+
rule id, Name::Label
|
168
|
+
end
|
169
|
+
|
170
|
+
state :section_variables do
|
171
|
+
mixin :section_include
|
172
|
+
|
173
|
+
rule %r/[$@&%]\{/ do
|
174
|
+
token Name::Variable
|
175
|
+
@next = :args
|
176
|
+
push :var
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
state :cell_start do
|
181
|
+
rule %r/#.*/, Comment
|
182
|
+
mixin :return
|
183
|
+
end
|
184
|
+
|
185
|
+
state :keyword do
|
186
|
+
rule %r/(\[)([A-Z]+(?: [A-Z]+)?)(\])/i do |m|
|
187
|
+
groups Punctuation, Name::Builtin::Pseudo, Punctuation
|
188
|
+
|
189
|
+
match = m[2].downcase
|
190
|
+
@is_template = true if match == "template"
|
191
|
+
if self.class.settings_with_keywords.include? match
|
192
|
+
@next = :keyword
|
193
|
+
elsif self.class.settings_with_args.include? match
|
194
|
+
@next = :args
|
195
|
+
end
|
196
|
+
|
197
|
+
pop!
|
198
|
+
end
|
199
|
+
|
200
|
+
rule %r/[$@&%]\{/ do
|
201
|
+
token Name::Variable
|
202
|
+
@next = :keyword unless @next.nil?
|
203
|
+
push :var
|
204
|
+
end
|
205
|
+
|
206
|
+
rule %r/FOR/i do
|
207
|
+
token Name::Function
|
208
|
+
@next = :keyword unless @next.nil?
|
209
|
+
end
|
210
|
+
|
211
|
+
rule %r/( )(?![ |])/, Name::Function
|
212
|
+
|
213
|
+
rule bdd, Name::Builtin
|
214
|
+
rule id do
|
215
|
+
token Name::Function
|
216
|
+
@next = nil
|
217
|
+
end
|
218
|
+
|
219
|
+
mixin :return
|
220
|
+
end
|
221
|
+
|
222
|
+
state :args do
|
223
|
+
rule %r/[$@&%]\{/ do
|
224
|
+
token Name::Variable
|
225
|
+
@next = :keyword unless @next.nil?
|
226
|
+
push :var
|
227
|
+
end
|
228
|
+
|
229
|
+
rule %r/[$@&%]+/, Str
|
230
|
+
rule %r/( )(?![ |])/, Str
|
231
|
+
rule id, Str
|
232
|
+
|
233
|
+
mixin :return
|
234
|
+
end
|
235
|
+
|
236
|
+
state :var do
|
237
|
+
rule %r/(\})( )(=)/ do
|
238
|
+
groups Name::Variable, Text::Whitespace, Punctuation
|
239
|
+
pop!
|
240
|
+
end
|
241
|
+
rule %r/[$@&%]\{/, Name::Variable, :var
|
242
|
+
rule %r/[{\[]/, Name::Variable, :var
|
243
|
+
rule %r/[}\]]/, Name::Variable, :pop!
|
244
|
+
rule %r/[^$@&%{}\[\]]+/, Name::Variable
|
245
|
+
rule %r/\}\[/, Name::Variable
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|