rouge 3.19.0 → 3.21.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rouge/demos/augeas +16 -0
  3. data/lib/rouge/demos/bibtex +12 -0
  4. data/lib/rouge/demos/brightscript +6 -0
  5. data/lib/rouge/demos/hlsl +20 -0
  6. data/lib/rouge/demos/janet +3 -0
  7. data/lib/rouge/demos/livescript +15 -0
  8. data/lib/rouge/demos/ssh +4 -0
  9. data/lib/rouge/demos/velocity +9 -0
  10. data/lib/rouge/demos/zig +6 -0
  11. data/lib/rouge/lexers/augeas.rb +93 -0
  12. data/lib/rouge/lexers/batchfile.rb +1 -1
  13. data/lib/rouge/lexers/bibtex.rb +115 -0
  14. data/lib/rouge/lexers/brightscript.rb +147 -0
  15. data/lib/rouge/lexers/cpp.rb +11 -4
  16. data/lib/rouge/lexers/css.rb +3 -1
  17. data/lib/rouge/lexers/diff.rb +1 -1
  18. data/lib/rouge/lexers/docker.rb +1 -1
  19. data/lib/rouge/lexers/haskell.rb +27 -19
  20. data/lib/rouge/lexers/hlsl.rb +166 -0
  21. data/lib/rouge/lexers/html.rb +7 -7
  22. data/lib/rouge/lexers/janet.rb +217 -0
  23. data/lib/rouge/lexers/javascript.rb +3 -3
  24. data/lib/rouge/lexers/jinja.rb +22 -7
  25. data/lib/rouge/lexers/jsx.rb +47 -59
  26. data/lib/rouge/lexers/julia.rb +4 -2
  27. data/lib/rouge/lexers/livescript.rb +310 -0
  28. data/lib/rouge/lexers/opentype_feature_file.rb +27 -42
  29. data/lib/rouge/lexers/perl.rb +21 -3
  30. data/lib/rouge/lexers/powershell.rb +5 -3
  31. data/lib/rouge/lexers/rego.rb +27 -12
  32. data/lib/rouge/lexers/sass/common.rb +1 -0
  33. data/lib/rouge/lexers/ssh.rb +33 -0
  34. data/lib/rouge/lexers/tsx.rb +10 -3
  35. data/lib/rouge/lexers/twig.rb +4 -4
  36. data/lib/rouge/lexers/typescript.rb +1 -12
  37. data/lib/rouge/lexers/typescript/common.rb +18 -4
  38. data/lib/rouge/lexers/velocity.rb +71 -0
  39. data/lib/rouge/lexers/xml.rb +5 -3
  40. data/lib/rouge/lexers/yaml.rb +5 -3
  41. data/lib/rouge/lexers/zig.rb +139 -0
  42. data/lib/rouge/version.rb +1 -1
  43. metadata +20 -2
@@ -12,24 +12,30 @@ module Rouge
12
12
 
13
13
  def self.keywords
14
14
  @keywords ||= %w(
15
- Ascender Attach CapHeight CaretOffset CodePageRange Descender FontRevision FSType
16
- GlyphClassDef HorizAxis.BaseScriptList HorizAxis.BaseTagList HorizAxis.MinMax
17
- IgnoreBaseGlyphs IgnoreLigatures IgnoreMarks LigatureCaretByDev LigatureCaretByIndex
18
- LigatureCaretByPos LineGap MarkAttachClass MarkAttachmentType NULL Panose RightToLeft
19
- TypoAscender TypoDescender TypoLineGap UnicodeRange UseMarkFilteringSet Vendor
20
- VertAdvanceY VertAxis.BaseScriptList VertAxis.BaseTagList VertAxis.MinMax VertOriginY
21
- VertTypoAscender VertTypoDescender VertTypoLineGap WeightClass WidthClass XHeight
22
-
23
- anchorDef anchor anonymous anon by contour cursive device enumerate enum
24
- exclude_dflt featureNames feature from ignore include_dflt include languagesystem
25
- language lookupflag lookup markClass mark nameid name parameters position pos required
26
- reversesub rsub script sizemenuname substitute subtable sub table useExtension
15
+ Ascender Attach AxisValue CapHeight CaretOffset CodePageRange
16
+ DesignAxis Descender ElidedFallbackName ElidedFallbackNameID
17
+ ElidableAxisValueName FeatUILabelNameID FeatUITooltipTextNameID
18
+ FontRevision FSType GlyphClassDef HorizAxis.BaseScriptList
19
+ HorizAxis.BaseTagList HorizAxis.MinMax IgnoreBaseGlyphs
20
+ IgnoreLigatures IgnoreMarks LigatureCaretByDev LigatureCaretByIndex
21
+ LigatureCaretByPos LineGap MarkAttachClass MarkAttachmentType NULL
22
+ OlderSiblingFontAttribute Panose ParamUILabelNameID RightToLeft
23
+ SampleTextNameID TypoAscender TypoDescender TypoLineGap UnicodeRange
24
+ UseMarkFilteringSet Vendor VertAdvanceY VertAxis.BaseScriptList
25
+ VertAxis.BaseTagList VertAxis.MinMax VertOriginY VertTypoAscender
26
+ VertTypoDescender VertTypoLineGap WeightClass WidthClass XHeight
27
+
28
+ anchorDef anchor anonymous anon by contour cursive device enumerate
29
+ enum exclude_dflt featureNames feature flag from ignore include_dflt
30
+ include languagesystem language location lookupflag lookup markClass
31
+ mark nameid name parameters position pos required reversesub rsub
32
+ script sizemenuname substitute subtable sub table useExtension
27
33
  valueRecordDef winAscent winDescent
28
34
  )
29
35
  end
30
36
 
31
37
 
32
- identifier = %r/[a-z_][a-z0-9\/_]*/i
38
+ identifier = %r/[a-z_][a-z0-9\/_.-]*/i
33
39
 
34
40
  state :root do
35
41
  rule %r/\s+/m, Text::Whitespace
@@ -41,17 +47,18 @@ module Rouge
41
47
  push :featurename
42
48
  end
43
49
  # } <tag> ;
44
- rule %r/(\})((?:\s)*)/ do
50
+ rule %r/(\})((?:\s))/ do
45
51
  groups Punctuation, Text
46
52
  push :featurename
47
53
  end
48
54
  # solve include( ../path)
49
- rule %r/(include)/i, Keyword, :includepath
55
+ rule %r/include\b/i, Keyword, :includepath
50
56
 
51
57
  rule %r/[\-\[\]\/(){},.:;=%*<>']/, Punctuation
52
58
 
53
59
  rule %r/`.*?/, Str::Backtick
54
- rule %r/\"/, Str, :dqs
60
+ rule %r/\"/, Str, :strings
61
+ rule %r/\\[^.*\s]+/i, Str::Escape
55
62
 
56
63
  # classes, start with @<nameOfClass>
57
64
  rule %r/@#{identifier}/, Name::Class
@@ -66,6 +73,7 @@ module Rouge
66
73
  end
67
74
 
68
75
  rule identifier, Name
76
+ rule %r/(?:0x|\\)[0-9A-Fa-f]+/, Num::Hex
69
77
  rule %r/-?\d+/, Num::Integer
70
78
  end
71
79
 
@@ -77,37 +85,14 @@ module Rouge
77
85
  rule %r/\s+/, Text::Whitespace
78
86
  rule %r/\)/, Punctuation, :pop!
79
87
  rule %r/\(/, Punctuation
80
- rule %r/[a-z0-9\/_.]*/i, Str
88
+ rule %r/[^\s()]+/, Str
81
89
  end
82
90
 
83
91
  state :strings do
84
- rule %r/(\([a-z0-9_]+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?/i, Str
85
- end
86
-
87
- state :strings_double do
88
- rule %r/[^\\"%\n]+/, Str
89
- mixin :strings
90
- end
91
-
92
- state :escape do
93
- rule %r(\\
94
- ( [\\abfnrtv"']
95
- | \n
96
- | N{[a-zA-z][a-zA-Z ]+[a-zA-Z]}
97
- | u[a-fA-F0-9]{4}
98
- | U[a-fA-F0-9]{8}
99
- | x[a-fA-F0-9]{2}
100
- | [0-7]{1,3}
101
- )
102
- )x, Str::Escape
103
- end
104
-
105
- state :dqs do
106
92
  rule %r/"/, Str, :pop!
107
- mixin :escape
108
- mixin :strings_double
93
+ rule %r/[^"%\n]+/, Str
94
+ rule %r/(\([a-z0-9_]+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?/i, Str
109
95
  end
110
-
111
96
  end
112
97
  end
113
98
  end
@@ -65,7 +65,7 @@ module Rouge
65
65
  end
66
66
 
67
67
  state :root do
68
- rule %r/#.*?$/, Comment::Single
68
+ rule %r/#.*/, Comment::Single
69
69
  rule %r/^=[a-zA-Z0-9]+\s+.*?\n=cut/m, Comment::Multiline
70
70
  rule %r/(?:#{keywords.join('|')})\b/, Keyword
71
71
 
@@ -99,6 +99,9 @@ module Rouge
99
99
  re_tok, :balanced_regex
100
100
 
101
101
  rule %r/\s+/, Text
102
+
103
+ rule(/(?=[a-z_]\w*(\s*#.*\n)*\s*=>)/i) { push :fat_comma }
104
+
102
105
  rule %r/(?:#{builtins.join('|')})\b/, Name::Builtin
103
106
  rule %r/((__(DIE|WARN)__)|(DATA|STD(IN|OUT|ERR)))\b/,
104
107
  Name::Builtin::Pseudo
@@ -142,6 +145,13 @@ module Rouge
142
145
  rule %r/.*?\n/, Str::Interpol
143
146
  end
144
147
 
148
+ state :fat_comma do
149
+ rule %r/#.*/, Comment::Single
150
+ rule %r/\w+/, Str
151
+ rule %r/\s+/, Text
152
+ rule %r/=>/, Operator, :pop!
153
+ end
154
+
145
155
  state :name_common do
146
156
  rule %r/\w+::/, Name::Namespace
147
157
  rule %r/[\w:]+/, Name::Variable, :pop!
@@ -178,16 +188,24 @@ module Rouge
178
188
  end
179
189
 
180
190
  state :sq do
181
- rule %r/\\[']/, Str::Escape
191
+ rule %r/\\[\\']/, Str::Escape
182
192
  rule %r/[^\\']+/, Str::Single
183
193
  rule %r/'/, Punctuation, :pop!
194
+ rule %r/\\/, Str::Single
184
195
  end
185
196
 
186
197
  state :dq do
187
198
  mixin :string_intp
188
- rule %r/\\[\\tnr"]/, Str::Escape
199
+ rule %r/\\[\\tnrabefluLUE"$@]/, Str::Escape
200
+ rule %r/\\0\d{2}/, Str::Escape
201
+ rule %r/\\o\{\d+\}/, Str::Escape
202
+ rule %r/\\x\h{2}/, Str::Escape
203
+ rule %r/\\x\{\h+\}/, Str::Escape
204
+ rule %r/\\c./, Str::Escape
205
+ rule %r/\\N\{[^\}]+\}/, Str::Escape
189
206
  rule %r/[^\\"]+?/, Str::Double
190
207
  rule %r/"/, Punctuation, :pop!
208
+ rule %r/\\/, Str::Escape
191
209
  end
192
210
 
193
211
  state :bq do
@@ -165,6 +165,7 @@ module Rouge
165
165
  end
166
166
 
167
167
  state :parameters do
168
+ rule %r/`./m, Str::Escape
168
169
  rule %r/\s*?\n/, Text::Whitespace, :pop!
169
170
  rule %r/[;(){}\]]/, Punctuation, :pop!
170
171
  rule %r/[|=]/, Operator, :pop!
@@ -201,7 +202,7 @@ module Rouge
201
202
  rule %r/(?:#{KEYWORDS})\b(?![-.])/i, Keyword::Reserved
202
203
 
203
204
  rule %r/-{1,2}\w+/, Name::Tag
204
-
205
+
205
206
  rule %r/(\.)?([-\w]+)(\[)/ do |m|
206
207
  groups Operator, Name::Function, Punctuation
207
208
  push :bracket
@@ -209,14 +210,15 @@ module Rouge
209
210
 
210
211
  rule %r/([\/\\~\w][-.:\/\\~\w]*)(\n)?/ do |m|
211
212
  groups Name::Function, Text::Whitespace
212
- push :parameters unless m[2]
213
+ push :parameters
213
214
  end
214
215
 
215
216
  rule %r/(\.)?([-\w]+)(?:(\()|(\n))?/ do |m|
216
217
  groups Operator, Name::Function, Punctuation, Text::Whitespace
217
- push :parameters unless m[3]
218
+ push :parameters unless m[3].nil?
218
219
  end
219
220
 
221
+ rule %r/\?/, Name::Function, :parameters
220
222
  rule %r/[-+*\/%=!.&|]/, Operator
221
223
  rule %r/@\{/, Punctuation, :hasht
222
224
  rule %r/@\(/, Punctuation, :array
@@ -9,36 +9,51 @@ module Rouge
9
9
  tag 'rego'
10
10
  filenames '*.rego'
11
11
 
12
+ def self.constants
13
+ @constants ||= Set.new %w(
14
+ true false null
15
+ )
16
+ end
17
+
18
+ def self.operators
19
+ @operators ||= Set.new %w(
20
+ as default else import not package some with
21
+ )
22
+ end
23
+
12
24
  state :basic do
13
25
  rule %r/\s+/, Text
14
26
  rule %r/#.*/, Comment::Single
15
-
27
+
16
28
  rule %r/[\[\](){}|.,;!]/, Punctuation
17
-
29
+
18
30
  rule %r/"[^"]*"/, Str::Double
19
-
31
+
20
32
  rule %r/-?\d+\.\d+([eE][+-]?\d+)?/, Num::Float
21
33
  rule %r/-?\d+([eE][+-]?\d+)?/, Num
22
34
 
23
35
  rule %r/\\u[0-9a-fA-F]{4}/, Num::Hex
24
36
  rule %r/\\["\/bfnrt]/, Str::Escape
25
37
  end
26
-
27
- state :atoms do
28
- rule %r/(true|false|null)/, Keyword::Constant
29
- rule %r/[[:word:]]*/, Str::Symbol
30
- end
31
-
38
+
32
39
  state :operators do
33
40
  rule %r/(=|!=|>=|<=|>|<|\+|-|\*|%|\/|\||&|:=)/, Operator
34
- rule %r/(default|not|package|import|as|with|else|some)/, Operator
35
41
  rule %r/[\/:?@^~]+/, Operator
36
42
  end
37
-
43
+
38
44
  state :root do
39
45
  mixin :basic
40
46
  mixin :operators
41
- mixin :atoms
47
+
48
+ rule %r/[[:word:]]+/ do |m|
49
+ if self.class.constants.include? m[0]
50
+ token Keyword::Constant
51
+ elsif self.class.operators.include? m[0]
52
+ token Operator::Word
53
+ else
54
+ token Name
55
+ end
56
+ end
42
57
  end
43
58
  end
44
59
  end
@@ -29,6 +29,7 @@ module Rouge
29
29
  end
30
30
 
31
31
  rule %r/@#{id}/, Keyword, :selector
32
+ rule %r/&/, Keyword, :selector
32
33
 
33
34
  # $variable: assignment
34
35
  rule %r/([$]#{id})([ \t]*)(:)/ do
@@ -0,0 +1,33 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Lexers
6
+ class SSH < RegexLexer
7
+ tag 'ssh'
8
+
9
+ title "SSH Config File"
10
+ desc 'A lexer for SSH configuration files'
11
+ filenames 'ssh_config'
12
+
13
+ state :root do
14
+ rule %r/[a-z0-9]+/i, Keyword, :statement
15
+ mixin :base
16
+ end
17
+
18
+ state :statement do
19
+ rule %r/\n/, Text, :pop!
20
+ rule %r/(?:yes|no|confirm|ask|always|auto|none|force)\b/, Name::Constant
21
+
22
+ rule %r/\d+/, Num
23
+ rule %r/[^#\s;{}$\\]+/, Text
24
+ mixin :base
25
+ end
26
+
27
+ state :base do
28
+ rule %r/\s+/, Text
29
+ rule %r/#.*/, Comment::Single
30
+ end
31
+ end
32
+ end
33
+ end
@@ -7,13 +7,20 @@ module Rouge
7
7
  load_lexer 'typescript/common.rb'
8
8
 
9
9
  class TSX < JSX
10
- include TypescriptCommon
10
+ extend TypescriptCommon
11
11
 
12
- title 'TypeScript'
13
- desc 'tsx'
12
+ title 'TSX'
13
+ desc 'TypeScript-compatible JSX (www.typescriptlang.org/docs/handbook/jsx.html)'
14
14
 
15
15
  tag 'tsx'
16
16
  filenames '*.tsx'
17
+
18
+ prepend :element_name do
19
+ rule %r/(\w+)(,)/ do
20
+ groups Name::Other, Punctuation
21
+ pop! 3
22
+ end
23
+ end
17
24
  end
18
25
  end
19
26
  end
@@ -17,10 +17,10 @@ module Rouge
17
17
 
18
18
  def self.keywords
19
19
  @@keywords ||= %w(as do extends flush from import include use else starts
20
- ends with without autoescape endautoescape block endblock
21
- embed endembed filter endfilter for endfor if endif
22
- macro endmacro sandbox endsandbox set endset
23
- spaceless endspaceless verbatim endverbatim)
20
+ ends with without autoescape endautoescape block
21
+ endblock embed endembed filter endfilter for endfor
22
+ if endif macro endmacro sandbox endsandbox set endset
23
+ spaceless endspaceless)
24
24
  end
25
25
 
26
26
  def self.tests
@@ -7,7 +7,7 @@ module Rouge
7
7
  load_lexer 'typescript/common.rb'
8
8
 
9
9
  class Typescript < Javascript
10
- include TypescriptCommon
10
+ extend TypescriptCommon
11
11
 
12
12
  title "TypeScript"
13
13
  desc "TypeScript, a superset of JavaScript"
@@ -18,17 +18,6 @@ module Rouge
18
18
  filenames '*.ts', '*.d.ts'
19
19
 
20
20
  mimetypes 'text/typescript'
21
-
22
- prepend :root do
23
- rule %r/[?][.]/, Punctuation
24
- end
25
-
26
- prepend :statement do
27
- rule %r/(#{Javascript.id_regex})(\??)(\s*)(:)/ do
28
- groups Name::Label, Punctuation, Text, Punctuation
29
- push :expr_start
30
- end
31
- end
32
21
  end
33
22
  end
34
23
  end
@@ -4,31 +4,45 @@
4
4
  module Rouge
5
5
  module Lexers
6
6
  module TypescriptCommon
7
- def self.keywords
7
+ def keywords
8
8
  @keywords ||= super + Set.new(%w(
9
9
  is namespace static private protected public
10
10
  implements readonly
11
11
  ))
12
12
  end
13
13
 
14
- def self.declarations
14
+ def declarations
15
15
  @declarations ||= super + Set.new(%w(
16
16
  type abstract
17
17
  ))
18
18
  end
19
19
 
20
- def self.reserved
20
+ def reserved
21
21
  @reserved ||= super + Set.new(%w(
22
22
  string any void number namespace module
23
23
  declare default interface keyof
24
24
  ))
25
25
  end
26
26
 
27
- def self.builtins
27
+ def builtins
28
28
  @builtins ||= super + %w(
29
29
  Pick Partial Readonly Record
30
30
  )
31
31
  end
32
+
33
+ def self.extended(base)
34
+ base.prepend :root do
35
+ rule %r/[?][.]/, base::Punctuation
36
+ rule %r/[?]{2}/, base::Operator
37
+ end
38
+
39
+ base.prepend :statement do
40
+ rule %r/(#{Javascript.id_regex})(\??)(\s*)(:)/ do
41
+ groups base::Name::Label, base::Punctuation, base::Text, base::Punctuation
42
+ push :expr_start
43
+ end
44
+ end
45
+ end
32
46
  end
33
47
  end
34
48
  end
@@ -0,0 +1,71 @@
1
+ # -*- coding: utf-8 -*- #
2
+
3
+ module Rouge
4
+ module Lexers
5
+ class Velocity < TemplateLexer
6
+ title 'Velocity'
7
+ desc 'Velocity is a Java-based template engine (velocity.apache.org)'
8
+ tag 'velocity'
9
+ filenames '*.vm', '*.velocity', '*.fhtml'
10
+ mimetypes 'text/html+velocity'
11
+
12
+ id = /[a-z_]\w*/i
13
+
14
+ state :root do
15
+ rule %r/[^{#$]+/ do
16
+ delegate parent
17
+ end
18
+
19
+ rule %r/(#)(\*.*?\*)(#)/m, Comment::Multiline
20
+ rule %r/(##)(.*?$)/, Comment::Single
21
+
22
+ rule %r/(#\{?)(#{id})(\}?)(\s?\()/m do
23
+ groups Punctuation, Name::Function, Punctuation, Punctuation
24
+ push :directive_params
25
+ end
26
+
27
+ rule %r/(#\{?)(#{id})(\}|\b)/m do
28
+ groups Punctuation, Name::Function, Punctuation
29
+ end
30
+
31
+ rule %r/\$\{?/, Punctuation, :variable
32
+ end
33
+
34
+ state :variable do
35
+ rule %r/#{id}/, Name::Variable
36
+ rule %r/\(/, Punctuation, :func_params
37
+ rule %r/(\.)(#{id})/ do
38
+ groups Punctuation, Name::Variable
39
+ end
40
+ rule %r/\}/, Punctuation, :pop!
41
+ rule(//) { pop! }
42
+ end
43
+
44
+ state :directive_params do
45
+ rule %r/(&&|\|\||==?|!=?|[-<>+*%&|^\/])|\b(eq|ne|gt|lt|ge|le|not|in)\b/, Operator
46
+ rule %r/\[/, Operator, :range_operator
47
+ rule %r/\b#{id}\b/, Name::Function
48
+ mixin :func_params
49
+ end
50
+
51
+ state :range_operator do
52
+ rule %r/[.]{2}/, Operator
53
+ mixin :func_params
54
+ rule %r/\]/, Operator, :pop!
55
+ end
56
+
57
+ state :func_params do
58
+ rule %r/\$\{?/, Punctuation, :variable
59
+ rule %r/\s+/, Text
60
+ rule %r/,/, Punctuation
61
+ rule %r/"(\\\\|\\"|[^"])*"/, Str::Double
62
+ rule %r/'(\\\\|\\'|[^'])*'/, Str::Single
63
+ rule %r/0[xX][0-9a-fA-F]+[Ll]?/, Num::Hex
64
+ rule %r/\b[0-9]+\b/, Num::Integer
65
+ rule %r/(true|false|null)\b/, Keyword::Constant
66
+ rule %r/[(\[]/, Punctuation, :push!
67
+ rule %r/[)\]}]/, Punctuation, :pop!
68
+ end
69
+ end
70
+ end
71
+ end