gitlab-rouge 1.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (185) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +23 -0
  3. data/LICENSE +186 -0
  4. data/bin/rougify +16 -0
  5. data/gitlab-rouge.gemspec +17 -0
  6. data/lib/rouge.rb +57 -0
  7. data/lib/rouge/cli.rb +363 -0
  8. data/lib/rouge/demos/apache +21 -0
  9. data/lib/rouge/demos/applescript +2 -0
  10. data/lib/rouge/demos/c +8 -0
  11. data/lib/rouge/demos/clojure +5 -0
  12. data/lib/rouge/demos/coffeescript +5 -0
  13. data/lib/rouge/demos/common_lisp +1 -0
  14. data/lib/rouge/demos/conf +4 -0
  15. data/lib/rouge/demos/cpp +8 -0
  16. data/lib/rouge/demos/csharp +5 -0
  17. data/lib/rouge/demos/css +4 -0
  18. data/lib/rouge/demos/dart +6 -0
  19. data/lib/rouge/demos/diff +7 -0
  20. data/lib/rouge/demos/elixir +1 -0
  21. data/lib/rouge/demos/erb +1 -0
  22. data/lib/rouge/demos/erlang +7 -0
  23. data/lib/rouge/demos/factor +5 -0
  24. data/lib/rouge/demos/gherkin +17 -0
  25. data/lib/rouge/demos/glsl +14 -0
  26. data/lib/rouge/demos/go +7 -0
  27. data/lib/rouge/demos/groovy +9 -0
  28. data/lib/rouge/demos/haml +5 -0
  29. data/lib/rouge/demos/handlebars +7 -0
  30. data/lib/rouge/demos/haskell +6 -0
  31. data/lib/rouge/demos/html +8 -0
  32. data/lib/rouge/demos/http +14 -0
  33. data/lib/rouge/demos/ini +4 -0
  34. data/lib/rouge/demos/io +11 -0
  35. data/lib/rouge/demos/java +5 -0
  36. data/lib/rouge/demos/javascript +1 -0
  37. data/lib/rouge/demos/json +1 -0
  38. data/lib/rouge/demos/json-doc +1 -0
  39. data/lib/rouge/demos/liquid +11 -0
  40. data/lib/rouge/demos/literate_coffeescript +3 -0
  41. data/lib/rouge/demos/literate_haskell +7 -0
  42. data/lib/rouge/demos/llvm +20 -0
  43. data/lib/rouge/demos/lua +12 -0
  44. data/lib/rouge/demos/make +6 -0
  45. data/lib/rouge/demos/markdown +4 -0
  46. data/lib/rouge/demos/matlab +6 -0
  47. data/lib/rouge/demos/moonscript +16 -0
  48. data/lib/rouge/demos/nginx +5 -0
  49. data/lib/rouge/demos/nim +27 -0
  50. data/lib/rouge/demos/objective_c +14 -0
  51. data/lib/rouge/demos/ocaml +12 -0
  52. data/lib/rouge/demos/perl +5 -0
  53. data/lib/rouge/demos/php +3 -0
  54. data/lib/rouge/demos/plaintext +1 -0
  55. data/lib/rouge/demos/powershell +49 -0
  56. data/lib/rouge/demos/prolog +9 -0
  57. data/lib/rouge/demos/properties +7 -0
  58. data/lib/rouge/demos/puppet +6 -0
  59. data/lib/rouge/demos/python +6 -0
  60. data/lib/rouge/demos/qml +9 -0
  61. data/lib/rouge/demos/r +8 -0
  62. data/lib/rouge/demos/racket +24 -0
  63. data/lib/rouge/demos/ruby +9 -0
  64. data/lib/rouge/demos/rust +12 -0
  65. data/lib/rouge/demos/sass +3 -0
  66. data/lib/rouge/demos/scala +3 -0
  67. data/lib/rouge/demos/scheme +4 -0
  68. data/lib/rouge/demos/scss +5 -0
  69. data/lib/rouge/demos/sed +4 -0
  70. data/lib/rouge/demos/shell +2 -0
  71. data/lib/rouge/demos/slim +17 -0
  72. data/lib/rouge/demos/smalltalk +6 -0
  73. data/lib/rouge/demos/sml +4 -0
  74. data/lib/rouge/demos/sql +1 -0
  75. data/lib/rouge/demos/swift +5 -0
  76. data/lib/rouge/demos/tcl +1 -0
  77. data/lib/rouge/demos/tex +1 -0
  78. data/lib/rouge/demos/toml +9 -0
  79. data/lib/rouge/demos/tulip +14 -0
  80. data/lib/rouge/demos/vb +4 -0
  81. data/lib/rouge/demos/viml +5 -0
  82. data/lib/rouge/demos/xml +2 -0
  83. data/lib/rouge/demos/yaml +4 -0
  84. data/lib/rouge/formatter.rb +50 -0
  85. data/lib/rouge/formatters/html.rb +117 -0
  86. data/lib/rouge/formatters/null.rb +19 -0
  87. data/lib/rouge/formatters/terminal256.rb +176 -0
  88. data/lib/rouge/lexer.rb +443 -0
  89. data/lib/rouge/lexers/apache.rb +68 -0
  90. data/lib/rouge/lexers/apache/keywords.yml +453 -0
  91. data/lib/rouge/lexers/apple_script.rb +367 -0
  92. data/lib/rouge/lexers/c.rb +212 -0
  93. data/lib/rouge/lexers/clojure.rb +112 -0
  94. data/lib/rouge/lexers/coffeescript.rb +174 -0
  95. data/lib/rouge/lexers/common_lisp.rb +345 -0
  96. data/lib/rouge/lexers/conf.rb +24 -0
  97. data/lib/rouge/lexers/cpp.rb +66 -0
  98. data/lib/rouge/lexers/csharp.rb +88 -0
  99. data/lib/rouge/lexers/css.rb +271 -0
  100. data/lib/rouge/lexers/dart.rb +104 -0
  101. data/lib/rouge/lexers/diff.rb +31 -0
  102. data/lib/rouge/lexers/elixir.rb +108 -0
  103. data/lib/rouge/lexers/erb.rb +56 -0
  104. data/lib/rouge/lexers/erlang.rb +118 -0
  105. data/lib/rouge/lexers/factor.rb +302 -0
  106. data/lib/rouge/lexers/gherkin.rb +137 -0
  107. data/lib/rouge/lexers/gherkin/keywords.rb +14 -0
  108. data/lib/rouge/lexers/glsl.rb +135 -0
  109. data/lib/rouge/lexers/go.rb +178 -0
  110. data/lib/rouge/lexers/groovy.rb +104 -0
  111. data/lib/rouge/lexers/haml.rb +228 -0
  112. data/lib/rouge/lexers/handlebars.rb +79 -0
  113. data/lib/rouge/lexers/haskell.rb +183 -0
  114. data/lib/rouge/lexers/html.rb +94 -0
  115. data/lib/rouge/lexers/http.rb +80 -0
  116. data/lib/rouge/lexers/ini.rb +57 -0
  117. data/lib/rouge/lexers/io.rb +68 -0
  118. data/lib/rouge/lexers/java.rb +76 -0
  119. data/lib/rouge/lexers/javascript.rb +297 -0
  120. data/lib/rouge/lexers/liquid.rb +287 -0
  121. data/lib/rouge/lexers/literate_coffeescript.rb +33 -0
  122. data/lib/rouge/lexers/literate_haskell.rb +36 -0
  123. data/lib/rouge/lexers/llvm.rb +84 -0
  124. data/lib/rouge/lexers/lua.rb +122 -0
  125. data/lib/rouge/lexers/lua/builtins.rb +22 -0
  126. data/lib/rouge/lexers/make.rb +116 -0
  127. data/lib/rouge/lexers/markdown.rb +154 -0
  128. data/lib/rouge/lexers/matlab.rb +74 -0
  129. data/lib/rouge/lexers/matlab/builtins.rb +11 -0
  130. data/lib/rouge/lexers/moonscript.rb +110 -0
  131. data/lib/rouge/lexers/nginx.rb +71 -0
  132. data/lib/rouge/lexers/nim.rb +152 -0
  133. data/lib/rouge/lexers/objective_c.rb +197 -0
  134. data/lib/rouge/lexers/ocaml.rb +111 -0
  135. data/lib/rouge/lexers/perl.rb +197 -0
  136. data/lib/rouge/lexers/php.rb +173 -0
  137. data/lib/rouge/lexers/php/builtins.rb +204 -0
  138. data/lib/rouge/lexers/plain_text.rb +25 -0
  139. data/lib/rouge/lexers/powershell.rb +96 -0
  140. data/lib/rouge/lexers/prolog.rb +64 -0
  141. data/lib/rouge/lexers/properties.rb +55 -0
  142. data/lib/rouge/lexers/puppet.rb +128 -0
  143. data/lib/rouge/lexers/python.rb +228 -0
  144. data/lib/rouge/lexers/qml.rb +72 -0
  145. data/lib/rouge/lexers/r.rb +56 -0
  146. data/lib/rouge/lexers/racket.rb +542 -0
  147. data/lib/rouge/lexers/ruby.rb +415 -0
  148. data/lib/rouge/lexers/rust.rb +191 -0
  149. data/lib/rouge/lexers/sass.rb +74 -0
  150. data/lib/rouge/lexers/sass/common.rb +180 -0
  151. data/lib/rouge/lexers/scala.rb +142 -0
  152. data/lib/rouge/lexers/scheme.rb +112 -0
  153. data/lib/rouge/lexers/scss.rb +34 -0
  154. data/lib/rouge/lexers/sed.rb +170 -0
  155. data/lib/rouge/lexers/shell.rb +152 -0
  156. data/lib/rouge/lexers/slim.rb +228 -0
  157. data/lib/rouge/lexers/smalltalk.rb +116 -0
  158. data/lib/rouge/lexers/sml.rb +347 -0
  159. data/lib/rouge/lexers/sql.rb +140 -0
  160. data/lib/rouge/lexers/swift.rb +144 -0
  161. data/lib/rouge/lexers/tcl.rb +192 -0
  162. data/lib/rouge/lexers/tex.rb +72 -0
  163. data/lib/rouge/lexers/toml.rb +71 -0
  164. data/lib/rouge/lexers/tulip.rb +75 -0
  165. data/lib/rouge/lexers/vb.rb +164 -0
  166. data/lib/rouge/lexers/viml.rb +101 -0
  167. data/lib/rouge/lexers/viml/keywords.rb +12 -0
  168. data/lib/rouge/lexers/xml.rb +59 -0
  169. data/lib/rouge/lexers/yaml.rb +364 -0
  170. data/lib/rouge/plugins/redcarpet.rb +30 -0
  171. data/lib/rouge/regex_lexer.rb +439 -0
  172. data/lib/rouge/template_lexer.rb +22 -0
  173. data/lib/rouge/text_analyzer.rb +48 -0
  174. data/lib/rouge/theme.rb +195 -0
  175. data/lib/rouge/themes/base16.rb +130 -0
  176. data/lib/rouge/themes/colorful.rb +67 -0
  177. data/lib/rouge/themes/github.rb +71 -0
  178. data/lib/rouge/themes/molokai.rb +82 -0
  179. data/lib/rouge/themes/monokai.rb +92 -0
  180. data/lib/rouge/themes/monokai_sublime.rb +90 -0
  181. data/lib/rouge/themes/thankful_eyes.rb +71 -0
  182. data/lib/rouge/token.rb +182 -0
  183. data/lib/rouge/util.rb +101 -0
  184. data/lib/rouge/version.rb +7 -0
  185. metadata +231 -0
@@ -0,0 +1,74 @@
1
+ # -*- coding: utf-8 -*- #
2
+
3
+ module Rouge
4
+ module Lexers
5
+ load_const :SassCommon, 'sass/common.rb'
6
+
7
+ class Sass < SassCommon
8
+ include Indentation
9
+
10
+ title "Sass"
11
+ desc 'The Sass stylesheet language language (sass-lang.com)'
12
+
13
+ tag 'sass'
14
+ filenames '*.sass'
15
+ mimetypes 'text/x-sass'
16
+
17
+ id = /[\w-]+/
18
+
19
+ state :root do
20
+ rule /[ \t]*\n/, Text
21
+ rule(/[ \t]*/) { |m| token Text; indentation(m[0]) }
22
+ end
23
+
24
+ state :content do
25
+ # block comments
26
+ rule %r(//.*?\n) do
27
+ token Comment::Single
28
+ pop!; starts_block :single_comment
29
+ end
30
+
31
+ rule %r(/[*].*?\n) do
32
+ token Comment::Multiline
33
+ pop!; starts_block :multi_comment
34
+ end
35
+
36
+ rule /@import\b/, Keyword, :import
37
+
38
+ mixin :content_common
39
+
40
+ rule %r(=#{id}), Name::Function, :value
41
+ rule %r([+]#{id}), Name::Decorator, :value
42
+
43
+ rule /:/, Name::Attribute, :old_style_attr
44
+
45
+ rule(/(?=.+?:([^a-z]|$))/) { push :attribute }
46
+
47
+ rule(//) { push :selector }
48
+ end
49
+
50
+ state :single_comment do
51
+ rule /.*?\n/, Comment::Single, :pop!
52
+ end
53
+
54
+ state :multi_comment do
55
+ rule /.*?\n/, Comment::Multiline, :pop!
56
+ end
57
+
58
+ state :import do
59
+ rule /[ \t]+/, Text
60
+ rule /\S+/, Str
61
+ rule /\n/, Text, :pop!
62
+ end
63
+
64
+ state :old_style_attr do
65
+ mixin :attr_common
66
+ rule(//) { pop!; push :value }
67
+ end
68
+
69
+ state :end_section do
70
+ rule(/\n/) { token Text; reset_stack }
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,180 @@
1
+ # -*- coding: utf-8 -*- #
2
+
3
+ module Rouge
4
+ module Lexers
5
+ # shared states with SCSS
6
+ class SassCommon < RegexLexer
7
+ id = /[\w-]+/
8
+
9
+ state :content_common do
10
+ rule /@for\b/, Keyword, :for
11
+ rule /@(debug|warn|if|each|while|else|return|media)/, Keyword, :value
12
+
13
+ rule /(@mixin)(\s+)(#{id})/ do
14
+ groups Keyword, Text, Name::Function
15
+ push :value
16
+ end
17
+
18
+ rule /(@function)(\s+)(#{id})/ do
19
+ groups Keyword, Text, Name::Function
20
+ push :value
21
+ end
22
+
23
+ rule /@extend\b/, Keyword, :selector
24
+
25
+ rule /(@include)(\s+)(#{id})/ do
26
+ groups Keyword, Text, Name::Decorator
27
+ push :value
28
+ end
29
+
30
+ rule /@#{id}/, Keyword, :selector
31
+
32
+ # $variable: assignment
33
+ rule /([$]#{id})([ \t]*)(:)/ do
34
+ groups Name::Variable, Text, Punctuation
35
+ push :value
36
+ end
37
+ end
38
+
39
+ state :value do
40
+ mixin :end_section
41
+ rule /[ \t]+/, Text
42
+ rule /[$]#{id}/, Name::Variable
43
+ rule /url[(]/, Str::Other, :string_url
44
+ rule /#{id}(?=\s*[(])/, Name::Function
45
+ rule /%#{id}/, Name::Decorator
46
+
47
+ # named literals
48
+ rule /(true|false)\b/, Name::Builtin::Pseudo
49
+ rule /(and|or|not)\b/, Operator::Word
50
+
51
+ # colors and numbers
52
+ rule /#[a-z0-9]{1,6}/i, Num::Hex
53
+ rule /-?\d+(%|[a-z]+)?/, Num
54
+ rule /-?\d*\.\d+(%|[a-z]+)?/, Num::Integer
55
+
56
+ mixin :has_strings
57
+ mixin :has_interp
58
+
59
+ rule /[~^*!&%<>\|+=@:,.\/?-]+/, Operator
60
+ rule /[\[\]()]+/, Punctuation
61
+ rule %r(/[*]), Comment::Multiline, :inline_comment
62
+ rule %r(//[^\n]*), Comment::Single
63
+
64
+ # identifiers
65
+ rule(id) do |m|
66
+ if CSS.builtins.include? m[0]
67
+ token Name::Builtin
68
+ elsif CSS.constants.include? m[0]
69
+ token Name::Constant
70
+ else
71
+ token Name
72
+ end
73
+ end
74
+ end
75
+
76
+ state :has_interp do
77
+ rule /[#][{]/, Str::Interpol, :interpolation
78
+ end
79
+
80
+ state :has_strings do
81
+ rule /"/, Str::Double, :dq
82
+ rule /'/, Str::Single, :sq
83
+ end
84
+
85
+ state :interpolation do
86
+ rule /}/, Str::Interpol, :pop!
87
+ mixin :value
88
+ end
89
+
90
+ state :selector do
91
+ mixin :end_section
92
+
93
+ mixin :has_strings
94
+ mixin :has_interp
95
+ rule /[ \t]+/, Text
96
+ rule /:/, Name::Decorator, :pseudo_class
97
+ rule /[.]/, Name::Class, :class
98
+ rule /#/, Name::Namespace, :id
99
+ rule /%/, Name::Variable, :placeholder
100
+ rule id, Name::Tag
101
+ rule /&/, Keyword
102
+ rule /[~^*!&\[\]()<>\|+=@:;,.\/?-]/, Operator
103
+ end
104
+
105
+ state :dq do
106
+ rule /"/, Str::Double, :pop!
107
+ mixin :has_interp
108
+ rule /(\\.|#(?![{])|[^\n"#])+/, Str::Double
109
+ end
110
+
111
+ state :sq do
112
+ rule /'/, Str::Single, :pop!
113
+ mixin :has_interp
114
+ rule /(\\.|#(?![{])|[^\n'#])+/, Str::Single
115
+ end
116
+
117
+ state :string_url do
118
+ rule /[)]/, Str::Other, :pop!
119
+ rule /(\\.|#(?![{])|[^\n)#])+/, Str::Other
120
+ mixin :has_interp
121
+ end
122
+
123
+ state :selector_piece do
124
+ mixin :has_interp
125
+ rule(//) { pop! }
126
+ end
127
+
128
+ state :pseudo_class do
129
+ rule id, Name::Decorator
130
+ mixin :selector_piece
131
+ end
132
+
133
+ state :class do
134
+ rule id, Name::Class
135
+ mixin :selector_piece
136
+ end
137
+
138
+ state :id do
139
+ rule id, Name::Namespace
140
+ mixin :selector_piece
141
+ end
142
+
143
+ state :placeholder do
144
+ rule id, Name::Variable
145
+ mixin :selector_piece
146
+ end
147
+
148
+ state :for do
149
+ rule /(from|to|through)/, Operator::Word
150
+ mixin :value
151
+ end
152
+
153
+ state :attr_common do
154
+ mixin :has_interp
155
+ rule id do |m|
156
+ if CSS.attributes.include? m[0]
157
+ token Name::Label
158
+ else
159
+ token Name::Attribute
160
+ end
161
+ end
162
+ end
163
+
164
+ state :attribute do
165
+ mixin :attr_common
166
+
167
+ rule /([ \t]*)(:)/ do
168
+ groups Text, Punctuation
169
+ push :value
170
+ end
171
+ end
172
+
173
+ state :inline_comment do
174
+ rule /(\\#|#(?=[^\n{])|\*(?=[^\n\/])|[^\n#*])+/, Comment::Multiline
175
+ mixin :has_interp
176
+ rule %r([*]/), Comment::Multiline, :pop!
177
+ end
178
+ end
179
+ end
180
+ end
@@ -0,0 +1,142 @@
1
+ # -*- coding: utf-8 #
2
+
3
+ module Rouge
4
+ module Lexers
5
+ class Scala < RegexLexer
6
+ title "Scala"
7
+ desc "The Scala programming language (scala-lang.org)"
8
+ tag 'scala'
9
+ aliases 'scala'
10
+ filenames '*.scala', '*.sbt'
11
+
12
+ mimetypes 'text/x-scala', 'application/x-scala'
13
+
14
+ # As documented in the ENBF section of the scala specification
15
+ # http://www.scala-lang.org/docu/files/ScalaReference.pdf
16
+ whitespace = /\p{Space}/
17
+ letter = /[\p{L}$_]/
18
+ upper = /[\p{Lu}$_]/
19
+ digits = /[0-9]/
20
+ parens = /[(){}\[\]]/
21
+ delims = %r([‘’".;,])
22
+
23
+ # negative lookahead to filter out other classes
24
+ op = %r(
25
+ (?!#{whitespace}|#{letter}|#{digits}|#{parens}|#{delims})
26
+ [\u0020-\u007F\p{Sm}\p{So}]
27
+ )x
28
+
29
+ idrest = %r(#{letter}(?:#{letter}|#{digits})*(?:(?<=_)#{op}+)?)x
30
+
31
+ keywords = %w(
32
+ abstract case catch def do else extends final finally for forSome
33
+ if implicit lazy match new override private protected requires return
34
+ sealed super this throw try val var while with yield
35
+ )
36
+
37
+ state :root do
38
+ rule /(class|trait|object)(\s+)/ do
39
+ groups Keyword, Text
40
+ push :class
41
+ end
42
+ rule /'#{idrest}[^']/, Str::Symbol
43
+ rule /[^\S\n]+/, Text
44
+
45
+ rule %r(//.*?\n), Comment::Single
46
+ rule %r(/\*), Comment::Multiline, :comment
47
+
48
+ rule /@#{idrest}/, Name::Decorator
49
+ rule %r(
50
+ (#{keywords.join("|")})\b|
51
+ (<[%:-]|=>|>:|[#=@_\u21D2\u2190])(\b|(?=\s)|$)
52
+ )x, Keyword
53
+ rule /:(?!#{op})/, Keyword, :type
54
+ rule /#{upper}#{idrest}\b/, Name::Class
55
+ rule /(true|false|null)\b/, Keyword::Constant
56
+ rule /(import|package)(\s+)/ do
57
+ groups Keyword, Text
58
+ push :import
59
+ end
60
+
61
+ rule /(type)(\s+)/ do
62
+ groups Keyword, Text
63
+ push :type
64
+ end
65
+
66
+ rule /""".*?"""(?!")/m, Str
67
+ rule /"(\\\\|\\"|[^"])*"/, Str
68
+ rule /'\\.'|'[^\\]'|'\\u[0-9a-fA-F]{4}'/, Str::Char
69
+
70
+ rule idrest, Name
71
+ rule /`[^`]+`/, Name
72
+
73
+ rule /\[/, Operator, :typeparam
74
+ rule /[\(\)\{\};,.#]/, Operator
75
+ rule /#{op}+/, Operator
76
+
77
+ rule /([0-9][0-9]*\.[0-9]*|\.[0-9]+)([eE][+-]?[0-9]+)?[fFdD]?/, Num::Float
78
+ rule /([0-9][0-9]*[fFdD])/, Num::Float
79
+ rule /0x[0-9a-fA-F]+/, Num::Hex
80
+ rule /[0-9]+L?/, Num::Integer
81
+ rule /\n/, Text
82
+ end
83
+
84
+ state :class do
85
+ rule /(#{idrest}|#{op}+|`[^`]+`)(\s*)(\[)/ do
86
+ groups Name::Class, Text, Operator
87
+ push :typeparam
88
+ end
89
+
90
+ rule /\s+/, Text
91
+ rule /{/, Operator, :pop!
92
+ rule /\(/, Operator, :pop!
93
+ rule %r(//.*?\n), Comment::Single, :pop!
94
+ rule %r(#{idrest}|#{op}+|`[^`]+`), Name::Class, :pop!
95
+ end
96
+
97
+ state :type do
98
+ rule /\s+/, Text
99
+ rule /<[%:]|>:|[#_\u21D2]|forSome|type/, Keyword
100
+ rule /([,\);}]|=>|=)(\s*)/ do
101
+ groups Operator, Text
102
+ pop!
103
+ end
104
+ rule /[\(\{]/, Operator, :type
105
+
106
+ typechunk = /(?:#{idrest}|#{op}+\`[^`]+`)/
107
+ rule /(#{typechunk}(?:\.#{typechunk})*)(\s*)(\[)/ do
108
+ groups Keyword::Type, Text, Operator
109
+ pop!
110
+ push :typeparam
111
+ end
112
+
113
+ rule /(#{typechunk}(?:\.#{typechunk})*)(\s*)$/ do
114
+ groups Keyword::Type, Text
115
+ pop!
116
+ end
117
+
118
+ rule %r(//.*?\n), Comment::Single, :pop!
119
+ rule /\.|#{idrest}|#{op}+|`[^`]+`/, Keyword::Type
120
+ end
121
+
122
+ state :typeparam do
123
+ rule /[\s,]+/, Text
124
+ rule /<[%:]|=>|>:|[#_\u21D2]|forSome|type/, Keyword
125
+ rule /([\]\)\}])/, Operator, :pop!
126
+ rule /[\(\[\{]/, Operator, :typeparam
127
+ rule /\.|#{idrest}|#{op}+|`[^`]+`/, Keyword::Type
128
+ end
129
+
130
+ state :comment do
131
+ rule %r([^/\*]+), Comment::Multiline
132
+ rule %r(/\*), Comment::Multiline, :comment
133
+ rule %r(\*/), Comment::Multiline, :pop!
134
+ rule %r([*/]), Comment::Multiline
135
+ end
136
+
137
+ state :import do
138
+ rule %r((#{idrest}|\.)+), Name::Namespace, :pop!
139
+ end
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,112 @@
1
+ # -*- coding: utf-8 -*- #
2
+
3
+ module Rouge
4
+ module Lexers
5
+ class Scheme < RegexLexer
6
+ title "Scheme"
7
+ desc "The Scheme variant of Lisp"
8
+
9
+ tag 'scheme'
10
+ filenames '*.scm', '*.ss'
11
+ mimetypes 'text/x-scheme', 'application/x-scheme'
12
+
13
+ def self.keywords
14
+ @keywords ||= Set.new %w(
15
+ lambda define if else cond and or case let let* letrec begin
16
+ do delay set! => quote quasiquote unquote unquote-splicing
17
+ define-syntax let-syntax letrec-syntax syntax-rules
18
+ )
19
+ end
20
+
21
+ def self.builtins
22
+ @builtins ||= Set.new %w(
23
+ * + - / < <= = > >= abs acos angle append apply asin
24
+ assoc assq assv atan boolean? caaaar caaadr caaar caadar
25
+ caaddr caadr caar cadaar cadadr cadar caddar cadddr caddr
26
+ cadr call-with-current-continuation call-with-input-file
27
+ call-with-output-file call-with-values call/cc car cdaaar cdaadr
28
+ cdaar cdadar cdaddr cdadr cdar cddaar cddadr cddar cdddar cddddr
29
+ cdddr cddr cdr ceiling char->integer char-alphabetic? char-ci<=?
30
+ char-ci<? char-ci=? char-ci>=? char-ci>? char-downcase
31
+ char-lower-case? char-numeric? char-ready? char-upcase
32
+ char-upper-case? char-whitespace? char<=? char<? char=? char>=?
33
+ char>? char? close-input-port close-output-port complex? cons
34
+ cos current-input-port current-output-port denominator
35
+ display dynamic-wind eof-object? eq? equal? eqv? eval
36
+ even? exact->inexact exact? exp expt floor for-each force gcd
37
+ imag-part inexact->exact inexact? input-port? integer->char
38
+ integer? interaction-environment lcm length list list->string
39
+ list->vector list-ref list-tail list? load log magnitude
40
+ make-polar make-rectangular make-string make-vector map
41
+ max member memq memv min modulo negative? newline not
42
+ null-environment null? number->string number? numerator odd?
43
+ open-input-file open-output-file output-port? pair? peek-char
44
+ port? positive? procedure? quotient rational? rationalize
45
+ read read-char real-part real? remainder reverse round
46
+ scheme-report-environment set-car! set-cdr! sin sqrt string
47
+ string->list string->number string->symbol string-append
48
+ string-ci<=? string-ci<? string-ci=? string-ci>=? string-ci>?
49
+ string-copy string-fill! string-length string-ref
50
+ string-set! string<=? string<? string=? string>=?
51
+ string>? string? substring symbol->string symbol?
52
+ tan transcript-off transcript-on truncate values vector
53
+ vector->list vector-fill! vector-length vector-ref
54
+ vector-set! vector? with-input-from-file with-output-to-file
55
+ write write-char zero?
56
+ )
57
+ end
58
+
59
+ id = /[a-z0-9!$\%&*+,\/:<=>?@^_~|-]+/i
60
+
61
+ state :root do
62
+ # comments
63
+ rule /;.*$/, Comment::Single
64
+ rule /\s+/m, Text
65
+ rule /-?\d+\.\d+/, Num::Float
66
+ rule /-?\d+/, Num::Integer
67
+
68
+ # Racket infinitites
69
+ rule /[+-]inf[.][f0]/, Num
70
+
71
+ rule /#b[01]+/, Num::Bin
72
+ rule /#o[0-7]+/, Num::Oct
73
+ rule /#d[0-9]+/, Num::Integer
74
+ rule /#x[0-9a-f]+/i, Num::Hex
75
+ rule /#[ei][\d.]+/, Num::Other
76
+
77
+ rule /"(\\\\|\\"|[^"])*"/, Str
78
+ rule /'#{id}/i, Str::Symbol
79
+ rule /#\\([()\/'"._!\$%& ?=+-]{1}|[a-z0-9]+)/i,
80
+ Str::Char
81
+ rule /#t|#f/, Name::Constant
82
+ rule /(?:'|#|`|,@|,|\.)/, Operator
83
+
84
+ rule /(['#])(\s*)(\()/m do
85
+ groups Str::Symbol, Text, Punctuation
86
+ end
87
+
88
+ rule /\(/, Punctuation, :command
89
+ rule /\)/, Punctuation
90
+
91
+ rule id, Name::Variable
92
+ end
93
+
94
+ state :command do
95
+ rule id, Name::Function do |m|
96
+ if self.class.keywords.include? m[0]
97
+ token Keyword
98
+ elsif self.class.builtins.include? m[0]
99
+ token Name::Builtin
100
+ else
101
+ token Name::Function
102
+ end
103
+
104
+ pop!
105
+ end
106
+
107
+ rule(//) { pop! }
108
+ end
109
+
110
+ end
111
+ end
112
+ end