rouge 1.10.1 → 1.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rouge/cli.rb +1 -1
  3. data/lib/rouge/demos/actionscript +4 -0
  4. data/lib/rouge/demos/apiblueprint +33 -0
  5. data/lib/rouge/demos/biml +38 -0
  6. data/lib/rouge/demos/ceylon +7 -0
  7. data/lib/rouge/demos/cmake +7 -0
  8. data/lib/rouge/demos/coq +11 -0
  9. data/lib/rouge/demos/d +16 -0
  10. data/lib/rouge/demos/eiffel +30 -0
  11. data/lib/rouge/demos/fortran +22 -0
  12. data/lib/rouge/demos/gradle +10 -0
  13. data/lib/rouge/demos/jinja +9 -0
  14. data/lib/rouge/demos/jsonnet +28 -0
  15. data/lib/rouge/demos/julia +11 -0
  16. data/lib/rouge/demos/nasm +26 -0
  17. data/lib/rouge/demos/objective_c +4 -0
  18. data/lib/rouge/demos/protobuf +5 -0
  19. data/lib/rouge/demos/shell_session +10 -0
  20. data/lib/rouge/demos/smarty +12 -0
  21. data/lib/rouge/demos/tap +5 -0
  22. data/lib/rouge/demos/twig +9 -0
  23. data/lib/rouge/demos/typescript +1 -0
  24. data/lib/rouge/demos/verilog +27 -0
  25. data/lib/rouge/demos/viml +14 -5
  26. data/lib/rouge/formatters/html_wrapper.rb +11 -0
  27. data/lib/rouge/formatters/terminal256.rb +1 -1
  28. data/lib/rouge/lexer.rb +4 -2
  29. data/lib/rouge/lexers/actionscript.rb +195 -0
  30. data/lib/rouge/lexers/apache.rb +23 -20
  31. data/lib/rouge/lexers/apache/keywords.yml +721 -410
  32. data/lib/rouge/lexers/apiblueprint.rb +51 -0
  33. data/lib/rouge/lexers/biml.rb +41 -0
  34. data/lib/rouge/lexers/c.rb +7 -2
  35. data/lib/rouge/lexers/ceylon.rb +123 -0
  36. data/lib/rouge/lexers/clojure.rb +1 -1
  37. data/lib/rouge/lexers/cmake.rb +206 -0
  38. data/lib/rouge/lexers/coffeescript.rb +1 -1
  39. data/lib/rouge/lexers/coq.rb +187 -0
  40. data/lib/rouge/lexers/cpp.rb +12 -1
  41. data/lib/rouge/lexers/csharp.rb +12 -5
  42. data/lib/rouge/lexers/css.rb +2 -0
  43. data/lib/rouge/lexers/d.rb +176 -0
  44. data/lib/rouge/lexers/diff.rb +9 -9
  45. data/lib/rouge/lexers/eiffel.rb +65 -0
  46. data/lib/rouge/lexers/fortran.rb +142 -0
  47. data/lib/rouge/lexers/gradle.rb +37 -0
  48. data/lib/rouge/lexers/groovy.rb +2 -2
  49. data/lib/rouge/lexers/ini.rb +2 -2
  50. data/lib/rouge/lexers/java.rb +11 -8
  51. data/lib/rouge/lexers/javascript.rb +2 -1
  52. data/lib/rouge/lexers/jinja.rb +137 -0
  53. data/lib/rouge/lexers/jsonnet.rb +151 -0
  54. data/lib/rouge/lexers/julia.rb +172 -0
  55. data/lib/rouge/lexers/markdown.rb +1 -0
  56. data/lib/rouge/lexers/nasm.rb +203 -0
  57. data/lib/rouge/lexers/objective_c.rb +11 -0
  58. data/lib/rouge/lexers/php.rb +1 -1
  59. data/lib/rouge/lexers/powershell.rb +1 -1
  60. data/lib/rouge/lexers/protobuf.rb +70 -0
  61. data/lib/rouge/lexers/python.rb +23 -0
  62. data/lib/rouge/lexers/r.rb +53 -20
  63. data/lib/rouge/lexers/ruby.rb +4 -4
  64. data/lib/rouge/lexers/rust.rb +2 -2
  65. data/lib/rouge/lexers/shell_session.rb +29 -0
  66. data/lib/rouge/lexers/smarty.rb +91 -0
  67. data/lib/rouge/lexers/sql.rb +1 -1
  68. data/lib/rouge/lexers/swift.rb +20 -5
  69. data/lib/rouge/lexers/tap.rb +91 -0
  70. data/lib/rouge/lexers/twig.rb +37 -0
  71. data/lib/rouge/lexers/typescript.rb +46 -0
  72. data/lib/rouge/lexers/verilog.rb +164 -0
  73. data/lib/rouge/regex_lexer.rb +1 -1
  74. data/lib/rouge/version.rb +1 -1
  75. data/rouge.gemspec +1 -1
  76. metadata +47 -6
  77. data/lib/rouge/formatters/html_inline.rb +0 -20
  78. data/lib/rouge/formatters/html_linewise.rb +0 -31
@@ -43,7 +43,7 @@ module Rouge
43
43
  state :comments_and_whitespace do
44
44
  rule /\s+/m, Text
45
45
  rule /###.*?###/m, Comment::Multiline
46
- rule /#.*?\n/, Comment::Single
46
+ rule /#.*$/, Comment::Single
47
47
  end
48
48
 
49
49
  state :multiline_regex do
@@ -0,0 +1,187 @@
1
+ # -*- coding: utf-8 -*- #
2
+
3
+ module Rouge
4
+ module Lexers
5
+ class Coq < RegexLexer
6
+ title "Coq"
7
+ desc 'Coq (coq.inria.fr)'
8
+ tag 'coq'
9
+ mimetypes 'text/x-coq'
10
+
11
+ def self.analyze_text(text)
12
+ return 0.3 if text.include? "Require"
13
+ end
14
+
15
+ def self.gallina
16
+ @gallina ||= Set.new %w(
17
+ as fun if in let match then else return end Type Set Prop
18
+ forall
19
+ )
20
+ end
21
+
22
+ def self.coq
23
+ @coq ||= Set.new %w(
24
+ Definition Theorem Lemma Remark Example Fixpoint CoFixpoint
25
+ Record Inductive CoInductive Corollary Goal Proof
26
+ Ltac Require Import Export Module Section End Variable
27
+ Context Polymorphic Monomorphic Universe Universes
28
+ Variables Class Instance Global Local Include
29
+ Printing Notation Infix Arguments Hint Rewrite Immediate
30
+ Qed Defined Opaque Transparent Existing
31
+ Compute Eval Print SearchAbout Search About Check
32
+ )
33
+ end
34
+
35
+ def self.ltac
36
+ @ltac ||= Set.new %w(
37
+ apply eapply auto eauto rewrite setoid_rewrite
38
+ with in as at destruct split inversion injection
39
+ intro intros unfold fold cbv cbn lazy subst
40
+ clear symmetry transitivity etransitivity erewrite
41
+ edestruct constructor econstructor eexists exists
42
+ f_equal refine instantiate revert simpl
43
+ specialize generalize dependent red induction
44
+ beta iota zeta delta exfalso autorewrite setoid_rewrite
45
+ compute vm_compute native_compute
46
+ )
47
+ end
48
+
49
+ def self.tacticals
50
+ @tacticals ||= Set.new %w(
51
+ repeat first try
52
+ )
53
+ end
54
+
55
+ def self.terminators
56
+ @terminators ||= Set.new %w(
57
+ omega solve congruence reflexivity exact
58
+ assumption eassumption
59
+ )
60
+ end
61
+
62
+ def self.keyopts
63
+ @keyopts ||= Set.new %w(
64
+ := => -> /\\ \\/ _ ; :> :
65
+ )
66
+ end
67
+
68
+ def self.end_sentence
69
+ @end_sentence ||= Punctuation::Indicator
70
+ end
71
+
72
+ def self.classify(x)
73
+ if self.coq.include? x
74
+ return Keyword
75
+ elsif self.gallina.include? x
76
+ return Keyword::Reserved
77
+ elsif self.ltac.include? x
78
+ return Keyword::Pseudo
79
+ elsif self.terminators.include? x
80
+ return Name::Exception
81
+ elsif self.tacticals.include? x
82
+ return Keyword::Pseudo
83
+ else
84
+ return Name::Constant
85
+ end
86
+ end
87
+
88
+ operator = %r([\[\];,{}_()!$%&*+./:<=>?@^|~#-]+)
89
+ id = /(?:[a-z][\w']*)|(?:[_a-z][\w']+)/i
90
+ dot_id = /\.((?:[a-z][\w']*)|(?:[_a-z][\w']+))/i
91
+ dot_space = /\.(\s+)/
92
+ module_type = /Module(\s+)Type(\s+)/
93
+ set_options = /(Set|Unset)(\s+)(Universe|Printing|Implicit|Strict)(\s+)(Polymorphism|All|Notations|Arguments|Universes|Implicit)(\s*)\./m
94
+
95
+ state :root do
96
+ rule /[(][*](?![)])/, Comment, :comment
97
+ rule /\s+/m, Text::Whitespace
98
+ rule module_type do |m|
99
+ token Keyword , 'Module'
100
+ token Text::Whitespace , m[1]
101
+ token Keyword , 'Type'
102
+ token Text::Whitespace , m[2]
103
+ end
104
+ rule set_options do |m|
105
+ token Keyword , m[1]
106
+ i = 2
107
+ while m[i] != ''
108
+ token Text::Whitespace , m[i]
109
+ token Keyword , m[i+1]
110
+ i += 2
111
+ end
112
+ token self.class.end_sentence , '.'
113
+ end
114
+ rule id do |m|
115
+ @name = m[0]
116
+ @continue = false
117
+ push :continue_id
118
+ end
119
+ rule /\/\\/, Operator
120
+ rule /\\\//, Operator
121
+ rule operator do |m|
122
+ match = m[0]
123
+ if self.class.keyopts.include? match
124
+ token Punctuation
125
+ else
126
+ token Operator
127
+ end
128
+ end
129
+
130
+ rule /-?\d[\d_]*(.[\d_]*)?(e[+-]?\d[\d_]*)/i, Num::Float
131
+ rule /\d[\d_]*/, Num::Integer
132
+
133
+ rule /'(?:(\\[\\"'ntbr ])|(\\[0-9]{3})|(\\x\h{2}))'/, Str::Char
134
+ rule /'/, Keyword
135
+ rule /"/, Str::Double, :string
136
+ rule /[~?]#{id}/, Name::Variable
137
+ end
138
+
139
+ state :comment do
140
+ rule /[^(*)]+/, Comment
141
+ rule(/[(][*]/) { token Comment; push }
142
+ rule /[*][)]/, Comment, :pop!
143
+ rule /[(*)]/, Comment
144
+ end
145
+
146
+ state :string do
147
+ rule /[^\\"]+/, Str::Double
148
+ mixin :escape_sequence
149
+ rule /\\\n/, Str::Double
150
+ rule /"/, Str::Double, :pop!
151
+ end
152
+
153
+ state :continue_id do
154
+ # the stream starts with an id (stored in @name) and continues here
155
+ rule dot_id do |m|
156
+ token Name::Namespace , @name
157
+ token Punctuation , '.'
158
+ @continue = true
159
+ @name = m[1]
160
+ end
161
+ rule dot_space do |m|
162
+ if @continue
163
+ token Name::Constant , @name
164
+ else
165
+ token self.class.classify(@name) , @name
166
+ end
167
+ token self.class.end_sentence , '.'
168
+ token Text::Whitespace , m[1]
169
+ @name = false
170
+ @continue = false
171
+ pop!
172
+ end
173
+ rule // do
174
+ if @continue
175
+ token Name::Constant , @name
176
+ else
177
+ token self.class.classify(@name) , @name
178
+ end
179
+ @name = false
180
+ @continue = false
181
+ pop!
182
+ end
183
+ end
184
+
185
+ end
186
+ end
187
+ end
@@ -24,6 +24,15 @@ module Rouge
24
24
  friend mutable namespace new operator private protected public
25
25
  reinterpret_cast restrict static_cast template this throw
26
26
  throws typeid typename using virtual
27
+
28
+ alignas alignof constexpr decltype noexcept static_assert
29
+ thread_local try
30
+ ))
31
+ end
32
+
33
+ def self.keywords_type
34
+ @keywords_type ||= super + Set.new(%w(
35
+ bool
27
36
  ))
28
37
  end
29
38
 
@@ -34,7 +43,7 @@ module Rouge
34
43
  ))
35
44
  end
36
45
 
37
- id = /[a-zA-Z_][a-zA-Z0-9]*/
46
+ id = /[a-zA-Z_][a-zA-Z0-9_]*/
38
47
 
39
48
  prepend :root do
40
49
  # Offload C++ extensions, http://offload.codeplay.com/
@@ -52,6 +61,8 @@ module Rouge
52
61
  rule /0x\h('?\h)*[lu]*/i, Num::Hex
53
62
  rule /0[0-7]('?[0-7])*[lu]*/i, Num::Oct
54
63
  rule /#{dq}[lu]*/i, Num::Integer
64
+ rule /\bnullptr\b/, Name::Builtin
65
+ rule /(?:u8|u|U|L)?R"([a-zA-Z0-9_{}\[\]#<>%:;.?*\+\-\/\^&|~!=,"']{,16})\(.*?\)\1"/m, Str
55
66
  end
56
67
 
57
68
  state :classname do
@@ -14,19 +14,26 @@ module Rouge
14
14
  # TODO: support more of unicode
15
15
  id = /@?[_a-z]\w*/i
16
16
 
17
+ #Reserved Identifiers
18
+ #Contextual Keywords
19
+ #LINQ Query Expressions
17
20
  keywords = %w(
18
- abstract alias as base break case catch checked const continue
21
+ abstract as base break case catch checked const continue
19
22
  default delegate do else enum event explicit extern false
20
- finally fixed for foreach global goto if implicit in interface
23
+ finally fixed for foreach goto if implicit in interface
21
24
  internal is lock new null operator out override params private
22
25
  protected public readonly ref return sealed sizeof stackalloc
23
26
  static switch this throw true try typeof unchecked unsafe
24
- virtual void while get set new partial yield add remove value
27
+ virtual void volatile while
28
+ add alias async await get global partial remove set value where
29
+ yield
30
+ ascending by descending equals from group in into join let on
31
+ orderby select
25
32
  )
26
33
 
27
34
  keywords_type = %w(
28
- bool byte char decimal double float int long object sbyte
29
- short string uint ulong ushort
35
+ bool byte char decimal double dynamic float int long object
36
+ sbyte short string uint ulong ushort var
30
37
  )
31
38
 
32
39
  cpp_keywords = %w(
@@ -191,6 +191,8 @@ module Rouge
191
191
  rule /@#{identifier}/, Keyword, :at_rule
192
192
  rule identifier, Name::Tag
193
193
  rule %r([~^*!%&\[\]()<>|+=@:;,./?-]), Operator
194
+ rule /"(\\\\|\\"|[^"])*"/, Str::Single
195
+ rule /'(\\\\|\\'|[^'])*'/, Str::Double
194
196
  end
195
197
 
196
198
  state :value do
@@ -0,0 +1,176 @@
1
+ # -*- coding: utf-8 -*- #
2
+
3
+ module Rouge
4
+ module Lexers
5
+ class D < RegexLexer
6
+ tag 'd'
7
+ aliases 'dlang'
8
+ filenames '*.d', '*.di'
9
+ mimetypes 'application/x-dsrc', 'text/x-dsrc'
10
+
11
+ title "D"
12
+ desc 'The D programming language(dlag.org)'
13
+
14
+ keywords = %w(
15
+ abstract alias align asm assert auto body
16
+ break case cast catch class const continue
17
+ debug default delegate delete deprecated do else
18
+ enum export extern finally final foreach_reverse
19
+ foreach for function goto if immutable import
20
+ interface invariant inout in is lazy mixin
21
+ module new nothrow out override package pragma
22
+ private protected public pure ref return scope
23
+ shared static struct super switch synchronized
24
+ template this throw try typedef typeid typeof
25
+ union unittest version volatile while with
26
+ __gshared __traits __vector __parameters
27
+ )
28
+
29
+ keywords_type = %w(
30
+ bool byte cdouble cent cfloat char creal
31
+ dchar double float idouble ifloat int ireal
32
+ long real short ubyte ucent uint ulong
33
+ ushort void wchar
34
+ )
35
+
36
+ keywords_pseudo = %w(
37
+ __FILE__ __MODULE__ __LINE__ __FUNCTION__ __PRETTY_FUNCTION__
38
+ __DATE__ __EOF__ __TIME__ __TIMESTAMP__ __VENDOR__
39
+ __VERSION__
40
+ )
41
+
42
+ state :whitespace do
43
+ rule /\n/m, Text
44
+ rule /\s+/m, Text
45
+ end
46
+
47
+ state :root do
48
+ mixin :whitespace
49
+ # Comments
50
+ rule %r(//(.*?)\n), Comment::Single
51
+ rule %r(/(\\\n)?[*](.|\n)*?[*](\\\n)?/), Comment::Multiline
52
+ rule %r(/\+), Comment::Multiline, :nested_comment
53
+ # Keywords
54
+ rule /(#{keywords.join('|')})\b/, Keyword
55
+ rule /(#{keywords_type.join('|')})\b/, Keyword::Type
56
+ rule /(false|true|null)\b/, Keyword::Constant
57
+ rule /(#{keywords_pseudo.join('|')})\b/, Keyword::Pseudo
58
+ rule /macro\b/, Keyword::Reserved
59
+ rule /(string|wstring|dstring|size_t|ptrdiff_t)\b/, Name::Builtin
60
+ # Literals
61
+ # HexFloat
62
+ rule /0[xX]([0-9a-fA-F_]*\.[0-9a-fA-F_]+|[0-9a-fA-F_]+)[pP][+\-]?[0-9_]+[fFL]?[i]?/, Num::Float
63
+ # DecimalFloat
64
+ rule /[0-9_]+(\.[0-9_]+[eE][+\-]?[0-9_]+|\.[0-9_]*|[eE][+\-]?[0-9_]+)[fFL]?[i]?/, Num::Float
65
+ rule /\.(0|[1-9][0-9_]*)([eE][+\-]?[0-9_]+)?[fFL]?[i]?/, Num::Float
66
+ # IntegerLiteral
67
+ # Binary
68
+ rule /0[Bb][01_]+/, Num::Bin
69
+ # Octal
70
+ # TODO: 0[0-7] isn't supported use octal![0-7] instead
71
+ rule /0[0-7_]+/, Num::Oct
72
+ # Hexadecimal
73
+ rule /0[xX][0-9a-fA-F_]+/, Num::Hex
74
+ # Decimal
75
+ rule /(0|[1-9][0-9_]*)([LUu]|Lu|LU|uL|UL)?/, Num::Integer
76
+ # CharacterLiteral
77
+ rule /'(\\['"?\\abfnrtv]|\\x[0-9a-fA-F]{2}|\\[0-7]{1,3}|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}|\\&\w+;|.)'/, Str::Char
78
+ # StringLiteral
79
+ # WysiwygString
80
+ rule /r"[^"]*"[cwd]?/, Str
81
+ # Alternate WysiwygString
82
+ rule /`[^`]*`[cwd]?/, Str
83
+ # DoubleQuotedString
84
+ rule /"(\\\\|\\"|[^"])*"[cwd]?/, Str
85
+ # EscapeSequence
86
+ rule /\\(['\"?\\abfnrtv]|x[0-9a-fA-F]{2}|[0-7]{1,3}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8}|&\w+;)/, Str
87
+ # HexString
88
+ rule /x"[0-9a-fA-F_\s]*"[cwd]?/, Str
89
+ # DelimitedString
90
+ rule /q"\[/, Str, :delimited_bracket
91
+ rule /q"\(/, Str, :delimited_parenthesis
92
+ rule /q"</, Str, :delimited_angle
93
+ rule /q"\{/, Str, :delimited_curly
94
+ rule /q"([a-zA-Z_]\w*)\n.*?\n\1"/, Str
95
+ rule /q"(.).*?\1"/, Str
96
+ # TokenString
97
+ rule /q\{/, Str, :token_string
98
+ # Attributes
99
+ rule /@([a-zA-Z_]\w*)?/, Name::Decorator
100
+ # Tokens
101
+ rule %r`(~=|\^=|%=|\*=|==|!>=|!<=|!<>=|!<>|!<|!>|!=|>>>=|>>>|>>=|>>|>=|<>=|<>|<<=|<<|<=|\+\+|\+=|--|-=|\|\||\|=|&&|&=|\.\.\.|\.\.|/=)|[/.&|\-+<>!()\[\]{}?,;:$=*%^~]`, Punctuation
102
+ # Identifier
103
+ rule /[a-zA-Z_]\w*/, Name
104
+ # Line
105
+ rule /#line\s.*\n/, Comment::Special
106
+ end
107
+
108
+ state :nested_comment do
109
+ rule %r([^+/]+), Comment::Multiline
110
+ rule %r(/\+), Comment::Multiline, :push
111
+ rule %r(\+/), Comment::Multiline, :pop!
112
+ rule %r([+/]), Comment::Multiline
113
+ end
114
+
115
+ state :token_string do
116
+ rule /\{/, Punctuation, :token_string_nest
117
+ rule /\}/, Str, :pop!
118
+ mixin :root
119
+ end
120
+
121
+ state :token_string_nest do
122
+ rule /\{/, Punctuation, :push
123
+ rule /\}/, Punctuation, :pop!
124
+ mixin :root
125
+ end
126
+
127
+ state :delimited_bracket do
128
+ rule /[^\[\]]+/, Str
129
+ rule /\[/, Str, :delimited_inside_bracket
130
+ rule /\]"/, Str, :pop!
131
+ end
132
+
133
+ state :delimited_inside_bracket do
134
+ rule /[^\[\]]+/, Str
135
+ rule /\[/, Str, :push
136
+ rule /\]/, Str, :pop!
137
+ end
138
+
139
+ state :delimited_parenthesis do
140
+ rule /[^()]+/, Str
141
+ rule /\(/, Str, :delimited_inside_parenthesis
142
+ rule /\)"/, Str, :pop!
143
+ end
144
+
145
+ state :delimited_inside_parenthesis do
146
+ rule /[^()]+/, Str
147
+ rule /\(/, Str, :push
148
+ rule /\)/, Str, :pop!
149
+ end
150
+
151
+ state :delimited_angle do
152
+ rule /[^<>]+/, Str
153
+ rule /</, Str, :delimited_inside_angle
154
+ rule />"/, Str, :pop!
155
+ end
156
+
157
+ state :delimited_inside_angle do
158
+ rule /[^<>]+/, Str
159
+ rule /</, Str, :push
160
+ rule />/, Str, :pop!
161
+ end
162
+
163
+ state :delimited_curly do
164
+ rule /[^{}]+/, Str
165
+ rule /\{/, Str, :delimited_inside_curly
166
+ rule /\}"/, Str, :pop!
167
+ end
168
+
169
+ state :delimited_inside_curly do
170
+ rule /[^{}]+/, Str
171
+ rule /\{/, Str, :push
172
+ rule /\}/, Str, :pop!
173
+ end
174
+ end
175
+ end
176
+ end