rouge 4.1.3 → 4.7.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.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +10 -7
  3. data/LICENSE +2 -1
  4. data/lib/rouge/cli.rb +4 -5
  5. data/lib/rouge/demos/bicep +10 -0
  6. data/lib/rouge/demos/cobol +103 -0
  7. data/lib/rouge/demos/codeowners +6 -0
  8. data/lib/rouge/demos/gjs +23 -0
  9. data/lib/rouge/demos/gts +36 -0
  10. data/lib/rouge/demos/iecst +21 -0
  11. data/lib/rouge/demos/json5 +12 -0
  12. data/lib/rouge/demos/mojo +10 -0
  13. data/lib/rouge/demos/p4 +99 -0
  14. data/lib/rouge/demos/svelte +29 -0
  15. data/lib/rouge/formatters/html_legacy.rb +0 -3
  16. data/lib/rouge/guessers/disambiguation.rb +24 -3
  17. data/lib/rouge/lexer.rb +8 -6
  18. data/lib/rouge/lexers/ada.rb +5 -5
  19. data/lib/rouge/lexers/bicep.rb +111 -0
  20. data/lib/rouge/lexers/bpf.rb +10 -10
  21. data/lib/rouge/lexers/brainfuck.rb +1 -0
  22. data/lib/rouge/lexers/clean.rb +4 -4
  23. data/lib/rouge/lexers/cobol.rb +137 -0
  24. data/lib/rouge/lexers/codeowners.rb +30 -0
  25. data/lib/rouge/lexers/cpp.rb +5 -4
  26. data/lib/rouge/lexers/crystal.rb +17 -17
  27. data/lib/rouge/lexers/csharp.rb +37 -34
  28. data/lib/rouge/lexers/css.rb +192 -150
  29. data/lib/rouge/lexers/dart.rb +1 -1
  30. data/lib/rouge/lexers/docker.rb +2 -2
  31. data/lib/rouge/lexers/ecl.rb +2 -2
  32. data/lib/rouge/lexers/eiffel.rb +1 -1
  33. data/lib/rouge/lexers/elixir.rb +5 -1
  34. data/lib/rouge/lexers/gdscript.rb +4 -4
  35. data/lib/rouge/lexers/ghc_cmm.rb +3 -3
  36. data/lib/rouge/lexers/gjs.rb +39 -0
  37. data/lib/rouge/lexers/go.rb +7 -5
  38. data/lib/rouge/lexers/groovy.rb +6 -4
  39. data/lib/rouge/lexers/gts.rb +39 -0
  40. data/lib/rouge/lexers/hcl.rb +1 -0
  41. data/lib/rouge/lexers/html.rb +1 -1
  42. data/lib/rouge/lexers/iecst.rb +92 -0
  43. data/lib/rouge/lexers/ini.rb +7 -5
  44. data/lib/rouge/lexers/java.rb +1 -1
  45. data/lib/rouge/lexers/javascript.rb +4 -4
  46. data/lib/rouge/lexers/json5.rb +74 -0
  47. data/lib/rouge/lexers/julia.rb +3 -2
  48. data/lib/rouge/lexers/kotlin.rb +1 -1
  49. data/lib/rouge/lexers/lua.rb +24 -3
  50. data/lib/rouge/lexers/make.rb +5 -1
  51. data/lib/rouge/lexers/markdown.rb +2 -1
  52. data/lib/rouge/lexers/mathematica.rb +1 -1
  53. data/lib/rouge/lexers/meson.rb +0 -1
  54. data/lib/rouge/lexers/mojo.rb +35 -0
  55. data/lib/rouge/lexers/nasm.rb +5 -4
  56. data/lib/rouge/lexers/nginx.rb +1 -0
  57. data/lib/rouge/lexers/objective_c/common.rb +0 -2
  58. data/lib/rouge/lexers/objective_c.rb +1 -1
  59. data/lib/rouge/lexers/ocl.rb +2 -2
  60. data/lib/rouge/lexers/openedge.rb +0 -2
  61. data/lib/rouge/lexers/p4.rb +81 -0
  62. data/lib/rouge/lexers/php/keywords.rb +86 -136
  63. data/lib/rouge/lexers/php.rb +42 -2
  64. data/lib/rouge/lexers/plsql.rb +5 -5
  65. data/lib/rouge/lexers/python.rb +59 -32
  66. data/lib/rouge/lexers/robot_framework.rb +1 -1
  67. data/lib/rouge/lexers/ruby.rb +21 -21
  68. data/lib/rouge/lexers/sass/common.rb +1 -1
  69. data/lib/rouge/lexers/scala.rb +5 -2
  70. data/lib/rouge/lexers/sql.rb +1 -1
  71. data/lib/rouge/lexers/svelte.rb +91 -0
  72. data/lib/rouge/lexers/syzlang.rb +0 -1
  73. data/lib/rouge/lexers/tcl.rb +7 -2
  74. data/lib/rouge/lexers/terraform.rb +4 -3
  75. data/lib/rouge/lexers/toml.rb +56 -45
  76. data/lib/rouge/lexers/ttcn3.rb +0 -2
  77. data/lib/rouge/lexers/typescript/common.rb +9 -0
  78. data/lib/rouge/lexers/xojo.rb +6 -6
  79. data/lib/rouge/lexers/yang.rb +1 -1
  80. data/lib/rouge/regex_lexer.rb +13 -0
  81. data/lib/rouge/tex_theme_renderer.rb +1 -1
  82. data/lib/rouge/themes/base16.rb +23 -18
  83. data/lib/rouge/themes/bw.rb +1 -0
  84. data/lib/rouge/themes/colorful.rb +1 -0
  85. data/lib/rouge/themes/github.rb +1 -0
  86. data/lib/rouge/themes/gruvbox.rb +4 -1
  87. data/lib/rouge/themes/igor_pro.rb +3 -0
  88. data/lib/rouge/themes/magritte.rb +1 -0
  89. data/lib/rouge/themes/molokai.rb +2 -1
  90. data/lib/rouge/themes/monokai.rb +2 -1
  91. data/lib/rouge/themes/monokai_sublime.rb +4 -3
  92. data/lib/rouge/themes/pastie.rb +1 -0
  93. data/lib/rouge/themes/thankful_eyes.rb +1 -0
  94. data/lib/rouge/themes/tulip.rb +1 -0
  95. data/lib/rouge/token.rb +2 -1
  96. data/lib/rouge/version.rb +1 -1
  97. metadata +23 -6
@@ -7,11 +7,13 @@ module Rouge
7
7
  title "Groovy"
8
8
  desc 'The Groovy programming language (http://www.groovy-lang.org/)'
9
9
  tag 'groovy'
10
- filenames '*.groovy', 'Jenkinsfile', '*.Jenkinsfile'
10
+ aliases 'nextflow', 'nf'
11
+ filenames '*.groovy', 'Jenkinsfile', '*.Jenkinsfile', '*.nf'
11
12
  mimetypes 'text/x-groovy'
12
13
 
13
14
  def self.detect?(text)
14
15
  return true if text.shebang?(/groovy/)
16
+ return true if text.shebang?(/nextflow/)
15
17
  end
16
18
 
17
19
  def self.keywords
@@ -23,7 +25,7 @@ module Rouge
23
25
 
24
26
  def self.declarations
25
27
  @declarations ||= Set.new %w(
26
- abstract const enum extends final implements native private
28
+ abstract const extends final implements native private
27
29
  protected public static strictfp super synchronized throws
28
30
  transient volatile
29
31
  )
@@ -31,7 +33,7 @@ module Rouge
31
33
 
32
34
  def self.types
33
35
  @types ||= Set.new %w(
34
- def boolean byte char double float int long short void
36
+ def var boolean byte char double float int long short void
35
37
  )
36
38
  end
37
39
 
@@ -56,7 +58,7 @@ module Rouge
56
58
  rule %r(//.*?$), Comment::Single
57
59
  rule %r(/[*].*?[*]/)m, Comment::Multiline
58
60
  rule %r/@\w[\w.]*/, Name::Decorator
59
- rule %r/(class|interface|trait)\b/, Keyword::Declaration, :class
61
+ rule %r/(class|interface|trait|enum|record)\b/, Keyword::Declaration, :class
60
62
  rule %r/package\b/, Keyword::Namespace, :import
61
63
  rule %r/import\b/, Keyword::Namespace, :import
62
64
 
@@ -0,0 +1,39 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Lexers
6
+ load_lexer 'typescript.rb'
7
+
8
+ class Gts < Typescript
9
+ title "Template Tag (gts)"
10
+ desc "Ember.js, TypeScript with <template> tags"
11
+ tag "gts"
12
+ filenames "*.gts"
13
+ mimetypes "text/x-gts", "application/x-gts"
14
+
15
+ def initialize(*)
16
+ super
17
+ @handlebars = Handlebars.new(options)
18
+ end
19
+
20
+ prepend :root do
21
+ rule %r/(<)(template)(>)/ do
22
+ groups Name::Tag, Keyword, Name::Tag
23
+ push :template
24
+ end
25
+ end
26
+
27
+ state :template do
28
+ rule %r((</)(template)(>)) do
29
+ groups Name::Tag, Keyword, Name::Tag
30
+ pop!
31
+ end
32
+
33
+ rule %r/.+?(?=<\/template>)/m do
34
+ delegate @handlebars
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -26,6 +26,7 @@ module Rouge
26
26
  state :primitives do
27
27
  rule %r/[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?([kKmMgG]b?)?/, Num::Float
28
28
  rule %r/[0-9]+([kKmMgG]b?)?/, Num::Integer
29
+ rule %r/[-+*\/!%&<>|=:?]/, Operator
29
30
 
30
31
  rule %r/"/, Str::Double, :dq
31
32
  rule %r/'/, Str::Single, :sq
@@ -7,7 +7,7 @@ module Rouge
7
7
  title "HTML"
8
8
  desc "HTML, the markup language of the web"
9
9
  tag 'html'
10
- filenames '*.htm', '*.html', '*.xhtml', '*.cshtml'
10
+ filenames '*.htm', '*.html', '*.xhtml', '*.cshtml', '*.razor'
11
11
  mimetypes 'text/html', 'application/xhtml+xml'
12
12
 
13
13
  def self.detect?(text)
@@ -0,0 +1,92 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Lexers
6
+ class IecST < RegexLexer
7
+ tag 'iecst'
8
+ title "IEC 61131-3 Structured Text"
9
+ desc 'Structured text is a programming language for PLCs (programmable logic controllers).'
10
+ filenames '*.awl', '*.scl', '*.st'
11
+
12
+ mimetypes 'text/x-iecst'
13
+
14
+ def self.keywords
15
+ blocks = %w(
16
+ PROGRAM CONFIGURATION INITIAL_STEP INTERFACE FUNCTION_BLOCK FUNCTION ACTION TRANSITION
17
+ TYPE STRUCT STEP NAMESPACE LIBRARY CHANNEL FOLDER RESOURCE
18
+ VAR_ACCESS VAR_CONFIG VAR_EXTERNAL VAR_GLOBAL VAR_INPUT VAR_IN_OUT VAR_OUTPUT VAR_TEMP VAR
19
+ CONST METHOD PROPERTY
20
+ CASE FOR IF REPEAT WHILE
21
+ )
22
+ @keywords ||= Set.new %w(
23
+ AT BEGIN BY CONSTANT CONTINUE DO ELSE ELSIF EXIT EXTENDS FROM GET GOTO IMPLEMENTS JMP
24
+ NON_RETAIN OF PRIVATE PROTECTED PUBLIC RETAIN RETURN SET TASK THEN TO UNTIL USING WITH
25
+ __CATCH __ENDTRY __FINALLY __TRY
26
+ ) + blocks + blocks.map {|kw| "END_" + kw}
27
+ end
28
+
29
+ def self.types
30
+ @types ||= Set.new %w(
31
+ ANY ARRAY BOOL BYTE POINTER STRING
32
+ DATE DATE_AND_TIME DT TIME TIME_OF_DAY TOD
33
+ INT DINT LINT SINT UINT UDINT ULINT USINT
34
+ WORD DWORD LWORD
35
+ REAL LREAL
36
+ )
37
+ end
38
+
39
+ def self.literals
40
+ @literals ||= Set.new %w(TRUE FALSE NULL)
41
+ end
42
+
43
+ def self.operators
44
+ @operators ||= Set.new %w(AND EQ EXPT GE GT LE LT MOD NE NOT OR XOR)
45
+ end
46
+
47
+ state :whitespace do
48
+ # Spaces
49
+ rule %r/\s+/m, Text
50
+ # // Comments
51
+ rule %r((//).*$\n?), Comment::Single
52
+ # (* Comments *)
53
+ rule %r(\(\*.*?\*\))m, Comment::Multiline
54
+ # { Comments }
55
+ rule %r(\{.*?\})m, Comment::Special
56
+ end
57
+
58
+ state :root do
59
+ mixin :whitespace
60
+
61
+ rule %r/'[^']+'/, Literal::String::Single
62
+ rule %r/"[^"]+"/, Literal::String::Symbol
63
+ rule %r/%[IQM][XBWDL][\d.]*|%[IQ][\d.]*/, Name::Variable::Magic
64
+ rule %r/\b(?:D|DT|T|TOD)#[\d_shmd:]*/i, Literal::Date
65
+ rule %r/\b(?:16#[\d_a-f]+|0x[\d_a-f]+)\b/i, Literal::Number::Hex
66
+ rule %r/\b2#[01_]+/, Literal::Number::Bin
67
+ rule %r/(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i, Literal::Number::Float
68
+ rule %r/\b[\d.,_]+/, Literal::Number
69
+
70
+ rule %r/\b[A-Z_]+\b/i do |m|
71
+ name = m[0].upcase
72
+ if self.class.keywords.include?(name)
73
+ token Keyword
74
+ elsif self.class.types.include?(name)
75
+ token Keyword::Type
76
+ elsif self.class.literals.include?(name)
77
+ token Literal
78
+ elsif self.class.operators.include?(name)
79
+ token Operator
80
+ else
81
+ token Name
82
+ end
83
+ end
84
+
85
+ rule %r/S?R?:?=>?|&&?|\*\*?|<[=>]?|>=?|[-:^\/+#]/, Operator
86
+ rule %r/\b[a-z_]\w*(?=\s*\()/i, Name::Function
87
+ rule %r/\b[a-z_]\w*\b/i, Name
88
+ rule %r/[()\[\].,;]/, Punctuation
89
+ end
90
+ end
91
+ end
92
+ end
@@ -8,15 +8,14 @@ module Rouge
8
8
  desc 'the INI configuration format'
9
9
  tag 'ini'
10
10
 
11
- # TODO add more here
12
- filenames '*.ini', '*.INI', '*.gitconfig'
13
- mimetypes 'text/x-ini'
11
+ filenames '*.ini', '*.INI', '*.gitconfig', '*.cfg', '.editorconfig', '*.inf'
12
+ mimetypes 'text/x-ini', 'text/inf'
14
13
 
15
14
  identifier = /[\w\-.]+/
16
15
 
17
16
  state :basic do
17
+ rule %r/\s+/, Text::Whitespace
18
18
  rule %r/[;#].*?\n/, Comment
19
- rule %r/\s+/, Text
20
19
  rule %r/\\\n/, Str::Escape
21
20
  end
22
21
 
@@ -24,11 +23,14 @@ module Rouge
24
23
  mixin :basic
25
24
 
26
25
  rule %r/(#{identifier})(\s*)(=)/ do
27
- groups Name::Property, Text, Punctuation
26
+ groups Name::Property, Text::Whitespace, Punctuation
28
27
  push :value
29
28
  end
30
29
 
31
30
  rule %r/\[.*?\]/, Name::Namespace
31
+
32
+ # standalone option, supported by some INI parsers
33
+ rule %r/(.+?)/, Name::Attribute
32
34
  end
33
35
 
34
36
  state :value do
@@ -51,7 +51,7 @@ module Rouge
51
51
  rule %r/(?:#{declarations.join('|')})\b/, Keyword::Declaration
52
52
  rule %r/(?:#{types.join('|')})\b/, Keyword::Type
53
53
  rule %r/(?:true|false|null)\b/, Keyword::Constant
54
- rule %r/(?:class|interface)\b/, Keyword::Declaration, :class
54
+ rule %r/(?:class|interface|record)\b/, Keyword::Declaration, :class
55
55
  rule %r/(?:import|package)\b/, Keyword::Namespace, :import
56
56
  rule %r/"""\s*\n.*?(?<!\\)"""/m, Str::Heredoc
57
57
  rule %r/"(\\\\|\\"|[^"])*"/, Str
@@ -100,7 +100,7 @@ module Rouge
100
100
 
101
101
  def self.keywords
102
102
  @keywords ||= Set.new %w(
103
- as async await break case catch continue debugger default delete
103
+ async await break case catch continue debugger default delete
104
104
  do else export finally from for if import in instanceof new of
105
105
  return super switch this throw try typeof void while yield
106
106
  )
@@ -190,8 +190,8 @@ module Rouge
190
190
 
191
191
  rule %r/function(?=(\(.*\)))/, Keyword::Declaration # For anonymous functions
192
192
 
193
- rule %r/(#{id})[ \t]*(?=(\(.*\)))/m do |m|
194
- if self.class.keywords.include? m[1]
193
+ rule %r/(#?#{id})[ \t]*(?=(\(.*\)))/m do |m|
194
+ if self.class.keywords.include?(m[1])
195
195
  # "if" in "if (...)" or "switch" in "switch (...)" are recognized as keywords.
196
196
  token Keyword
197
197
  else
@@ -201,7 +201,7 @@ module Rouge
201
201
 
202
202
  rule %r/[{}]/, Punctuation, :statement
203
203
 
204
- rule id do |m|
204
+ rule %r/#?#{id}/ do |m|
205
205
  if self.class.keywords.include? m[0]
206
206
  token Keyword
207
207
  push :expr_start
@@ -0,0 +1,74 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Lexers
6
+ load_lexer 'json.rb'
7
+
8
+ class JSON5 < JSON
9
+ title 'JSON 5'
10
+ tag 'json5'
11
+ filenames '*.json5'
12
+ mimetypes 'application/json5', 'application/x-json5'
13
+
14
+ desc 'JSON 5 extension for JSON (json5.org)'
15
+
16
+ append :whitespace do
17
+ rule %r://.*$:, Comment
18
+
19
+ # comments are non-nesting, so a single regex will do
20
+ rule %r:/[*].*?[*]/:m, Comment
21
+ end
22
+
23
+ prepend :name do
24
+ rule Javascript.id_regex, Name::Label
25
+ rule %r/".*?"/, Name::Label
26
+ end
27
+
28
+ # comments can appear between keys and :, so we have to
29
+ # manage our states a little more carefully
30
+ append :object do
31
+ rule %r/:/ do
32
+ token Punctuation
33
+ goto :object_value
34
+ end
35
+ end
36
+
37
+ state :object_value do
38
+ mixin :value
39
+ rule %r/,/ do
40
+ token Punctuation
41
+ goto :object
42
+ end
43
+
44
+ rule %r/}/, Punctuation, :pop!
45
+ end
46
+
47
+ append :value do
48
+ rule %r/'/, Str::Single, :sstring
49
+ end
50
+
51
+ state :sstring do
52
+ rule %r/[^\\']+/, Str::Single
53
+ rule %r/\\./m, Str::Escape
54
+ rule %r/'/, Str::Single, :pop!
55
+ end
56
+
57
+ # can escape newlines
58
+ append :string do
59
+ rule %r/\\./m, Str::Escape
60
+ end
61
+
62
+ # override: numbers are very different in json5
63
+ state :constants do
64
+ rule %r/\b(?:true|false|null)\b/, Keyword::Constant
65
+ rule %r/[+-]?\b(?:Infinity|NaN)\b/, Keyword::Constant
66
+ rule %r/[+-]?0x\h+/i, Num::Hex
67
+
68
+ rule %r/[+-.]?[0-9]+[.]?[0-9]?([eE][-]?[0-9]+)?/i, Num::Float
69
+ rule %r/[+-]?\d+e[+-]?\d+/, Num::Integer
70
+ rule %r/[+-]?(?:0|[1-9]\d*)(?:e[+-]?\d+)?/i, Num::Integer
71
+ end
72
+ end
73
+ end
74
+ end
@@ -252,15 +252,16 @@ module Rouge
252
252
  rule %r/\d+/, Literal::Number::Integer
253
253
  end
254
254
 
255
+ NAME_RE = %r/[\p{L}\p{Nl}\p{S}_][\p{Word}\p{S}\p{Po}!]*/
255
256
 
256
257
  state :funcname do
257
- rule %r/[\p{L}\p{Nl}\p{S}_][\p{Word}\p{S}\p{Po}!]*/, Name::Function, :pop!
258
+ rule NAME_RE, Name::Function, :pop!
258
259
  rule %r/\([^\s\w{]{1,2}\)/, Operator, :pop!
259
260
  rule %r/[^\s\w{]{1,2}/, Operator, :pop!
260
261
  end
261
262
 
262
263
  state :typename do
263
- rule %r/[\p{L}\p{Nl}\p{S}_][\p{Word}\p{S}\p{Po}!]*/, Name::Class, :pop!
264
+ rule NAME_RE, Name::Class, :pop!
264
265
  end
265
266
 
266
267
  state :stringescape do
@@ -24,7 +24,7 @@ module Rouge
24
24
  while yield
25
25
  )
26
26
 
27
- name_chars = %r'[-_\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Nl}\p{Nd}\p{Pc}\p{Cf}\p{Mn}\p{Mc}]*'
27
+ name_chars = %r'[-\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Nl}\p{Nd}\p{Pc}\p{Cf}\p{Mn}\p{Mc}]*'
28
28
 
29
29
  class_name = %r'`?[\p{Lu}]#{name_chars}`?'
30
30
  name = %r'`?[_\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Nl}]#{name_chars}`?'
@@ -105,7 +105,26 @@ module Rouge
105
105
  rule %r/\)/, Punctuation, :pop!
106
106
  rule %r/[(,]/, Punctuation
107
107
  rule %r/\s+/, Text
108
- rule %r/"/, Str::Regex, :regex
108
+ rule %r/'/, Str::Regex, :regex_sq
109
+ rule %r/"/, Str::Regex, :regex_dq
110
+ end
111
+
112
+ state :regex_sq do
113
+ rule %r(') do
114
+ token Str::Regex
115
+ goto :regex_end
116
+ end
117
+
118
+ mixin :regex
119
+ end
120
+
121
+ state :regex_dq do
122
+ rule %r(") do
123
+ token Str::Regex
124
+ goto :regex_end
125
+ end
126
+
127
+ mixin :regex
109
128
  end
110
129
 
111
130
  state :regex do
@@ -151,13 +170,15 @@ module Rouge
151
170
  end
152
171
 
153
172
  state :sqs do
173
+ rule %r(\\'), Str::Escape
154
174
  rule %r('), Str::Single, :pop!
155
- rule %r([^']+), Str::Single
175
+ rule %r([^'\\]+), Str::Single
156
176
  end
157
177
 
158
178
  state :dqs do
179
+ rule %r(\\"), Str::Escape
159
180
  rule %r("), Str::Double, :pop!
160
- rule %r([^"]+), Str::Double
181
+ rule %r([^"\\]+), Str::Double
161
182
  end
162
183
  end
163
184
  end
@@ -40,6 +40,10 @@ module Rouge
40
40
  groups Keyword, Text, Name::Variable
41
41
  end
42
42
 
43
+ rule %r/(else\b)([\t ]+)((?:ifn?def|ifn?eq)\b)([\t ]+)([^#\n]+)/ do
44
+ groups Keyword, Text, Keyword, Text, Name::Variable
45
+ end
46
+
43
47
  rule %r/(?:else|endif|endef|endfor)[\t ]*(?=[#\n])/, Keyword
44
48
 
45
49
  rule %r/(export)([\t ]+)(?=[\w\${}()\t -]+\n)/ do
@@ -73,7 +77,7 @@ module Rouge
73
77
  end
74
78
 
75
79
  state :export do
76
- rule %r/[\w[\$]{1,2}{}()-]/, Name::Variable
80
+ rule %r/[\w\${}()-]/, Name::Variable
77
81
  rule %r/\n/, Text, :pop!
78
82
  rule %r/[\t ]+/, Text
79
83
  end
@@ -107,7 +107,8 @@ module Rouge
107
107
  push :link
108
108
  end
109
109
 
110
- rule %r/[*][*]#{edot}*?[*][*]/, Generic::Strong
110
+ rule %r/[*]{2}[^* \n][^*\n]*[*]{2}/, Generic::Strong
111
+ rule %r/[*]{3}[^* \n][^*\n]*[*]{3}/, Generic::EmphStrong
111
112
  rule %r/__#{edot}*?__/, Generic::Strong
112
113
 
113
114
  rule %r/[*]#{edot}*?[*]/, Generic::Emph
@@ -7,7 +7,7 @@ module Rouge
7
7
  title "Mathematica"
8
8
  desc "Wolfram Mathematica, the world's definitive system for modern technical computing."
9
9
  tag 'mathematica'
10
- aliases 'wl'
10
+ aliases 'wl', 'wolfram'
11
11
  filenames '*.m', '*.wl'
12
12
  mimetypes 'application/vnd.wolfram.mathematica.package', 'application/vnd.wolfram.wl'
13
13
 
@@ -38,7 +38,6 @@ module Rouge
38
38
  end
39
39
 
40
40
  identifier = /[[:alpha:]_][[:alnum:]_]*/
41
- dotted_identifier = /[[:alpha:]_.][[:alnum:]_.]*/
42
41
 
43
42
  def current_string
44
43
  @current_string ||= StringRegister.new
@@ -0,0 +1,35 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Lexers
6
+ load_lexer 'python.rb'
7
+
8
+ class Mojo < Python
9
+ title "Mojo"
10
+ desc "The Mojo programming language (modular.com)"
11
+ tag 'mojo'
12
+ aliases 'mojo'
13
+ filenames '*.mojo', '*.🔥'
14
+ mimetypes 'text/x-mojo', 'application/x-mojo'
15
+
16
+ def self.detect?(text)
17
+ return true if text.shebang?(/mojow?(?:[23](?:\.\d+)?)?/)
18
+ end
19
+
20
+ def self.keywords
21
+ @keywords ||= super + %w(
22
+ fn self alias out read mut owned ref var
23
+ struct trait raises with in match case
24
+ )
25
+ end
26
+
27
+ def self.builtins
28
+ @builtins ||= super + %w(
29
+ __mlir_attr __mlir_type __mlir_op parameter alwaysinline
30
+ register_passable
31
+ )
32
+ end
33
+ end
34
+ end
35
+ end
@@ -14,11 +14,12 @@ module Rouge
14
14
  mimetypes 'text/x-nasm'
15
15
 
16
16
  state :root do
17
- rule %r/^\s*%/, Comment::Preproc, :preproc
17
+ rule %r/^\s*%/, Comment::Preproc, :preproc
18
18
 
19
- mixin :whitespace
19
+ mixin :whitespace
20
+ mixin :punctuation
20
21
 
21
- rule %r/[a-z$._?][\w$.?#@~]*:/i, Name::Label
22
+ rule %r/[a-z$._?][\w$.?#@~]*:/i, Name::Label
22
23
 
23
24
  rule %r/([a-z$._?][\w$.?#@~]*)(\s+)(equ)/i do
24
25
  groups Name::Constant, Keyword::Declaration, Keyword::Declaration
@@ -32,7 +33,7 @@ module Rouge
32
33
  end
33
34
 
34
35
  state :instruction_args do
35
- rule %r/"(\\\\"|[^"\\n])*"|'(\\\\'|[^'\\n])*'|`(\\\\`|[^`\\n])*`/, Str
36
+ rule %r/"(\\\\"|[^"\\n])*"|'(\\\\'|[^'\\n])*'|`(\\\\`|[^`\\n])*`/, Str
36
37
  rule %r/(?:0x[\da-f]+|$0[\da-f]*|\d+[\da-f]*h)/i, Num::Hex
37
38
  rule %r/[0-7]+q/i, Num::Oct
38
39
  rule %r/[01]+b/i, Num::Bin
@@ -53,6 +53,7 @@ module Rouge
53
53
  # mimetype
54
54
  rule %r([a-z-]+/[a-z-]+)i, Name::Class
55
55
 
56
+ rule %r/\d+\.\d+/, Num::Float
56
57
  rule %r/[0-9]+[kmg]?\b/i, Num::Integer
57
58
  rule %r/(~)(\s*)([^\s{]+)/ do
58
59
  groups Punctuation, Text, Str::Regex
@@ -4,8 +4,6 @@
4
4
  module Rouge
5
5
  module Lexers
6
6
  module ObjectiveCCommon
7
- id = /[a-z$_][a-z0-9$_]*/i
8
-
9
7
  def at_keywords
10
8
  @at_keywords ||= %w(
11
9
  selector private protected public encode synchronized try
@@ -12,7 +12,7 @@ module Rouge
12
12
  tag 'objective_c'
13
13
  title "Objective-C"
14
14
  desc 'an extension of C commonly used to write Apple software'
15
- aliases 'objc', 'obj-c', 'obj_c', 'objectivec'
15
+ aliases 'objc', 'obj-c', 'obj_c', 'objectivec', 'objective-c'
16
16
  filenames '*.m', '*.h'
17
17
 
18
18
  mimetypes 'text/x-objective_c', 'application/x-objective_c'
@@ -61,9 +61,9 @@ module Rouge
61
61
  rule %r/--.*/, Comment::Single
62
62
  rule %r/\d+/, Num::Integer
63
63
  rule %r/'/, Str::Single, :single_string
64
- rule %r([->|+*/<>=~!@#%&|?^-]), Operator
64
+ rule %r([-|+*/<>=~!@#%&?^]), Operator
65
65
  rule %r/[;:()\[\],.]/, Punctuation
66
- rule %r/\w[\w\d]*/ do |m|
66
+ rule %r/[a-zA-Z]\w*/ do |m|
67
67
  if self.class.operators.include? m[0]
68
68
  token Operator
69
69
  elsif self.class.keywords_type.include? m[0]
@@ -12,8 +12,6 @@ module Rouge
12
12
  title 'OpenEdge ABL'
13
13
  desc 'The OpenEdge ABL programming language'
14
14
 
15
- # optional comment or whitespace
16
- ws = %r((?:\s|//.*?\n|/[*].*?[*]/)+)
17
15
  id = /[a-zA-Z_&{}!][a-zA-Z0-9_\-&!}]*/
18
16
 
19
17
  def self.keywords
@@ -0,0 +1,81 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Lexers
6
+ class P4 < RegexLexer
7
+ tag 'p4'
8
+ title 'P4'
9
+ desc 'The P4 programming language'
10
+ filenames '*.p4'
11
+ mimetypes 'text/x-p4'
12
+
13
+ def self.keywords
14
+ @keywords ||= %w(
15
+ abstract action actions apply const default default_action else enum
16
+ entries extern exit if in inout key list out package packet_in
17
+ packet_out return size select switch this transition tuple type
18
+ typedef
19
+ )
20
+ end
21
+
22
+ def self.operators
23
+ @operators ||= %w(
24
+ \|\+\| \|-\| \? \& \&\&\& < > << >> \* \| ~ \^ - \+ /
25
+ \# \. = != <= >= \+\+
26
+ )
27
+ end
28
+
29
+ def self.decls
30
+ @decls ||= %w(
31
+ control header header_union parser state struct table
32
+ value_set
33
+ )
34
+ end
35
+
36
+ def self.builtins
37
+ @builtins ||= %w(
38
+ bit bool error extract int isValid setValid setInvalid match_kind
39
+ string varbit verify void
40
+ )
41
+ end
42
+
43
+ state :whitespace do
44
+ rule %r/\s+/m, Text
45
+ end
46
+
47
+ state :comment do
48
+ rule %r((//).*$\n?), Comment::Single
49
+ rule %r/\/\*(?:(?!\*\/).)*\*\//m, Comment::Multiline
50
+ end
51
+
52
+ state :number do
53
+ rule %r/([0-9]+[sw])?0[oO][0-7_]+/, Num
54
+ rule %r/([0-9]+[sw])?0[xX][0-9a-fA-F_]+/, Num
55
+ rule %r/([0-9]+[sw])?0[bB][01_]+/, Num
56
+ rule %r/([0-9]+[sw])?0[dD][0-9_]+/, Num
57
+ rule %r/([0-9]+[sw])?[0-9_]+/, Num
58
+ end
59
+
60
+ id = /[\p{XID_Start}_]\p{XID_Continue}*/
61
+ string_element = /\\"|[^"]/x
62
+
63
+ state :root do
64
+ mixin :whitespace
65
+ mixin :comment
66
+
67
+ rule %r/#\s*#{id}/, Comment::Preproc
68
+ rule %r/\b(?:#{P4.keywords.join('|')})\b/, Keyword
69
+ rule %r/\b(?:#{P4.decls.join('|')})\b/, Keyword::Declaration
70
+ rule %r/\b(?:#{P4.builtins.join('|')})\b/, Name::Builtin
71
+ rule %r/\b#{id}_[th]\b/x, Name::Class
72
+ rule %r/(?:#{P4.operators.join('|')})/x, Operator
73
+ rule %r/[(){}\[\]<>,:;\.]/, Punctuation
74
+ mixin :number
75
+ rule %r/@#{id}/x, Name::Label
76
+ rule %r/#{id}/x, Text
77
+ rule %r/"(?: #{string_element} )*"/x, Str::String
78
+ end
79
+ end
80
+ end
81
+ end