rougegal 2.1.2

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 (311) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +26 -0
  3. data/LICENSE +186 -0
  4. data/bin/rougify +17 -0
  5. data/lib/rouge/cli.rb +394 -0
  6. data/lib/rouge/demos/abap +6 -0
  7. data/lib/rouge/demos/actionscript +4 -0
  8. data/lib/rouge/demos/apache +21 -0
  9. data/lib/rouge/demos/apiblueprint +33 -0
  10. data/lib/rouge/demos/applescript +2 -0
  11. data/lib/rouge/demos/awk +4 -0
  12. data/lib/rouge/demos/biml +38 -0
  13. data/lib/rouge/demos/bsl +7 -0
  14. data/lib/rouge/demos/c +8 -0
  15. data/lib/rouge/demos/ceylon +7 -0
  16. data/lib/rouge/demos/cfscript +18 -0
  17. data/lib/rouge/demos/clojure +5 -0
  18. data/lib/rouge/demos/cmake +7 -0
  19. data/lib/rouge/demos/coffeescript +5 -0
  20. data/lib/rouge/demos/common_lisp +1 -0
  21. data/lib/rouge/demos/conf +4 -0
  22. data/lib/rouge/demos/console +6 -0
  23. data/lib/rouge/demos/coq +13 -0
  24. data/lib/rouge/demos/cpp +8 -0
  25. data/lib/rouge/demos/csharp +5 -0
  26. data/lib/rouge/demos/css +4 -0
  27. data/lib/rouge/demos/d +16 -0
  28. data/lib/rouge/demos/dart +6 -0
  29. data/lib/rouge/demos/diff +7 -0
  30. data/lib/rouge/demos/digdag +19 -0
  31. data/lib/rouge/demos/docker +9 -0
  32. data/lib/rouge/demos/dot +5 -0
  33. data/lib/rouge/demos/eiffel +30 -0
  34. data/lib/rouge/demos/elixir +1 -0
  35. data/lib/rouge/demos/erb +1 -0
  36. data/lib/rouge/demos/erlang +7 -0
  37. data/lib/rouge/demos/factor +5 -0
  38. data/lib/rouge/demos/fortran +22 -0
  39. data/lib/rouge/demos/fsharp +12 -0
  40. data/lib/rouge/demos/gal +22 -0
  41. data/lib/rouge/demos/gherkin +17 -0
  42. data/lib/rouge/demos/glsl +14 -0
  43. data/lib/rouge/demos/go +7 -0
  44. data/lib/rouge/demos/gradle +10 -0
  45. data/lib/rouge/demos/graphql +17 -0
  46. data/lib/rouge/demos/groovy +9 -0
  47. data/lib/rouge/demos/haml +5 -0
  48. data/lib/rouge/demos/handlebars +7 -0
  49. data/lib/rouge/demos/haskell +6 -0
  50. data/lib/rouge/demos/html +8 -0
  51. data/lib/rouge/demos/http +14 -0
  52. data/lib/rouge/demos/hylang +10 -0
  53. data/lib/rouge/demos/idlang +8 -0
  54. data/lib/rouge/demos/igorpro +9 -0
  55. data/lib/rouge/demos/ini +4 -0
  56. data/lib/rouge/demos/io +11 -0
  57. data/lib/rouge/demos/irb +4 -0
  58. data/lib/rouge/demos/irb_output +2 -0
  59. data/lib/rouge/demos/java +5 -0
  60. data/lib/rouge/demos/javascript +1 -0
  61. data/lib/rouge/demos/jinja +9 -0
  62. data/lib/rouge/demos/json +1 -0
  63. data/lib/rouge/demos/json-doc +1 -0
  64. data/lib/rouge/demos/jsonnet +28 -0
  65. data/lib/rouge/demos/jsx +17 -0
  66. data/lib/rouge/demos/julia +11 -0
  67. data/lib/rouge/demos/kotlin +3 -0
  68. data/lib/rouge/demos/lasso +12 -0
  69. data/lib/rouge/demos/liquid +11 -0
  70. data/lib/rouge/demos/literate_coffeescript +3 -0
  71. data/lib/rouge/demos/literate_haskell +7 -0
  72. data/lib/rouge/demos/llvm +20 -0
  73. data/lib/rouge/demos/lua +12 -0
  74. data/lib/rouge/demos/make +6 -0
  75. data/lib/rouge/demos/markdown +4 -0
  76. data/lib/rouge/demos/matlab +6 -0
  77. data/lib/rouge/demos/moonscript +16 -0
  78. data/lib/rouge/demos/mosel +10 -0
  79. data/lib/rouge/demos/mxml +22 -0
  80. data/lib/rouge/demos/nasm +26 -0
  81. data/lib/rouge/demos/nginx +5 -0
  82. data/lib/rouge/demos/nim +27 -0
  83. data/lib/rouge/demos/objective_c +18 -0
  84. data/lib/rouge/demos/ocaml +12 -0
  85. data/lib/rouge/demos/pascal +14 -0
  86. data/lib/rouge/demos/perl +5 -0
  87. data/lib/rouge/demos/php +3 -0
  88. data/lib/rouge/demos/plaintext +1 -0
  89. data/lib/rouge/demos/plist +142 -0
  90. data/lib/rouge/demos/pony +17 -0
  91. data/lib/rouge/demos/powershell +49 -0
  92. data/lib/rouge/demos/praat +26 -0
  93. data/lib/rouge/demos/prolog +9 -0
  94. data/lib/rouge/demos/prometheus +9 -0
  95. data/lib/rouge/demos/properties +7 -0
  96. data/lib/rouge/demos/protobuf +5 -0
  97. data/lib/rouge/demos/puppet +6 -0
  98. data/lib/rouge/demos/python +6 -0
  99. data/lib/rouge/demos/q +2 -0
  100. data/lib/rouge/demos/qml +9 -0
  101. data/lib/rouge/demos/r +8 -0
  102. data/lib/rouge/demos/racket +24 -0
  103. data/lib/rouge/demos/ruby +9 -0
  104. data/lib/rouge/demos/rust +12 -0
  105. data/lib/rouge/demos/sass +3 -0
  106. data/lib/rouge/demos/scala +3 -0
  107. data/lib/rouge/demos/scheme +4 -0
  108. data/lib/rouge/demos/scss +5 -0
  109. data/lib/rouge/demos/sed +4 -0
  110. data/lib/rouge/demos/shell +2 -0
  111. data/lib/rouge/demos/sieve +10 -0
  112. data/lib/rouge/demos/slim +17 -0
  113. data/lib/rouge/demos/smalltalk +6 -0
  114. data/lib/rouge/demos/smarty +12 -0
  115. data/lib/rouge/demos/sml +4 -0
  116. data/lib/rouge/demos/sql +1 -0
  117. data/lib/rouge/demos/swift +5 -0
  118. data/lib/rouge/demos/tap +5 -0
  119. data/lib/rouge/demos/tcl +1 -0
  120. data/lib/rouge/demos/tex +1 -0
  121. data/lib/rouge/demos/toml +9 -0
  122. data/lib/rouge/demos/tsx +17 -0
  123. data/lib/rouge/demos/tulip +13 -0
  124. data/lib/rouge/demos/turtle +26 -0
  125. data/lib/rouge/demos/twig +9 -0
  126. data/lib/rouge/demos/typescript +1 -0
  127. data/lib/rouge/demos/vala +8 -0
  128. data/lib/rouge/demos/vb +4 -0
  129. data/lib/rouge/demos/verilog +27 -0
  130. data/lib/rouge/demos/vhdl +23 -0
  131. data/lib/rouge/demos/viml +14 -0
  132. data/lib/rouge/demos/vue +11 -0
  133. data/lib/rouge/demos/wollok +11 -0
  134. data/lib/rouge/demos/xml +2 -0
  135. data/lib/rouge/demos/yaml +4 -0
  136. data/lib/rouge/formatter.rb +75 -0
  137. data/lib/rouge/formatters/html.rb +37 -0
  138. data/lib/rouge/formatters/html_inline.rb +30 -0
  139. data/lib/rouge/formatters/html_legacy.rb +44 -0
  140. data/lib/rouge/formatters/html_linewise.rb +27 -0
  141. data/lib/rouge/formatters/html_pygments.rb +16 -0
  142. data/lib/rouge/formatters/html_table.rb +61 -0
  143. data/lib/rouge/formatters/null.rb +19 -0
  144. data/lib/rouge/formatters/terminal256.rb +172 -0
  145. data/lib/rouge/guesser.rb +55 -0
  146. data/lib/rouge/guessers/filename.rb +25 -0
  147. data/lib/rouge/guessers/glob_mapping.rb +46 -0
  148. data/lib/rouge/guessers/mimetype.rb +14 -0
  149. data/lib/rouge/guessers/modeline.rb +42 -0
  150. data/lib/rouge/guessers/source.rb +39 -0
  151. data/lib/rouge/lexer.rb +452 -0
  152. data/lib/rouge/lexers/abap.rb +238 -0
  153. data/lib/rouge/lexers/actionscript.rb +195 -0
  154. data/lib/rouge/lexers/apache.rb +71 -0
  155. data/lib/rouge/lexers/apache/keywords.yml +764 -0
  156. data/lib/rouge/lexers/apiblueprint.rb +51 -0
  157. data/lib/rouge/lexers/apple_script.rb +367 -0
  158. data/lib/rouge/lexers/awk.rb +161 -0
  159. data/lib/rouge/lexers/biml.rb +41 -0
  160. data/lib/rouge/lexers/bsl.rb +81 -0
  161. data/lib/rouge/lexers/c.rb +217 -0
  162. data/lib/rouge/lexers/ceylon.rb +123 -0
  163. data/lib/rouge/lexers/cfscript.rb +153 -0
  164. data/lib/rouge/lexers/clojure.rb +112 -0
  165. data/lib/rouge/lexers/cmake.rb +206 -0
  166. data/lib/rouge/lexers/coffeescript.rb +174 -0
  167. data/lib/rouge/lexers/common_lisp.rb +345 -0
  168. data/lib/rouge/lexers/conf.rb +24 -0
  169. data/lib/rouge/lexers/console.rb +136 -0
  170. data/lib/rouge/lexers/coq.rb +191 -0
  171. data/lib/rouge/lexers/cpp.rb +78 -0
  172. data/lib/rouge/lexers/csharp.rb +114 -0
  173. data/lib/rouge/lexers/css.rb +273 -0
  174. data/lib/rouge/lexers/d.rb +176 -0
  175. data/lib/rouge/lexers/dart.rb +104 -0
  176. data/lib/rouge/lexers/diff.rb +31 -0
  177. data/lib/rouge/lexers/digdag.rb +72 -0
  178. data/lib/rouge/lexers/docker.rb +50 -0
  179. data/lib/rouge/lexers/dot.rb +68 -0
  180. data/lib/rouge/lexers/eiffel.rb +65 -0
  181. data/lib/rouge/lexers/elixir.rb +133 -0
  182. data/lib/rouge/lexers/erb.rb +56 -0
  183. data/lib/rouge/lexers/erlang.rb +118 -0
  184. data/lib/rouge/lexers/factor.rb +302 -0
  185. data/lib/rouge/lexers/fortran.rb +170 -0
  186. data/lib/rouge/lexers/fsharp.rb +118 -0
  187. data/lib/rouge/lexers/gal.rb +50 -0
  188. data/lib/rouge/lexers/gherkin.rb +137 -0
  189. data/lib/rouge/lexers/gherkin/keywords.rb +14 -0
  190. data/lib/rouge/lexers/glsl.rb +135 -0
  191. data/lib/rouge/lexers/go.rb +178 -0
  192. data/lib/rouge/lexers/gradle.rb +37 -0
  193. data/lib/rouge/lexers/graphql.rb +243 -0
  194. data/lib/rouge/lexers/groovy.rb +112 -0
  195. data/lib/rouge/lexers/haml.rb +233 -0
  196. data/lib/rouge/lexers/handlebars.rb +79 -0
  197. data/lib/rouge/lexers/haskell.rb +183 -0
  198. data/lib/rouge/lexers/html.rb +138 -0
  199. data/lib/rouge/lexers/http.rb +80 -0
  200. data/lib/rouge/lexers/hylang.rb +93 -0
  201. data/lib/rouge/lexers/idlang.rb +316 -0
  202. data/lib/rouge/lexers/igorpro.rb +407 -0
  203. data/lib/rouge/lexers/ini.rb +57 -0
  204. data/lib/rouge/lexers/io.rb +68 -0
  205. data/lib/rouge/lexers/irb.rb +66 -0
  206. data/lib/rouge/lexers/java.rb +87 -0
  207. data/lib/rouge/lexers/javascript.rb +269 -0
  208. data/lib/rouge/lexers/jinja.rb +137 -0
  209. data/lib/rouge/lexers/json.rb +29 -0
  210. data/lib/rouge/lexers/json_doc.rb +23 -0
  211. data/lib/rouge/lexers/jsonnet.rb +151 -0
  212. data/lib/rouge/lexers/jsx.rb +102 -0
  213. data/lib/rouge/lexers/julia.rb +172 -0
  214. data/lib/rouge/lexers/kotlin.rb +84 -0
  215. data/lib/rouge/lexers/lasso.rb +217 -0
  216. data/lib/rouge/lexers/lasso/keywords.yml +446 -0
  217. data/lib/rouge/lexers/liquid.rb +287 -0
  218. data/lib/rouge/lexers/literate_coffeescript.rb +33 -0
  219. data/lib/rouge/lexers/literate_haskell.rb +36 -0
  220. data/lib/rouge/lexers/llvm.rb +84 -0
  221. data/lib/rouge/lexers/lua.rb +125 -0
  222. data/lib/rouge/lexers/lua/builtins.rb +22 -0
  223. data/lib/rouge/lexers/make.rb +116 -0
  224. data/lib/rouge/lexers/markdown.rb +154 -0
  225. data/lib/rouge/lexers/matlab.rb +75 -0
  226. data/lib/rouge/lexers/matlab/builtins.rb +11 -0
  227. data/lib/rouge/lexers/moonscript.rb +114 -0
  228. data/lib/rouge/lexers/mosel.rb +231 -0
  229. data/lib/rouge/lexers/mxml.rb +68 -0
  230. data/lib/rouge/lexers/nasm.rb +203 -0
  231. data/lib/rouge/lexers/nginx.rb +71 -0
  232. data/lib/rouge/lexers/nim.rb +152 -0
  233. data/lib/rouge/lexers/objective_c.rb +208 -0
  234. data/lib/rouge/lexers/ocaml.rb +100 -0
  235. data/lib/rouge/lexers/pascal.rb +66 -0
  236. data/lib/rouge/lexers/perl.rb +197 -0
  237. data/lib/rouge/lexers/php.rb +193 -0
  238. data/lib/rouge/lexers/php/builtins.rb +194 -0
  239. data/lib/rouge/lexers/plain_text.rb +26 -0
  240. data/lib/rouge/lexers/plist.rb +49 -0
  241. data/lib/rouge/lexers/pony.rb +93 -0
  242. data/lib/rouge/lexers/powershell.rb +132 -0
  243. data/lib/rouge/lexers/praat.rb +350 -0
  244. data/lib/rouge/lexers/prolog.rb +64 -0
  245. data/lib/rouge/lexers/prometheus.rb +121 -0
  246. data/lib/rouge/lexers/properties.rb +55 -0
  247. data/lib/rouge/lexers/protobuf.rb +70 -0
  248. data/lib/rouge/lexers/puppet.rb +128 -0
  249. data/lib/rouge/lexers/python.rb +231 -0
  250. data/lib/rouge/lexers/q.rb +124 -0
  251. data/lib/rouge/lexers/qml.rb +73 -0
  252. data/lib/rouge/lexers/r.rb +89 -0
  253. data/lib/rouge/lexers/racket.rb +542 -0
  254. data/lib/rouge/lexers/ruby.rb +437 -0
  255. data/lib/rouge/lexers/rust.rb +192 -0
  256. data/lib/rouge/lexers/sass.rb +74 -0
  257. data/lib/rouge/lexers/sass/common.rb +180 -0
  258. data/lib/rouge/lexers/scala.rb +142 -0
  259. data/lib/rouge/lexers/scheme.rb +112 -0
  260. data/lib/rouge/lexers/scss.rb +34 -0
  261. data/lib/rouge/lexers/sed.rb +172 -0
  262. data/lib/rouge/lexers/shell.rb +180 -0
  263. data/lib/rouge/lexers/sieve.rb +96 -0
  264. data/lib/rouge/lexers/slim.rb +228 -0
  265. data/lib/rouge/lexers/smalltalk.rb +116 -0
  266. data/lib/rouge/lexers/smarty.rb +91 -0
  267. data/lib/rouge/lexers/sml.rb +348 -0
  268. data/lib/rouge/lexers/sql.rb +140 -0
  269. data/lib/rouge/lexers/swift.rb +161 -0
  270. data/lib/rouge/lexers/tap.rb +91 -0
  271. data/lib/rouge/lexers/tcl.rb +192 -0
  272. data/lib/rouge/lexers/tex.rb +69 -0
  273. data/lib/rouge/lexers/toml.rb +71 -0
  274. data/lib/rouge/lexers/tsx.rb +19 -0
  275. data/lib/rouge/lexers/tulip.rb +107 -0
  276. data/lib/rouge/lexers/turtle.rb +72 -0
  277. data/lib/rouge/lexers/twig.rb +39 -0
  278. data/lib/rouge/lexers/typescript.rb +22 -0
  279. data/lib/rouge/lexers/typescript/common.rb +33 -0
  280. data/lib/rouge/lexers/vala.rb +77 -0
  281. data/lib/rouge/lexers/vb.rb +164 -0
  282. data/lib/rouge/lexers/verilog.rb +164 -0
  283. data/lib/rouge/lexers/vhdl.rb +97 -0
  284. data/lib/rouge/lexers/viml.rb +101 -0
  285. data/lib/rouge/lexers/viml/keywords.rb +12 -0
  286. data/lib/rouge/lexers/vue.rb +124 -0
  287. data/lib/rouge/lexers/wollok.rb +107 -0
  288. data/lib/rouge/lexers/xml.rb +59 -0
  289. data/lib/rouge/lexers/yaml.rb +373 -0
  290. data/lib/rouge/plugins/redcarpet.rb +30 -0
  291. data/lib/rouge/regex_lexer.rb +441 -0
  292. data/lib/rouge/template_lexer.rb +20 -0
  293. data/lib/rouge/text_analyzer.rb +48 -0
  294. data/lib/rouge/theme.rb +213 -0
  295. data/lib/rouge/themes/base16.rb +130 -0
  296. data/lib/rouge/themes/colorful.rb +67 -0
  297. data/lib/rouge/themes/github.rb +71 -0
  298. data/lib/rouge/themes/gruvbox.rb +167 -0
  299. data/lib/rouge/themes/igor_pro.rb +20 -0
  300. data/lib/rouge/themes/molokai.rb +82 -0
  301. data/lib/rouge/themes/monokai.rb +92 -0
  302. data/lib/rouge/themes/monokai_sublime.rb +90 -0
  303. data/lib/rouge/themes/pastie.rb +69 -0
  304. data/lib/rouge/themes/thankful_eyes.rb +74 -0
  305. data/lib/rouge/themes/tulip.rb +69 -0
  306. data/lib/rouge/token.rb +182 -0
  307. data/lib/rouge/util.rb +101 -0
  308. data/lib/rouge/version.rb +7 -0
  309. data/lib/rougegal.rb +80 -0
  310. data/rougegal.gemspec +18 -0
  311. metadata +356 -0
@@ -0,0 +1,118 @@
1
+ # -*- coding: utf-8 -*- #
2
+
3
+ module Rouge
4
+ module Lexers
5
+ class Erlang < RegexLexer
6
+ title "Erlang"
7
+ desc "The Erlang programming language (erlang.org)"
8
+ tag 'erlang'
9
+ aliases 'erl'
10
+ filenames '*.erl', '*.hrl'
11
+
12
+ mimetypes 'text/x-erlang', 'application/x-erlang'
13
+
14
+ def self.analyze_text(text)
15
+ return 0.3 if text =~ /^-module[(]\w+[)][.]/
16
+ end
17
+
18
+ keywords = %w(
19
+ after begin case catch cond end fun if
20
+ let of query receive try when
21
+ )
22
+
23
+ builtins = %w(
24
+ abs append_element apply atom_to_list binary_to_list
25
+ bitstring_to_list binary_to_term bit_size bump_reductions
26
+ byte_size cancel_timer check_process_code delete_module
27
+ demonitor disconnect_node display element erase exit
28
+ float float_to_list fun_info fun_to_list
29
+ function_exported garbage_collect get get_keys
30
+ group_leader hash hd integer_to_list iolist_to_binary
31
+ iolist_size is_atom is_binary is_bitstring is_boolean
32
+ is_builtin is_float is_function is_integer is_list
33
+ is_number is_pid is_port is_process_alive is_record
34
+ is_reference is_tuple length link list_to_atom
35
+ list_to_binary list_to_bitstring list_to_existing_atom
36
+ list_to_float list_to_integer list_to_pid list_to_tuple
37
+ load_module localtime_to_universaltime make_tuple md5
38
+ md5_final md5_update memory module_loaded monitor
39
+ monitor_node node nodes open_port phash phash2
40
+ pid_to_list port_close port_command port_connect
41
+ port_control port_call port_info port_to_list
42
+ process_display process_flag process_info purge_module
43
+ put read_timer ref_to_list register resume_process
44
+ round send send_after send_nosuspend set_cookie
45
+ setelement size spawn spawn_link spawn_monitor
46
+ spawn_opt split_binary start_timer statistics
47
+ suspend_process system_flag system_info system_monitor
48
+ system_profile term_to_binary tl trace trace_delivered
49
+ trace_info trace_pattern trunc tuple_size tuple_to_list
50
+ universaltime_to_localtime unlink unregister whereis
51
+ )
52
+
53
+ operators = %r{(\+\+?|--?|\*|/|<|>|/=|=:=|=/=|=<|>=|==?|<-|!|\?)}
54
+ word_operators = %w(
55
+ and andalso band bnot bor bsl bsr bxor
56
+ div not or orelse rem xor
57
+ )
58
+
59
+ atom_re = %r{(?:[a-z][a-zA-Z0-9_]*|'[^\n']*[^\\]')}
60
+
61
+ variable_re = %r{(?:[A-Z_][a-zA-Z0-9_]*)}
62
+
63
+ escape_re = %r{(?:\\(?:[bdefnrstv\'"\\/]|[0-7][0-7]?[0-7]?|\^[a-zA-Z]))}
64
+
65
+ macro_re = %r{(?:#{variable_re}|#{atom_re})}
66
+
67
+ base_re = %r{(?:[2-9]|[12][0-9]|3[0-6])}
68
+
69
+ state :root do
70
+ rule(/\s+/, Text)
71
+ rule(/%.*\n/, Comment)
72
+ rule(%r{(#{keywords.join('|')})\b}, Keyword)
73
+ rule(%r{(#{builtins.join('|')})\b}, Name::Builtin)
74
+ rule(%r{(#{word_operators.join('|')})\b}, Operator::Word)
75
+ rule(/^-/, Punctuation, :directive)
76
+ rule(operators, Operator)
77
+ rule(/"/, Str, :string)
78
+ rule(/<</, Name::Label)
79
+ rule(/>>/, Name::Label)
80
+ rule %r{(#{atom_re})(:)} do
81
+ groups Name::Namespace, Punctuation
82
+ end
83
+ rule %r{(?:^|(?<=:))(#{atom_re})(\s*)(\()} do
84
+ groups Name::Function, Text, Punctuation
85
+ end
86
+ rule(%r{[+-]?#{base_re}#[0-9a-zA-Z]+}, Num::Integer)
87
+ rule(/[+-]?\d+/, Num::Integer)
88
+ rule(/[+-]?\d+.\d+/, Num::Float)
89
+ rule(%r{[\]\[:_@\".{}()|;,]}, Punctuation)
90
+ rule(variable_re, Name::Variable)
91
+ rule(atom_re, Name)
92
+ rule(%r{\?#{macro_re}}, Name::Constant)
93
+ rule(%r{\$(?:#{escape_re}|\\[ %]|[^\\])}, Str::Char)
94
+ rule(%r{##{atom_re}(:?\.#{atom_re})?}, Name::Label)
95
+ end
96
+
97
+ state :string do
98
+ rule(escape_re, Str::Escape)
99
+ rule(/"/, Str, :pop!)
100
+ rule(%r{~[0-9.*]*[~#+bBcdefginpPswWxX]}, Str::Interpol)
101
+ rule(%r{[^"\\~]+}, Str)
102
+ rule(/~/, Str)
103
+ end
104
+
105
+ state :directive do
106
+ rule %r{(define)(\s*)(\()(#{macro_re})} do
107
+ groups Name::Entity, Text, Punctuation, Name::Constant
108
+ pop!
109
+ end
110
+ rule %r{(record)(\s*)(\()(#{macro_re})} do
111
+ groups Name::Entity, Text, Punctuation, Name::Label
112
+ pop!
113
+ end
114
+ rule(atom_re, Name::Entity, :pop!)
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,302 @@
1
+ # -*- coding: utf-8 -*- #
2
+
3
+ module Rouge
4
+ module Lexers
5
+ class Factor < RegexLexer
6
+ title "Factor"
7
+ desc "Factor, the practical stack language (factorcode.org)"
8
+ tag 'factor'
9
+ filenames '*.factor'
10
+ mimetypes 'text/x-factor'
11
+
12
+ def self.analyze_text(text)
13
+ return 1 if text.shebang? 'factor'
14
+ end
15
+
16
+ def self.builtins
17
+ @builtins ||= {}.tap do |builtins|
18
+ builtins[:kernel] = Set.new %w(
19
+ or 2bi 2tri while wrapper nip 4dip wrapper? bi*
20
+ callstack>array both? hashcode die dupd callstack
21
+ callstack? 3dup tri@ pick curry build ?execute 3bi prepose
22
+ >boolean if clone eq? tri* ? = swapd 2over 2keep 3keep clear
23
+ 2dup when not tuple? dup 2bi* 2tri* call tri-curry object bi@
24
+ do unless* if* loop bi-curry* drop when* assert= retainstack
25
+ assert? -rot execute 2bi@ 2tri@ boa with either? 3drop bi
26
+ curry? datastack until 3dip over 3curry tri-curry* tri-curry@
27
+ swap and 2nip throw bi-curry (clone) hashcode* compose 2dip if
28
+ 3tri unless compose? tuple keep 2curry equal? assert tri 2drop
29
+ most <wrapper> boolean? identity-hashcode identity-tuple?
30
+ null new dip bi-curry@ rot xor identity-tuple boolean
31
+ )
32
+
33
+ builtins[:assocs] = Set.new %w(
34
+ ?at assoc? assoc-clone-like assoc= delete-at* assoc-partition
35
+ extract-keys new-assoc value? assoc-size map>assoc push-at
36
+ assoc-like key? assoc-intersect assoc-refine update
37
+ assoc-union assoc-combine at* assoc-empty? at+ set-at
38
+ assoc-all? assoc-subset? assoc-hashcode change-at assoc-each
39
+ assoc-diff zip values value-at rename-at inc-at enum? at cache
40
+ assoc>map <enum> assoc assoc-map enum value-at* assoc-map-as
41
+ >alist assoc-filter-as clear-assoc assoc-stack maybe-set-at
42
+ substitute assoc-filter 2cache delete-at assoc-find keys
43
+ assoc-any? unzip
44
+ )
45
+
46
+ builtins[:combinators] = Set.new %w(
47
+ case execute-effect no-cond no-case? 3cleave>quot 2cleave
48
+ cond>quot wrong-values? no-cond? cleave>quot no-case case>quot
49
+ 3cleave wrong-values to-fixed-point alist>quot case-find
50
+ cond cleave call-effect 2cleave>quot recursive-hashcode
51
+ linear-case-quot spread spread>quot
52
+ )
53
+
54
+ builtins[:math] = Set.new %w(
55
+ number= if-zero next-power-of-2 each-integer ?1+
56
+ fp-special? imaginary-part unless-zero float>bits number?
57
+ fp-infinity? bignum? fp-snan? denominator fp-bitwise= *
58
+ + power-of-2? - u>= / >= bitand log2-expects-positive <
59
+ log2 > integer? number bits>double 2/ zero? (find-integer)
60
+ bits>float float? shift ratio? even? ratio fp-sign bitnot
61
+ >fixnum complex? /i /f byte-array>bignum when-zero sgn >bignum
62
+ next-float u< u> mod recip rational find-last-integer >float
63
+ (all-integers?) 2^ times integer fixnum? neg fixnum sq bignum
64
+ (each-integer) bit? fp-qnan? find-integer complex <fp-nan>
65
+ real double>bits bitor rem fp-nan-payload all-integers?
66
+ real-part log2-expects-positive? prev-float align unordered?
67
+ float fp-nan? abs bitxor u<= odd? <= /mod rational? >integer
68
+ real? numerator
69
+ )
70
+
71
+ builtins[:sequences] = Set.new %w(
72
+ member-eq? append assert-sequence= find-last-from
73
+ trim-head-slice clone-like 3sequence assert-sequence? map-as
74
+ last-index-from reversed index-from cut* pad-tail
75
+ remove-eq! concat-as but-last snip trim-tail nths
76
+ nth 2selector sequence slice? <slice> partition
77
+ remove-nth tail-slice empty? tail* if-empty
78
+ find-from virtual-sequence? member? set-length
79
+ drop-prefix unclip unclip-last-slice iota map-sum
80
+ bounds-error? sequence-hashcode-step selector-for
81
+ accumulate-as map start midpoint@ (accumulate) rest-slice
82
+ prepend fourth sift accumulate! new-sequence follow map! like
83
+ first4 1sequence reverse slice unless-empty padding virtual@
84
+ repetition? set-last index 4sequence max-length set-second
85
+ immutable-sequence first2 first3 replicate-as reduce-index
86
+ unclip-slice supremum suffix! insert-nth trim-tail-slice
87
+ tail 3append short count suffix concat flip filter sum
88
+ immutable? reverse! 2sequence map-integers delete-all start*
89
+ indices snip-slice check-slice sequence? head map-find
90
+ filter! append-as reduce sequence= halves collapse-slice
91
+ interleave 2map filter-as binary-reduce slice-error? product
92
+ bounds-check? bounds-check harvest immutable virtual-exemplar
93
+ find produce remove pad-head last replicate set-fourth
94
+ remove-eq shorten reversed? map-find-last 3map-as
95
+ 2unclip-slice shorter? 3map find-last head-slice pop* 2map-as
96
+ tail-slice* but-last-slice 2map-reduce iota? collector-for
97
+ accumulate each selector append! new-resizable cut-slice
98
+ each-index head-slice* 2reverse-each sequence-hashcode
99
+ pop set-nth ?nth <flat-slice> second join when-empty
100
+ collector immutable-sequence? <reversed> all? 3append-as
101
+ virtual-sequence subseq? remove-nth! push-either new-like
102
+ length last-index push-if 2all? lengthen assert-sequence
103
+ copy map-reduce move third first 3each tail? set-first prefix
104
+ bounds-error any? <repetition> trim-slice exchange surround
105
+ 2reduce cut change-nth min-length set-third produce-as
106
+ push-all head? delete-slice rest sum-lengths 2each head*
107
+ infimum remove! glue slice-error subseq trim replace-slice
108
+ push repetition map-index trim-head unclip-last mismatch
109
+ )
110
+
111
+ builtins[:namespaces] = Set.new %w(
112
+ global +@ change set-namestack change-global init-namespaces
113
+ on off set-global namespace set with-scope bind with-variable
114
+ inc dec counter initialize namestack get get-global make-assoc
115
+ )
116
+
117
+ builtins[:arrays] = Set.new %w(
118
+ <array> 2array 3array pair >array 1array 4array pair?
119
+ array resize-array array?
120
+ )
121
+
122
+ builtins[:io] = Set.new %w(
123
+ +character+ bad-seek-type? readln each-morsel
124
+ stream-seek read print with-output-stream contents
125
+ write1 stream-write1 stream-copy stream-element-type
126
+ with-input-stream stream-print stream-read stream-contents
127
+ stream-tell tell-output bl seek-output bad-seek-type nl
128
+ stream-nl write flush stream-lines +byte+ stream-flush
129
+ read1 seek-absolute? stream-read1 lines stream-readln
130
+ stream-read-until each-line seek-end with-output-stream*
131
+ seek-absolute with-streams seek-input seek-relative?
132
+ input-stream stream-write read-partial seek-end?
133
+ seek-relative error-stream read-until with-input-stream*
134
+ with-streams* tell-input each-block output-stream
135
+ stream-read-partial each-stream-block each-stream-line
136
+ )
137
+
138
+ builtins[:strings] = Set.new %w(
139
+ resize-string >string <string> 1string string string?
140
+ )
141
+
142
+ builtins[:vectors] = Set.new %w(
143
+ with-return restarts return-continuation with-datastack
144
+ recover rethrow-restarts <restart> ifcc set-catchstack
145
+ >continuation< cleanup ignore-errors restart?
146
+ compute-restarts attempt-all-error error-thread
147
+ continue <continuation> attempt-all-error? condition?
148
+ <condition> throw-restarts error catchstack continue-with
149
+ thread-error-hook continuation rethrow callcc1
150
+ error-continuation callcc0 attempt-all condition
151
+ continuation? restart return
152
+ )
153
+
154
+ builtins[:continuations] = Set.new %w(
155
+ with-return restarts return-continuation with-datastack
156
+ recover rethrow-restarts <restart> ifcc set-catchstack
157
+ >continuation< cleanup ignore-errors restart?
158
+ compute-restarts attempt-all-error error-thread
159
+ continue <continuation> attempt-all-error? condition?
160
+ <condition> throw-restarts error catchstack continue-with
161
+ thread-error-hook continuation rethrow callcc1
162
+ error-continuation callcc0 attempt-all condition
163
+ continuation? restart return
164
+ )
165
+ end
166
+ end
167
+
168
+ state :root do
169
+ rule /\s+/m, Text
170
+
171
+ rule /(:|::|MACRO:|MEMO:|GENERIC:|HELP:)(\s+)(\S+)/m do
172
+ groups Keyword, Text, Name::Function
173
+ end
174
+
175
+ rule /(M:|HOOK:|GENERIC#)(\s+)(\S+)(\s+)(\S+)/m do
176
+ groups Keyword, Text, Name::Class, Text, Name::Function
177
+ end
178
+
179
+ rule /\((?=\s)/, Name::Function, :stack_effect
180
+ rule /;(?=\s)/, Keyword
181
+
182
+ rule /(USING:)((?:\s|\\\s)+)/m do
183
+ groups Keyword::Namespace, Text
184
+ push :import
185
+ end
186
+
187
+ rule /(IN:|USE:|UNUSE:|QUALIFIED:|QUALIFIED-WITH:)(\s+)(\S+)/m do
188
+ groups Keyword::Namespace, Text, Name::Namespace
189
+ end
190
+
191
+ rule /(FROM:|EXCLUDE:)(\s+)(\S+)(\s+)(=>)/m do
192
+ groups Keyword::Namespace, Text, Name::Namespace, Text, Punctuation
193
+ end
194
+
195
+ rule /(?:ALIAS|DEFER|FORGET|POSTPONE):/, Keyword::Namespace
196
+
197
+ rule /(TUPLE:)(\s+)(\S+)(\s+)(<)(\s+)(\S+)/m do
198
+ groups(
199
+ Keyword, Text,
200
+ Name::Class, Text,
201
+ Punctuation, Text,
202
+ Name::Class
203
+ )
204
+ push :slots
205
+ end
206
+
207
+ rule /(TUPLE:)(\s+)(\S+)/m do
208
+ groups Keyword, Text, Name::Class
209
+ push :slots
210
+ end
211
+
212
+ rule /(UNION:|INTERSECTION:)(\s+)(\S+)/m do
213
+ groups Keyword, Text, Name::Class
214
+ end
215
+
216
+ rule /(PREDICATE:)(\s+)(\S+)(\s+)(<)(\s+)(\S+)/m do
217
+ groups(
218
+ Keyword, Text,
219
+ Name::Class, Text,
220
+ Punctuation, Text,
221
+ Name::Class
222
+ )
223
+ end
224
+
225
+ rule /(C:)(\s+)(\S+)(\s+)(\S+)/m do
226
+ groups(
227
+ Keyword, Text,
228
+ Name::Function, Text,
229
+ Name::Class
230
+ )
231
+ end
232
+
233
+ rule %r(
234
+ (INSTANCE|SLOT|MIXIN|SINGLETONS?|CONSTANT|SYMBOLS?|ERROR|SYNTAX
235
+ |ALIEN|TYPEDEF|FUNCTION|STRUCT):
236
+ )x, Keyword
237
+
238
+ rule /(?:<PRIVATE|PRIVATE>)/, Keyword::Namespace
239
+
240
+ rule /(MAIN:)(\s+)(\S+)/ do
241
+ groups Keyword::Namespace, Text, Name::Function
242
+ end
243
+
244
+ # strings
245
+ rule /"""\s+.*?\s+"""/, Str
246
+ rule /"(\\.|[^\\])*?"/, Str
247
+ rule /(CHAR:)(\s+)(\\[\\abfnrstv]*|\S)(?=\s)/, Str::Char
248
+
249
+ # comments
250
+ rule /!\s+.*$/, Comment
251
+ rule /#!\s+.*$/, Comment
252
+
253
+ # booleans
254
+ rule /[tf](?=\s)/, Name::Constant
255
+
256
+ # numbers
257
+ rule /-?\d+\.\d+(?=\s)/, Num::Float
258
+ rule /-?\d+(?=\s)/, Num::Integer
259
+
260
+ rule /HEX:\s+[a-fA-F\d]+(?=\s)/m, Num::Hex
261
+ rule /BIN:\s+[01]+(?=\s)/, Num::Bin
262
+ rule /OCT:\s+[0-7]+(?=\s)/, Num::Oct
263
+
264
+ rule %r([-+/*=<>^](?=\s)), Operator
265
+
266
+ rule /(?:deprecated|final|foldable|flushable|inline|recursive)(?=\s)/,
267
+ Keyword
268
+
269
+ rule /\S+/ do |m|
270
+ name = m[0]
271
+
272
+ if self.class.builtins.values.any? { |b| b.include? name }
273
+ token Name::Builtin
274
+ else
275
+ token Name
276
+ end
277
+ end
278
+ end
279
+
280
+ state :stack_effect do
281
+ rule /\s+/, Text
282
+ rule /\(/, Name::Function, :stack_effect
283
+ rule /\)/, Name::Function, :pop!
284
+
285
+ rule /--/, Name::Function
286
+ rule /\S+/, Name::Variable
287
+ end
288
+
289
+ state :slots do
290
+ rule /\s+/, Text
291
+ rule /;(?=\s)/, Keyword, :pop!
292
+ rule /\S+/, Name::Variable
293
+ end
294
+
295
+ state :import do
296
+ rule /;(?=\s)/, Keyword, :pop!
297
+ rule /\s+/, Text
298
+ rule /\S+/, Name::Namespace
299
+ end
300
+ end
301
+ end
302
+ end
@@ -0,0 +1,170 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # vim: set ts=2 sw=2 et:
3
+
4
+ # TODO: Implement format list support.
5
+
6
+ module Rouge
7
+ module Lexers
8
+ class Fortran < RegexLexer
9
+ title "Fortran"
10
+ desc "Fortran 2008 (free-form)"
11
+
12
+ tag 'fortran'
13
+ filenames '*.f90', '*.f95', '*.f03', '*.f08',
14
+ '*.F90', '*.F95', '*.F03', '*.F08'
15
+ mimetypes 'text/x-fortran'
16
+
17
+ name = /[A-Z][_A-Z0-9]*/i
18
+ kind_param = /(\d+|#{name})/
19
+ exponent = /[ED][+-]?\d+/i
20
+
21
+ def self.keywords
22
+ # Fortran allows to omit whitespace between certain keywords...
23
+ @keywords ||= Set.new %w(
24
+ abstract all allocatable allocate assign assignment asynchronous
25
+ backspace bind block blockdata close common concurrent contiguous call
26
+ case class codimension contains continue cycle data deallocate
27
+ deferred dimension do elemental else elseif elsewhere end endblock
28
+ endblockdata enddo endenum endfile endforall endfunction endif
29
+ endinterface endmodule endprogram endselect endsubmodule endsubroutine
30
+ endtype endwhere endwhile entry enum enumerator equivalence error exit
31
+ external final flush forall format function generic go goto if
32
+ implicit import in include inout inquire intent interface intrinsic is
33
+ module namelist non_overridable none nopass nullify only open operator
34
+ optional out parameter pass pause pointer print private procedure
35
+ program protected public pure read recursive result return rewind save
36
+ select selectcase sequence stop submodule subroutine target then to
37
+ type use value volatile wait where while write
38
+ )
39
+ end
40
+
41
+ def self.types
42
+ # There is a separate rule for "double precision" (two words) below
43
+ @types ||= Set.new %w(
44
+ character complex doubleprecision integer logical real
45
+ )
46
+ end
47
+
48
+ def self.intrinsics
49
+ @intrinsics ||= Set.new %w(
50
+ abs achar acos acosh adjustl adjustr aimag aint all allocated anint
51
+ any asin asinh associated atan atan2 atanh bessel_j0 bessel_j1
52
+ bessel_jn bessel_y0 bessel_y1 bessel_yn bge bgt bit_size ble blt btest
53
+ c_associated c_f_pointer c_f_procpointer c_funloc c_loc c_sizeof
54
+ ceiling char cmplx command_argument_count compiler_options
55
+ compiler_version conjg cos cosh count cpu_time cshift date_and_time
56
+ dble digits dim dot_product dprod dshiftl dshiftr eoshift epsilon erf
57
+ erfc_scaled erfc execute_command_line exp exponent extends_type_of
58
+ findloc floor fraction gamma get_command_argument get_command
59
+ get_environment_variable huge hypot iachar iall iand iany ibclr ibits
60
+ ibset ichar ieee_class ieee_copy_sign ieee_get_flag
61
+ ieee_get_halting_mode ieee_get_rounding_mode ieee_get_status
62
+ ieee_get_underflow_mode ieee_is_finite ieee_is_nan ieee_is_normal
63
+ ieee_logb ieee_next_after ieee_rem ieee_rint ieee_scalb
64
+ ieee_selected_real_kind ieee_set_flag ieee_set_halting_mode
65
+ ieee_set_rounding_mode ieee_set_status ieee_set_underflow_mode
66
+ ieee_support_datatype ieee_support_denormal ieee_support_divide
67
+ ieee_support_flag ieee_support_halting ieee_support_inf
68
+ ieee_support_io ieee_support_nan ieee_support_rounding
69
+ ieee_support_sqrt ieee_support_standard ieee_support_underflow_control
70
+ ieee_unordered ieee_value ieor image_index index int ior iparity
71
+ is_contiguous is_iostat_end is_iostat_eor ishft ishftc kind lbound
72
+ lcobound leadz len_trim len lge lgt lle llt log_gamma log log10
73
+ logical maskl maskr matmul max maxexponent maxloc maxval merge_bits
74
+ merge min minexponent minloc minval mod modulo move_alloc mvbits
75
+ nearest new_line nint norm2 not null num_images pack parity popcnt
76
+ poppar present product radix random_number random_seed range real
77
+ repeat reshape rrspacing same_type_as scale scan selected_char_kind
78
+ selected_int_kind selected_real_kind set_exponent shape shifta shiftl
79
+ shiftr sign sin sinh size spacing spread sqrt storage_size sum
80
+ system_clock tan tanh this_image tiny trailz transfer transpose trim
81
+ ubound ucobound unpack verify
82
+ )
83
+ end
84
+
85
+ state :root do
86
+ rule /[\s\n]+/, Text::Whitespace
87
+ rule /!.*$/, Comment::Single
88
+ rule /^#.*$/, Comment::Preproc
89
+
90
+ rule /::|[()\/;,:&\[\]]/, Punctuation
91
+
92
+ # TODO: This does not take into account line continuation.
93
+ rule /^(\s*)([0-9]+)\b/m do |m|
94
+ token Text::Whitespace, m[1]
95
+ token Name::Label, m[2]
96
+ end
97
+
98
+ # Format statements are quite a strange beast.
99
+ # Better process them in their own state.
100
+ rule /\b(FORMAT)(\s*)(\()/mi do |m|
101
+ token Keyword, m[1]
102
+ token Text::Whitespace, m[2]
103
+ token Punctuation, m[3]
104
+ push :format_spec
105
+ end
106
+
107
+ rule %r(
108
+ [+-]? # sign
109
+ (
110
+ (\d+[.]\d*|[.]\d+)(#{exponent})?
111
+ | \d+#{exponent} # exponent is mandatory
112
+ )
113
+ (_#{kind_param})? # kind parameter
114
+ )xi, Num::Float
115
+
116
+ rule /[+-]?\d+(_#{kind_param})?/i, Num::Integer
117
+ rule /B'[01]+'|B"[01]+"/i, Num::Bin
118
+ rule /O'[0-7]+'|O"[0-7]+"/i, Num::Oct
119
+ rule /Z'[0-9A-F]+'|Z"[0-9A-F]+"/i, Num::Hex
120
+ rule /(#{kind_param}_)?'/, Str::Single, :string_single
121
+ rule /(#{kind_param}_)?"/, Str::Double, :string_double
122
+ rule /[.](TRUE|FALSE)[.](_#{kind_param})?/i, Keyword::Constant
123
+
124
+ rule %r{\*\*|//|==|/=|<=|>=|=>|[-+*/<>=%]}, Operator
125
+ rule /\.(?:EQ|NE|LT|LE|GT|GE|NOT|AND|OR|EQV|NEQV|[A-Z]+)\./i, Operator::Word
126
+
127
+ # To make sure "double precision" written as two words is highlighted
128
+ # properly. "doubleprecision" is covered by a different rule.
129
+ rule /double\s+precision\b/i, Keyword::Type
130
+
131
+ rule /#{name}/m do |m|
132
+ match = m[0].downcase
133
+ if self.class.keywords.include? match
134
+ token Keyword
135
+ elsif self.class.types.include? match
136
+ token Keyword::Type
137
+ elsif self.class.intrinsics.include? match
138
+ token Name::Builtin
139
+ else
140
+ token Name
141
+ end
142
+ end
143
+
144
+ end
145
+
146
+ state :string_single do
147
+ rule /[^']+/, Str::Single
148
+ rule /''/, Str::Escape
149
+ rule /'/, Str::Single, :pop!
150
+ end
151
+
152
+ state :string_double do
153
+ rule /[^"]+/, Str::Double
154
+ rule /""/, Str::Escape
155
+ rule /"/, Str::Double, :pop!
156
+ end
157
+
158
+ state :format_spec do
159
+ rule /'/, Str::Single, :string_single
160
+ rule /"/, Str::Double, :string_double
161
+ rule /\(/, Punctuation, :format_spec
162
+ rule /\)/, Punctuation, :pop!
163
+ rule /,/, Punctuation
164
+ rule /[\s\n]+/, Text::Whitespace
165
+ # Edit descriptors could be seen as a kind of "format literal".
166
+ rule /[^\s'"(),]+/, Literal
167
+ end
168
+ end
169
+ end
170
+ end