rouge 3.17.0 → 3.18.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 (50) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rouge.rb +65 -51
  3. data/lib/rouge/demos/cypher +5 -0
  4. data/lib/rouge/demos/datastudio +21 -0
  5. data/lib/rouge/demos/ghc-cmm +23 -0
  6. data/lib/rouge/demos/isbl +4 -0
  7. data/lib/rouge/demos/rego +8 -0
  8. data/lib/rouge/demos/solidity +13 -0
  9. data/lib/rouge/demos/yang +17 -0
  10. data/lib/rouge/lexer.rb +2 -1
  11. data/lib/rouge/lexers/apache.rb +4 -8
  12. data/lib/rouge/lexers/apache/keywords.rb +15 -0
  13. data/lib/rouge/lexers/cmake.rb +1 -0
  14. data/lib/rouge/lexers/console.rb +53 -37
  15. data/lib/rouge/lexers/cpp.rb +12 -5
  16. data/lib/rouge/lexers/cypher.rb +108 -0
  17. data/lib/rouge/lexers/datastudio.rb +138 -0
  18. data/lib/rouge/lexers/fsharp.rb +1 -0
  19. data/lib/rouge/lexers/ghc_cmm.rb +340 -0
  20. data/lib/rouge/lexers/gherkin.rb +1 -1
  21. data/lib/rouge/lexers/isbl.rb +97 -0
  22. data/lib/rouge/lexers/isbl/builtins.rb +17 -0
  23. data/lib/rouge/lexers/json.rb +3 -0
  24. data/lib/rouge/lexers/json_doc.rb +1 -0
  25. data/lib/rouge/lexers/kotlin.rb +4 -0
  26. data/lib/rouge/lexers/lasso.rb +4 -9
  27. data/lib/rouge/lexers/lasso/keywords.rb +14 -0
  28. data/lib/rouge/lexers/lua.rb +1 -1
  29. data/lib/rouge/lexers/markdown.rb +1 -1
  30. data/lib/rouge/lexers/mathematica.rb +1 -1
  31. data/lib/rouge/lexers/matlab.rb +3 -4
  32. data/lib/rouge/lexers/matlab/builtins.rb +11 -0
  33. data/lib/rouge/lexers/pascal.rb +1 -1
  34. data/lib/rouge/lexers/php.rb +47 -32
  35. data/lib/rouge/lexers/python.rb +66 -57
  36. data/lib/rouge/lexers/racket.rb +24 -1
  37. data/lib/rouge/lexers/rego.rb +45 -0
  38. data/lib/rouge/lexers/ruby.rb +11 -1
  39. data/lib/rouge/lexers/solidity.rb +185 -0
  40. data/lib/rouge/lexers/sqf.rb +1 -1
  41. data/lib/rouge/lexers/terraform.rb +15 -0
  42. data/lib/rouge/lexers/typescript.rb +4 -0
  43. data/lib/rouge/lexers/viml.rb +1 -1
  44. data/lib/rouge/lexers/vue.rb +4 -1
  45. data/lib/rouge/lexers/yang.rb +147 -0
  46. data/lib/rouge/version.rb +1 -1
  47. metadata +20 -5
  48. data/lib/rouge/lexers/apache/keywords.yml +0 -764
  49. data/lib/rouge/lexers/lasso/keywords.yml +0 -446
  50. data/lib/rouge/lexers/matlab/builtins.yml +0 -3515
@@ -488,6 +488,9 @@ module Rouge
488
488
  state :root do
489
489
  # comments
490
490
  rule %r/;.*$/, Comment::Single
491
+ rule %r/#!.*/, Comment::Single
492
+ rule %r/#\|/, Comment::Multiline, :block_comment
493
+ rule %r/#;/, Comment::Multiline, :sexp_comment
491
494
  rule %r/\s+/m, Text
492
495
 
493
496
  rule %r/[+-]inf[.][f0]/, Num::Float
@@ -510,7 +513,7 @@ module Rouge
510
513
  rule %r/['`]#{id}/i, Str::Symbol
511
514
  rule %r/#\\([()\/'"._!\$%& ?=+-]{1}|[a-z0-9]+)/i,
512
515
  Str::Char
513
- rule %r/#t|#f/, Name::Constant
516
+ rule %r/#t(rue)?|#f(alse)?/i, Name::Constant
514
517
  rule %r/(?:'|#|`|,@|,|\.)/, Operator
515
518
 
516
519
  rule %r/(['#])(\s*)(\()/m do
@@ -524,6 +527,26 @@ module Rouge
524
527
  rule id, Name::Variable
525
528
  end
526
529
 
530
+ state :block_comment do
531
+ rule %r/[^|#]+/, Comment::Multiline
532
+ rule %r/\|#/, Comment::Multiline, :pop!
533
+ rule %r/#\|/, Comment::Multiline, :block_comment
534
+ rule %r/[|#]/, Comment::Multiline
535
+ end
536
+
537
+ state :sexp_comment do
538
+ rule %r/[({\[]/, Comment::Multiline, :sexp_comment_inner
539
+ rule %r/"(?:\\"|[^"])*?"/, Comment::Multiline, :pop!
540
+ rule %r/[^\s]+/, Comment::Multiline, :pop!
541
+ rule(//) { pop! }
542
+ end
543
+
544
+ state :sexp_comment_inner do
545
+ rule %r/[^(){}\[\]]+/, Comment::Multiline
546
+ rule %r/[)}\]]/, Comment::Multiline, :pop!
547
+ rule %r/[({\[]/, Comment::Multiline, :sexp_comment_inner
548
+ end
549
+
527
550
  state :command do
528
551
  rule id, Name::Function do |m|
529
552
  if self.class.keywords.include? m[0]
@@ -0,0 +1,45 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Lexers
6
+ class Rego < RegexLexer
7
+ title "Rego"
8
+ desc "The Rego open-policy-agent (OPA) policy language (openpolicyagent.org)"
9
+ tag 'rego'
10
+ filenames '*.rego'
11
+
12
+ state :basic do
13
+ rule %r/\s+/, Text
14
+ rule %r/#.*/, Comment::Single
15
+
16
+ rule %r/[\[\](){}|.,;!]/, Punctuation
17
+
18
+ rule %r/"[^"]*"/, Str::Double
19
+
20
+ rule %r/-?\d+\.\d+([eE][+-]?\d+)?/, Num::Float
21
+ rule %r/-?\d+([eE][+-]?\d+)?/, Num
22
+
23
+ rule %r/\\u[0-9a-fA-F]{4}/, Num::Hex
24
+ rule %r/\\["\/bfnrt]/, Str::Escape
25
+ end
26
+
27
+ state :atoms do
28
+ rule %r/(true|false|null)/, Keyword::Constant
29
+ rule %r/[[:word:]]*/, Str::Symbol
30
+ end
31
+
32
+ state :operators do
33
+ rule %r/(=|!=|>=|<=|>|<|\+|-|\*|%|\/|\||&|:=)/, Operator
34
+ rule %r/(default|not|package|import|as|with|else|some)/, Operator
35
+ rule %r/[\/:?@^~]+/, Operator
36
+ end
37
+
38
+ state :root do
39
+ mixin :basic
40
+ mixin :operators
41
+ mixin :atoms
42
+ end
43
+ end
44
+ end
45
+ end
@@ -309,6 +309,8 @@ module Rouge
309
309
 
310
310
  state :classname do
311
311
  rule %r/\s+/, Text
312
+ rule %r/\w+(::\w+)+/, Name::Class
313
+
312
314
  rule %r/\(/ do
313
315
  token Punctuation
314
316
  push :defexpr
@@ -327,7 +329,15 @@ module Rouge
327
329
  end
328
330
 
329
331
  state :ternary do
330
- rule(/:(?!:)/) { token Punctuation; goto :expr_start }
332
+ rule %r/(:)(\s+)/ do
333
+ groups Punctuation, Text
334
+ goto :expr_start
335
+ end
336
+
337
+ rule %r/:(?![^#\n]*?[:\\])/ do
338
+ token Punctuation
339
+ goto :expr_start
340
+ end
331
341
 
332
342
  mixin :root
333
343
  end
@@ -0,0 +1,185 @@
1
+ # -*- coding: utf-8 -*- #
2
+
3
+ module Rouge
4
+ module Lexers
5
+ class Solidity < RegexLexer
6
+ title "Solidity"
7
+ desc "Solidity, an Ethereum smart contract programming language"
8
+ tag 'solidity'
9
+ filenames '*.sol', '*.solidity'
10
+ mimetypes 'text/x-solidity'
11
+
12
+ # optional comment or whitespace
13
+ ws = %r((?:\s|//.*?\n|/[*].*?[*]/)+)
14
+ id = /[a-zA-Z$_][\w$_]*/
15
+
16
+ def self.detect?(text)
17
+ return true if text.start_with? 'pragma solidity'
18
+ end
19
+
20
+ # TODO: seperate by "type"
21
+ def self.keywords
22
+ @keywords ||= Set.new %w(
23
+ abstract anonymous as assembly break catch calldata constant
24
+ constructor continue contract do delete else emit enum event
25
+ external fallback for function hex if indexed interface
26
+ internal import is library mapping memory modifier new
27
+ override payable public pure pragma private receive return
28
+ returns storage struct throw try type using var view virtual
29
+ while
30
+ )
31
+ end
32
+
33
+ def self.builtins
34
+ return @builtins if @builtins
35
+
36
+ @builtins = Set.new %w(
37
+ now
38
+ false true
39
+ balance now selector super this
40
+ blockhash gasleft
41
+ assert require revert
42
+ selfdestruct suicide
43
+ call callcode delegatecall
44
+ send transfer
45
+ addmod ecrecover keccak256 mulmod sha256 sha3 ripemd160
46
+ )
47
+
48
+ # TODO: use (currently shadowed by catch-all in :statements)
49
+ abi = %w(decode encode encodePacked encodeWithSelector encodeWithSignature)
50
+ @builtins.merge( abi.map { |i| "abi.#{i}" } )
51
+ block = %w(coinbase difficulty gaslimit hash number timestamp)
52
+ @builtins.merge( block.map { |i| "block.#{i}" } )
53
+ msg = %w(data gas sender sig value)
54
+ @builtins.merge( msg.map { |i| "msg.#{i}" } )
55
+ tx = %w(gasprice origin)
56
+ @builtins.merge( tx.map { |i| "tx.#{i}" } )
57
+ end
58
+
59
+ def self.constants
60
+ @constants ||= Set.new %w(
61
+ wei finney szabo ether
62
+ seconds minutes hours days weeks years
63
+ )
64
+ end
65
+
66
+ def self.keywords_type
67
+ @keywords_type ||= Set.new %w(
68
+ address bool byte bytes int string uint
69
+ )
70
+ end
71
+
72
+ def self.reserved
73
+ @reserved ||= Set.new %w(
74
+ alias after apply auto case copyof default define final fixed
75
+ immutable implements in inline let macro match mutable null of
76
+ partial promise reference relocatable sealed sizeof static
77
+ supports switch typedef typeof ufixed unchecked
78
+ )
79
+ end
80
+
81
+ start { push :bol }
82
+
83
+ state :expr_bol do
84
+ mixin :inline_whitespace
85
+
86
+ rule(//) { pop! }
87
+ end
88
+
89
+ # :expr_bol is the same as :bol but without labels, since
90
+ # labels can only appear at the beginning of a statement.
91
+ state :bol do
92
+ mixin :expr_bol
93
+ end
94
+
95
+ # TODO: natspec in comments
96
+ state :inline_whitespace do
97
+ rule %r/[ \t\r]+/, Text
98
+ rule %r/\\\n/, Text # line continuation
99
+ rule %r(/\*), Comment::Multiline, :comment_multi
100
+ end
101
+
102
+ state :whitespace do
103
+ rule %r/\n+/m, Text, :bol
104
+ rule %r(//(\\.|.)*?\n), Comment::Single, :bol
105
+ mixin :inline_whitespace
106
+ end
107
+
108
+ state :expr_whitespace do
109
+ rule %r/\n+/m, Text, :expr_bol
110
+ mixin :whitespace
111
+ end
112
+
113
+ state :statements do
114
+ mixin :whitespace
115
+ rule %r/(hex)?\"/, Str, :string_double
116
+ rule %r/(hex)?\'/, Str, :string_single
117
+ rule %r('(\\.|\\[0-7]{1,3}|\\x[a-f0-9]{1,2}|[^\\'\n])')i, Str::Char
118
+ rule %r/\d\d*\.\d+([eE]\d+)?/i, Num::Float
119
+ rule %r/0x[0-9a-f]+/i, Num::Hex
120
+ rule %r/\d+([eE]\d+)?/i, Num::Integer
121
+ rule %r(\*/), Error
122
+ rule %r([~!%^&*+=\|?:<>/-]), Operator
123
+ rule %r/[()\[\],.]/, Punctuation
124
+ rule %r/u?fixed\d+x\d+/, Keyword::Reserved
125
+ rule %r/bytes\d+/, Keyword::Type
126
+ rule %r/u?int\d+/, Keyword::Type
127
+ rule id do |m|
128
+ name = m[0]
129
+
130
+ if self.class.keywords.include? name
131
+ token Keyword
132
+ elsif self.class.builtins.include? name
133
+ token Name::Builtin
134
+ elsif self.class.constants.include? name
135
+ token Keyword::Constant
136
+ elsif self.class.keywords_type.include? name
137
+ token Keyword::Type
138
+ elsif self.class.reserved.include? name
139
+ token Keyword::Reserved
140
+ else
141
+ token Name
142
+ end
143
+ end
144
+ end
145
+
146
+ state :root do
147
+ mixin :expr_whitespace
148
+ rule(//) { push :statement }
149
+ # TODO: function declarations
150
+ end
151
+
152
+ state :statement do
153
+ rule %r/;/, Punctuation, :pop!
154
+ mixin :expr_whitespace
155
+ mixin :statements
156
+ rule %r/[{}]/, Punctuation
157
+ end
158
+
159
+ state :string_common do
160
+ rule %r/\\(u[a-fA-F0-9]{4}|x..|[^x])/, Str::Escape
161
+ rule %r/[^\\\"\'\n]+/, Str
162
+ rule %r/\\\n/, Str # line continuation
163
+ rule %r/\\/, Str # stray backslash
164
+ end
165
+
166
+ state :string_double do
167
+ mixin :string_common
168
+ rule %r/\"/, Str, :pop!
169
+ rule %r/\'/, Str
170
+ end
171
+
172
+ state :string_single do
173
+ mixin :string_common
174
+ rule %r/\'/, Str, :pop!
175
+ rule %r/\"/, Str
176
+ end
177
+
178
+ state :comment_multi do
179
+ rule %r(\*/), Comment::Multiline, :pop!
180
+ rule %r([^*/]+), Comment::Multiline
181
+ rule %r([*/]), Comment::Multiline
182
+ end
183
+ end
184
+ end
185
+ end
@@ -55,7 +55,7 @@ module Rouge
55
55
  end
56
56
 
57
57
  def self.commands
58
- load File.join(__dir__, "sqf/commands.rb")
58
+ load File.join(Lexers::BASE_DIR, "sqf/commands.rb")
59
59
  @commands = self.commands
60
60
  end
61
61
 
@@ -81,9 +81,24 @@ module Rouge
81
81
  mixin :expression
82
82
  end
83
83
 
84
+ state :regexps do
85
+ rule %r/"\// do
86
+ token Str::Delimiter
87
+ goto :regexp_inner
88
+ end
89
+ end
90
+
91
+ state :regexp_inner do
92
+ rule %r/[^"\/\\]+/, Str::Regex
93
+ rule %r/\\./, Str::Regex
94
+ rule %r/\/"/, Str::Delimiter, :pop!
95
+ rule %r/["\/]/, Str::Regex
96
+ end
97
+
84
98
  id = /[$a-z_\-][a-z0-9_\-]*/io
85
99
 
86
100
  state :expression do
101
+ mixin :regexps
87
102
  mixin :primitives
88
103
  rule %r/\s+/, Text
89
104
 
@@ -19,6 +19,10 @@ module Rouge
19
19
 
20
20
  mimetypes 'text/typescript'
21
21
 
22
+ prepend :root do
23
+ rule %r/[?][.]/, Punctuation
24
+ end
25
+
22
26
  prepend :statement do
23
27
  rule %r/(#{Javascript.id_regex})(\??)(\s*)(:)/ do
24
28
  groups Name::Label, Punctuation, Text, Punctuation
@@ -14,7 +14,7 @@ module Rouge
14
14
  mimetypes 'text/x-vim'
15
15
 
16
16
  def self.keywords
17
- load File.join(__dir__, 'viml/keywords.rb')
17
+ load File.join(Lexers::BASE_DIR, 'viml/keywords.rb')
18
18
  self.keywords
19
19
  end
20
20
 
@@ -58,6 +58,10 @@ module Rouge
58
58
  end
59
59
  end
60
60
 
61
+ prepend :tag do
62
+ rule %r/[a-zA-Z0-9_:#\[\]()*.-]+\s*=\s*/m, Name::Attribute, :attr
63
+ end
64
+
61
65
  state :style do
62
66
  rule %r/(<\s*\/\s*)(style)(\s*>)/ do
63
67
  groups Name::Tag, Keyword, Name::Tag
@@ -121,4 +125,3 @@ module Rouge
121
125
  end
122
126
  end
123
127
  end
124
-
@@ -0,0 +1,147 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Lexers
6
+ class YANG < RegexLexer
7
+ title 'YANG'
8
+ desc "Lexer for the YANG 1.1 modeling language (RFC7950)"
9
+ tag 'yang'
10
+ filenames '*.yang'
11
+ mimetypes 'application/yang'
12
+
13
+ id = /[\w_-]+(?=[^\w\-\:])\b/
14
+
15
+ #Keywords from RFC7950 ; oriented at BNF style
16
+ def self.top_stmts_keywords
17
+ @top_stms_keywords ||= Set.new %w(
18
+ module submodule
19
+ )
20
+ end
21
+
22
+ def self.module_header_stmts_keywords
23
+ @module_header_stmts_keywords ||= Set.new %w(
24
+ belongs-to namespace prefix yang-version
25
+ )
26
+ end
27
+
28
+ def self.meta_stmts_keywords
29
+ @meta_stmts_keywords ||= Set.new %w(
30
+ contact description organization reference revision
31
+ )
32
+ end
33
+
34
+ def self.linkage_stmts_keywords
35
+ @linkage_stmts_keywords ||= Set.new %w(
36
+ import include revision-date
37
+ )
38
+ end
39
+
40
+ def self.body_stmts_keywords
41
+ @body_stms_keywords ||= Set.new %w(
42
+ action argument augment deviation extension feature grouping identity
43
+ if-feature input notification output rpc typedef
44
+ )
45
+ end
46
+
47
+ def self.data_def_stmts_keywords
48
+ @data_def_stms_keywords ||= Set.new %w(
49
+ anydata anyxml case choice config container deviate leaf leaf-list
50
+ list must presence refine uses when
51
+ )
52
+ end
53
+
54
+ def self.type_stmts_keywords
55
+ @type_stmts_keywords ||= Set.new %w(
56
+ base bit default enum error-app-tag error-message fraction-digits
57
+ length max-elements min-elements modifier ordered-by path pattern
58
+ position range require-instance status type units value yin-element
59
+ )
60
+ end
61
+
62
+ def self.list_stmts_keywords
63
+ @list_stmts_keywords ||= Set.new %w(
64
+ key mandatory unique
65
+ )
66
+ end
67
+
68
+ #RFC7950 other keywords
69
+ def self.constants_keywords
70
+ @constants_keywords ||= Set.new %w(
71
+ add current delete deprecated false invert-match max min
72
+ not-supported obsolete replace true unbounded user
73
+ )
74
+ end
75
+
76
+ #RFC7950 Built-In Types
77
+ def self.types
78
+ @types ||= Set.new %w(
79
+ binary bits boolean decimal64 empty enumeration identityref
80
+ instance-identifier int16 int32 int64 int8 leafref string uint16
81
+ uint32 uint64 uint8 union
82
+ )
83
+ end
84
+
85
+ state :comment do
86
+ rule %r/[^*\/]/, Comment
87
+ rule %r/\/\*/, Comment, :comment
88
+ rule %r/\*\//, Comment, :pop!
89
+ rule %r/[*\/]/, Comment
90
+ end
91
+
92
+ #Keyword::Reserved
93
+ #groups Name::Tag, Text::Whitespace
94
+ state :root do
95
+ rule %r/\s+/, Text::Whitespace
96
+ rule %r/[\{\}\;]+/, Punctuation
97
+ rule %r/(?<![\-\w])(and|or|not|\+|\.)(?![\-\w])/, Operator
98
+
99
+ rule %r/"(?:\\"|[^"])*?"/, Str::Double #for double quotes
100
+ rule %r/'(?:\\'|[^'])*?'/, Str::Single #for single quotes
101
+
102
+ rule %r/\/\*/, Comment, :comment
103
+ rule %r/\/\/.*?$/, Comment
104
+
105
+ #match BNF stmt for `node-identifier` with [ prefix ":"]
106
+ rule %r/(?:^|(?<=[\s{};]))([\w.-]+)(:)([\w.-]+)(?=[\s{};])/ do
107
+ groups Name::Namespace, Punctuation, Name
108
+ end
109
+
110
+ #match BNF stmt `date-arg-str`
111
+ rule %r/([0-9]{4}\-[0-9]{2}\-[0-9]{2})(?=[\s\{\}\;])/, Name::Label
112
+ rule %r/([0-9]+\.[0-9]+)(?=[\s\{\}\;])/, Num::Float
113
+ rule %r/([0-9]+)(?=[\s\{\}\;])/, Num::Integer
114
+
115
+ rule id do |m|
116
+ name = m[0].downcase
117
+
118
+ if self.class.top_stmts_keywords.include? name
119
+ token Keyword::Declaration
120
+ elsif self.class.module_header_stmts_keywords.include? name
121
+ token Keyword::Declaration
122
+ elsif self.class.meta_stmts_keywords.include? name
123
+ token Keyword::Declaration
124
+ elsif self.class.linkage_stmts_keywords.include? name
125
+ token Keyword::Declaration
126
+ elsif self.class.body_stmts_keywords.include? name
127
+ token Keyword::Declaration
128
+ elsif self.class.data_def_stmts_keywords.include? name
129
+ token Keyword::Declaration
130
+ elsif self.class.type_stmts_keywords.include? name
131
+ token Keyword::Declaration
132
+ elsif self.class.list_stmts_keywords.include? name
133
+ token Keyword::Declaration
134
+ elsif self.class.types.include? name
135
+ token Keyword::Type
136
+ elsif self.class.constants_keywords.include? name
137
+ token Name::Constant
138
+ else
139
+ token Name
140
+ end
141
+ end
142
+
143
+ rule %r/[^;{}\s'"]+/, Name
144
+ end
145
+ end
146
+ end
147
+ end