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,34 @@
1
+ # -*- coding: utf-8 -*- #
2
+
3
+ module Rouge
4
+ module Lexers
5
+ load_const :SassCommon, 'sass/common.rb'
6
+
7
+ class Scss < SassCommon
8
+ title "SCSS"
9
+ desc "SCSS stylesheets (sass-lang.com)"
10
+ tag 'scss'
11
+ filenames '*.scss'
12
+ mimetypes 'text/x-scss'
13
+
14
+ state :root do
15
+ rule /\s+/, Text
16
+ rule %r(//.*?\n), Comment::Single
17
+ rule %r(/[*].*?[*]/)m, Comment::Multiline
18
+ rule /@import\b/, Keyword, :value
19
+
20
+ mixin :content_common
21
+
22
+ rule(/(?=[^;{}][;}])/) { push :attribute }
23
+ rule(/(?=[^;{}:]+:[^a-z])/) { push :attribute }
24
+
25
+ rule(//) { push :selector }
26
+ end
27
+
28
+ state :end_section do
29
+ rule /\n/, Text
30
+ rule(/[;{}]/) { token Punctuation; reset_stack }
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,170 @@
1
+ # -*- coding: utf-8 -*- #
2
+
3
+ module Rouge
4
+ module Lexers
5
+ class Sed < RegexLexer
6
+ title "sed"
7
+ desc 'sed, the ultimate stream editor'
8
+
9
+ tag 'sed'
10
+ filenames '*.sed'
11
+ mimetypes 'text/x-sed'
12
+
13
+ def self.analyze_text(text)
14
+ return 1 if text.shebang? 'sed'
15
+ end
16
+
17
+ class Regex < RegexLexer
18
+ state :root do
19
+ rule /\\./, Str::Escape
20
+ rule /\[/, Punctuation, :brackets
21
+ rule /[$^.*]/, Operator
22
+ rule /[()]/, Punctuation
23
+ rule /./, Str::Regex
24
+ end
25
+
26
+ state :brackets do
27
+ rule /\^?/ do
28
+ token Punctuation
29
+ goto :brackets_int
30
+ end
31
+ end
32
+
33
+ state :brackets_int do
34
+ # ranges
35
+ rule /.-./, Name::Variable
36
+ rule /\]/, Punctuation, :pop!
37
+ rule /./, Str::Regex
38
+ end
39
+ end
40
+
41
+ class Replacement < RegexLexer
42
+ state :root do
43
+ rule /\\./m, Str::Escape
44
+ rule /&/, Operator
45
+ rule /[^\\&]+/m, Text
46
+ end
47
+ end
48
+
49
+ def regex
50
+ @regex ||= Regex.new(options)
51
+ end
52
+
53
+ def replacement
54
+ @replacement ||= Replacement.new(options)
55
+ end
56
+
57
+ start { regex.reset!; replacement.reset! }
58
+
59
+ state :whitespace do
60
+ rule /\s+/m, Text
61
+ rule(/#.*?\n/) { token Comment; reset_stack }
62
+ rule(/\n/) { token Text; reset_stack }
63
+ rule(/;/) { token Punctuation; reset_stack }
64
+ end
65
+
66
+ state :root do
67
+ mixin :addr_range
68
+ end
69
+
70
+ edot = /\\.|./m
71
+
72
+ state :command do
73
+ mixin :whitespace
74
+
75
+ # subst and transliteration
76
+ rule /(s)(.)(#{edot}*?)(\2)(#{edot}*?)(\2)/m do |m|
77
+ token Keyword, m[1]
78
+ token Punctuation, m[2]
79
+ delegate regex, m[3]
80
+ token Punctuation, m[4]
81
+ delegate replacement, m[5]
82
+ token Punctuation, m[6]
83
+
84
+
85
+ goto :flags
86
+ end
87
+
88
+ rule /(y)(.)(#{edot}*?)(\2)(#{edot}*?)(\2)/m do |m|
89
+ token Keyword, m[1]
90
+ token Punctuation, m[2]
91
+ delegate replacement, m[3]
92
+ token Punctuation, m[4]
93
+ delegate replacement, m[5]
94
+ token Punctuation, m[6]
95
+
96
+ pop!
97
+ end
98
+
99
+ # commands that take a text segment as an argument
100
+ rule /([aic])(\s*)/ do
101
+ groups Keyword, Text; goto :text
102
+ end
103
+
104
+ rule /[pd]/, Keyword
105
+
106
+ # commands that take a number argument
107
+ rule /([qQl])(\s+)(\d+)/i do
108
+ groups Keyword, Text, Num
109
+ pop!
110
+ end
111
+
112
+ # no-argument commands
113
+ rule /[={}dDgGhHlnpPqx]/, Keyword, :pop!
114
+
115
+ # commands that take a filename argument
116
+ rule /([rRwW])(\s+)(\S+)/ do
117
+ groups Keyword, Text, Name
118
+ pop!
119
+ end
120
+
121
+ # commands that take a label argument
122
+ rule /([:btT])(\s+)(\S+)/ do
123
+ groups Keyword, Text, Name::Label
124
+ pop!
125
+ end
126
+ end
127
+
128
+ state :addr_range do
129
+ mixin :whitespace
130
+
131
+ ### address ranges ###
132
+ addr_tok = Keyword::Namespace
133
+ rule /\d+/, addr_tok
134
+ rule /[$,~+!]/, addr_tok
135
+
136
+ rule %r((/)(\\.|.)*?(/)) do |m|
137
+ token addr_tok, m[1]; delegate regex, m[2]; token addr_tok, m[3]
138
+ end
139
+
140
+ # alternate regex rage delimiters
141
+ rule %r((\\)(.)(\\.|.)*?(\2)) do |m|
142
+ token addr_tok, m[1] + m[2]
143
+ delegate regex, m[3]
144
+ token addr_tok, m[4]
145
+ end
146
+
147
+ rule(//) { push :command }
148
+ end
149
+
150
+ state :text do
151
+ rule /[^\\\n]+/, Str
152
+ rule /\\\n/, Str::Escape
153
+ rule /\\/, Str
154
+ rule /\n/, Text, :pop!
155
+ end
156
+
157
+ state :flags do
158
+ rule /[gp]+/, Keyword, :pop!
159
+
160
+ # writing to a file with the subst command.
161
+ # who'da thunk...?
162
+ rule /([wW])(\s+)(\S+)/ do
163
+ token Keyword; token Text; token Name
164
+ end
165
+
166
+ rule(//) { pop! }
167
+ end
168
+ end
169
+ end
170
+ end
@@ -0,0 +1,152 @@
1
+ # -*- coding: utf-8 -*- #
2
+
3
+ module Rouge
4
+ module Lexers
5
+ class Shell < RegexLexer
6
+ title "shell"
7
+ desc "Various shell languages, including sh and bash"
8
+
9
+ tag 'shell'
10
+ aliases 'bash', 'zsh', 'ksh', 'sh'
11
+ filenames '*.sh', '*.bash', '*.zsh', '*.ksh',
12
+ '.bashrc', '.zshrc', '.kshrc', '.profile', 'PKGBUILD'
13
+
14
+ mimetypes 'application/x-sh', 'application/x-shellscript'
15
+
16
+ def self.analyze_text(text)
17
+ text.shebang?(/(ba|z|k)?sh/) ? 1 : 0
18
+ end
19
+
20
+ KEYWORDS = %w(
21
+ if fi else while do done for then return function
22
+ select continue until esac elif in
23
+ ).join('|')
24
+
25
+ BUILTINS = %w(
26
+ alias bg bind break builtin caller cd command compgen
27
+ complete declare dirs disown echo enable eval exec exit
28
+ export false fc fg getopts hash help history jobs kill let
29
+ local logout popd printf pushd pwd read readonly set shift
30
+ shopt source suspend test time times trap true type typeset
31
+ ulimit umask unalias unset wait
32
+ ).join('|')
33
+
34
+ state :basic do
35
+ rule /#.*$/, Comment
36
+
37
+ rule /\b(#{KEYWORDS})\s*\b/, Keyword
38
+ rule /\bcase\b/, Keyword, :case
39
+
40
+ rule /\b(#{BUILTINS})\s*\b(?!\.)/, Name::Builtin
41
+
42
+ rule /^\S*[\$%>#] +/, Generic::Prompt
43
+
44
+ rule /(\b\w+)(=)/ do |m|
45
+ groups Name::Variable, Operator
46
+ end
47
+
48
+ rule /[\[\]{}()=]/, Operator
49
+ rule /&&|\|\|/, Operator
50
+ # rule /\|\|/, Operator
51
+
52
+ rule /<<</, Operator # here-string
53
+ rule /<<-?\s*(\'?)\\?(\w+)\1/ do |m|
54
+ lsh = Str::Heredoc
55
+ token lsh
56
+ heredocstr = Regexp.escape(m[2])
57
+
58
+ push do
59
+ rule /\s*#{heredocstr}\s*\n/, lsh, :pop!
60
+ rule /.*?\n/, lsh
61
+ end
62
+ end
63
+ end
64
+
65
+ state :double_quotes do
66
+ # NB: "abc$" is literally the string abc$.
67
+ # Here we prevent :interp from interpreting $" as a variable.
68
+ rule /(?:\$#?)?"/, Str::Double, :pop!
69
+ mixin :interp
70
+ rule /[^"`\\$]+/, Str::Double
71
+ end
72
+
73
+ state :single_quotes do
74
+ rule /'/, Str::Single, :pop!
75
+ rule /[^']+/, Str::Single
76
+ end
77
+
78
+ state :data do
79
+ rule /\s+/, Text
80
+ rule /\\./, Str::Escape
81
+ rule /\$?"/, Str::Double, :double_quotes
82
+
83
+ # single quotes are much easier than double quotes - we can
84
+ # literally just scan until the next single quote.
85
+ # POSIX: Enclosing characters in single-quotes ( '' )
86
+ # shall preserve the literal value of each character within the
87
+ # single-quotes. A single-quote cannot occur within single-quotes.
88
+ rule /$?'/, Str::Single, :single_quotes
89
+
90
+ rule /\*/, Keyword
91
+
92
+ rule /;/, Text
93
+ rule /[^=\*\s{}()$"'`\\<]+/, Text
94
+ rule /\d+(?= |\Z)/, Num
95
+ rule /</, Text
96
+ mixin :interp
97
+ end
98
+
99
+ state :curly do
100
+ rule /}/, Keyword, :pop!
101
+ rule /:-/, Keyword
102
+ rule /[a-zA-Z0-9_]+/, Name::Variable
103
+ rule /[^}:"`'$]+/, Punctuation
104
+ mixin :root
105
+ end
106
+
107
+ state :paren do
108
+ rule /\)/, Keyword, :pop!
109
+ mixin :root
110
+ end
111
+
112
+ state :math do
113
+ rule /\)\)/, Keyword, :pop!
114
+ rule %r([-+*/%^|&]|\*\*|\|\|), Operator
115
+ rule /\d+/, Num
116
+ mixin :root
117
+ end
118
+
119
+ state :case do
120
+ rule /\besac\b/, Keyword, :pop!
121
+ rule /\|/, Punctuation
122
+ rule /\)/, Punctuation, :case_stanza
123
+ mixin :root
124
+ end
125
+
126
+ state :case_stanza do
127
+ rule /;;/, Punctuation, :pop!
128
+ mixin :root
129
+ end
130
+
131
+ state :backticks do
132
+ rule /`/, Str::Backtick, :pop!
133
+ mixin :root
134
+ end
135
+
136
+ state :interp do
137
+ rule /\\$/, Str::Escape # line continuation
138
+ rule /\\./, Str::Escape
139
+ rule /\$\(\(/, Keyword, :math
140
+ rule /\$\(/, Keyword, :paren
141
+ rule /\${#?/, Keyword, :curly
142
+ rule /`/, Str::Backtick, :backticks
143
+ rule /\$#?(\w+|.)/, Name::Variable
144
+ end
145
+
146
+ state :root do
147
+ mixin :basic
148
+ mixin :data
149
+ end
150
+ end
151
+ end
152
+ end
@@ -0,0 +1,228 @@
1
+ # -*- coding: utf-8 -*- #
2
+
3
+ module Rouge
4
+ module Lexers
5
+ # A lexer for the Slim tempalte language
6
+ # @see http://slim-lang.org
7
+ class Slim < RegexLexer
8
+ include Indentation
9
+
10
+ title "Slim"
11
+ desc 'The Slim template language'
12
+
13
+ tag 'slim'
14
+
15
+ filenames '*.slim'
16
+
17
+ # Ruby identifier characters
18
+ ruby_chars = /[\w\!\?\@\$]/
19
+
20
+ # Since you are allowed to wrap lines with a backslash, include \\\n in characters
21
+ dot = /(\\\n|.)/
22
+
23
+ def ruby
24
+ @ruby ||= Ruby.new(options)
25
+ end
26
+
27
+ def html
28
+ @html ||= HTML.new(options)
29
+ end
30
+
31
+ def filters
32
+ @filters ||= {
33
+ 'ruby' => ruby,
34
+ 'erb' => ERB.new(options),
35
+ 'javascript' => Javascript.new(options),
36
+ 'css' => CSS.new(options),
37
+ 'coffee' => Coffeescript.new(options),
38
+ 'markdown' => Markdown.new(options),
39
+ 'scss' => Scss.new(options),
40
+ 'sass' => Sass.new(options)
41
+ }
42
+ end
43
+
44
+ start { ruby.reset!; html.reset! }
45
+
46
+ state :root do
47
+ rule /\s*\n/, Text
48
+ rule(/\s*/) { |m| token Text; indentation(m[0]) }
49
+ end
50
+
51
+ state :content do
52
+ mixin :css
53
+
54
+ rule /\/#{dot}*/, Comment, :indented_block
55
+
56
+ rule /(doctype)(\s+)(.*)/ do
57
+ groups Name::Namespace, Text::Whitespace, Text
58
+ pop!
59
+ end
60
+
61
+ # filters, shamelessly ripped from HAML
62
+ rule /(\w*):\s*\n/ do |m|
63
+ token Name::Decorator
64
+ pop!
65
+ starts_block :filter_block
66
+
67
+ filter_name = m[1].strip
68
+
69
+ @filter_lexer = self.filters[filter_name]
70
+ @filter_lexer.reset! unless @filter_lexer.nil?
71
+
72
+ puts " slim: filter #{filter_name.inspect} #{@filter_lexer.inspect}" if @debug
73
+ end
74
+
75
+ # Text
76
+ rule %r([\|'](?=\s)) do
77
+ token Punctuation
78
+ pop!
79
+ starts_block :plain_block
80
+ goto :plain_block
81
+ end
82
+
83
+ rule /-|==|=/, Punctuation, :ruby_line
84
+
85
+ # Dynamic tags
86
+ rule /(\*)(#{ruby_chars}+\(.*?\))/ do |m|
87
+ token Punctuation, m[1]
88
+ delegate ruby, m[2]
89
+ push :tag
90
+ end
91
+
92
+ rule /(\*)(#{ruby_chars}+)/ do |m|
93
+ token Punctuation, m[1]
94
+ delegate ruby, m[2]
95
+ push :tag
96
+ end
97
+
98
+ #rule /<\w+(?=.*>)/, Keyword::Constant, :tag # Maybe do this, look ahead and stuff
99
+ rule %r((</?[\w\s\=\'\"]+?/?>)) do |m| # Dirty html
100
+ delegate html, m[1]
101
+ pop!
102
+ end
103
+
104
+ # Ordinary slim tags
105
+ rule /\w+/, Name::Tag, :tag
106
+
107
+ end
108
+
109
+ state :tag do
110
+ mixin :css
111
+ mixin :indented_block
112
+ mixin :interpolation
113
+
114
+ # Whitespace control
115
+ rule /[<>]/, Punctuation
116
+
117
+ # Trim whitespace
118
+ rule /\s+?/, Text::Whitespace
119
+
120
+ # Splats, these two might be mergable?
121
+ rule /(\*)(#{ruby_chars}+)/ do |m|
122
+ token Punctuation, m[1]
123
+ delegate ruby, m[2]
124
+ end
125
+
126
+ rule /(\*)(\{#{dot}+?\})/ do |m|
127
+ token Punctuation, m[1]
128
+ delegate ruby, m[2]
129
+ end
130
+
131
+ # Attributes
132
+ rule /([\w\-]+)(\s*)(\=)/ do |m|
133
+ token Name::Attribute, m[1]
134
+ token Text::Whitespace, m[2]
135
+ token Punctuation, m[3]
136
+ push :html_attr
137
+ end
138
+
139
+ # Ruby value
140
+ rule /(\=)(#{dot}+)/ do |m|
141
+ token Punctuation, m[1]
142
+ #token Keyword::Constant, m[2]
143
+ delegate ruby, m[2]
144
+ end
145
+
146
+ # HTML Entities
147
+ rule(/&\S*?;/, Name::Entity)
148
+
149
+ rule /#{dot}+?/, Text
150
+
151
+ rule /\s*\n/, Text::Whitespace, :pop!
152
+ end
153
+
154
+ state :css do
155
+ rule(/\.[\w-]*/) { token Name::Class; goto :tag }
156
+ rule(/#[a-zA-Z][\w:-]*/) { token Name::Function; goto :tag }
157
+ end
158
+
159
+ state :html_attr do
160
+ # Strings, double/single quoted
161
+ rule(/\s*(['"])#{dot}*?\1/, Literal::String, :pop!)
162
+
163
+ # Ruby stuff
164
+ rule(/(#{ruby_chars}+\(.*?\))/) { |m| delegate ruby, m[1]; pop! }
165
+ rule(/(#{ruby_chars}+)/) { |m| delegate ruby, m[1]; pop! }
166
+
167
+ rule /\s+/, Text::Whitespace
168
+ end
169
+
170
+ state :ruby_line do
171
+ # Need at top
172
+ mixin :indented_block
173
+
174
+ rule(/,\s*\n/) { delegate ruby }
175
+ rule /[ ]\|[ \t]*\n/, Str::Escape
176
+ rule(/.*?(?=(,$| \|)?[ \t]*$)/) { delegate ruby }
177
+ end
178
+
179
+ state :filter_block do
180
+ rule /([^#\n]|#[^{\n]|(\\\\)*\\#\{)+/ do
181
+ if @filter_lexer
182
+ delegate @filter_lexer
183
+ else
184
+ token Name::Decorator
185
+ end
186
+ end
187
+
188
+ mixin :interpolation
189
+ mixin :indented_block
190
+ end
191
+
192
+ state :plain_block do
193
+ mixin :interpolation
194
+
195
+ rule %r((</?[\w\s\=\'\"]+?/?>)) do |m| # Dirty html
196
+ delegate html, m[1]
197
+ end
198
+
199
+ # HTML Entities
200
+ rule(/&\S*?;/, Name::Entity)
201
+
202
+ #rule /([^#\n]|#[^{\n]|(\\\\)*\\#\{)+/ do
203
+ rule /#{dot}+?/, Text
204
+
205
+ mixin :indented_block
206
+ end
207
+
208
+ state :interpolation do
209
+ rule /#[{]/, Str::Interpol, :ruby_interp
210
+ end
211
+
212
+ state :ruby_interp do
213
+ rule /[}]/, Str::Interpol, :pop!
214
+ mixin :ruby_interp_inner
215
+ end
216
+
217
+ state :ruby_interp_inner do
218
+ rule(/[{]/) { delegate ruby; push :ruby_interp_inner }
219
+ rule(/[}]/) { delegate ruby; pop! }
220
+ rule(/[^{}]+/) { delegate ruby }
221
+ end
222
+
223
+ state :indented_block do
224
+ rule(/(?<!\\)\n/) { token Text; reset_stack }
225
+ end
226
+ end
227
+ end
228
+ end