coderay 1.0.0.800pre → 1.0.0.815pre
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.
- data/{README.rdoc → README_INDEX.rdoc} +2 -0
- data/Rakefile +3 -3
- data/bin/coderay +31 -9
- data/lib/coderay.rb +2 -1
- data/lib/coderay/encoder.rb +11 -1
- data/lib/coderay/encoders/_map.rb +0 -1
- data/lib/coderay/encoders/count.rb +9 -3
- data/lib/coderay/encoders/debug.rb +1 -1
- data/lib/coderay/encoders/filter.rb +12 -6
- data/lib/coderay/encoders/html.rb +11 -1
- data/lib/coderay/encoders/html/css.rb +1 -1
- data/lib/coderay/encoders/html/output.rb +0 -1
- data/lib/coderay/encoders/json.rb +20 -7
- data/lib/coderay/encoders/lines_of_code.rb +2 -1
- data/lib/coderay/encoders/statistic.rb +5 -6
- data/lib/coderay/encoders/text.rb +8 -5
- data/lib/coderay/encoders/token_kind_filter.rb +1 -0
- data/lib/coderay/encoders/xml.rb +5 -3
- data/lib/coderay/encoders/yaml.rb +13 -8
- data/lib/coderay/helpers/file_type.rb +4 -4
- data/lib/coderay/helpers/plugin.rb +7 -5
- data/lib/coderay/scanner.rb +30 -18
- data/lib/coderay/scanners/_map.rb +14 -13
- data/lib/coderay/scanners/clojure.rb +1 -1
- data/lib/coderay/scanners/css.rb +36 -27
- data/lib/coderay/scanners/{rhtml.rb → erb.rb} +3 -3
- data/lib/coderay/scanners/groovy.rb +1 -1
- data/lib/coderay/scanners/java_script.rb +1 -1
- data/lib/coderay/scanners/php.rb +2 -2
- data/lib/coderay/scanners/ruby.rb +11 -6
- data/lib/coderay/tokens.rb +1 -3
- data/test/functional/basic.rb +26 -19
- data/test/functional/examples.rb +2 -0
- data/test/functional/for_redcloth.rb +12 -6
- data/test/functional/suite.rb +2 -1
- metadata +26 -9
- data/lib/coderay/scanners/nitro_xhtml.rb +0 -136
- data/lib/coderay/scanners/scheme.rb +0 -136
data/lib/coderay/tokens.rb
CHANGED
@@ -73,9 +73,7 @@ module CodeRay
|
|
73
73
|
encoder.encode_tokens self, options
|
74
74
|
end
|
75
75
|
|
76
|
-
# Turn into a string
|
77
|
-
#
|
78
|
-
# +options+ are passed to the encoder if given.
|
76
|
+
# Turn tokens into a string by concatenating them.
|
79
77
|
def to_s
|
80
78
|
encode CodeRay::Encoders::Encoder.new
|
81
79
|
end
|
data/test/functional/basic.rb
CHANGED
@@ -1,21 +1,12 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'test/unit'
|
3
|
+
require File.expand_path('../../lib/assert_warning', __FILE__)
|
4
|
+
|
5
|
+
$:.unshift File.expand_path('../../../lib', __FILE__)
|
3
6
|
require 'coderay'
|
4
7
|
|
5
8
|
class BasicTest < Test::Unit::TestCase
|
6
9
|
|
7
|
-
def assert_warning expected_warning
|
8
|
-
require 'stringio'
|
9
|
-
oldstderr = $stderr
|
10
|
-
$stderr = StringIO.new
|
11
|
-
yield
|
12
|
-
$stderr.rewind
|
13
|
-
given_warning = $stderr.read.chomp
|
14
|
-
assert_equal expected_warning, given_warning
|
15
|
-
ensure
|
16
|
-
$stderr = oldstderr
|
17
|
-
end
|
18
|
-
|
19
10
|
def test_version
|
20
11
|
assert_nothing_raised do
|
21
12
|
assert_match(/\A\d\.\d\.\d?\z/, CodeRay::VERSION)
|
@@ -135,13 +126,9 @@ more code # and another comment, in-line.
|
|
135
126
|
assert_equal 0, CodeRay.scan(rHTML, :html).lines_of_code
|
136
127
|
assert_equal 0, CodeRay.scan(rHTML, :php).lines_of_code
|
137
128
|
assert_equal 0, CodeRay.scan(rHTML, :yaml).lines_of_code
|
138
|
-
assert_equal 4, CodeRay.scan(rHTML, :
|
129
|
+
assert_equal 4, CodeRay.scan(rHTML, :erb).lines_of_code
|
139
130
|
end
|
140
131
|
|
141
|
-
def test_rubygems_not_loaded
|
142
|
-
assert_equal nil, defined? Gem
|
143
|
-
end if ENV['check_rubygems'] && RUBY_VERSION < '1.9'
|
144
|
-
|
145
132
|
def test_list_of_encoders
|
146
133
|
assert_kind_of(Array, CodeRay::Encoders.list)
|
147
134
|
assert CodeRay::Encoders.list.include?(:count)
|
@@ -243,8 +230,28 @@ more code # and another comment, in-line.
|
|
243
230
|
scanner = CodeRay::Scanners::Plain.new "foo\nbär+quux"
|
244
231
|
assert_equal 0, scanner.pos
|
245
232
|
assert_equal 1, scanner.line
|
246
|
-
assert_equal
|
247
|
-
scanner.scan(/foo
|
233
|
+
assert_equal 1, scanner.column
|
234
|
+
scanner.scan(/foo/)
|
235
|
+
assert_equal 3, scanner.pos
|
236
|
+
assert_equal 1, scanner.line
|
237
|
+
assert_equal 4, scanner.column
|
238
|
+
scanner.scan(/\n/)
|
239
|
+
assert_equal 4, scanner.pos
|
240
|
+
assert_equal 2, scanner.line
|
241
|
+
assert_equal 1, scanner.column
|
242
|
+
scanner.scan(/b/)
|
243
|
+
assert_equal 5, scanner.pos
|
244
|
+
assert_equal 2, scanner.line
|
245
|
+
assert_equal 2, scanner.column
|
246
|
+
scanner.scan(/a/)
|
247
|
+
assert_equal 5, scanner.pos
|
248
|
+
assert_equal 2, scanner.line
|
249
|
+
assert_equal 2, scanner.column
|
250
|
+
scanner.scan(/ä/)
|
251
|
+
assert_equal 7, scanner.pos
|
252
|
+
assert_equal 2, scanner.line
|
253
|
+
assert_equal 4, scanner.column
|
254
|
+
scanner.scan(/r/)
|
248
255
|
assert_equal 8, scanner.pos
|
249
256
|
assert_equal 2, scanner.line
|
250
257
|
assert_equal 5, scanner.column
|
data/test/functional/examples.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'test/unit'
|
2
|
-
|
2
|
+
require File.expand_path('../../lib/assert_warning', __FILE__)
|
3
|
+
|
4
|
+
$:.unshift File.expand_path('../../../lib', __FILE__)
|
3
5
|
require 'coderay'
|
4
6
|
|
5
7
|
begin
|
@@ -64,15 +66,19 @@ class BasicTest < Test::Unit::TestCase
|
|
64
66
|
# See http://jgarber.lighthouseapp.com/projects/13054/tickets/124-code-markup-does-not-allow-brackets.
|
65
67
|
def test_for_redcloth_false_positive
|
66
68
|
require 'coderay/for_redcloth'
|
67
|
-
|
68
|
-
|
69
|
+
assert_warning 'CodeRay::Scanners could not load plugin :project; falling back to :text' do
|
70
|
+
assert_equal '<p><code>[project]_dff.skjd</code></p>',
|
71
|
+
RedCloth.new('@[project]_dff.skjd@').to_html
|
72
|
+
end
|
69
73
|
# false positive, but expected behavior / known issue
|
70
74
|
assert_equal "<p><span lang=\"ruby\" class=\"CodeRay\">_dff.skjd</span></p>",
|
71
75
|
RedCloth.new('@[ruby]_dff.skjd@').to_html
|
72
|
-
|
76
|
+
assert_warning 'CodeRay::Scanners could not load plugin :project; falling back to :text' do
|
77
|
+
assert_equal <<-BLOCKCODE.chomp,
|
73
78
|
<pre><code>[project]_dff.skjd</code></pre>
|
74
|
-
|
75
|
-
|
79
|
+
BLOCKCODE
|
80
|
+
RedCloth.new('bc. [project]_dff.skjd').to_html
|
81
|
+
end
|
76
82
|
end
|
77
83
|
|
78
84
|
end if defined? RedCloth
|
data/test/functional/suite.rb
CHANGED
metadata
CHANGED
@@ -1,8 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coderay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 961912872
|
4
5
|
prerelease: 9
|
5
|
-
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
- 815
|
11
|
+
- pre
|
12
|
+
version: 1.0.0.815pre
|
6
13
|
platform: ruby
|
7
14
|
authors:
|
8
15
|
- Kornelius Kalnbach
|
@@ -10,7 +17,8 @@ autorequire:
|
|
10
17
|
bindir: bin
|
11
18
|
cert_chain: []
|
12
19
|
|
13
|
-
date: 2011-
|
20
|
+
date: 2011-08-19 00:00:00 +02:00
|
21
|
+
default_executable:
|
14
22
|
dependencies: []
|
15
23
|
|
16
24
|
description: Fast and easy syntax highlighting for selected languages, written in Ruby. Comes with RedCloth integration and LOC counter.
|
@@ -21,7 +29,7 @@ executables:
|
|
21
29
|
extensions: []
|
22
30
|
|
23
31
|
extra_rdoc_files:
|
24
|
-
-
|
32
|
+
- README_INDEX.rdoc
|
25
33
|
files:
|
26
34
|
- lib/coderay/duo.rb
|
27
35
|
- lib/coderay/encoder.rb
|
@@ -60,21 +68,19 @@ files:
|
|
60
68
|
- lib/coderay/scanners/debug.rb
|
61
69
|
- lib/coderay/scanners/delphi.rb
|
62
70
|
- lib/coderay/scanners/diff.rb
|
71
|
+
- lib/coderay/scanners/erb.rb
|
63
72
|
- lib/coderay/scanners/groovy.rb
|
64
73
|
- lib/coderay/scanners/html.rb
|
65
74
|
- lib/coderay/scanners/java/builtin_types.rb
|
66
75
|
- lib/coderay/scanners/java.rb
|
67
76
|
- lib/coderay/scanners/java_script.rb
|
68
77
|
- lib/coderay/scanners/json.rb
|
69
|
-
- lib/coderay/scanners/nitro_xhtml.rb
|
70
78
|
- lib/coderay/scanners/php.rb
|
71
79
|
- lib/coderay/scanners/python.rb
|
72
80
|
- lib/coderay/scanners/raydebug.rb
|
73
|
-
- lib/coderay/scanners/rhtml.rb
|
74
81
|
- lib/coderay/scanners/ruby/patterns.rb
|
75
82
|
- lib/coderay/scanners/ruby/string_state.rb
|
76
83
|
- lib/coderay/scanners/ruby.rb
|
77
|
-
- lib/coderay/scanners/scheme.rb
|
78
84
|
- lib/coderay/scanners/sql.rb
|
79
85
|
- lib/coderay/scanners/text.rb
|
80
86
|
- lib/coderay/scanners/xml.rb
|
@@ -89,20 +95,21 @@ files:
|
|
89
95
|
- lib/coderay/version.rb
|
90
96
|
- lib/coderay.rb
|
91
97
|
- Rakefile
|
92
|
-
-
|
98
|
+
- README_INDEX.rdoc
|
93
99
|
- LICENSE
|
94
100
|
- test/functional/basic.rb
|
95
101
|
- test/functional/examples.rb
|
96
102
|
- test/functional/for_redcloth.rb
|
97
103
|
- test/functional/suite.rb
|
98
104
|
- bin/coderay
|
105
|
+
has_rdoc: true
|
99
106
|
homepage: http://coderay.rubychan.de
|
100
107
|
licenses: []
|
101
108
|
|
102
109
|
post_install_message:
|
103
110
|
rdoc_options:
|
104
111
|
- -SNw2
|
105
|
-
- -
|
112
|
+
- -mREADME_INDEX.rdoc
|
106
113
|
- -t CodeRay Documentation
|
107
114
|
require_paths:
|
108
115
|
- lib
|
@@ -111,17 +118,27 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
111
118
|
requirements:
|
112
119
|
- - ">="
|
113
120
|
- !ruby/object:Gem::Version
|
121
|
+
hash: 57
|
122
|
+
segments:
|
123
|
+
- 1
|
124
|
+
- 8
|
125
|
+
- 7
|
114
126
|
version: 1.8.7
|
115
127
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
128
|
none: false
|
117
129
|
requirements:
|
118
130
|
- - ">"
|
119
131
|
- !ruby/object:Gem::Version
|
132
|
+
hash: 25
|
133
|
+
segments:
|
134
|
+
- 1
|
135
|
+
- 3
|
136
|
+
- 1
|
120
137
|
version: 1.3.1
|
121
138
|
requirements: []
|
122
139
|
|
123
140
|
rubyforge_project: coderay
|
124
|
-
rubygems_version: 1.
|
141
|
+
rubygems_version: 1.6.2
|
125
142
|
signing_key:
|
126
143
|
specification_version: 3
|
127
144
|
summary: Fast syntax highlighting for selected languages.
|
@@ -1,136 +0,0 @@
|
|
1
|
-
module CodeRay
|
2
|
-
module Scanners
|
3
|
-
|
4
|
-
load :html
|
5
|
-
load :ruby
|
6
|
-
|
7
|
-
# Nitro XHTML Scanner
|
8
|
-
#
|
9
|
-
# Alias: +nitro+
|
10
|
-
class NitroXHTML < Scanner
|
11
|
-
|
12
|
-
register_for :nitro_xhtml
|
13
|
-
file_extension :xhtml
|
14
|
-
title 'Nitro XHTML'
|
15
|
-
|
16
|
-
KINDS_NOT_LOC = HTML::KINDS_NOT_LOC
|
17
|
-
|
18
|
-
NITRO_RUBY_BLOCK = /
|
19
|
-
<\?r
|
20
|
-
(?>
|
21
|
-
[^\?]*
|
22
|
-
(?> \?(?!>) [^\?]* )*
|
23
|
-
)
|
24
|
-
(?: \?> )?
|
25
|
-
|
|
26
|
-
<ruby>
|
27
|
-
(?>
|
28
|
-
[^<]*
|
29
|
-
(?> <(?!\/ruby>) [^<]* )*
|
30
|
-
)
|
31
|
-
(?: <\/ruby> )?
|
32
|
-
|
|
33
|
-
<%
|
34
|
-
(?>
|
35
|
-
[^%]*
|
36
|
-
(?> %(?!>) [^%]* )*
|
37
|
-
)
|
38
|
-
(?: %> )?
|
39
|
-
/mx # :nodoc:
|
40
|
-
|
41
|
-
NITRO_VALUE_BLOCK = /
|
42
|
-
\#
|
43
|
-
(?:
|
44
|
-
\{
|
45
|
-
[^{}]*
|
46
|
-
(?>
|
47
|
-
\{ [^}]* \}
|
48
|
-
(?> [^{}]* )
|
49
|
-
)*
|
50
|
-
\}?
|
51
|
-
| \| [^|]* \|?
|
52
|
-
| \( [^)]* \)?
|
53
|
-
| \[ [^\]]* \]?
|
54
|
-
| \\ [^\\]* \\?
|
55
|
-
)
|
56
|
-
/x # :nodoc:
|
57
|
-
|
58
|
-
NITRO_ENTITY = /
|
59
|
-
% (?: \#\d+ | \w+ ) ;
|
60
|
-
/ # :nodoc:
|
61
|
-
|
62
|
-
START_OF_RUBY = /
|
63
|
-
(?=[<\#%])
|
64
|
-
< (?: \?r | % | ruby> )
|
65
|
-
| \# [{(|]
|
66
|
-
| % (?: \#\d+ | \w+ ) ;
|
67
|
-
/x # :nodoc:
|
68
|
-
|
69
|
-
CLOSING_PAREN = Hash.new { |h, p| h[p] = p } # :nodoc:
|
70
|
-
CLOSING_PAREN.update( {
|
71
|
-
'(' => ')',
|
72
|
-
'[' => ']',
|
73
|
-
'{' => '}',
|
74
|
-
} )
|
75
|
-
|
76
|
-
protected
|
77
|
-
|
78
|
-
def setup
|
79
|
-
@ruby_scanner = CodeRay.scanner :ruby, :tokens => @tokens, :keep_tokens => true
|
80
|
-
@html_scanner = CodeRay.scanner :html, :tokens => @tokens, :keep_tokens => true, :keep_state => true
|
81
|
-
end
|
82
|
-
|
83
|
-
def reset_instance
|
84
|
-
super
|
85
|
-
@html_scanner.reset
|
86
|
-
end
|
87
|
-
|
88
|
-
def scan_tokens encoder, options
|
89
|
-
|
90
|
-
until eos?
|
91
|
-
|
92
|
-
if (match = scan_until(/(?=#{START_OF_RUBY})/o) || scan_rest) and not match.empty?
|
93
|
-
@html_scanner.tokenize match
|
94
|
-
|
95
|
-
elsif match = scan(/#{NITRO_VALUE_BLOCK}/o)
|
96
|
-
start_tag = match[0,2]
|
97
|
-
delimiter = CLOSING_PAREN[start_tag[1,1]]
|
98
|
-
end_tag = match[-1,1] == delimiter ? delimiter : ''
|
99
|
-
encoder.begin_group :inline
|
100
|
-
encoder.text_token start_tag, :inline_delimiter
|
101
|
-
code = match[start_tag.size .. -1 - end_tag.size]
|
102
|
-
@ruby_scanner.tokenize code, :tokens => encoder
|
103
|
-
encoder.text_token end_tag, :inline_delimiter unless end_tag.empty?
|
104
|
-
encoder.end_group :inline
|
105
|
-
|
106
|
-
elsif match = scan(/#{NITRO_RUBY_BLOCK}/o)
|
107
|
-
start_tag = '<?r'
|
108
|
-
end_tag = match[-2,2] == '?>' ? '?>' : ''
|
109
|
-
encoder.begin_group :inline
|
110
|
-
encoder.text_token start_tag, :inline_delimiter
|
111
|
-
code = match[start_tag.size .. -(end_tag.size)-1]
|
112
|
-
@ruby_scanner.tokenize code, :tokens => encoder
|
113
|
-
encoder.text_token end_tag, :inline_delimiter unless end_tag.empty?
|
114
|
-
encoder.end_group :inline
|
115
|
-
|
116
|
-
elsif entity = scan(/#{NITRO_ENTITY}/o)
|
117
|
-
encoder.text_token entity, :entity
|
118
|
-
|
119
|
-
elsif scan(/%/)
|
120
|
-
encoder.text_token matched, :error
|
121
|
-
|
122
|
-
else
|
123
|
-
raise_inspect 'else-case reached!', encoder
|
124
|
-
|
125
|
-
end
|
126
|
-
|
127
|
-
end
|
128
|
-
|
129
|
-
encoder
|
130
|
-
|
131
|
-
end
|
132
|
-
|
133
|
-
end
|
134
|
-
|
135
|
-
end
|
136
|
-
end
|
@@ -1,136 +0,0 @@
|
|
1
|
-
module CodeRay
|
2
|
-
module Scanners
|
3
|
-
|
4
|
-
# Scheme scanner for CodeRay (by closure).
|
5
|
-
#
|
6
|
-
# Thanks to murphy for putting CodeRay into public.
|
7
|
-
class Scheme < Scanner
|
8
|
-
|
9
|
-
# TODO: function defs
|
10
|
-
# TODO: built-in functions
|
11
|
-
|
12
|
-
register_for :scheme
|
13
|
-
file_extension 'scm'
|
14
|
-
|
15
|
-
CORE_FORMS = %w[
|
16
|
-
lambda let let* letrec syntax-case define-syntax let-syntax
|
17
|
-
letrec-syntax begin define quote if or and cond case do delay
|
18
|
-
quasiquote set! cons force call-with-current-continuation call/cc
|
19
|
-
] # :nodoc:
|
20
|
-
|
21
|
-
IDENT_KIND = CaseIgnoringWordList.new(:ident).
|
22
|
-
add(CORE_FORMS, :keyword) # :nodoc:
|
23
|
-
|
24
|
-
#IDENTIFIER_INITIAL = /[a-z!@\$%&\*\/\:<=>\?~_\^]/i
|
25
|
-
#IDENTIFIER_SUBSEQUENT = /#{IDENTIFIER_INITIAL}|\d|\.|\+|-/
|
26
|
-
#IDENTIFIER = /#{IDENTIFIER_INITIAL}#{IDENTIFIER_SUBSEQUENT}*|\+|-|\.{3}/
|
27
|
-
IDENTIFIER = /[a-zA-Z!@$%&*\/:<=>?~_^][\w!@$%&*\/:<=>?~^.+\-]*|[+-]|\.\.\./ # :nodoc:
|
28
|
-
DIGIT = /\d/ # :nodoc:
|
29
|
-
DIGIT10 = /\d/ # :nodoc:
|
30
|
-
DIGIT16 = /[0-9a-f]/i # :nodoc:
|
31
|
-
DIGIT8 = /[0-7]/ # :nodoc:
|
32
|
-
DIGIT2 = /[01]/ # :nodoc:
|
33
|
-
RADIX16 = /\#x/i # :nodoc:
|
34
|
-
RADIX8 = /\#o/i # :nodoc:
|
35
|
-
RADIX2 = /\#b/i # :nodoc:
|
36
|
-
RADIX10 = /\#d/i # :nodoc:
|
37
|
-
EXACTNESS = /#i|#e/i # :nodoc:
|
38
|
-
SIGN = /[\+-]?/ # :nodoc:
|
39
|
-
EXP_MARK = /[esfdl]/i # :nodoc:
|
40
|
-
EXP = /#{EXP_MARK}#{SIGN}#{DIGIT}+/ # :nodoc:
|
41
|
-
SUFFIX = /#{EXP}?/ # :nodoc:
|
42
|
-
PREFIX10 = /#{RADIX10}?#{EXACTNESS}?|#{EXACTNESS}?#{RADIX10}?/ # :nodoc:
|
43
|
-
PREFIX16 = /#{RADIX16}#{EXACTNESS}?|#{EXACTNESS}?#{RADIX16}/ # :nodoc:
|
44
|
-
PREFIX8 = /#{RADIX8}#{EXACTNESS}?|#{EXACTNESS}?#{RADIX8}/ # :nodoc:
|
45
|
-
PREFIX2 = /#{RADIX2}#{EXACTNESS}?|#{EXACTNESS}?#{RADIX2}/ # :nodoc:
|
46
|
-
UINT10 = /#{DIGIT10}+#*/ # :nodoc:
|
47
|
-
UINT16 = /#{DIGIT16}+#*/ # :nodoc:
|
48
|
-
UINT8 = /#{DIGIT8}+#*/ # :nodoc:
|
49
|
-
UINT2 = /#{DIGIT2}+#*/ # :nodoc:
|
50
|
-
DECIMAL = /#{DIGIT10}+#+\.#*#{SUFFIX}|#{DIGIT10}+\.#{DIGIT10}*#*#{SUFFIX}|\.#{DIGIT10}+#*#{SUFFIX}|#{UINT10}#{EXP}/ # :nodoc:
|
51
|
-
UREAL10 = /#{UINT10}\/#{UINT10}|#{DECIMAL}|#{UINT10}/ # :nodoc:
|
52
|
-
UREAL16 = /#{UINT16}\/#{UINT16}|#{UINT16}/ # :nodoc:
|
53
|
-
UREAL8 = /#{UINT8}\/#{UINT8}|#{UINT8}/ # :nodoc:
|
54
|
-
UREAL2 = /#{UINT2}\/#{UINT2}|#{UINT2}/ # :nodoc:
|
55
|
-
REAL10 = /#{SIGN}#{UREAL10}/ # :nodoc:
|
56
|
-
REAL16 = /#{SIGN}#{UREAL16}/ # :nodoc:
|
57
|
-
REAL8 = /#{SIGN}#{UREAL8}/ # :nodoc:
|
58
|
-
REAL2 = /#{SIGN}#{UREAL2}/ # :nodoc:
|
59
|
-
IMAG10 = /i|#{UREAL10}i/ # :nodoc:
|
60
|
-
IMAG16 = /i|#{UREAL16}i/ # :nodoc:
|
61
|
-
IMAG8 = /i|#{UREAL8}i/ # :nodoc:
|
62
|
-
IMAG2 = /i|#{UREAL2}i/ # :nodoc:
|
63
|
-
COMPLEX10 = /#{REAL10}@#{REAL10}|#{REAL10}\+#{IMAG10}|#{REAL10}-#{IMAG10}|\+#{IMAG10}|-#{IMAG10}|#{REAL10}/ # :nodoc:
|
64
|
-
COMPLEX16 = /#{REAL16}@#{REAL16}|#{REAL16}\+#{IMAG16}|#{REAL16}-#{IMAG16}|\+#{IMAG16}|-#{IMAG16}|#{REAL16}/ # :nodoc:
|
65
|
-
COMPLEX8 = /#{REAL8}@#{REAL8}|#{REAL8}\+#{IMAG8}|#{REAL8}-#{IMAG8}|\+#{IMAG8}|-#{IMAG8}|#{REAL8}/ # :nodoc:
|
66
|
-
COMPLEX2 = /#{REAL2}@#{REAL2}|#{REAL2}\+#{IMAG2}|#{REAL2}-#{IMAG2}|\+#{IMAG2}|-#{IMAG2}|#{REAL2}/ # :nodoc:
|
67
|
-
NUM10 = /#{PREFIX10}?#{COMPLEX10}/ # :nodoc:
|
68
|
-
NUM16 = /#{PREFIX16}#{COMPLEX16}/ # :nodoc:
|
69
|
-
NUM8 = /#{PREFIX8}#{COMPLEX8}/ # :nodoc:
|
70
|
-
NUM2 = /#{PREFIX2}#{COMPLEX2}/ # :nodoc:
|
71
|
-
NUM = /#{NUM10}|#{NUM16}|#{NUM8}|#{NUM2}/ # :nodoc:
|
72
|
-
|
73
|
-
protected
|
74
|
-
|
75
|
-
def scan_tokens encoder, options
|
76
|
-
|
77
|
-
state = :initial
|
78
|
-
ident_kind = IDENT_KIND
|
79
|
-
|
80
|
-
until eos?
|
81
|
-
|
82
|
-
case state
|
83
|
-
when :initial
|
84
|
-
if match = scan(/ \s+ | \\\n /x)
|
85
|
-
encoder.text_token match, :space
|
86
|
-
elsif match = scan(/['\(\[\)\]]|#\(/)
|
87
|
-
encoder.text_token match, :operator
|
88
|
-
elsif match = scan(/;.*/)
|
89
|
-
encoder.text_token match, :comment
|
90
|
-
elsif match = scan(/#\\(?:newline|space|.?)/)
|
91
|
-
encoder.text_token match, :char
|
92
|
-
elsif match = scan(/#[ft]/)
|
93
|
-
encoder.text_token match, :predefined_constant
|
94
|
-
elsif match = scan(/#{IDENTIFIER}/o)
|
95
|
-
encoder.text_token match, ident_kind[matched]
|
96
|
-
elsif match = scan(/\./)
|
97
|
-
encoder.text_token match, :operator
|
98
|
-
elsif match = scan(/"/)
|
99
|
-
encoder.begin_group :string
|
100
|
-
encoder.text_token match, :delimiter
|
101
|
-
state = :string
|
102
|
-
elsif match = scan(/#{NUM}/o) and not matched.empty?
|
103
|
-
encoder.text_token match, :integer
|
104
|
-
else
|
105
|
-
encoder.text_token getch, :error
|
106
|
-
end
|
107
|
-
|
108
|
-
when :string
|
109
|
-
if match = scan(/[^"\\]+|\\.?/)
|
110
|
-
encoder.text_token match, :content
|
111
|
-
elsif match = scan(/"/)
|
112
|
-
encoder.text_token match, :delimiter
|
113
|
-
encoder.end_group :string
|
114
|
-
state = :initial
|
115
|
-
else
|
116
|
-
raise_inspect "else case \" reached; %p not handled." % peek(1),
|
117
|
-
encoder, state
|
118
|
-
end
|
119
|
-
|
120
|
-
else
|
121
|
-
raise 'else case reached'
|
122
|
-
|
123
|
-
end
|
124
|
-
|
125
|
-
end
|
126
|
-
|
127
|
-
if state == :string
|
128
|
-
encoder.end_group state
|
129
|
-
end
|
130
|
-
|
131
|
-
encoder
|
132
|
-
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|