rouge 3.28.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +5 -11
  3. data/lib/rouge/cli.rb +23 -20
  4. data/lib/rouge/demos/brainfuck +1 -1
  5. data/lib/rouge/demos/brightscript +1 -1
  6. data/lib/rouge/demos/bsl +1 -1
  7. data/lib/rouge/demos/cfscript +1 -1
  8. data/lib/rouge/demos/coq +1 -1
  9. data/lib/rouge/demos/csvs +1 -1
  10. data/lib/rouge/demos/datastudio +0 -1
  11. data/lib/rouge/demos/ecl +0 -1
  12. data/lib/rouge/demos/erlang +1 -1
  13. data/lib/rouge/demos/fsharp +1 -1
  14. data/lib/rouge/demos/glsl +1 -1
  15. data/lib/rouge/demos/haxe +0 -1
  16. data/lib/rouge/demos/idris +13 -0
  17. data/lib/rouge/demos/isabelle +16 -0
  18. data/lib/rouge/demos/lean +8 -0
  19. data/lib/rouge/demos/meson +10 -0
  20. data/lib/rouge/demos/nesasm +1 -1
  21. data/lib/rouge/demos/nial +35 -0
  22. data/lib/rouge/demos/opentype_feature_file +0 -1
  23. data/lib/rouge/demos/plsql +2 -0
  24. data/lib/rouge/demos/rml +33 -0
  25. data/lib/rouge/demos/smarty +0 -1
  26. data/lib/rouge/demos/syzlang +15 -0
  27. data/lib/rouge/demos/syzprog +8 -0
  28. data/lib/rouge/formatters/html_inline.rb +0 -1
  29. data/lib/rouge/guessers/disambiguation.rb +7 -0
  30. data/lib/rouge/lexer.rb +2 -2
  31. data/lib/rouge/lexers/apache/keywords.rb +1 -1
  32. data/lib/rouge/lexers/apple_script.rb +1 -1
  33. data/lib/rouge/lexers/cpp.rb +1 -0
  34. data/lib/rouge/lexers/dart.rb +2 -1
  35. data/lib/rouge/lexers/diff.rb +14 -4
  36. data/lib/rouge/lexers/docker.rb +4 -0
  37. data/lib/rouge/lexers/eiffel.rb +0 -1
  38. data/lib/rouge/lexers/gherkin/keywords.rb +1 -1
  39. data/lib/rouge/lexers/groovy.rb +1 -1
  40. data/lib/rouge/lexers/handlebars.rb +1 -1
  41. data/lib/rouge/lexers/haxe.rb +30 -11
  42. data/lib/rouge/lexers/http.rb +1 -1
  43. data/lib/rouge/lexers/hylang.rb +0 -1
  44. data/lib/rouge/lexers/idris.rb +210 -0
  45. data/lib/rouge/lexers/isabelle.rb +251 -0
  46. data/lib/rouge/lexers/javascript.rb +1 -1
  47. data/lib/rouge/lexers/jsx.rb +0 -1
  48. data/lib/rouge/lexers/lasso/keywords.rb +1 -1
  49. data/lib/rouge/lexers/lean.rb +164 -0
  50. data/lib/rouge/lexers/llvm/keywords.rb +1 -1
  51. data/lib/rouge/lexers/lua/keywords.rb +1 -1
  52. data/lib/rouge/lexers/make.rb +25 -16
  53. data/lib/rouge/lexers/mathematica/keywords.rb +1 -1
  54. data/lib/rouge/lexers/matlab/keywords.rb +1 -1
  55. data/lib/rouge/lexers/matlab.rb +3 -2
  56. data/lib/rouge/lexers/meson.rb +159 -0
  57. data/lib/rouge/lexers/nial.rb +166 -0
  58. data/lib/rouge/lexers/ocl.rb +0 -1
  59. data/lib/rouge/lexers/pascal.rb +2 -1
  60. data/lib/rouge/lexers/php/keywords.rb +1 -1
  61. data/lib/rouge/lexers/php.rb +7 -5
  62. data/lib/rouge/lexers/plsql.rb +578 -0
  63. data/lib/rouge/lexers/praat.rb +20 -2
  64. data/lib/rouge/lexers/prometheus.rb +0 -1
  65. data/lib/rouge/lexers/python.rb +3 -1
  66. data/lib/rouge/lexers/q.rb +0 -1
  67. data/lib/rouge/lexers/rml.rb +142 -0
  68. data/lib/rouge/lexers/sqf/keywords.rb +1 -1
  69. data/lib/rouge/lexers/supercollider.rb +0 -1
  70. data/lib/rouge/lexers/syzlang.rb +317 -0
  71. data/lib/rouge/lexers/syzprog.rb +122 -0
  72. data/lib/rouge/lexers/tap.rb +0 -1
  73. data/lib/rouge/lexers/toml.rb +12 -7
  74. data/lib/rouge/lexers/tsx.rb +7 -1
  75. data/lib/rouge/lexers/tulip.rb +0 -1
  76. data/lib/rouge/lexers/typescript/common.rb +4 -1
  77. data/lib/rouge/lexers/viml/keywords.rb +1 -1
  78. data/lib/rouge/version.rb +1 -1
  79. data/rouge.gemspec +1 -1
  80. metadata +22 -6
  81. data/lib/rouge/demos/solidity +0 -13
  82. data/lib/rouge/lexers/solidity.rb +0 -185
@@ -0,0 +1,210 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Lexers
6
+ class Idris < RegexLexer
7
+ title "Idris"
8
+ desc "The Idris programming language (idris-lang.org)"
9
+
10
+ tag 'idris'
11
+ aliases 'idr'
12
+ filenames '*.idr'
13
+ mimetypes 'text/x-idris'
14
+
15
+ def self.reserved_keywords
16
+ @reserved_keywords ||= %w(
17
+ _ data class instance namespace
18
+ infix[lr]? let where of with type
19
+ do if then else case in
20
+ )
21
+ end
22
+
23
+ def self.ascii
24
+ @ascii ||= %w(
25
+ NUL SOH [SE]TX EOT ENQ ACK BEL BS HT LF VT FF CR S[OI] DLE
26
+ DC[1-4] NAK SYN ETB CAN EM SUB ESC [FGRU]S SP DEL
27
+ )
28
+ end
29
+
30
+ def self.prelude_functions
31
+ @prelude_functions ||= %w(
32
+ abs acos all and any asin atan atan2 break ceiling compare concat
33
+ concatMap const cos cosh curry cycle div drop dropWhile elem
34
+ encodeFloat enumFrom enumFromThen enumFromThenTo enumFromTo exp
35
+ fail filter flip floor foldl foldl1 foldr foldr1 fromInteger fst
36
+ gcd getChar getLine head id init iterate last lcm length lines log
37
+ lookup map max maxBound maximum maybe min minBound minimum mod
38
+ negate not null or pi pred print product putChar putStr putStrLn
39
+ readFile recip repeat replicate return reverse scanl scanl1 sequence
40
+ sequence_ show sin sinh snd span splitAt sqrt succ sum tail take
41
+ takeWhile tan tanh uncurry unlines unwords unzip unzip3 words
42
+ writeFile zip zip3 zipWith zipWith3
43
+ )
44
+ end
45
+
46
+ state :basic do
47
+ rule %r/\s+/m, Text
48
+ rule %r/{-#/, Comment::Preproc, :comment_preproc
49
+ rule %r/{-/, Comment::Multiline, :comment
50
+ rule %r/^\|\|\|.*$/, Comment::Doc
51
+ rule %r/--(?![!#\$\%&*+.\/<=>?@\^\|_~]).*?$/, Comment::Single
52
+ end
53
+
54
+ # nested commenting
55
+ state :comment do
56
+ rule %r/-}/, Comment::Multiline, :pop!
57
+ rule %r/{-/, Comment::Multiline, :comment
58
+ rule %r/[^-{}]+/, Comment::Multiline
59
+ rule %r/[-{}]/, Comment::Multiline
60
+ end
61
+ state :comment_preproc do
62
+ rule %r/-}/, Comment::Preproc, :pop!
63
+ rule %r/{-/, Comment::Preproc, :comment
64
+ rule %r/[^-{}]+/, Comment::Preproc
65
+ rule %r/[-{}]/, Comment::Preproc
66
+ end
67
+
68
+ state :directive do
69
+ rule %r/\%(default)\s+(total|partial)/, Keyword # totality
70
+ rule %r/\%(access)\s+(public|abstract|private|export)/, Keyword # export
71
+ rule %r/\%(language)\s+(.*)/, Keyword # language
72
+ rule %r/\%(provide)\s+.*\s+(with)\s+/, Keyword # type
73
+ end
74
+
75
+ state :prelude do
76
+ rule %r/\b(Type|Exists|World|IO|IntTy|FTy|File|Mode|Dec|Bool|Ordering|Either|IsJust|List|Maybe|Nat|Stream|StrM|Not|Lazy|Inf)\s/, Keyword::Type
77
+ rule %r/\b(Eq|Ord|Num|MinBound|MaxBound|Integral|Applicative|Alternative|Cast|Foldable|Functor|Monad|Traversable|Uninhabited|Semigroup|Monoid)\s/, Name::Class
78
+ rule %r/\b(?:#{Idris.prelude_functions.join('|')})[ ]+(?![=:-])/, Name::Builtin
79
+ end
80
+
81
+ state :root do
82
+ mixin :basic
83
+ mixin :directive
84
+
85
+ rule %r/\bimport\b/, Keyword::Reserved, :import
86
+ rule %r/\bmodule\b/, Keyword::Reserved, :module
87
+ rule %r/\b(?:#{Idris.reserved_keywords.join('|')})\b/, Keyword::Reserved
88
+ rule %r/\b(Just|Nothing|Left|Right|True|False|LT|LTE|EQ|GT|GTE)\b/, Keyword::Constant
89
+ # function signature
90
+ rule %r/^[\w']+\s*:/, Name::Function
91
+ # should be below as you can override names defined in Prelude
92
+ mixin :prelude
93
+ rule %r/[_a-z][\w']*/, Name
94
+ rule %r/[A-Z][\w']*/, Keyword::Type
95
+
96
+ # lambda operator
97
+ rule %r(\\(?![:!#\$\%&*+.\\/<=>?@^\|~-]+)), Name::Function
98
+ # special operators
99
+ rule %r((<-|::|->|=>|=)(?![:!#\$\%&*+.\\/<=>?@^\|~-]+)), Operator
100
+ # constructor/type operators
101
+ rule %r(:[:!#\$\%&*+.\\/<=>?@^\|~-]*), Operator
102
+ # other operators
103
+ rule %r([:!#\$\%&*+.\\/<=>?@^\|~-]+), Operator
104
+
105
+ rule %r/\d+(\.\d+)?(e[+-]?\d+)?/i, Num::Float
106
+ rule %r/0o[0-7]+/i, Num::Oct
107
+ rule %r/0x[\da-f]+/i, Num::Hex
108
+ rule %r/\d+/, Num::Integer
109
+
110
+ rule %r/'/, Str::Char, :character
111
+ rule %r/"/, Str, :string
112
+
113
+ rule %r/\[\s*\]/, Keyword::Type
114
+ rule %r/\(\s*\)/, Name::Builtin
115
+
116
+ # Quasiquotations
117
+ rule %r/(\[)([_a-z][\w']*)(\|)/ do |m|
118
+ token Operator, m[1]
119
+ token Name, m[2]
120
+ token Operator, m[3]
121
+ push :quasiquotation
122
+ end
123
+
124
+ rule %r/[\[\](),;`{}]/, Punctuation
125
+ end
126
+
127
+ state :import do
128
+ rule %r/\s+/, Text
129
+ rule %r/"/, Str, :string
130
+ # import X as Y
131
+ rule %r/([A-Z][\w.]*)(\s+)(as)(\s+)([A-Z][a-zA-Z0-9_.]*)/ do
132
+ groups(
133
+ Name::Namespace, # X
134
+ Text, Keyword, # as
135
+ Text, Name # Y
136
+ )
137
+ pop!
138
+ end
139
+
140
+ # import X (functions)
141
+ rule %r/([A-Z][\w.]*)(\s+)(\()/ do
142
+ groups(
143
+ Name::Namespace, # X
144
+ Text,
145
+ Punctuation # (
146
+ )
147
+ goto :funclist
148
+ end
149
+
150
+ rule %r/[\w.]+/, Name::Namespace, :pop!
151
+ end
152
+
153
+ state :module do
154
+ rule %r/\s+/, Text
155
+ # module X
156
+ rule %r/([A-Z][\w.]*)/, Name::Namespace, :pop!
157
+ end
158
+
159
+ state :funclist do
160
+ mixin :basic
161
+ rule %r/[A-Z]\w*/, Keyword::Type
162
+ rule %r/(_[\w\']+|[a-z][\w\']*)/, Name::Function
163
+ rule %r/,/, Punctuation
164
+ rule %r/[:!#\$\%&*+.\\\/<=>?@^\|~-]+/, Operator
165
+ rule %r/\(/, Punctuation, :funclist
166
+ rule %r/\)/, Punctuation, :pop!
167
+ end
168
+
169
+ state :character do
170
+ rule %r/\\/ do
171
+ token Str::Escape
172
+ goto :character_end
173
+ push :escape
174
+ end
175
+
176
+ rule %r/./ do
177
+ token Str::Char
178
+ goto :character_end
179
+ end
180
+ end
181
+
182
+ state :character_end do
183
+ rule %r/'/, Str::Char, :pop!
184
+ rule %r/./, Error, :pop!
185
+ end
186
+
187
+ state :quasiquotation do
188
+ rule %r/\|\]/, Operator, :pop!
189
+ rule %r/[^\|]+/m, Text
190
+ rule %r/\|/, Text
191
+ end
192
+
193
+ state :string do
194
+ rule %r/"/, Str, :pop!
195
+ rule %r/\\/, Str::Escape, :escape
196
+ rule %r/[^\\"]+/, Str
197
+ end
198
+
199
+ state :escape do
200
+ rule %r/[abfnrtv"'&\\]/, Str::Escape, :pop!
201
+ rule %r/\^[\]\[A-Z@\^_]/, Str::Escape, :pop!
202
+ rule %r/#{Idris.ascii.join('|')}/, Str::Escape, :pop!
203
+ rule %r/o[0-7]+/i, Str::Escape, :pop!
204
+ rule %r/x[\da-fA-F]+/i, Str::Escape, :pop!
205
+ rule %r/\d+/, Str::Escape, :pop!
206
+ rule %r/\s+\\/, Str::Escape, :pop!
207
+ end
208
+ end
209
+ end
210
+ end
@@ -0,0 +1,251 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+ # Lexer adapted from https://github.com/pygments/pygments/blob/ad55974ce83b85dbb333ab57764415ab84169461/pygments/lexers/theorem.py
4
+
5
+ module Rouge
6
+ module Lexers
7
+ class Isabelle < RegexLexer
8
+ title "Isabelle"
9
+ desc 'Isabelle theories (isabelle.in.tum.de)'
10
+ tag 'isabelle'
11
+ aliases 'isa', 'Isabelle'
12
+ filenames '*.thy'
13
+ mimetypes 'text/x-isabelle'
14
+
15
+ def self.keyword_minor
16
+ @keyword_minor ||= Set.new %w(
17
+ and assumes attach avoids binder checking
18
+ class_instance class_relation code_module congs
19
+ constant constrains datatypes defines file fixes
20
+ for functions hints identifier if imports in
21
+ includes infix infixl infixr is keywords lazy
22
+ module_name monos morphisms no_discs_sels notes
23
+ obtains open output overloaded parametric permissive
24
+ pervasive rep_compat shows structure type_class
25
+ type_constructor unchecked unsafe where
26
+ )
27
+ end
28
+
29
+ def self.keyword_diag
30
+ @keyword_diag ||= Set.new %w(
31
+ ML_command ML_val class_deps code_deps code_thms
32
+ display_drafts find_consts find_theorems find_unused_assms
33
+ full_prf help locale_deps nitpick pr prf
34
+ print_abbrevs print_antiquotations print_attributes
35
+ print_binds print_bnfs print_bundles
36
+ print_case_translations print_cases print_claset
37
+ print_classes print_codeproc print_codesetup
38
+ print_coercions print_commands print_context
39
+ print_defn_rules print_dependencies print_facts
40
+ print_induct_rules print_inductives print_interps
41
+ print_locale print_locales print_methods print_options
42
+ print_orders print_quot_maps print_quotconsts
43
+ print_quotients print_quotientsQ3 print_quotmapsQ3
44
+ print_rules print_simpset print_state print_statement
45
+ print_syntax print_theorems print_theory print_trans_rules
46
+ prop pwd quickcheck refute sledgehammer smt_status
47
+ solve_direct spark_status term thm thm_deps thy_deps
48
+ try try0 typ unused_thms value values welcome
49
+ print_ML_antiquotations print_term_bindings values_prolog
50
+ )
51
+ end
52
+
53
+ def self.keyword_thy
54
+ @keyword_thy ||= Set.new %w(theory begin end)
55
+ end
56
+
57
+ def self.keyword_section
58
+ @keyword_section ||= Set.new %w(header chapter)
59
+ end
60
+
61
+ def self.keyword_subsection
62
+ @keyword_subsection ||= Set.new %w(section subsection subsubsection sect subsect subsubsect)
63
+ end
64
+
65
+ def self.keyword_theory_decl
66
+ @keyword_theory_decl ||= Set.new %w(
67
+ ML ML_file abbreviation adhoc_overloading arities
68
+ atom_decl attribute_setup axiomatization bundle
69
+ case_of_simps class classes classrel codatatype
70
+ code_abort code_class code_const code_datatype
71
+ code_identifier code_include code_instance code_modulename
72
+ code_monad code_printing code_reflect code_reserved
73
+ code_type coinductive coinductive_set consts context
74
+ datatype datatype_new datatype_new_compat declaration
75
+ declare default_sort defer_recdef definition defs
76
+ domain domain_isomorphism domaindef equivariance
77
+ export_code extract extract_type fixrec fun
78
+ fun_cases hide_class hide_const hide_fact hide_type
79
+ import_const_map import_file import_tptp import_type_map
80
+ inductive inductive_set instantiation judgment lemmas
81
+ lifting_forget lifting_update local_setup locale
82
+ method_setup nitpick_params no_adhoc_overloading
83
+ no_notation no_syntax no_translations no_type_notation
84
+ nominal_datatype nonterminal notation notepad oracle
85
+ overloading parse_ast_translation parse_translation
86
+ partial_function primcorec primrec primrec_new
87
+ print_ast_translation print_translation quickcheck_generator
88
+ quickcheck_params realizability realizers recdef record
89
+ refute_params setup setup_lifting simproc_setup
90
+ simps_of_case sledgehammer_params spark_end spark_open
91
+ spark_open_siv spark_open_vcg spark_proof_functions
92
+ spark_types statespace syntax syntax_declaration text
93
+ text_raw theorems translations type_notation
94
+ type_synonym typed_print_translation typedecl hoarestate
95
+ install_C_file install_C_types wpc_setup c_defs c_types
96
+ memsafe SML_export SML_file SML_import approximate
97
+ bnf_axiomatization cartouche datatype_compat
98
+ free_constructors functor nominal_function
99
+ nominal_termination permanent_interpretation
100
+ binds defining smt2_status term_cartouche
101
+ boogie_file text_cartouche
102
+ )
103
+ end
104
+
105
+ def self.keyword_theory_script
106
+ @keyword_theory_script ||= Set.new %w(inductive_cases inductive_simps)
107
+ end
108
+
109
+ def self.keyword_theory_goal
110
+ @keyword_theory_goal ||= Set.new %w(
111
+ ax_specification bnf code_pred corollary cpodef
112
+ crunch crunch_ignore
113
+ enriched_type function instance interpretation lemma
114
+ lift_definition nominal_inductive nominal_inductive2
115
+ nominal_primrec pcpodef primcorecursive
116
+ quotient_definition quotient_type recdef_tc rep_datatype
117
+ schematic_corollary schematic_lemma schematic_theorem
118
+ spark_vc specification subclass sublocale termination
119
+ theorem typedef wrap_free_constructors
120
+ )
121
+ end
122
+
123
+ def self.keyword_qed
124
+ @keyword_qed ||= Set.new %w(by done qed)
125
+ end
126
+
127
+ def self.keyword_abandon_proof
128
+ @keyword_abandon_proof ||= Set.new %w(sorry oops)
129
+ end
130
+
131
+ def self.keyword_proof_goal
132
+ @keyword_proof_goal ||= Set.new %w(have hence interpret)
133
+ end
134
+
135
+ def self.keyword_proof_block
136
+ @keyword_proof_block ||= Set.new %w(next proof)
137
+ end
138
+
139
+ def self.keyword_proof_chain
140
+ @keyword_proof_chain ||= Set.new %w(finally from then ultimately with)
141
+ end
142
+
143
+ def self.keyword_proof_decl
144
+ @keyword_proof_decl ||= Set.new %w(
145
+ ML_prf also include including let moreover note
146
+ txt txt_raw unfolding using write
147
+ )
148
+ end
149
+
150
+ def self.keyword_proof_asm
151
+ @keyword_proof_asm ||= Set.new %w(assume case def fix presume)
152
+ end
153
+
154
+ def self.keyword_proof_asm_goal
155
+ @keyword_proof_asm_goal ||= Set.new %w(guess obtain show thus)
156
+ end
157
+
158
+ def self.keyword_proof_script
159
+ @keyword_proof_script ||= Set.new %w(apply apply_end apply_trace back defer prefer)
160
+ end
161
+
162
+ state :root do
163
+ rule %r/\s+/, Text::Whitespace
164
+ rule %r/\(\*/, Comment, :comment
165
+ rule %r/\{\*|‹/, Text, :text
166
+
167
+ rule %r/::|\[|\]|-|[:()_=,|+!?]/, Operator
168
+ rule %r/[{}.]|\.\./, Operator::Word
169
+
170
+ def word(keywords)
171
+ return %r/\b(#{keywords.join('|')})\b/
172
+ end
173
+
174
+ rule %r/[a-zA-Z]\w*/ do |m|
175
+ sym = m[0]
176
+
177
+ if self.class.keyword_minor.include?(sym) ||
178
+ self.class.keyword_proof_script.include?(sym)
179
+ token Keyword::Pseudo
180
+ elsif self.class.keyword_diag.include?(sym)
181
+ token Keyword::Type
182
+ elsif self.class.keyword_thy.include?(sym) ||
183
+ self.class.keyword_theory_decl.include?(sym) ||
184
+ self.class.keyword_qed.include?(sym) ||
185
+ self.class.keyword_proof_goal.include?(sym) ||
186
+ self.class.keyword_proof_block.include?(sym) ||
187
+ self.class.keyword_proof_decl.include?(sym) ||
188
+ self.class.keyword_proof_chain.include?(sym) ||
189
+ self.class.keyword_proof_asm.include?(sym) ||
190
+ self.class.keyword_proof_asm_goal.include?(sym)
191
+ token Keyword
192
+ elsif self.class.keyword_section.include?(sym)
193
+ token Generic::Heading
194
+ elsif self.class.keyword_subsection.include?(sym)
195
+ token Generic::Subheading
196
+ elsif self.class.keyword_theory_goal.include?(sym) ||
197
+ self.class.keyword_theory_script.include?(sym)
198
+ token Keyword::Namespace
199
+ elsif self.class.keyword_abandon_proof.include?(sym)
200
+ token Generic::Error
201
+ else
202
+ token Name
203
+ end
204
+ end
205
+
206
+ rule %r/\\<\w*>/, Str::Symbol
207
+
208
+ rule %r/'[^\W\d][.\w']*/, Name::Variable
209
+
210
+ rule %r/0[xX][\da-fA-F][\da-fA-F_]*/, Num::Hex
211
+ rule %r/0[oO][0-7][0-7_]*/, Num::Oct
212
+ rule %r/0[bB][01][01_]*/, Num::Bin
213
+
214
+ rule %r/"/, Str, :string
215
+ rule %r/`/, Str::Other, :fact
216
+ # Everything except for (most) operators whitespaces may be name
217
+ rule %r/[^\s:|\[\]\-()=,+!?{}._][^\s:|\[\]\-()=,+!?{}]*/, Name
218
+ end
219
+
220
+ state :comment do
221
+ rule %r/[^(*)]+/, Comment
222
+ rule %r/\(\*/, Comment, :comment
223
+ rule %r/\*\)/, Comment, :pop!
224
+ rule %r/[(*)]/, Comment
225
+ end
226
+
227
+ state :text do
228
+ rule %r/[^{*}‹›]+/, Text
229
+ rule %r/\{\*|‹/, Text, :text
230
+ rule %r/\*\}|›/, Text, :pop!
231
+ rule %r/[{*}]/, Text
232
+ end
233
+
234
+ state :string do
235
+ rule %r/[^"\\]+/, Str
236
+ rule %r/\\<\w*>/, Str::Symbol
237
+ rule %r/\\"/, Str
238
+ rule %r/\\/, Str
239
+ rule %r/"/, Str, :pop!
240
+ end
241
+
242
+ state :fact do
243
+ rule %r/[^`\\]+/, Str::Other
244
+ rule %r/\\<\w*>/, Str::Symbol
245
+ rule %r/\\`/, Str::Other
246
+ rule %r/\\/, Str::Other
247
+ rule %r/`/, Str::Other, :pop!
248
+ end
249
+ end
250
+ end
251
+ end
@@ -149,7 +149,7 @@ module Rouge
149
149
  rule %r/\A\s*#!.*?\n/m, Comment::Preproc, :statement
150
150
  rule %r((?<=\n)(?=\s|/|<!--)), Text, :expr_start
151
151
  mixin :comments_and_whitespace
152
- rule %r(\+\+ | -- | ~ | && | \|\| | \\(?=\n) | << | >>>? | ===
152
+ rule %r(\+\+ | -- | ~ | \?\?=? | && | \|\| | \\(?=\n) | << | >>>? | ===
153
153
  | !== )x,
154
154
  Operator, :expr_start
155
155
  rule %r([-<>+*%&|\^/!=]=?), Operator, :expr_start
@@ -89,4 +89,3 @@ module Rouge
89
89
  end
90
90
  end
91
91
  end
92
-
@@ -17,4 +17,4 @@ module Rouge
17
17
  end
18
18
  end
19
19
  end
20
- end
20
+ end
@@ -0,0 +1,164 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ # NOTE: This is for Lean 3 (community fork).
5
+ module Rouge
6
+ module Lexers
7
+ class Lean < RegexLexer
8
+ title 'Lean'
9
+ desc 'The Lean programming language (leanprover.github.io)'
10
+ tag 'lean'
11
+ aliases 'lean'
12
+ filenames '*.lean'
13
+
14
+ def self.keywords
15
+ @keywords ||= Set.new %w(
16
+ abbreviation
17
+ add_rewrite
18
+ alias
19
+ assume
20
+ axiom
21
+ begin
22
+ by
23
+ calc
24
+ calc_refl
25
+ calc_subst
26
+ calc_trans
27
+ #check
28
+ coercion
29
+ conjecture
30
+ constant
31
+ constants
32
+ context
33
+ corollary
34
+ def
35
+ definition
36
+ end
37
+ #eval
38
+ example
39
+ export
40
+ expose
41
+ exposing
42
+ exit
43
+ extends
44
+ from
45
+ fun
46
+ have
47
+ help
48
+ hiding
49
+ hott
50
+ hypothesis
51
+ import
52
+ include
53
+ including
54
+ inductive
55
+ infix
56
+ infixl
57
+ infixr
58
+ inline
59
+ instance
60
+ irreducible
61
+ lemma
62
+ match
63
+ namespace
64
+ notation
65
+ opaque
66
+ opaque_hint
67
+ open
68
+ options
69
+ parameter
70
+ parameters
71
+ postfix
72
+ precedence
73
+ prefix
74
+ #print
75
+ private
76
+ protected
77
+ #reduce
78
+ reducible
79
+ renaming
80
+ repeat
81
+ section
82
+ set_option
83
+ show
84
+ tactic_hint
85
+ theorem
86
+ universe
87
+ universes
88
+ using
89
+ variable
90
+ variables
91
+ with
92
+ )
93
+ end
94
+
95
+ def self.types
96
+ @types ||= %w(
97
+ Sort
98
+ Prop
99
+ Type
100
+ )
101
+ end
102
+
103
+ def self.operators
104
+ @operators ||= %w(
105
+ != # & && \* \+ - / @ ! ` -\. ->
106
+ \. \.\. \.\.\. :: :> ; ;; <
107
+ <- = == > _ \| \|\| ~ => <= >=
108
+ /\ \/ ∀ Π λ ↔ ∧ ∨ ≠ ≤ ≥ ⊎
109
+ ¬ ⁻¹ ⬝ ▸ → ∃ ℕ ℤ ≈ × ⌞ ⌟ ≡ ⟨ ⟩
110
+ )
111
+ end
112
+
113
+ state :root do
114
+ # comments starting after some space
115
+ rule %r/\s*--+\s+.*?$/, Comment::Doc
116
+
117
+ rule %r/"/, Str, :string
118
+ rule %r/\d+/, Num::Integer
119
+
120
+ # special commands or keywords
121
+ rule(/#?\w+/) do |m|
122
+ match = m[0]
123
+ if self.class.keywords.include?(match)
124
+ token Keyword
125
+ elsif self.class.types.include?(match)
126
+ token Keyword::Type
127
+ else
128
+ token Name
129
+ end
130
+ end
131
+
132
+ # special unicode keywords
133
+ rule %r/[λ]/, Keyword
134
+
135
+ # ----------------
136
+ # operators rules
137
+ # ----------------
138
+
139
+ rule %r/\:=?/, Text
140
+ rule %r/\.[0-9]*/, Operator
141
+
142
+ rule %r(#{Lean.operators.join('|')}), Operator
143
+
144
+ # unmatched symbols
145
+ rule %r/[\s\(\),\[\]αβ‹›]+/, Text
146
+
147
+ # show missing matches
148
+ rule %r/./, Error
149
+
150
+ end
151
+
152
+ state :string do
153
+ rule %r/"/, Str, :pop!
154
+ rule %r/\\/, Str::Escape, :escape
155
+ rule %r/[^\\"]+/, Str
156
+ end
157
+
158
+ state :escape do
159
+ rule %r/[nrt"'\\]/, Str::Escape, :pop!
160
+ rule %r/x[\da-f]+/i, Str::Escape, :pop!
161
+ end
162
+ end
163
+ end
164
+ end
@@ -22,4 +22,4 @@ module Rouge
22
22
 
23
23
  end
24
24
  end
25
- end
25
+ end
@@ -25,4 +25,4 @@ module Rouge
25
25
  end
26
26
  end
27
27
  end
28
- end
28
+ end