rouge 0.0.7 → 0.0.8

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.
@@ -28,6 +28,8 @@ load load_dir.join('rouge/lexers/html.rb')
28
28
  load load_dir.join('rouge/lexers/tcl.rb')
29
29
  load load_dir.join('rouge/lexers/python.rb')
30
30
 
31
+ load load_dir.join('rouge/lexers/haskell.rb')
32
+
31
33
  load load_dir.join('rouge/formatter.rb')
32
34
  load load_dir.join('rouge/formatters/html.rb')
33
35
 
@@ -0,0 +1,174 @@
1
+ module Rouge
2
+ module Lexers
3
+ class Haskell < RegexLexer
4
+ tag 'haskell'
5
+ aliases 'hs'
6
+ filenames '*.hs'
7
+ mimetypes 'text/x-haskell'
8
+
9
+ def self.analyze_text(text)
10
+ return 1 if text.shebang?('runhaskell')
11
+ end
12
+
13
+ reserved = %w(
14
+ _ case class data default deriving do else if in
15
+ infix[lr]? instance let newtype of then type where
16
+ )
17
+
18
+ ascii = %w(
19
+ NUL SOH [SE]TX EOT ENQ ACK BEL BS HT LF VT FF CR S[OI] DLE
20
+ DC[1-4] NAK SYN ETB CAN EM SUB ESC [FGRU]S SP DEL
21
+ )
22
+
23
+ state :basic do
24
+ rule /\s+/m, 'Text'
25
+ rule /{-#/, 'Comment.Preproc', :comment_preproc
26
+ rule /{-/, 'Comment.Multiline', :comment
27
+ rule /^--\s+\|.*?$/, 'Comment.Doc'
28
+ # this is complicated in order to support custom symbols
29
+ # like -->
30
+ rule /--(?![!#\$\%&*+.\/<=>?@\^\|_~]).*?$/, 'Comment.Single'
31
+ end
32
+
33
+ # nested commenting
34
+ state :comment do
35
+ rule /-}/, 'Comment.Multiline', :pop!
36
+ rule /{-/, 'Comment.Multiline', :comment
37
+ rule /[^-{}]+/, 'Comment.Multiline'
38
+ rule /[-{}]/, 'Comment.Multiline'
39
+ end
40
+
41
+ state :root do
42
+ mixin :basic
43
+
44
+ rule /\bimport\b/, 'Keyword.Reserved', :import
45
+ rule /\bmodule\b/, 'Keyword.Reserved', :module
46
+ rule /\berror\b/, 'Name.Exception'
47
+ rule /\b(?:#{reserved.join('|')})\b/, 'Keyword.Reserved'
48
+ # not sure why, but ^ doesn't work here
49
+ # rule /^[_a-z][\w']*/, 'Name.Function'
50
+ rule /[_a-z][\w']*/, 'Name'
51
+ rule /[A-Z][\w']*/, 'Keyword.Type'
52
+
53
+ # lambda operator
54
+ rule %r(\\(?![:!#\$\%&*+.\\/<=>?@^\|~-]+)), 'Name.Function'
55
+ # special operators
56
+ rule %r((<-|::|->|=>|=)(?![:!#\$\%&*+.\\/<=>?@^\|~-]+)), 'Operator'
57
+ # constructor/type operators
58
+ rule %r(:[:!#\$\%&*+.\\/<=>?@^\|~-]*), 'Operator'
59
+ # other operators
60
+ rule %r([:!#\$\%&*+.\\/<=>?@^\|~-]+), 'Operator'
61
+
62
+ rule /\d+e[+-]?\d+/i, 'Literal.Number.Float'
63
+ rule /\d+\.\d+(e[+-]?\d+)?/i, 'Literal.Number.Float'
64
+ rule /0o[0-7]+/i, 'Literal.Number.Oct'
65
+ rule /0x[\da-f]+/i, 'Literal.Number.Hex'
66
+ rule /\d+/, 'Literal.Number.Integer'
67
+
68
+ rule /'/, 'Literal.String.Char', :character
69
+ rule /"/, 'Literal.String', :string
70
+
71
+ rule /\[\s*\]/, 'Keyword.Type'
72
+ rule /\(\s*\)/, 'Name.Builtin'
73
+ rule /[\[\](),;`{}]/, 'Punctuation'
74
+ end
75
+
76
+ state :import do
77
+ rule /\s+/, 'Text'
78
+ rule /"/, 'Literal.String', :string
79
+ rule /\bqualified\b/, 'Keyword'
80
+ # import X as Y
81
+ rule /([A-Z][\w.]*)(\s+)(as)(\s+)([A-Z][a-zA-Z0-9_.]*)/ do
82
+ group 'Name.Namespace' # X
83
+ group 'Text'
84
+ group 'Keyword' # as
85
+ group 'Text'
86
+ group 'Name' # Y
87
+ pop!
88
+ end
89
+
90
+ # import X hiding (functions)
91
+ rule /([A-Z][\w.]*)(\s+)(hiding)(\s+)(\()/ do
92
+ group 'Name.Namespace' # X
93
+ group 'Text'
94
+ group 'Keyword' # hiding
95
+ group 'Text'
96
+ group 'Punctuation' # (
97
+ pop!
98
+ push :funclist
99
+ end
100
+
101
+ # import X (functions)
102
+ rule /([A-Z][\w.]*)(\s+)(\()/ do
103
+ group 'Name.Namespace' # X
104
+ group 'Text'
105
+ group 'Punctuation' # (
106
+ pop!
107
+ push :funclist
108
+ end
109
+
110
+ rule /[\w.]+/, 'Name.Namespace', :pop!
111
+ end
112
+
113
+ state :module do
114
+ rule /\s+/, 'Text'
115
+ # module Foo (functions)
116
+ rule /([A-Z][\w.]*)(\s+)(\()/ do
117
+ group 'Name.Namespace'
118
+ group 'Text'
119
+ group 'Punctuation'
120
+ push :funclist
121
+ end
122
+
123
+ rule /\bwhere\b/, 'Keyword.Reserved', :pop!
124
+
125
+ rule /[A-Z][a-zA-Z0-9_.]*/, 'Name.Namespace', :pop!
126
+ end
127
+
128
+ state :funclist do
129
+ mixin :basic
130
+ rule /[A-Z]\w*/, 'Keyword.Type'
131
+ rule /(_[\w\']+|[a-z][\w\']*)/, 'Name.Function'
132
+ rule /,/, 'Punctuation'
133
+ rule /[:!#\$\%&*+.\\\/<=>?@^\|~-]+/, 'Operator'
134
+ rule /\(/, 'Punctuation', :funclist
135
+ rule /\)/, 'Punctuation', :pop!
136
+ end
137
+
138
+ state :character do
139
+ rule /\\/ do
140
+ token 'Literal.String.Escape'
141
+ push :character_end
142
+ push :escape
143
+ end
144
+
145
+ rule /./ do
146
+ token 'Literal.String.Char'
147
+ pop!
148
+ push :character_end
149
+ end
150
+ end
151
+
152
+ state :character_end do
153
+ rule /'/, 'Literal.String.Char', :pop!
154
+ rule /./, 'Error', :pop!
155
+ end
156
+
157
+ state :string do
158
+ rule /"/, 'Literal.String', :pop!
159
+ rule /\\/, 'Literal.String.Escape', :escape
160
+ rule /[^\\"]+/, 'Literal.String'
161
+ end
162
+
163
+ state :escape do
164
+ rule /[abfnrtv"'&\\]/, 'Literal.String.Escape', :pop!
165
+ rule /\^[\]\[A-Z@\^_]/, 'Literal.String.Escape', :pop!
166
+ rule /#{ascii.join('|')}/, 'Literal.String.Escape', :pop!
167
+ rule /o[0-7]+/i, 'Literal.String.Escape', :pop!
168
+ rule /x[\da-f]/i, 'Literal.String.Escape', :pop!
169
+ rule /\d+/, 'Literal.String.Escape', :pop!
170
+ rule /\s+\\/, 'Literal.String.Escape', :pop!
171
+ end
172
+ end
173
+ end
174
+ end
@@ -1,5 +1,5 @@
1
1
  module Rouge
2
2
  def self.version
3
- "0.0.7"
3
+ "0.0.8"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rouge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -40,6 +40,7 @@ files:
40
40
  - lib/rouge/lexers/shell.rb
41
41
  - lib/rouge/lexers/javascript.rb
42
42
  - lib/rouge/lexers/diff.rb
43
+ - lib/rouge/lexers/haskell.rb
43
44
  - lib/rouge/lexers/text.rb
44
45
  - lib/rouge/lexers/html.rb
45
46
  - lib/rouge/lexers/tcl.rb