rouge 3.4.1 → 3.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rouge.rb +3 -0
  3. data/lib/rouge/cli.rb +19 -2
  4. data/lib/rouge/demos/bpf +7 -0
  5. data/lib/rouge/demos/brainfuck +5 -0
  6. data/lib/rouge/demos/magik +6 -0
  7. data/lib/rouge/formatter.rb +2 -2
  8. data/lib/rouge/formatters/tex.rb +90 -0
  9. data/lib/rouge/guessers/glob_mapping.rb +1 -1
  10. data/lib/rouge/lexer.rb +22 -10
  11. data/lib/rouge/lexers/abap.rb +11 -11
  12. data/lib/rouge/lexers/actionscript.rb +34 -34
  13. data/lib/rouge/lexers/apache.rb +8 -8
  14. data/lib/rouge/lexers/apple_script.rb +15 -14
  15. data/lib/rouge/lexers/awk.rb +25 -25
  16. data/lib/rouge/lexers/biml.rb +4 -4
  17. data/lib/rouge/lexers/bpf.rb +104 -0
  18. data/lib/rouge/lexers/brainfuck.rb +53 -0
  19. data/lib/rouge/lexers/bsl.rb +12 -12
  20. data/lib/rouge/lexers/c.rb +30 -30
  21. data/lib/rouge/lexers/ceylon.rb +1 -29
  22. data/lib/rouge/lexers/cfscript.rb +26 -26
  23. data/lib/rouge/lexers/clojure.rb +14 -14
  24. data/lib/rouge/lexers/cmake.rb +14 -14
  25. data/lib/rouge/lexers/coffeescript.rb +30 -30
  26. data/lib/rouge/lexers/common_lisp.rb +36 -36
  27. data/lib/rouge/lexers/conf.rb +6 -6
  28. data/lib/rouge/lexers/coq.rb +18 -18
  29. data/lib/rouge/lexers/cpp.rb +8 -8
  30. data/lib/rouge/lexers/crystal.rb +70 -70
  31. data/lib/rouge/lexers/csharp.rb +28 -28
  32. data/lib/rouge/lexers/css.rb +23 -23
  33. data/lib/rouge/lexers/d.rb +59 -59
  34. data/lib/rouge/lexers/dart.rb +33 -33
  35. data/lib/rouge/lexers/digdag.rb +1 -1
  36. data/lib/rouge/lexers/docker.rb +10 -10
  37. data/lib/rouge/lexers/dot.rb +16 -16
  38. data/lib/rouge/lexers/eiffel.rb +20 -20
  39. data/lib/rouge/lexers/elixir.rb +29 -28
  40. data/lib/rouge/lexers/elm.rb +29 -29
  41. data/lib/rouge/lexers/erb.rb +4 -4
  42. data/lib/rouge/lexers/factor.rb +40 -40
  43. data/lib/rouge/lexers/fortran.rb +32 -32
  44. data/lib/rouge/lexers/fsharp.rb +26 -26
  45. data/lib/rouge/lexers/gherkin.rb +13 -13
  46. data/lib/rouge/lexers/glsl.rb +0 -4
  47. data/lib/rouge/lexers/go.rb +1 -1
  48. data/lib/rouge/lexers/graphql.rb +62 -62
  49. data/lib/rouge/lexers/groovy.rb +23 -25
  50. data/lib/rouge/lexers/hack.rb +1 -1
  51. data/lib/rouge/lexers/haml.rb +25 -29
  52. data/lib/rouge/lexers/handlebars.rb +18 -18
  53. data/lib/rouge/lexers/haskell.rb +66 -65
  54. data/lib/rouge/lexers/hcl.rb +25 -25
  55. data/lib/rouge/lexers/html.rb +31 -31
  56. data/lib/rouge/lexers/http.rb +4 -4
  57. data/lib/rouge/lexers/hylang.rb +14 -14
  58. data/lib/rouge/lexers/idlang.rb +32 -32
  59. data/lib/rouge/lexers/igorpro.rb +30 -30
  60. data/lib/rouge/lexers/ini.rb +12 -12
  61. data/lib/rouge/lexers/io.rb +7 -7
  62. data/lib/rouge/lexers/irb.rb +5 -5
  63. data/lib/rouge/lexers/java.rb +24 -24
  64. data/lib/rouge/lexers/javascript.rb +51 -51
  65. data/lib/rouge/lexers/jinja.rb +22 -22
  66. data/lib/rouge/lexers/json.rb +11 -10
  67. data/lib/rouge/lexers/json_doc.rb +2 -2
  68. data/lib/rouge/lexers/jsonnet.rb +18 -18
  69. data/lib/rouge/lexers/jsp.rb +28 -28
  70. data/lib/rouge/lexers/jsx.rb +16 -16
  71. data/lib/rouge/lexers/julia.rb +44 -44
  72. data/lib/rouge/lexers/kotlin.rb +3 -3
  73. data/lib/rouge/lexers/lasso.rb +50 -50
  74. data/lib/rouge/lexers/liquid.rb +53 -53
  75. data/lib/rouge/lexers/literate_coffeescript.rb +2 -2
  76. data/lib/rouge/lexers/literate_haskell.rb +5 -5
  77. data/lib/rouge/lexers/llvm.rb +23 -16
  78. data/lib/rouge/lexers/lua.rb +3 -3
  79. data/lib/rouge/lexers/m68k.rb +18 -19
  80. data/lib/rouge/lexers/magik.rb +126 -0
  81. data/lib/rouge/lexers/make.rb +22 -28
  82. data/lib/rouge/lexers/markdown.rb +37 -37
  83. data/lib/rouge/lexers/mathematica.rb +11 -11
  84. data/lib/rouge/lexers/matlab.rb +20 -20
  85. data/lib/rouge/lexers/moonscript.rb +3 -3
  86. data/lib/rouge/lexers/mosel.rb +17 -17
  87. data/lib/rouge/lexers/mxml.rb +18 -18
  88. data/lib/rouge/lexers/nasm.rb +24 -25
  89. data/lib/rouge/lexers/nginx.rb +14 -14
  90. data/lib/rouge/lexers/nim.rb +1 -1
  91. data/lib/rouge/lexers/nix.rb +42 -42
  92. data/lib/rouge/lexers/objective_c.rb +38 -38
  93. data/lib/rouge/lexers/ocaml.rb +29 -29
  94. data/lib/rouge/lexers/pascal.rb +4 -4
  95. data/lib/rouge/lexers/perl.rb +68 -68
  96. data/lib/rouge/lexers/php.rb +38 -38
  97. data/lib/rouge/lexers/plist.rb +14 -14
  98. data/lib/rouge/lexers/pony.rb +19 -19
  99. data/lib/rouge/lexers/powershell.rb +25 -25
  100. data/lib/rouge/lexers/praat.rb +75 -75
  101. data/lib/rouge/lexers/prolog.rb +26 -20
  102. data/lib/rouge/lexers/prometheus.rb +30 -30
  103. data/lib/rouge/lexers/properties.rb +12 -12
  104. data/lib/rouge/lexers/protobuf.rb +22 -22
  105. data/lib/rouge/lexers/puppet.rb +31 -31
  106. data/lib/rouge/lexers/python.rb +52 -52
  107. data/lib/rouge/lexers/q.rb +12 -12
  108. data/lib/rouge/lexers/qml.rb +12 -12
  109. data/lib/rouge/lexers/r.rb +12 -12
  110. data/lib/rouge/lexers/racket.rb +22 -22
  111. data/lib/rouge/lexers/ruby.rb +71 -69
  112. data/lib/rouge/lexers/rust.rb +30 -30
  113. data/lib/rouge/lexers/sass.rb +8 -8
  114. data/lib/rouge/lexers/sass/common.rb +40 -40
  115. data/lib/rouge/lexers/scala.rb +43 -43
  116. data/lib/rouge/lexers/scheme.rb +18 -18
  117. data/lib/rouge/lexers/scss.rb +3 -3
  118. data/lib/rouge/lexers/sed.rb +29 -29
  119. data/lib/rouge/lexers/shell.rb +61 -52
  120. data/lib/rouge/lexers/sieve.rb +8 -8
  121. data/lib/rouge/lexers/slim.rb +24 -24
  122. data/lib/rouge/lexers/smalltalk.rb +33 -33
  123. data/lib/rouge/lexers/smarty.rb +12 -12
  124. data/lib/rouge/lexers/sml.rb +67 -67
  125. data/lib/rouge/lexers/sqf.rb +1 -1
  126. data/lib/rouge/lexers/sql.rb +21 -21
  127. data/lib/rouge/lexers/supercollider.rb +19 -19
  128. data/lib/rouge/lexers/swift.rb +42 -39
  129. data/lib/rouge/lexers/tap.rb +20 -20
  130. data/lib/rouge/lexers/tcl.rb +27 -27
  131. data/lib/rouge/lexers/terraform.rb +13 -13
  132. data/lib/rouge/lexers/tex.rb +19 -19
  133. data/lib/rouge/lexers/toml.rb +18 -18
  134. data/lib/rouge/lexers/tulip.rb +36 -36
  135. data/lib/rouge/lexers/turtle.rb +35 -38
  136. data/lib/rouge/lexers/vala.rb +17 -17
  137. data/lib/rouge/lexers/vb.rb +27 -27
  138. data/lib/rouge/lexers/verilog.rb +25 -27
  139. data/lib/rouge/lexers/vhdl.rb +10 -10
  140. data/lib/rouge/lexers/viml.rb +14 -14
  141. data/lib/rouge/lexers/vue.rb +9 -9
  142. data/lib/rouge/lexers/wollok.rb +25 -25
  143. data/lib/rouge/lexers/xml.rb +17 -21
  144. data/lib/rouge/lexers/xojo.rb +15 -15
  145. data/lib/rouge/lexers/yaml.rb +61 -61
  146. data/lib/rouge/plugins/redcarpet.rb +1 -1
  147. data/lib/rouge/tex_theme_renderer.rb +128 -0
  148. data/lib/rouge/theme.rb +4 -0
  149. data/lib/rouge/themes/magritte.rb +78 -0
  150. data/lib/rouge/version.rb +1 -1
  151. metadata +11 -2
@@ -15,7 +15,7 @@ module Rouge
15
15
  attr_reader :keywords
16
16
  end
17
17
  # Load Apache keywords from separate YML file
18
- @keywords = ::YAML.load_file(Pathname.new(__FILE__).dirname.join('apache/keywords.yml')).tap do |h|
18
+ @keywords = ::YAML.load_file(File.join(__dir__, 'apache/keywords.yml')).tap do |h|
19
19
  h.each do |k,v|
20
20
  h[k] = Set.new v
21
21
  end
@@ -30,19 +30,19 @@ module Rouge
30
30
  end
31
31
 
32
32
  state :whitespace do
33
- rule /\#.*/, Comment
34
- rule /\s+/m, Text
33
+ rule %r/\#.*/, Comment
34
+ rule %r/\s+/m, Text
35
35
  end
36
36
 
37
37
  state :root do
38
38
  mixin :whitespace
39
39
 
40
- rule /(<\/?)(\w+)/ do |m|
40
+ rule %r/(<\/?)(\w+)/ do |m|
41
41
  groups Punctuation, name_for_token(m[2].downcase, :sections, Name::Label)
42
42
  push :section
43
43
  end
44
44
 
45
- rule /\w+/ do |m|
45
+ rule %r/\w+/ do |m|
46
46
  token name_for_token(m[0].downcase, :directives, Name::Class)
47
47
  push :directive
48
48
  end
@@ -50,7 +50,7 @@ module Rouge
50
50
 
51
51
  state :section do
52
52
  # Match section arguments
53
- rule /([^>]+)?(>(?:\r\n?|\n)?)/ do |m|
53
+ rule %r/([^>]+)?(>(?:\r\n?|\n)?)/ do |m|
54
54
  groups Literal::String::Regex, Punctuation
55
55
  pop!
56
56
  end
@@ -60,11 +60,11 @@ module Rouge
60
60
 
61
61
  state :directive do
62
62
  # Match value literals and other directive arguments
63
- rule /\r\n?|\n/, Text, :pop!
63
+ rule %r/\r\n?|\n/, Text, :pop!
64
64
 
65
65
  mixin :whitespace
66
66
 
67
- rule /\S+/ do |m|
67
+ rule %r/\S+/ do |m|
68
68
  token name_for_token(m[0], :values, Literal::String::Symbol)
69
69
  end
70
70
  end
@@ -319,28 +319,28 @@ module Rouge
319
319
  identifiers = %r(\b([a-zA-Z]\w*)\b)
320
320
 
321
321
  state :root do
322
- rule /\s+/, Text::Whitespace
323
- rule /¬\n/, Literal::String::Escape
324
- rule /'s\s+/, Text
325
- rule /(--|#).*?$/, Comment::Single
326
- rule /\(\*/, Comment::Multiline
327
- rule /[\(\){}!,.:]/, Punctuation
328
- rule /(«)([^»]+)(»)/ do |match|
322
+ rule %r/\s+/, Text::Whitespace
323
+ rule %r/¬\n/, Literal::String::Escape
324
+ rule %r/'s\s+/, Text
325
+ rule %r/(--|#).*?$/, Comment::Single
326
+ rule %r/\(\*/, Comment::Multiline
327
+ rule %r/[\(\){}!,.:]/, Punctuation
328
+ rule %r/(«)([^»]+)(»)/ do |match|
329
329
  token Text, match[1]
330
330
  token Name::Builtin, match[2]
331
331
  token Text, match[3]
332
332
  end
333
- rule /\b((?:considering|ignoring)\s*)(application responses|case|diacriticals|hyphens|numeric strings|punctuation|white space)/ do |match|
333
+ rule %r/\b((?:considering|ignoring)\s*)(application responses|case|diacriticals|hyphens|numeric strings|punctuation|white space)/ do |match|
334
334
  token Keyword, match[1]
335
335
  token Name::Builtin, match[2]
336
336
  end
337
- rule /(-|\*|\+|&|≠|>=?|<=?|=|≥|≤|\/|÷|\^)/, Operator
337
+ rule %r/(-|\*|\+|&|≠|>=?|<=?|=|≥|≤|\/|÷|\^)/, Operator
338
338
  rule operators, Operator::Word
339
- rule /^(\s*(?:on|end)\s+)'r'(%s)/ do |match|
339
+ rule %r/^(\s*(?:on|end)\s+)'r'(%s)/ do |match|
340
340
  token Keyword, match[1]
341
341
  token Name::Function, match[2]
342
342
  end
343
- rule /^(\s*)(in|on|script|to)(\s+)/ do |match|
343
+ rule %r/^(\s*)(in|on|script|to)(\s+)/ do |match|
344
344
  token Text, match[1]
345
345
  token Keyword, match[2]
346
346
  token Text, match[3]
@@ -349,6 +349,7 @@ module Rouge
349
349
  token Keyword, match[1]
350
350
  token Name::Class, match[2]
351
351
  end
352
+ rule literals, Name::Builtin
352
353
  rule commands, Name::Builtin
353
354
  rule controls, Keyword
354
355
  rule declarations, Keyword
@@ -359,10 +360,10 @@ module Rouge
359
360
  rule studio_classes, Name::Builtin
360
361
  rule studio_commands, Name::Builtin
361
362
  rule references, Name::Builtin
362
- rule /"(\\\\|\\"|[^"])*"/, Literal::String::Double
363
+ rule %r/"(\\\\|\\"|[^"])*"/, Literal::String::Double
363
364
  rule identifiers, Name::Variable
364
- rule /[-+]?(\d+\.\d*|\d*\.\d+)(E[-+][0-9]+)?/, Literal::Number::Float
365
- rule /[-+]?\d+/, Literal::Number::Integer
365
+ rule %r/[-+]?(\d+\.\d*|\d*\.\d+)(E[-+][0-9]+)?/, Literal::Number::Float
366
+ rule %r/[-+]?\d+/, Literal::Number::Integer
366
367
  end
367
368
  end
368
369
  end
@@ -47,7 +47,7 @@ module Rouge
47
47
  end
48
48
 
49
49
  state :comments_and_whitespace do
50
- rule /\s+/, Text
50
+ rule %r/\s+/, Text
51
51
  rule %r(#.*?$), Comment::Single
52
52
  end
53
53
 
@@ -57,7 +57,7 @@ module Rouge
57
57
  token Str::Regex
58
58
  goto :regex
59
59
  end
60
- rule //, Text, :pop!
60
+ rule %r//, Text, :pop!
61
61
  end
62
62
 
63
63
  state :regex do
@@ -68,14 +68,14 @@ module Rouge
68
68
 
69
69
  rule %r([^/]\n), Error, :pop!
70
70
 
71
- rule /\n/, Error, :pop!
72
- rule /\[\^/, Str::Escape, :regex_group
73
- rule /\[/, Str::Escape, :regex_group
74
- rule /\\./, Str::Escape
71
+ rule %r/\n/, Error, :pop!
72
+ rule %r/\[\^/, Str::Escape, :regex_group
73
+ rule %r/\[/, Str::Escape, :regex_group
74
+ rule %r/\\./, Str::Escape
75
75
  rule %r{[(][?][:=<!]}, Str::Escape
76
- rule /[{][\d,]+[}]/, Str::Escape
77
- rule /[()?]/, Str::Escape
78
- rule /./, Str::Regex
76
+ rule %r/[{][\d,]+[}]/, Str::Escape
77
+ rule %r/[()?]/, Str::Escape
78
+ rule %r/./, Str::Regex
79
79
  end
80
80
 
81
81
  state :regex_end do
@@ -85,20 +85,20 @@ module Rouge
85
85
  state :regex_group do
86
86
  # specially highlight / in a group to indicate that it doesn't
87
87
  # close the regex
88
- rule /\//, Str::Escape
88
+ rule %r(/), Str::Escape
89
89
 
90
90
  rule %r([^/]\n) do
91
91
  token Error
92
92
  pop! 2
93
93
  end
94
94
 
95
- rule /\]/, Str::Escape, :pop!
96
- rule /\\./, Str::Escape
97
- rule /./, Str::Regex
95
+ rule %r/\]/, Str::Escape, :pop!
96
+ rule %r/\\./, Str::Escape
97
+ rule %r/./, Str::Regex
98
98
  end
99
99
 
100
100
  state :bad_regex do
101
- rule /[^\n]+/, Error, :pop!
101
+ rule %r/[^\n]+/, Error, :pop!
102
102
  end
103
103
 
104
104
  state :root do
@@ -106,17 +106,17 @@ module Rouge
106
106
  rule %r((?<=\n)(?=\s|/)), Text, :expr_start
107
107
  rule %r([-<>+*/%\^!=]=?|in\b|\+\+|--|\|), Operator, :expr_start
108
108
  rule %r(&&|\|\||~!?), Operator, :expr_start
109
- rule /[(\[,]/, Punctuation, :expr_start
110
- rule /;/, Punctuation, :statement
111
- rule /[)\].]/, Punctuation
109
+ rule %r/[(\[,]/, Punctuation, :expr_start
110
+ rule %r/;/, Punctuation, :statement
111
+ rule %r/[)\].]/, Punctuation
112
112
 
113
- rule /[?]/ do
113
+ rule %r/[?]/ do
114
114
  token Punctuation
115
115
  push :ternary
116
116
  push :expr_start
117
117
  end
118
118
 
119
- rule /[{}]/, Punctuation, :statement
119
+ rule %r/[{}]/, Punctuation, :statement
120
120
 
121
121
  rule id do |m|
122
122
  if self.class.keywords.include? m[0]
@@ -138,19 +138,19 @@ module Rouge
138
138
  end
139
139
  end
140
140
 
141
- rule /[0-9]+\.[0-9]+/, Num::Float
142
- rule /[0-9]+/, Num::Integer
143
- rule /"(\\[\\"]|[^"])*"/, Str::Double
144
- rule /:/, Punctuation
141
+ rule %r/[0-9]+\.[0-9]+/, Num::Float
142
+ rule %r/[0-9]+/, Num::Integer
143
+ rule %r/"(\\[\\"]|[^"])*"/, Str::Double
144
+ rule %r/:/, Punctuation
145
145
  end
146
146
 
147
147
  state :statement do
148
- rule /[{}]/, Punctuation
148
+ rule %r/[{}]/, Punctuation
149
149
  mixin :expr_start
150
150
  end
151
151
 
152
152
  state :ternary do
153
- rule /:/ do
153
+ rule %r/:/ do
154
154
  token Punctuation
155
155
  goto :expr_start
156
156
  end
@@ -26,16 +26,16 @@ module Rouge
26
26
  end
27
27
 
28
28
  state :directive_as_csharp do
29
- rule /\s*#>\s*/m, Name::Tag, :pop!
29
+ rule %r/\s*#>\s*/m, Name::Tag, :pop!
30
30
  rule %r(.*?(?=\s*#>\s*))m do
31
31
  delegate CSharp
32
32
  end
33
33
  end
34
34
 
35
35
  state :directive_tag do
36
- rule /\s+/m, Text
37
- rule /[\w.:-]+\s*=/m, Name::Attribute, :attr
38
- rule /[\w]+\s*/m, Name::Attribute
36
+ rule %r/\s+/m, Text
37
+ rule %r/[\w.:-]+\s*=/m, Name::Attribute, :attr
38
+ rule %r/\w+\s*/m, Name::Attribute
39
39
  rule %r(/?\s*#>), Name::Tag, :pop!
40
40
  end
41
41
  end
@@ -0,0 +1,104 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Lexers
6
+ class BPF < RegexLexer
7
+ title "BPF"
8
+ desc "BPF bytecode syntax"
9
+ tag 'bpf'
10
+
11
+ TYPE_KEYWORDS = %w(
12
+ u8 u16 u32 u64 ll
13
+ ).join('|')
14
+
15
+ MISC_KEYWORDS = %w(
16
+ be16 be32 be64 exit lock
17
+ ).join('|')
18
+
19
+ state :root do
20
+ # Calls to helpers
21
+ rule %r/(call)(\s+)(\d+)/i do |m|
22
+ groups Keyword, Text::Whitespace, Literal::Number::Integer
23
+ end
24
+
25
+ # Unconditional jumps
26
+ rule %r/(goto)(\s*)(\+\d+)?(\s*)(<?\w+>?)/i do |m|
27
+ groups Keyword, Text::Whitespace, Literal::Number::Integer, Text::Whitespace, Name::Label
28
+ end
29
+
30
+ # Conditional jumps
31
+ rule %r/(if)(\s+)(r\d+)(\s*)([s!=<>]+)(\s*)(0x\h+|[-]?\d+)(\s*)(goto)(\s*)(\+\d+)?(\s*)(<?\w+>?)/i do |m|
32
+ groups Keyword, Text::Whitespace, Name, Text::Whitespace, Operator, Text::Whitespace, Literal::Number, Text::Whitespace, Keyword, Text::Whitespace, Literal::Number::Integer, Text::Whitespace, Name::Label
33
+ end
34
+ rule %r/(if)(\s+)(r\d+)(\s*)([s!=<>]+)(\s*)(r\d+)(\s*)(goto)(\s*)(\+\d+)?(\s*)(<?\w+>?)/i do |m|
35
+ groups Keyword, Text::Whitespace, Name, Text::Whitespace, Operator, Text::Whitespace, Name, Text::Whitespace, Keyword, Text::Whitespace, Literal::Number::Integer, Text::Whitespace, Name::Label
36
+ end
37
+
38
+ # Dereferences
39
+ rule %r/(\*)(\s*)(\()(#{TYPE_KEYWORDS})(\s*)(\*)(\))/i do |m|
40
+ groups Operator, Text::Whitespace, Punctuation, Keyword::Type, Text::Whitespace, Operator, Punctuation
41
+ push :address
42
+ end
43
+
44
+ # Operators
45
+ rule %r/[+-\/\*&|><^s]{0,3}=/i, Operator
46
+
47
+ # Registers
48
+ rule %r/([+-]?)(r\d+)/i do |m|
49
+ groups Punctuation, Name
50
+ end
51
+
52
+ # Comments
53
+ rule %r/\/\//, Comment::Single, :linecomment
54
+ rule %r/\/\*/, Comment::Multiline, :multilinescomment
55
+
56
+ rule %r/#{MISC_KEYWORDS}/i, Keyword
57
+
58
+ # Literals and global objects (maps) refered by name
59
+ rule %r/(0x\h+|[-]?\d+)(\s*)(ll)?/i do |m|
60
+ groups Literal::Number, Text::Whitespace, Keyword::Type
61
+ end
62
+ rule %r/(\w+)(\s*)(ll)/i do |m|
63
+ groups Name, Text::Whitespace, Keyword::Type
64
+ end
65
+
66
+ # Labels
67
+ rule %r/(\w+)(\s*)(:)/i do |m|
68
+ groups Name::Label, Text::Whitespace, Punctuation
69
+ end
70
+
71
+ rule %r{.}m, Text
72
+ end
73
+
74
+ state :address do
75
+ # Address is offset from register
76
+ rule %r/(\()(r\d+)(\s*)([+-])(\s*)(\d+)(\))/i do |m|
77
+ groups Punctuation, Name, Text::Whitespace, Operator, Text::Whitespace, Literal::Number::Integer, Punctuation
78
+ pop!
79
+ end
80
+
81
+ # Address is array subscript
82
+ rule %r/(\w+)(\[)(\d+)(\])/i do |m|
83
+ groups Name, Punctuation, Literal::Number::Integer, Punctuation
84
+ pop!
85
+ end
86
+ rule %r/(\w+)(\[)(r\d+)(\])/i do |m|
87
+ groups Name, Punctuation, Name, Punctuation
88
+ pop!
89
+ end
90
+ end
91
+
92
+ state :linecomment do
93
+ rule %r/\n/, Comment::Single, :pop!
94
+ rule %r/.+/, Comment::Single
95
+ end
96
+
97
+ state :multilinescomment do
98
+ rule %r/\*\//, Comment::Multiline, :pop!
99
+ rule %r/([^\*\/]+)/, Comment::Multiline
100
+ rule %r/([\*\/])/, Comment::Multiline
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,53 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Lexers
6
+ class Brainfuck < RegexLexer
7
+ tag 'brainfuck'
8
+ filenames '*.b', '*.bf'
9
+ mimetypes 'text/x-brainfuck'
10
+
11
+ title "Brainfuck"
12
+ desc "The Brainfuck programming language"
13
+
14
+ start { push :bol }
15
+
16
+ state :bol do
17
+ rule %r/\s+/m, Text
18
+ rule %r/\[/, Comment::Multiline, :comment_multi
19
+ rule(//) { pop! }
20
+ end
21
+
22
+ state :root do
23
+ rule %r/\]/, Error
24
+ rule %r/\[/, Punctuation, :loop
25
+
26
+ mixin :comment_single
27
+ mixin :commands
28
+ end
29
+
30
+ state :comment_multi do
31
+ rule %r/\[/, Comment::Multiline, :comment_multi
32
+ rule %r/\]/, Comment::Multiline, :pop!
33
+ rule %r/[^\[\]]+?/m, Comment::Multiline
34
+ end
35
+
36
+ state :comment_single do
37
+ rule %r/[^><+\-.,\[\]]+/, Comment::Single
38
+ end
39
+
40
+ state :loop do
41
+ rule %r/\[/, Punctuation, :loop
42
+ rule %r/\]/, Punctuation, :pop!
43
+ mixin :comment_single
44
+ mixin :commands
45
+ end
46
+
47
+ state :commands do
48
+ rule %r/[><]+/, Name::Builtin
49
+ rule %r/[+\-.,]+/, Name::Function
50
+ end
51
+ end
52
+ end
53
+ end
@@ -60,22 +60,22 @@ module Rouge
60
60
  )\s*(?=\()/ix
61
61
 
62
62
  state :root do
63
- rule /\n/, Text
64
- rule /[^\S\n]+/, Text
65
- rule /\/\/.*$/, Comment::Single
66
- rule /[\[\]:(),;]/, Punctuation
67
- rule /(?<=[^\wа-яё]|^)\&.*$/, Keyword::Declaration
68
- rule /[-+\/=<>*%=<>.?&]/, Operator
69
- rule /(?<=[^\wа-яё]|^)\#.*$/, Keyword::Declaration
63
+ rule %r/\n/, Text
64
+ rule %r/[^\S\n]+/, Text
65
+ rule %r(//.*$), Comment::Single
66
+ rule %r/[\[\]:(),;]/, Punctuation
67
+ rule %r/(?<=[^\wа-яё]|^)\&.*$/, Keyword::Declaration
68
+ rule %r/[-+\/*%=<>.?&]/, Operator
69
+ rule %r/(?<=[^\wа-яё]|^)\#.*$/, Keyword::Declaration
70
70
  rule KEYWORDS, Keyword
71
71
  rule BUILTINS, Name::Builtin
72
- rule /[\wа-яё_][\wа-яё0-9_]*/i, Name::Variable
72
+ rule %r/[\wа-яё][\wа-яё]*/i, Name::Variable
73
73
 
74
74
  #literals
75
- rule /\b((\h{8}-(\h{4}-){3}\h{12})|\d+\.?\d*)\b/, Literal::Number
76
- rule /\'.*\'/, Literal::Date
77
- rule /".*?("|$)/, Literal::String::Single
78
- rule /(?<=[^\wа-яё]|^)\|((?!\"\").)*?(\"|$)/, Literal::String
75
+ rule %r/\b((\h{8}-(\h{4}-){3}\h{12})|\d+\.?\d*)\b/, Literal::Number
76
+ rule %r/\'.*\'/, Literal::Date
77
+ rule %r/".*?("|$)/, Literal::String::Single
78
+ rule %r/(?<=[^\wа-яё]|^)\|((?!\"\").)*?(\"|$)/, Literal::String
79
79
  end
80
80
  end
81
81
  end
@@ -65,8 +65,8 @@ module Rouge
65
65
  state :expr_bol do
66
66
  mixin :inline_whitespace
67
67
 
68
- rule /#if\s0/, Comment, :if_0
69
- rule /#/, Comment::Preproc, :macro
68
+ rule %r/#if\s0/, Comment, :if_0
69
+ rule %r/#/, Comment::Preproc, :macro
70
70
 
71
71
  rule(//) { pop! }
72
72
  end
@@ -74,41 +74,41 @@ module Rouge
74
74
  # :expr_bol is the same as :bol but without labels, since
75
75
  # labels can only appear at the beginning of a statement.
76
76
  state :bol do
77
- rule /#{id}:(?!:)/, Name::Label
77
+ rule %r/#{id}:(?!:)/, Name::Label
78
78
  mixin :expr_bol
79
79
  end
80
80
 
81
81
  state :inline_whitespace do
82
- rule /[ \t\r]+/, Text
83
- rule /\\\n/, Text # line continuation
82
+ rule %r/[ \t\r]+/, Text
83
+ rule %r/\\\n/, Text # line continuation
84
84
  rule %r(/(\\\n)?[*].*?[*](\\\n)?/)m, Comment::Multiline
85
85
  end
86
86
 
87
87
  state :whitespace do
88
- rule /\n+/m, Text, :bol
88
+ rule %r/\n+/m, Text, :bol
89
89
  rule %r(//(\\.|.)*?$), Comment::Single, :bol
90
90
  mixin :inline_whitespace
91
91
  end
92
92
 
93
93
  state :expr_whitespace do
94
- rule /\n+/m, Text, :expr_bol
94
+ rule %r/\n+/m, Text, :expr_bol
95
95
  mixin :whitespace
96
96
  end
97
97
 
98
98
  state :statements do
99
99
  mixin :whitespace
100
- rule /(u8|u|U|L)?"/, Str, :string
100
+ rule %r/(u8|u|U|L)?"/, Str, :string
101
101
  rule %r((u8|u|U|L)?'(\\.|\\[0-7]{1,3}|\\x[a-f0-9]{1,2}|[^\\'\n])')i, Str::Char
102
102
  rule %r((\d+[.]\d*|[.]?\d+)e[+-]?\d+[lu]*)i, Num::Float
103
103
  rule %r(\d+e[+-]?\d+[lu]*)i, Num::Float
104
- rule /0x[0-9a-f]+[lu]*/i, Num::Hex
105
- rule /0[0-7]+[lu]*/i, Num::Oct
106
- rule /\d+[lu]*/i, Num::Integer
104
+ rule %r/0x[0-9a-f]+[lu]*/i, Num::Hex
105
+ rule %r/0[0-7]+[lu]*/i, Num::Oct
106
+ rule %r/\d+[lu]*/i, Num::Integer
107
107
  rule %r(\*/), Error
108
108
  rule %r([~!%^&*+=\|?:<>/-]), Operator
109
- rule /[()\[\],.;]/, Punctuation
110
- rule /\bcase\b/, Keyword, :case
111
- rule /(?:true|false|NULL)\b/, Name::Builtin
109
+ rule %r/[()\[\],.;]/, Punctuation
110
+ rule %r/\bcase\b/, Keyword, :case
111
+ rule %r/(?:true|false|NULL)\b/, Name::Builtin
112
112
  rule id do |m|
113
113
  name = m[0]
114
114
 
@@ -127,7 +127,7 @@ module Rouge
127
127
  end
128
128
 
129
129
  state :case do
130
- rule /:/, Punctuation, :pop!
130
+ rule %r/:/, Punctuation, :pop!
131
131
  mixin :statements
132
132
  end
133
133
 
@@ -149,41 +149,41 @@ module Rouge
149
149
  push :function
150
150
  end
151
151
  end
152
- rule /\{/, Punctuation, :function
152
+ rule %r/\{/, Punctuation, :function
153
153
  mixin :statements
154
154
  end
155
155
 
156
156
  state :function do
157
157
  mixin :whitespace
158
158
  mixin :statements
159
- rule /;/, Punctuation
160
- rule /{/, Punctuation, :function
161
- rule /}/, Punctuation, :pop!
159
+ rule %r/;/, Punctuation
160
+ rule %r/{/, Punctuation, :function
161
+ rule %r/}/, Punctuation, :pop!
162
162
  end
163
163
 
164
164
  state :string do
165
- rule /"/, Str, :pop!
166
- rule /\\([\\abfnrtv"']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})/, Str::Escape
167
- rule /[^\\"\n]+/, Str
168
- rule /\\\n/, Str
169
- rule /\\/, Str # stray backslash
165
+ rule %r/"/, Str, :pop!
166
+ rule %r/\\([\\abfnrtv"']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})/, Str::Escape
167
+ rule %r/[^\\"\n]+/, Str
168
+ rule %r/\\\n/, Str
169
+ rule %r/\\/, Str # stray backslash
170
170
  end
171
171
 
172
172
  state :macro do
173
173
  # NB: pop! goes back to :bol
174
- rule /\n/, Comment::Preproc, :pop!
174
+ rule %r/\n/, Comment::Preproc, :pop!
175
175
  rule %r([^/\n\\]+), Comment::Preproc
176
- rule /\\./m, Comment::Preproc
176
+ rule %r/\\./m, Comment::Preproc
177
177
  mixin :inline_whitespace
178
178
  rule %r(/), Comment::Preproc
179
179
  end
180
180
 
181
181
  state :if_0 do
182
182
  # NB: no \b here, to cover #ifdef and #ifndef
183
- rule /^\s*#if/, Comment, :if_0
184
- rule /^\s*#\s*el(?:se|if)/, Comment, :pop!
185
- rule /^\s*#\s*endif\b.*?(?<!\\)\n/m, Comment, :pop!
186
- rule /.*?\n/, Comment
183
+ rule %r/^\s*#if/, Comment, :if_0
184
+ rule %r/^\s*#\s*el(?:se|if)/, Comment, :pop!
185
+ rule %r/^\s*#\s*endif\b.*?(?<!\\)\n/m, Comment, :pop!
186
+ rule %r/.*?\n/, Comment
187
187
  end
188
188
  end
189
189
  end