rouge 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. data/Gemfile +2 -0
  2. data/bin/rougify +1 -1
  3. data/lib/rouge/demos/{text → plaintext} +0 -0
  4. data/lib/rouge/formatters/html.rb +13 -8
  5. data/lib/rouge/formatters/terminal256.rb +15 -11
  6. data/lib/rouge/lexer.rb +3 -1
  7. data/lib/rouge/lexers/c.rb +65 -55
  8. data/lib/rouge/lexers/clojure.rb +19 -19
  9. data/lib/rouge/lexers/coffeescript.rb +42 -42
  10. data/lib/rouge/lexers/common_lisp.rb +49 -48
  11. data/lib/rouge/lexers/conf.rb +6 -6
  12. data/lib/rouge/lexers/cpp.rb +48 -48
  13. data/lib/rouge/lexers/csharp.rb +25 -25
  14. data/lib/rouge/lexers/css.rb +32 -33
  15. data/lib/rouge/lexers/diff.rb +8 -8
  16. data/lib/rouge/lexers/elixir.rb +30 -30
  17. data/lib/rouge/lexers/erb.rb +5 -5
  18. data/lib/rouge/lexers/erlang.rb +38 -38
  19. data/lib/rouge/lexers/factor.rb +56 -56
  20. data/lib/rouge/lexers/gherkin.rb +27 -27
  21. data/lib/rouge/lexers/go.rb +21 -21
  22. data/lib/rouge/lexers/groovy.rb +32 -32
  23. data/lib/rouge/lexers/haml.rb +35 -35
  24. data/lib/rouge/lexers/handlebars.rb +27 -27
  25. data/lib/rouge/lexers/haskell.rb +78 -79
  26. data/lib/rouge/lexers/html.rb +28 -28
  27. data/lib/rouge/lexers/http.rb +13 -13
  28. data/lib/rouge/lexers/ini.rb +13 -13
  29. data/lib/rouge/lexers/io.rb +19 -19
  30. data/lib/rouge/lexers/java.rb +29 -29
  31. data/lib/rouge/lexers/javascript.rb +49 -52
  32. data/lib/rouge/lexers/literate_haskell.rb +5 -5
  33. data/lib/rouge/lexers/llvm.rb +14 -14
  34. data/lib/rouge/lexers/lua.rb +33 -33
  35. data/lib/rouge/lexers/make.rb +26 -26
  36. data/lib/rouge/lexers/markdown.rb +49 -49
  37. data/lib/rouge/lexers/nginx.rb +19 -19
  38. data/lib/rouge/lexers/perl.rb +53 -54
  39. data/lib/rouge/lexers/php.rb +42 -43
  40. data/lib/rouge/lexers/{text.rb → plain_text.rb} +3 -2
  41. data/lib/rouge/lexers/prolog.rb +19 -19
  42. data/lib/rouge/lexers/puppet.rb +40 -40
  43. data/lib/rouge/lexers/python.rb +63 -63
  44. data/lib/rouge/lexers/r.rb +15 -15
  45. data/lib/rouge/lexers/racket.rb +29 -29
  46. data/lib/rouge/lexers/ruby.rb +94 -97
  47. data/lib/rouge/lexers/rust.rb +37 -37
  48. data/lib/rouge/lexers/sass.rb +15 -15
  49. data/lib/rouge/lexers/sass/common.rb +144 -136
  50. data/lib/rouge/lexers/scheme.rb +25 -25
  51. data/lib/rouge/lexers/scss.rb +7 -7
  52. data/lib/rouge/lexers/sed.rb +39 -39
  53. data/lib/rouge/lexers/shell.rb +45 -45
  54. data/lib/rouge/lexers/smalltalk.rb +36 -36
  55. data/lib/rouge/lexers/sql.rb +27 -27
  56. data/lib/rouge/lexers/tcl.rb +34 -34
  57. data/lib/rouge/lexers/tex.rb +24 -24
  58. data/lib/rouge/lexers/toml.rb +18 -18
  59. data/lib/rouge/lexers/viml.rb +19 -19
  60. data/lib/rouge/lexers/xml.rb +16 -16
  61. data/lib/rouge/lexers/yaml.rb +78 -81
  62. data/lib/rouge/plugins/redcarpet.rb +1 -1
  63. data/lib/rouge/regex_lexer.rb +31 -14
  64. data/lib/rouge/template_lexer.rb +1 -1
  65. data/lib/rouge/theme.rb +12 -10
  66. data/lib/rouge/themes/thankful_eyes.rb +43 -43
  67. data/lib/rouge/token.rb +145 -148
  68. data/lib/rouge/version.rb +1 -1
  69. metadata +4 -4
data/Gemfile CHANGED
@@ -17,3 +17,5 @@ gem 'shotgun'
17
17
  # docs
18
18
  gem 'yard'
19
19
  gem 'github-markup'
20
+
21
+ gem 'pry'
data/bin/rougify CHANGED
@@ -9,6 +9,6 @@ load ROOT_DIR.join('lib/rouge/cli.rb')
9
9
  begin
10
10
  Rouge::CLI.start
11
11
  rescue => e
12
- $stderr.puts e.message
12
+ $stderr.puts "rouge: #{e.message}"
13
13
  exit 1
14
14
  end
File without changes
@@ -22,9 +22,9 @@ module Rouge
22
22
  # Content will be wrapped in a `<pre>` tag with the given
23
23
  # `:css_class` unless `:wrap` is set to `false`.
24
24
  def initialize(opts={})
25
- @css_class = opts[:css_class] || 'highlight'
26
- @line_numbers = opts.fetch(:line_numbers) { false }
27
- @inline_theme = opts.fetch(:inline_theme) { nil }
25
+ @css_class = opts.fetch(:css_class, 'highlight')
26
+ @line_numbers = opts.fetch(:line_numbers, false)
27
+ @inline_theme = opts.fetch(:inline_theme, nil)
28
28
  @wrap = opts.fetch(:wrap, true)
29
29
  end
30
30
 
@@ -48,15 +48,20 @@ module Rouge
48
48
 
49
49
  def stream_tableized(tokens, &b)
50
50
  num_lines = 0
51
- code = ''
51
+ last_val = ''
52
+ formatted = ''
52
53
 
53
54
  tokens.each do |tok, val|
55
+ last_val = val
54
56
  num_lines += val.scan(/\n/).size
55
- span(tok, val) { |str| code << str }
57
+ span(tok, val) { |str| formatted << str }
56
58
  end
57
59
 
58
- # add an extra line number for non-newline-terminated strings
59
- num_lines += 1 if code[-1] != "\n"
60
+ # add an extra line for non-newline-terminated strings
61
+ if last_val[-1] != "\n"
62
+ num_lines += 1
63
+ span(Token::Tokens::Text::Whitespace, "\n") { |str| formatted << str }
64
+ end
60
65
 
61
66
  # generate a string of newline-separated line numbers for the gutter
62
67
  numbers = num_lines.times.map do |x|
@@ -72,7 +77,7 @@ module Rouge
72
77
  yield '</td>'
73
78
 
74
79
  yield '<td class="code">'
75
- yield code
80
+ yield formatted
76
81
  yield '</td>'
77
82
 
78
83
  yield '</tr></tbody></table>'
@@ -118,7 +118,7 @@ module Rouge
118
118
  when 3
119
119
  color.chars.map { |c| "#{c}#{c}" }
120
120
  when 6
121
- color.scan /../
121
+ color.scan(/../)
122
122
  else
123
123
  raise "invalid color: #{color}"
124
124
  end
@@ -127,19 +127,23 @@ module Rouge
127
127
  end
128
128
 
129
129
  def self.closest_color(r, g, b)
130
- distance = 257 * 257 * 3 # (max distance, from #000000 to #ffffff)
130
+ @@colors_cache ||= {}
131
+ key = (r << 16) + (g << 8) + b
132
+ @@colors_cache.fetch(key) do
133
+ distance = 257 * 257 * 3 # (max distance, from #000000 to #ffffff)
131
134
 
132
- match = 0
135
+ match = 0
133
136
 
134
- xterm_colors.each_with_index do |(cr, cg, cb), i|
135
- d = (r - cr)**2 + (g - cg)**2 + (b - cb)**2
136
- next if d >= distance
137
+ xterm_colors.each_with_index do |(cr, cg, cb), i|
138
+ d = (r - cr)**2 + (g - cg)**2 + (b - cb)**2
139
+ next if d >= distance
137
140
 
138
- match = i
139
- distance = d
140
- end
141
+ match = i
142
+ distance = d
143
+ end
141
144
 
142
- match
145
+ match
146
+ end
143
147
  end
144
148
  end
145
149
 
@@ -151,7 +155,7 @@ module Rouge
151
155
  end
152
156
 
153
157
  def get_style(token)
154
- return text_style if token.name == 'Text'
158
+ return text_style if token == Token::Tokens::Text
155
159
 
156
160
  theme.get_own_style(token) || text_style
157
161
  end
data/lib/rouge/lexer.rb CHANGED
@@ -6,6 +6,8 @@ module Rouge
6
6
  # @abstract
7
7
  # A lexer transforms text into a stream of `[token, chunk]` pairs.
8
8
  class Lexer
9
+ include Token::Tokens
10
+
9
11
  class << self
10
12
  # Lexes `stream` with the given options. The lex is delegated to a
11
13
  # new instance.
@@ -141,7 +143,7 @@ module Rouge
141
143
  def guess(info={})
142
144
  lexers = guesses(info)
143
145
 
144
- return Lexers::Text if lexers.empty?
146
+ return Lexers::PlainText if lexers.empty?
145
147
  return lexers[0] if lexers.size == 1
146
148
 
147
149
  raise AmbiguousGuess.new(lexers)
@@ -34,53 +34,63 @@ module Rouge
34
34
  )
35
35
  end
36
36
 
37
- state :whitespace do
38
- rule /^#if\s+0\b/, 'Comment.Preproc', :if_0
39
- rule /^#/, 'Comment.Preproc', :macro
40
- rule /^#{ws}#if\s+0\b/, 'Comment.Preproc', :if_0
41
- rule /^#{ws}#/, 'Comment.Preproc', :macro
42
- rule /^(\s*)(#{id}:(?!:))/ do
43
- group 'Text'
44
- group 'Name.Label'
45
- end
37
+ start { push :bol }
38
+
39
+ state :bol do
40
+ mixin :inline_whitespace
41
+
42
+ rule /#if\s0/, Comment::Preproc, :if_0
43
+
44
+ rule /#/, Comment::Preproc, :macro
45
+
46
+ rule /#{id}:(?!:)/, Name::Label
46
47
 
47
- rule /\s+/m, 'Text'
48
- rule /\\\n/, 'Text' # line continuation
49
- rule %r(//(\n|(.|\n)*?[^\\]\n)), 'Comment.Single'
50
- rule %r(/(\\\n)?[*](.|\n)*?[*](\\\n)?/), 'Comment.Multiline'
48
+ rule(//) { pop! }
49
+ end
50
+
51
+ state :inline_whitespace do
52
+ rule /[ \t\r]+/, Text
53
+ rule /\\\n/, Text # line continuation
54
+ rule %r(/(\\\n)?[*].*?[*](\\\n)?/)m, Comment::Multiline
55
+ end
56
+
57
+ state :whitespace do
58
+ rule /\n+/, Text, :bol
59
+ rule %r(//(\\.|.)*?\n), Comment::Single, :bol
60
+ mixin :inline_whitespace
51
61
  end
52
62
 
53
63
  state :statements do
54
- rule /\s+/m, 'Text'
55
-
56
- rule /L?"/, 'Literal.String', :string
57
- rule %r(L?'(\\.|\\[0-7]{1,3}|\\x[a-f0-9]{1,2}|[^\\'\n])')i, 'Literal.String.Char'
58
- rule %r((\d+\.\d*|\.\d+|\d+)[e][+-]?\d+[lu]*)i, 'Literal.Number.Float'
59
- rule /0x[0-9a-f]+[lu]*/i, 'Literal.Number.Hex'
60
- rule /0[0-7]+[lu]*/i, 'Literal.Number.Oct'
61
- rule /\d+[lu]*/i, 'Literal.Number.Integer'
62
- rule %r(\*/), 'Error'
63
- rule %r([~!%^&*+=\|?:<>/-]), 'Operator'
64
- rule /[()\[\],.]/, 'Punctuation'
65
- rule /\bcase\b/, 'Keyword', :case
66
- rule /(?:true|false|NULL)\b/, 'Name.Builtin'
64
+ rule /\s+/m, Text
65
+
66
+ rule /L?"/, Str, :string
67
+ rule %r(L?'(\\.|\\[0-7]{1,3}|\\x[a-f0-9]{1,2}|[^\\'\n])')i, Str::Char
68
+ rule %r((\d+\.\d*|\.\d+|\d+)[e][+-]?\d+[lu]*)i, Num::Float
69
+ rule /0x[0-9a-f]+[lu]*/i, Num::Hex
70
+ rule /0[0-7]+[lu]*/i, Num::Oct
71
+ rule /\d+[lu]*/i, Num::Integer
72
+ rule %r(\*/), Error
73
+ rule %r([~!%^&*+=\|?:<>/-]), Operator
74
+ rule /[()\[\],.]/, Punctuation
75
+ rule /\bcase\b/, Keyword, :case
76
+ rule /(?:true|false|NULL)\b/, Name::Builtin
67
77
  rule id do |m|
68
78
  name = m[0]
69
79
 
70
80
  if self.class.keywords.include? name
71
- token 'Keyword'
81
+ token Keyword
72
82
  elsif self.class.keywords_type.include? name
73
- token 'Keyword.Type'
83
+ token Keyword::Type
74
84
  elsif self.class.reserved.include? name
75
- token 'Keyword.Reserved'
85
+ token Keyword::Reserved
76
86
  else
77
- token 'Name'
87
+ token Name
78
88
  end
79
89
  end
80
90
  end
81
91
 
82
92
  state :case do
83
- rule /:/, 'Punctuation', :pop!
93
+ rule /:/, Punctuation, :pop!
84
94
  mixin :statements
85
95
  end
86
96
 
@@ -96,10 +106,10 @@ module Rouge
96
106
  )mx do |m|
97
107
  # TODO: do this better.
98
108
  delegate C, m[1]
99
- token 'Name.Function', m[2]
109
+ token Name::Function, m[2]
100
110
  delegate C, m[3]
101
111
  delegate C, m[4]
102
- token 'Punctuation', m[5]
112
+ token Punctuation, m[5]
103
113
  push :function
104
114
  end
105
115
 
@@ -112,10 +122,10 @@ module Rouge
112
122
  )mx do |m|
113
123
  # TODO: do this better.
114
124
  delegate C, m[1]
115
- token 'Name.Function'
125
+ token Name::Function
116
126
  delegate C, m[3]
117
127
  delegate C, m[4]
118
- token 'Punctuation'
128
+ token Punctuation
119
129
  push :statement
120
130
  end
121
131
 
@@ -123,42 +133,42 @@ module Rouge
123
133
  end
124
134
 
125
135
  state :statement do
126
- rule /;/, 'Punctuation', :pop!
136
+ rule /;/, Punctuation, :pop!
127
137
  mixin :whitespace
128
138
  mixin :statements
129
- rule /[{}]/, 'Punctuation'
139
+ rule /[{}]/, Punctuation
130
140
  end
131
141
 
132
142
  state :function do
133
143
  mixin :whitespace
134
144
  mixin :statements
135
- rule /;/, 'Punctuation'
136
- rule /{/, 'Punctuation', :function
137
- rule /}/, 'Punctuation', :pop!
145
+ rule /;/, Punctuation
146
+ rule /{/, Punctuation, :function
147
+ rule /}/, Punctuation, :pop!
138
148
  end
139
149
 
140
150
  state :string do
141
- rule /"/, 'Literal.String', :pop!
142
- rule /\\([\\abfnrtv"']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})/, 'Literal.String.Escape'
143
- rule /[^\\"\n]+/, 'Literal.String'
144
- rule /\\\n/, 'Literal.String'
145
- rule /\\/, 'Literal.String' # stray backslash
151
+ rule /"/, Str, :pop!
152
+ rule /\\([\\abfnrtv"']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})/, Str::Escape
153
+ rule /[^\\"\n]+/, Str
154
+ rule /\\\n/, Str
155
+ rule /\\/, Str # stray backslash
146
156
  end
147
157
 
148
158
  state :macro do
149
- rule %r([^/\n]+), 'Comment.Preproc'
150
- rule %r(/[*].*?[*]/)m, 'Comment.Multiliine'
151
- rule %r(//.*$), 'Comment.Single'
152
- rule %r(/), 'Comment.Preproc'
153
- rule /(?<=\\)\n/, 'Comment.Preproc'
154
- rule /\n/, 'Comment.Preproc', :pop!
159
+ rule %r([^/\n]+), Comment::Preproc
160
+ rule %r(/[*].*?[*]/)m, Comment::Multiline
161
+ rule %r(//.*$), Comment::Single
162
+ rule %r(/), Comment::Preproc
163
+ rule /(?<=\\)\n/, Comment::Preproc
164
+ rule /\n/, Comment::Preproc, :pop!
155
165
  end
156
166
 
157
167
  state :if_0 do
158
- rule /^\s*#if.*?(?<!\\)\n/, 'Comment.Preproc', :if_0
159
- rule /^\s*#el(?:se|if).*\n/, 'Comment.Preproc', :pop!
160
- rule /^\s*#endif.*?(?<!\\)\n/, 'Comment.Preproc', :pop!
161
- rule /.*?\n/, 'Comment'
168
+ rule /^\s*#if.*?(?<!\\)\n/, Comment, :if_0
169
+ rule /^\s*#el(?:se|if).*\n/, Comment::Preproc, :pop!
170
+ rule /^\s*#endif.*?(?<!\\)\n/, Comment, :pop!
171
+ rule /.*?\n/, Comment
162
172
  end
163
173
  end
164
174
  end
@@ -64,45 +64,45 @@ module Rouge
64
64
  keyword = %r([\w!\#$%*+,<=>?/.-]+)
65
65
 
66
66
  def name_token(name)
67
- return 'Keyword' if self.class.keywords.include?(name)
68
- return 'Name.Builtin' if self.class.builtins.include?(name)
67
+ return Keyword if self.class.keywords.include?(name)
68
+ return Name::Builtin if self.class.builtins.include?(name)
69
69
  nil
70
70
  end
71
71
 
72
72
  state :root do
73
- rule /;.*?\n/, 'Comment.Single'
74
- rule /\s+/m, 'Text.Whitespace'
73
+ rule /;.*?\n/, Comment::Single
74
+ rule /\s+/m, Text::Whitespace
75
75
 
76
- rule /-?\d+\.\d+/, 'Literal.Number.Float'
77
- rule /-?\d+/, 'Literal.Number.Integer'
78
- rule /0x-?[0-9a-fA-F]+/, 'Literal.Number.Hex'
76
+ rule /-?\d+\.\d+/, Num::Float
77
+ rule /-?\d+/, Num::Integer
78
+ rule /0x-?[0-9a-fA-F]+/, Num::Hex
79
79
 
80
- rule /"(\\.|[^"])*"/, 'Literal.String'
81
- rule /'#{keyword}/, 'Literal.String.Symbol'
82
- rule /:#{keyword}/, 'Name.Constant'
83
- rule /\\(.|[a-z]+)/i, 'Literal.String.Char'
80
+ rule /"(\\.|[^"])*"/, Str
81
+ rule /'#{keyword}/, Str::Symbol
82
+ rule /:#{keyword}/, Name::Constant
83
+ rule /\\(.|[a-z]+)/i, Str::Char
84
84
 
85
85
 
86
- rule /~@|[`\'#^~&]/, 'Operator'
86
+ rule /~@|[`\'#^~&]/, Operator
87
87
 
88
88
  rule /(\()(\s*)(#{identifier})/m do |m|
89
- token 'Punctuation', m[1]
90
- token 'Text.Whitespace', m[2]
91
- token(name_token(m[3]) || 'Name.Function', m[3])
89
+ token Punctuation, m[1]
90
+ token Text::Whitespace, m[2]
91
+ token(name_token(m[3]) || Name::Function, m[3])
92
92
  end
93
93
 
94
94
  rule identifier do |m|
95
- token name_token(m[0]) || 'Name'
95
+ token name_token(m[0]) || Name
96
96
  end
97
97
 
98
98
  # vectors
99
- rule /[\[\]]/, 'Punctuation'
99
+ rule /[\[\]]/, Punctuation
100
100
 
101
101
  # maps
102
- rule /[{}]/, 'Punctuation'
102
+ rule /[{}]/, Punctuation
103
103
 
104
104
  # parentheses
105
- rule /[()]/, 'Punctuation'
105
+ rule /[()]/, Punctuation
106
106
  end
107
107
  end
108
108
  end
@@ -38,9 +38,9 @@ module Rouge
38
38
  id = /[$a-zA-Z_][a-zA-Z0-9_]*/
39
39
 
40
40
  state :comments_and_whitespace do
41
- rule /\s+/m, 'Text'
42
- rule /###.*?###/m, 'Comment.Multiline'
43
- rule /#.*?\n/, 'Comment.Single'
41
+ rule /\s+/m, Text
42
+ rule /###.*?###/m, Comment::Multiline
43
+ rule /#.*?\n/, Comment::Single
44
44
  end
45
45
 
46
46
  state :multiline_regex do
@@ -49,22 +49,22 @@ module Rouge
49
49
  mixin :has_interpolation
50
50
  mixin :comments_and_whitespace
51
51
 
52
- rule %r(///([gim]+\b|\B)), 'Literal.String.Regex', :pop!
53
- rule %r(/), 'Literal.String.Regex'
54
- rule %r([^/#]+), 'Literal.String.Regex'
52
+ rule %r(///([gim]+\b|\B)), Str::Regex, :pop!
53
+ rule %r(/), Str::Regex
54
+ rule %r([^/#]+), Str::Regex
55
55
  end
56
56
 
57
57
  state :slash_starts_regex do
58
58
  mixin :comments_and_whitespace
59
59
  rule %r(///) do
60
- token 'Literal.String.Regex'
61
- pop!; push :multiline_regex
60
+ token Str::Regex
61
+ goto :multiline_regex
62
62
  end
63
63
 
64
64
  rule %r(
65
65
  /(\\.|[^\[/\\\n]|\[(\\.|[^\]\\\n])*\])+/ # a regex
66
66
  ([gim]+\b|\B)
67
- )x, 'Literal.String.Regex', :pop!
67
+ )x, Str::Regex, :pop!
68
68
 
69
69
  rule(//) { pop! }
70
70
  end
@@ -75,97 +75,97 @@ module Rouge
75
75
  rule %r(
76
76
  [+][+]|--|~|&&|\band\b|\bor\b|\bis\b|\bisnt\b|\bnot\b|[?]|:|=|
77
77
  [|][|]|\\(?=\n)|(<<|>>>?|==?|!=?|[-<>+*`%&|^/])=?
78
- )x, 'Operator', :slash_starts_regex
78
+ )x, Operator, :slash_starts_regex
79
79
 
80
- rule /[-=]>/, 'Name.Function'
80
+ rule /[-=]>/, Name::Function
81
81
 
82
82
  rule /(@)([ \t]*)(#{id})/ do
83
- group 'Name.Variable.Instance'; group 'Text'
84
- group 'Name.Attribute'
83
+ group Name::Variable::Instance; group Text
84
+ group Name::Attribute
85
85
  push :slash_starts_regex
86
86
  end
87
87
 
88
88
  rule /([.])([ \t]*)(#{id})/ do
89
- group 'Punctuation'; group 'Text'
90
- group 'Name.Attribute'
89
+ group Punctuation; group Text
90
+ group Name::Attribute
91
91
  push :slash_starts_regex
92
92
  end
93
93
 
94
- rule /#{id}(?=\s*:)/, 'Name.Attribute', :slash_starts_regex
94
+ rule /#{id}(?=\s*:)/, Name::Attribute, :slash_starts_regex
95
95
 
96
96
  rule /#{id}/ do |m|
97
97
  if self.class.keywords.include? m[0]
98
- token 'Keyword'
98
+ token Keyword
99
99
  elsif self.class.constants.include? m[0]
100
- token 'Name.Constant'
100
+ token Name::Constant
101
101
  elsif self.class.builtins.include? m[0]
102
- token 'Name.Builtin'
102
+ token Name::Builtin
103
103
  else
104
- token 'Name.Other'
104
+ token Name::Other
105
105
  end
106
106
 
107
107
  push :slash_starts_regex
108
108
  end
109
109
 
110
- rule /[{(\[;,]/, 'Punctuation', :slash_starts_regex
111
- rule /[})\].]/, 'Punctuation'
110
+ rule /[{(\[;,]/, Punctuation, :slash_starts_regex
111
+ rule /[})\].]/, Punctuation
112
112
 
113
- rule /\d+[.]\d+([eE]\d+)?[fd]?/, 'Literal.Number.Float'
114
- rule /0x[0-9a-fA-F]+/, 'Literal.Number.Hex'
115
- rule /\d+/, 'Literal.Number.Integer'
116
- rule /"""/, 'Literal.String', :tdqs
117
- rule /'''/, 'Literal.String', :tsqs
118
- rule /"/, 'Literal.String', :dqs
119
- rule /'/, 'Literal.String', :sqs
113
+ rule /\d+[.]\d+([eE]\d+)?[fd]?/, Num::Float
114
+ rule /0x[0-9a-fA-F]+/, Num::Hex
115
+ rule /\d+/, Num::Integer
116
+ rule /"""/, Str, :tdqs
117
+ rule /'''/, Str, :tsqs
118
+ rule /"/, Str, :dqs
119
+ rule /'/, Str, :sqs
120
120
  end
121
121
 
122
122
  state :strings do
123
123
  # all coffeescript strings are multi-line
124
- rule /[^#\\'"]+/m, 'Literal.String'
124
+ rule /[^#\\'"]+/m, Str
125
125
 
126
- rule /\\./, 'Literal.String.Escape'
127
- rule /#/, 'Literal.String'
126
+ rule /\\./, Str::Escape
127
+ rule /#/, Str
128
128
  end
129
129
 
130
130
  state :double_strings do
131
- rule /'/, 'Literal.String'
131
+ rule /'/, Str
132
132
  mixin :has_interpolation
133
133
  mixin :strings
134
134
  end
135
135
 
136
136
  state :single_strings do
137
- rule /"/, 'Literal.String'
137
+ rule /"/, Str
138
138
  mixin :strings
139
139
  end
140
140
 
141
141
  state :interpolation do
142
- rule /}/, 'Literal.String.Interpol', :pop!
142
+ rule /}/, Str::Interpol, :pop!
143
143
  mixin :root
144
144
  end
145
145
 
146
146
  state :has_interpolation do
147
- rule /[#][{]/, 'Literal.String.Interpol', :interpolation
147
+ rule /[#][{]/, Str::Interpol, :interpolation
148
148
  end
149
149
 
150
150
  state :dqs do
151
- rule /"/, 'Literal.String', :pop!
151
+ rule /"/, Str, :pop!
152
152
  mixin :double_strings
153
153
  end
154
154
 
155
155
  state :tdqs do
156
- rule /"""/, 'Literal.String', :pop!
157
- rule /"/, 'Literal.String'
156
+ rule /"""/, Str, :pop!
157
+ rule /"/, Str
158
158
  mixin :double_strings
159
159
  end
160
160
 
161
161
  state :sqs do
162
- rule /'/, 'Literal.String', :pop!
162
+ rule /'/, Str, :pop!
163
163
  mixin :single_strings
164
164
  end
165
165
 
166
166
  state :tsqs do
167
- rule /'''/, 'Literal.String', :pop!
168
- rule /'/, 'Literal.String'
167
+ rule /'''/, Str, :pop!
168
+ rule /'/, Str
169
169
  mixin :single_strings
170
170
  end
171
171
  end