rdoc 6.0.0.beta1 → 6.0.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rdoc might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.travis.yml +2 -12
- data/appveyor.yml +18 -0
- data/lib/rdoc.rb +2 -2
- data/lib/rdoc/constant.rb +2 -2
- data/lib/rdoc/context.rb +12 -0
- data/lib/rdoc/markup/to_html.rb +5 -3
- data/lib/rdoc/parser/c.rb +2 -4
- data/lib/rdoc/parser/ripper_state_lex.rb +587 -0
- data/lib/rdoc/parser/ruby.rb +441 -355
- data/lib/rdoc/parser/ruby_tools.rb +22 -10
- data/lib/rdoc/stats/normal.rb +2 -2
- data/lib/rdoc/token_stream.rb +31 -18
- data/rdoc.gemspec +5 -5
- metadata +18 -4
- data/lib/gauntlet_rdoc.rb +0 -82
- data/lib/rdoc/ruby_lex.rb +0 -1521
@@ -5,8 +5,6 @@
|
|
5
5
|
|
6
6
|
module RDoc::Parser::RubyTools
|
7
7
|
|
8
|
-
include RDoc::RubyToken
|
9
|
-
|
10
8
|
##
|
11
9
|
# Adds a token listener +obj+, but you should probably use token_listener
|
12
10
|
|
@@ -22,16 +20,25 @@ module RDoc::Parser::RubyTools
|
|
22
20
|
tk = nil
|
23
21
|
|
24
22
|
if @tokens.empty? then
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
if @scanner_point >= @scanner.size
|
24
|
+
return nil
|
25
|
+
else
|
26
|
+
tk = @scanner[@scanner_point]
|
27
|
+
@scanner_point += 1
|
28
|
+
@read.push tk[:text]
|
29
|
+
puts "get_tk1 => #{tk.inspect}" if $TOKEN_DEBUG
|
30
|
+
end
|
28
31
|
else
|
29
32
|
@read.push @unget_read.shift
|
30
33
|
tk = @tokens.shift
|
31
34
|
puts "get_tk2 => #{tk.inspect}" if $TOKEN_DEBUG
|
32
35
|
end
|
33
36
|
|
34
|
-
tk
|
37
|
+
if tk == nil || :on___end__ == tk[:kind]
|
38
|
+
tk = nil
|
39
|
+
end
|
40
|
+
|
41
|
+
return nil unless tk
|
35
42
|
|
36
43
|
# inform any listeners of our shiny new token
|
37
44
|
@token_listeners.each do |obj|
|
@@ -102,19 +109,24 @@ module RDoc::Parser::RubyTools
|
|
102
109
|
@tokens = []
|
103
110
|
@unget_read = []
|
104
111
|
@nest = 0
|
112
|
+
@scanner_point = 0
|
113
|
+
end
|
114
|
+
|
115
|
+
def tk_nl?(tk)
|
116
|
+
:on_nl == tk[:kind] or :on_ignored_nl == tk[:kind]
|
105
117
|
end
|
106
118
|
|
107
119
|
##
|
108
120
|
# Skips whitespace tokens including newlines if +skip_nl+ is true
|
109
121
|
|
110
|
-
def skip_tkspace(skip_nl = true)
|
122
|
+
def skip_tkspace(skip_nl = true)
|
111
123
|
tokens = []
|
112
124
|
|
113
|
-
while
|
114
|
-
tokens.push
|
125
|
+
while (tk = get_tk) and (:on_sp == tk[:kind] or (skip_nl and tk_nl?(tk))) do
|
126
|
+
tokens.push(tk)
|
115
127
|
end
|
116
128
|
|
117
|
-
unget_tk
|
129
|
+
unget_tk(tk)
|
118
130
|
tokens
|
119
131
|
end
|
120
132
|
|
data/lib/rdoc/stats/normal.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
|
-
require 'io/console
|
2
|
+
require 'io/console'
|
3
3
|
|
4
4
|
##
|
5
5
|
# Stats printer that prints just the files being documented with a progress
|
@@ -23,7 +23,7 @@ class RDoc::Stats::Normal < RDoc::Stats::Quiet
|
|
23
23
|
|
24
24
|
# Print a progress bar, but make sure it fits on a single line. Filename
|
25
25
|
# will be truncated if necessary.
|
26
|
-
terminal_width = IO.
|
26
|
+
terminal_width = IO.console.winsize[1].to_i.nonzero? || 80
|
27
27
|
max_filename_size = terminal_width - progress_bar.size
|
28
28
|
|
29
29
|
if filename.size > max_filename_size then
|
data/lib/rdoc/token_stream.rb
CHANGED
@@ -30,28 +30,41 @@ module RDoc::TokenStream
|
|
30
30
|
token_stream.map do |t|
|
31
31
|
next unless t
|
32
32
|
|
33
|
-
style = case t
|
34
|
-
when
|
35
|
-
when
|
36
|
-
when
|
37
|
-
when
|
38
|
-
when
|
39
|
-
when
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
when
|
33
|
+
style = case t[:kind]
|
34
|
+
when :on_const then 'ruby-constant'
|
35
|
+
when :on_kw then 'ruby-keyword'
|
36
|
+
when :on_ivar then 'ruby-ivar'
|
37
|
+
when :on_cvar then 'ruby-identifier'
|
38
|
+
when :on_gvar then 'ruby-identifier'
|
39
|
+
when '=' != t[:text] && :on_op then
|
40
|
+
if RDoc::RipperStateLex::EXPR_ARG == t[:state] then
|
41
|
+
'ruby-identifier'
|
42
|
+
else
|
43
|
+
'ruby-operator'
|
44
|
+
end
|
45
|
+
when :on_tlambda then 'ruby-operator'
|
46
|
+
when :on_ident then 'ruby-identifier'
|
47
|
+
when :on_label then 'ruby-value'
|
48
|
+
when :on_backref, :on_dstring
|
49
|
+
then 'ruby-node'
|
50
|
+
when :on_comment then 'ruby-comment'
|
51
|
+
when :on_embdoc then 'ruby-comment'
|
52
|
+
when :on_regexp then 'ruby-regexp'
|
53
|
+
when :on_tstring then 'ruby-string'
|
54
|
+
when :on_int, :on_float,
|
55
|
+
:on_rational, :on_imaginary,
|
56
|
+
:on_heredoc,
|
57
|
+
:on_symbol, :on_CHAR then 'ruby-value'
|
58
|
+
when :on_heredoc_beg, :on_heredoc_end
|
59
|
+
then 'ruby-identifier'
|
46
60
|
end
|
47
61
|
|
48
62
|
comment_with_nl = false
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
text = t.text.rstrip
|
63
|
+
if :on_comment == t[:kind] or :on_embdoc == t[:kind] or :on_heredoc_end == t[:kind]
|
64
|
+
comment_with_nl = true if "\n" == t[:text][-1]
|
65
|
+
text = t[:text].rstrip
|
53
66
|
else
|
54
|
-
text = t
|
67
|
+
text = t[:text]
|
55
68
|
end
|
56
69
|
text = CGI.escapeHTML text
|
57
70
|
|
data/rdoc.gemspec
CHANGED
@@ -1,11 +1,10 @@
|
|
1
|
-
|
2
|
-
$:.unshift File.expand_path("../lib", __FILE__)
|
3
|
-
require 'rdoc'
|
1
|
+
require_relative "lib/rdoc"
|
4
2
|
|
5
3
|
Gem::Specification.new do |s|
|
6
4
|
s.name = "rdoc"
|
7
5
|
s.version = RDoc::VERSION
|
8
|
-
|
6
|
+
s.date = "2017-09-12"
|
7
|
+
|
9
8
|
s.authors = [
|
10
9
|
"Eric Hodel",
|
11
10
|
"Dave Thomas",
|
@@ -28,7 +27,7 @@ RDoc includes the +rdoc+ and +ri+ tools for generating and displaying documentat
|
|
28
27
|
s.executables = ["rdoc", "ri"]
|
29
28
|
s.require_paths = ["lib"]
|
30
29
|
# for ruby core repository. It was generated by `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
31
|
-
s.files = [".document", ".gitignore", ".travis.yml", "CONTRIBUTING.rdoc", "CVE-2013-0256.rdoc", "ExampleMarkdown.md", "ExampleRDoc.rdoc", "Gemfile", "History.rdoc", "LEGAL.rdoc", "LICENSE.rdoc", "README.rdoc", "RI.rdoc", "Rakefile", "TODO.rdoc", "bin/console", "bin/setup", "exe/rdoc", "exe/ri", "lib/
|
30
|
+
s.files = [".document", ".gitignore", ".travis.yml", "CONTRIBUTING.rdoc", "CVE-2013-0256.rdoc", "ExampleMarkdown.md", "ExampleRDoc.rdoc", "Gemfile", "History.rdoc", "LEGAL.rdoc", "LICENSE.rdoc", "README.rdoc", "RI.rdoc", "Rakefile", "TODO.rdoc", "appveyor.yml", "bin/console", "bin/setup", "exe/rdoc", "exe/ri", "lib/rdoc.rb", "lib/rdoc/alias.rb", "lib/rdoc/anon_class.rb", "lib/rdoc/any_method.rb", "lib/rdoc/attr.rb", "lib/rdoc/class_module.rb", "lib/rdoc/code_object.rb", "lib/rdoc/code_objects.rb", "lib/rdoc/comment.rb", "lib/rdoc/constant.rb", "lib/rdoc/context.rb", "lib/rdoc/context/section.rb", "lib/rdoc/cross_reference.rb", "lib/rdoc/encoding.rb", "lib/rdoc/erb_partial.rb", "lib/rdoc/erbio.rb", "lib/rdoc/extend.rb", "lib/rdoc/generator.rb", "lib/rdoc/generator/darkfish.rb", "lib/rdoc/generator/json_index.rb", "lib/rdoc/generator/markup.rb", "lib/rdoc/generator/pot.rb", "lib/rdoc/generator/pot/message_extractor.rb", "lib/rdoc/generator/pot/po.rb", "lib/rdoc/generator/pot/po_entry.rb", "lib/rdoc/generator/ri.rb", "lib/rdoc/generator/template/darkfish/.document", "lib/rdoc/generator/template/darkfish/_footer.rhtml", "lib/rdoc/generator/template/darkfish/_head.rhtml", "lib/rdoc/generator/template/darkfish/_sidebar_VCS_info.rhtml", "lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml", "lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml", "lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml", "lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml", "lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml", "lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml", "lib/rdoc/generator/template/darkfish/_sidebar_navigation.rhtml", "lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml", "lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml", "lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml", "lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml", "lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml", "lib/rdoc/generator/template/darkfish/class.rhtml", "lib/rdoc/generator/template/darkfish/css/fonts.css", "lib/rdoc/generator/template/darkfish/css/rdoc.css", "lib/rdoc/generator/template/darkfish/fonts/Lato-Light.ttf", "lib/rdoc/generator/template/darkfish/fonts/Lato-LightItalic.ttf", "lib/rdoc/generator/template/darkfish/fonts/Lato-Regular.ttf", "lib/rdoc/generator/template/darkfish/fonts/Lato-RegularItalic.ttf", "lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Bold.ttf", "lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Regular.ttf", "lib/rdoc/generator/template/darkfish/images/add.png", "lib/rdoc/generator/template/darkfish/images/arrow_up.png", "lib/rdoc/generator/template/darkfish/images/brick.png", "lib/rdoc/generator/template/darkfish/images/brick_link.png", "lib/rdoc/generator/template/darkfish/images/bug.png", "lib/rdoc/generator/template/darkfish/images/bullet_black.png", "lib/rdoc/generator/template/darkfish/images/bullet_toggle_minus.png", "lib/rdoc/generator/template/darkfish/images/bullet_toggle_plus.png", "lib/rdoc/generator/template/darkfish/images/date.png", "lib/rdoc/generator/template/darkfish/images/delete.png", "lib/rdoc/generator/template/darkfish/images/find.png", "lib/rdoc/generator/template/darkfish/images/loadingAnimation.gif", "lib/rdoc/generator/template/darkfish/images/macFFBgHack.png", "lib/rdoc/generator/template/darkfish/images/package.png", "lib/rdoc/generator/template/darkfish/images/page_green.png", "lib/rdoc/generator/template/darkfish/images/page_white_text.png", "lib/rdoc/generator/template/darkfish/images/page_white_width.png", "lib/rdoc/generator/template/darkfish/images/plugin.png", "lib/rdoc/generator/template/darkfish/images/ruby.png", "lib/rdoc/generator/template/darkfish/images/tag_blue.png", "lib/rdoc/generator/template/darkfish/images/tag_green.png", "lib/rdoc/generator/template/darkfish/images/transparent.png", "lib/rdoc/generator/template/darkfish/images/wrench.png", "lib/rdoc/generator/template/darkfish/images/wrench_orange.png", "lib/rdoc/generator/template/darkfish/images/zoom.png", "lib/rdoc/generator/template/darkfish/index.rhtml", "lib/rdoc/generator/template/darkfish/js/darkfish.js", "lib/rdoc/generator/template/darkfish/js/jquery.js", "lib/rdoc/generator/template/darkfish/js/search.js", "lib/rdoc/generator/template/darkfish/page.rhtml", "lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml", "lib/rdoc/generator/template/darkfish/servlet_root.rhtml", "lib/rdoc/generator/template/darkfish/table_of_contents.rhtml", "lib/rdoc/generator/template/json_index/.document", "lib/rdoc/generator/template/json_index/js/navigation.js", "lib/rdoc/generator/template/json_index/js/searcher.js", "lib/rdoc/ghost_method.rb", "lib/rdoc/i18n.rb", "lib/rdoc/i18n/locale.rb", "lib/rdoc/i18n/text.rb", "lib/rdoc/include.rb", "lib/rdoc/known_classes.rb", "lib/rdoc/markdown.kpeg", "lib/rdoc/markdown/entities.rb", "lib/rdoc/markdown/literals.kpeg", "lib/rdoc/markdown/literals.rb", "lib/rdoc/markup.rb", "lib/rdoc/markup/attr_changer.rb", "lib/rdoc/markup/attr_span.rb", "lib/rdoc/markup/attribute_manager.rb", "lib/rdoc/markup/attributes.rb", "lib/rdoc/markup/blank_line.rb", "lib/rdoc/markup/block_quote.rb", "lib/rdoc/markup/document.rb", "lib/rdoc/markup/formatter.rb", "lib/rdoc/markup/formatter_test_case.rb", "lib/rdoc/markup/hard_break.rb", "lib/rdoc/markup/heading.rb", "lib/rdoc/markup/include.rb", "lib/rdoc/markup/indented_paragraph.rb", "lib/rdoc/markup/inline.rb", "lib/rdoc/markup/list.rb", "lib/rdoc/markup/list_item.rb", "lib/rdoc/markup/paragraph.rb", "lib/rdoc/markup/parser.rb", "lib/rdoc/markup/pre_process.rb", "lib/rdoc/markup/raw.rb", "lib/rdoc/markup/rule.rb", "lib/rdoc/markup/special.rb", "lib/rdoc/markup/text_formatter_test_case.rb", "lib/rdoc/markup/to_ansi.rb", "lib/rdoc/markup/to_bs.rb", "lib/rdoc/markup/to_html.rb", "lib/rdoc/markup/to_html_crossref.rb", "lib/rdoc/markup/to_html_snippet.rb", "lib/rdoc/markup/to_joined_paragraph.rb", "lib/rdoc/markup/to_label.rb", "lib/rdoc/markup/to_markdown.rb", "lib/rdoc/markup/to_rdoc.rb", "lib/rdoc/markup/to_table_of_contents.rb", "lib/rdoc/markup/to_test.rb", "lib/rdoc/markup/to_tt_only.rb", "lib/rdoc/markup/verbatim.rb", "lib/rdoc/meta_method.rb", "lib/rdoc/method_attr.rb", "lib/rdoc/mixin.rb", "lib/rdoc/normal_class.rb", "lib/rdoc/normal_module.rb", "lib/rdoc/options.rb", "lib/rdoc/parser.rb", "lib/rdoc/parser/c.rb", "lib/rdoc/parser/changelog.rb", "lib/rdoc/parser/markdown.rb", "lib/rdoc/parser/rd.rb", "lib/rdoc/parser/ripper_state_lex.rb", "lib/rdoc/parser/ruby.rb", "lib/rdoc/parser/ruby_tools.rb", "lib/rdoc/parser/simple.rb", "lib/rdoc/parser/text.rb", "lib/rdoc/rd.rb", "lib/rdoc/rd/block_parser.ry", "lib/rdoc/rd/inline.rb", "lib/rdoc/rd/inline_parser.ry", "lib/rdoc/rdoc.rb", "lib/rdoc/require.rb", "lib/rdoc/ri.rb", "lib/rdoc/ri/driver.rb", "lib/rdoc/ri/formatter.rb", "lib/rdoc/ri/paths.rb", "lib/rdoc/ri/store.rb", "lib/rdoc/ri/task.rb", "lib/rdoc/ruby_token.rb", "lib/rdoc/rubygems_hook.rb", "lib/rdoc/servlet.rb", "lib/rdoc/single_class.rb", "lib/rdoc/stats.rb", "lib/rdoc/stats/normal.rb", "lib/rdoc/stats/quiet.rb", "lib/rdoc/stats/verbose.rb", "lib/rdoc/store.rb", "lib/rdoc/task.rb", "lib/rdoc/test_case.rb", "lib/rdoc/text.rb", "lib/rdoc/token_stream.rb", "lib/rdoc/tom_doc.rb", "lib/rdoc/top_level.rb", "rdoc.gemspec"]
|
32
31
|
# files from .gitignore
|
33
32
|
s.files << "lib/rdoc/rd/block_parser.rb" << "lib/rdoc/rd/inline_parser.rb" << "lib/rdoc/markdown.rb"
|
34
33
|
|
@@ -54,4 +53,5 @@ RDoc includes the +rdoc+ and +ri+ tools for generating and displaying documentat
|
|
54
53
|
s.add_development_dependency("racc", "> 1.4.10")
|
55
54
|
s.add_development_dependency("kpeg")
|
56
55
|
s.add_development_dependency("minitest", "~> 4")
|
56
|
+
s.add_development_dependency("json")
|
57
57
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rdoc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.0.0.
|
4
|
+
version: 6.0.0.beta2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Hodel
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: exe
|
15
15
|
cert_chain: []
|
16
|
-
date: 2017-
|
16
|
+
date: 2017-09-12 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: rake
|
@@ -71,6 +71,20 @@ dependencies:
|
|
71
71
|
- - "~>"
|
72
72
|
- !ruby/object:Gem::Version
|
73
73
|
version: '4'
|
74
|
+
- !ruby/object:Gem::Dependency
|
75
|
+
name: json
|
76
|
+
requirement: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
type: :development
|
82
|
+
prerelease: false
|
83
|
+
version_requirements: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
74
88
|
description: |
|
75
89
|
RDoc produces HTML and command-line documentation for Ruby projects.
|
76
90
|
RDoc includes the +rdoc+ and +ri+ tools for generating and displaying documentation from the command-line.
|
@@ -112,11 +126,11 @@ files:
|
|
112
126
|
- RI.rdoc
|
113
127
|
- Rakefile
|
114
128
|
- TODO.rdoc
|
129
|
+
- appveyor.yml
|
115
130
|
- bin/console
|
116
131
|
- bin/setup
|
117
132
|
- exe/rdoc
|
118
133
|
- exe/ri
|
119
|
-
- lib/gauntlet_rdoc.rb
|
120
134
|
- lib/rdoc.rb
|
121
135
|
- lib/rdoc/alias.rb
|
122
136
|
- lib/rdoc/anon_class.rb
|
@@ -263,6 +277,7 @@ files:
|
|
263
277
|
- lib/rdoc/parser/changelog.rb
|
264
278
|
- lib/rdoc/parser/markdown.rb
|
265
279
|
- lib/rdoc/parser/rd.rb
|
280
|
+
- lib/rdoc/parser/ripper_state_lex.rb
|
266
281
|
- lib/rdoc/parser/ruby.rb
|
267
282
|
- lib/rdoc/parser/ruby_tools.rb
|
268
283
|
- lib/rdoc/parser/simple.rb
|
@@ -281,7 +296,6 @@ files:
|
|
281
296
|
- lib/rdoc/ri/paths.rb
|
282
297
|
- lib/rdoc/ri/store.rb
|
283
298
|
- lib/rdoc/ri/task.rb
|
284
|
-
- lib/rdoc/ruby_lex.rb
|
285
299
|
- lib/rdoc/ruby_token.rb
|
286
300
|
- lib/rdoc/rubygems_hook.rb
|
287
301
|
- lib/rdoc/servlet.rb
|
data/lib/gauntlet_rdoc.rb
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
Gem.load_yaml
|
2
|
-
require 'rdoc'
|
3
|
-
require 'gauntlet'
|
4
|
-
require 'fileutils'
|
5
|
-
|
6
|
-
##
|
7
|
-
# Allows for testing of RDoc against every gem
|
8
|
-
|
9
|
-
class RDoc::Gauntlet < Gauntlet
|
10
|
-
|
11
|
-
def initialize # :nodoc:
|
12
|
-
super
|
13
|
-
|
14
|
-
@args = nil
|
15
|
-
@type = nil
|
16
|
-
end
|
17
|
-
|
18
|
-
##
|
19
|
-
# Runs an RDoc generator for gem +name+
|
20
|
-
|
21
|
-
def run name
|
22
|
-
return if self.data.key? name
|
23
|
-
|
24
|
-
dir = File.expand_path "~/.gauntlet/data/#{@type}/#{name}"
|
25
|
-
FileUtils.rm_rf dir if File.exist? dir
|
26
|
-
|
27
|
-
yaml = File.read 'gemspec'
|
28
|
-
begin
|
29
|
-
spec = Gem::Specification.from_yaml yaml
|
30
|
-
rescue Psych::SyntaxError
|
31
|
-
puts "bad spec #{name}"
|
32
|
-
self.data[name] = false
|
33
|
-
return
|
34
|
-
end
|
35
|
-
|
36
|
-
args = @args.dup
|
37
|
-
args << '--op' << dir
|
38
|
-
args.concat spec.rdoc_options
|
39
|
-
args << spec.require_paths
|
40
|
-
args << spec.extra_rdoc_files
|
41
|
-
args = args.flatten.map { |a| a.to_s }
|
42
|
-
args.delete '--quiet'
|
43
|
-
|
44
|
-
puts "#{name} - rdoc #{args.join ' '}"
|
45
|
-
|
46
|
-
self.dirty = true
|
47
|
-
r = RDoc::RDoc.new
|
48
|
-
|
49
|
-
begin
|
50
|
-
r.document args
|
51
|
-
self.data[name] = true
|
52
|
-
puts 'passed'
|
53
|
-
FileUtils.rm_rf dir
|
54
|
-
rescue Interrupt, StandardError, RDoc::Error, SystemStackError => e
|
55
|
-
puts "failed - (#{e.class}) #{e.message}"
|
56
|
-
self.data[name] = false
|
57
|
-
end
|
58
|
-
rescue Gem::Exception
|
59
|
-
puts "bad gem #{name}"
|
60
|
-
ensure
|
61
|
-
puts
|
62
|
-
end
|
63
|
-
|
64
|
-
##
|
65
|
-
# Runs the gauntlet with the given +type+ (rdoc or ri) and +filter+ for
|
66
|
-
# which gems to run
|
67
|
-
|
68
|
-
def run_the_gauntlet type = 'rdoc', filter = nil
|
69
|
-
@type = type || 'rdoc'
|
70
|
-
@args = type == 'rdoc' ? [] : %w[--ri]
|
71
|
-
@data_file = "#{DATADIR}/#{@type}-data.yml"
|
72
|
-
|
73
|
-
super filter
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|
77
|
-
|
78
|
-
type = ARGV.shift
|
79
|
-
filter = ARGV.shift
|
80
|
-
filter = /#{filter}/ if filter
|
81
|
-
|
82
|
-
RDoc::Gauntlet.new.run_the_gauntlet type, filter
|
data/lib/rdoc/ruby_lex.rb
DELETED
@@ -1,1521 +0,0 @@
|
|
1
|
-
# coding: US-ASCII
|
2
|
-
# frozen_string_literal: false
|
3
|
-
|
4
|
-
#--
|
5
|
-
# irb/ruby-lex.rb - ruby lexcal analyzer
|
6
|
-
# $Release Version: 0.9.5$
|
7
|
-
# $Revision: 17979 $
|
8
|
-
# $Date: 2008-07-09 10:17:05 -0700 (Wed, 09 Jul 2008) $
|
9
|
-
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
|
10
|
-
#
|
11
|
-
#++
|
12
|
-
|
13
|
-
require "e2mmap"
|
14
|
-
require "irb/slex"
|
15
|
-
require "stringio"
|
16
|
-
|
17
|
-
##
|
18
|
-
# Ruby lexer adapted from irb.
|
19
|
-
#
|
20
|
-
# The internals are not documented because they are scary.
|
21
|
-
|
22
|
-
class RDoc::RubyLex
|
23
|
-
|
24
|
-
##
|
25
|
-
# Raised upon invalid input
|
26
|
-
|
27
|
-
class Error < RDoc::Error
|
28
|
-
end
|
29
|
-
|
30
|
-
# :stopdoc:
|
31
|
-
|
32
|
-
extend Exception2MessageMapper
|
33
|
-
|
34
|
-
def_exception(:AlreadyDefinedToken, "Already defined token(%s)")
|
35
|
-
def_exception(:TkReading2TokenNoKey, "key nothing(key='%s')")
|
36
|
-
def_exception(:TkSymbol2TokenNoKey, "key nothing(key='%s')")
|
37
|
-
def_exception(:TkReading2TokenDuplicateError,
|
38
|
-
"key duplicate(token_n='%s', key='%s')")
|
39
|
-
def_exception(:SyntaxError, "%s")
|
40
|
-
|
41
|
-
def_exception(:TerminateLineInput, "Terminate Line Input")
|
42
|
-
|
43
|
-
include RDoc::RubyToken
|
44
|
-
include IRB
|
45
|
-
|
46
|
-
attr_accessor :continue
|
47
|
-
attr_accessor :lex_state
|
48
|
-
attr_accessor :first_in_method_statement
|
49
|
-
attr_reader :reader
|
50
|
-
|
51
|
-
class << self
|
52
|
-
attr_accessor :debug_level
|
53
|
-
end
|
54
|
-
|
55
|
-
def self.debug?
|
56
|
-
@debug_level > 0
|
57
|
-
end
|
58
|
-
|
59
|
-
self.debug_level = 0
|
60
|
-
|
61
|
-
# :startdoc:
|
62
|
-
|
63
|
-
##
|
64
|
-
# Returns an Array of +ruby+ tokens. See ::new for a description of
|
65
|
-
# +options+.
|
66
|
-
|
67
|
-
def self.tokenize ruby, options
|
68
|
-
tokens = []
|
69
|
-
|
70
|
-
scanner = RDoc::RubyLex.new ruby, options
|
71
|
-
scanner.exception_on_syntax_error = true
|
72
|
-
|
73
|
-
while token = scanner.token do
|
74
|
-
tokens << token
|
75
|
-
end
|
76
|
-
|
77
|
-
tokens
|
78
|
-
end
|
79
|
-
|
80
|
-
##
|
81
|
-
# Creates a new lexer for +content+. +options+ is an RDoc::Options, only
|
82
|
-
# +tab_width is used.
|
83
|
-
|
84
|
-
def initialize(content, options)
|
85
|
-
lex_init
|
86
|
-
|
87
|
-
if /\t/ =~ content then
|
88
|
-
tab_width = options.tab_width
|
89
|
-
content = content.split(/\n/).map do |line|
|
90
|
-
1 while line.gsub!(/\t+/) {
|
91
|
-
' ' * (tab_width*$&.length - $`.length % tab_width)
|
92
|
-
} && $~
|
93
|
-
line
|
94
|
-
end.join("\n")
|
95
|
-
end
|
96
|
-
|
97
|
-
content << "\n" unless content[-1, 1] == "\n"
|
98
|
-
|
99
|
-
set_input StringIO.new content
|
100
|
-
|
101
|
-
@base_char_no = 0
|
102
|
-
@char_no = 0
|
103
|
-
@exp_line_no = @line_no = 1
|
104
|
-
@here_readed = []
|
105
|
-
@readed = []
|
106
|
-
@current_readed = @readed
|
107
|
-
@rests = []
|
108
|
-
@seek = 0
|
109
|
-
|
110
|
-
@heredoc_queue = []
|
111
|
-
|
112
|
-
@indent = 0
|
113
|
-
@indent_stack = []
|
114
|
-
@lex_state = :EXPR_BEG
|
115
|
-
@space_seen = false
|
116
|
-
@escaped_nl = false
|
117
|
-
@first_in_method_statement = false
|
118
|
-
@after_question = false
|
119
|
-
|
120
|
-
@continue = false
|
121
|
-
@line = ""
|
122
|
-
|
123
|
-
@skip_space = false
|
124
|
-
@readed_auto_clean_up = false
|
125
|
-
@exception_on_syntax_error = true
|
126
|
-
|
127
|
-
@prompt = nil
|
128
|
-
@prev_seek = nil
|
129
|
-
@ltype = nil
|
130
|
-
end
|
131
|
-
|
132
|
-
# :stopdoc:
|
133
|
-
|
134
|
-
def inspect # :nodoc:
|
135
|
-
"#<%s:0x%x pos %d lex_state %p space_seen %p>" % [
|
136
|
-
self.class, object_id,
|
137
|
-
@io.pos, @lex_state, @space_seen,
|
138
|
-
]
|
139
|
-
end
|
140
|
-
|
141
|
-
attr_accessor :skip_space
|
142
|
-
attr_accessor :readed_auto_clean_up
|
143
|
-
attr_accessor :exception_on_syntax_error
|
144
|
-
|
145
|
-
attr_reader :seek
|
146
|
-
attr_reader :char_no
|
147
|
-
attr_reader :line_no
|
148
|
-
attr_reader :indent
|
149
|
-
|
150
|
-
# io functions
|
151
|
-
def set_input(io, p = nil, &block)
|
152
|
-
@io = io
|
153
|
-
if p.respond_to?(:call)
|
154
|
-
@input = p
|
155
|
-
elsif block_given?
|
156
|
-
@input = block
|
157
|
-
else
|
158
|
-
@input = Proc.new{@io.gets}
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
def get_readed
|
163
|
-
if idx = @readed.rindex("\n")
|
164
|
-
@base_char_no = @readed.size - (idx + 1)
|
165
|
-
else
|
166
|
-
@base_char_no += @readed.size
|
167
|
-
end
|
168
|
-
|
169
|
-
readed = @readed.join("")
|
170
|
-
@readed.clear
|
171
|
-
readed
|
172
|
-
end
|
173
|
-
|
174
|
-
def getc
|
175
|
-
while @rests.empty?
|
176
|
-
# return nil unless buf_input
|
177
|
-
@rests.push nil unless buf_input
|
178
|
-
end
|
179
|
-
c = @rests.shift
|
180
|
-
@current_readed.push c
|
181
|
-
@seek += 1
|
182
|
-
if c == "\n".freeze
|
183
|
-
@line_no += 1
|
184
|
-
@char_no = 0
|
185
|
-
else
|
186
|
-
@char_no += 1
|
187
|
-
end
|
188
|
-
|
189
|
-
c
|
190
|
-
end
|
191
|
-
|
192
|
-
def gets
|
193
|
-
l = ""
|
194
|
-
while c = getc
|
195
|
-
l.concat(c)
|
196
|
-
break if c == "\n"
|
197
|
-
end
|
198
|
-
return nil if l == "" and c.nil?
|
199
|
-
l
|
200
|
-
end
|
201
|
-
|
202
|
-
def eof?
|
203
|
-
@io.eof?
|
204
|
-
end
|
205
|
-
|
206
|
-
def getc_of_rests
|
207
|
-
if @rests.empty?
|
208
|
-
nil
|
209
|
-
else
|
210
|
-
getc
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
def ungetc(c = nil)
|
215
|
-
if @here_readed.empty?
|
216
|
-
c2 = @readed.pop
|
217
|
-
else
|
218
|
-
c2 = @here_readed.pop
|
219
|
-
end
|
220
|
-
c = c2 unless c
|
221
|
-
@rests.unshift c #c =
|
222
|
-
@seek -= 1
|
223
|
-
if c == "\n"
|
224
|
-
@line_no -= 1
|
225
|
-
if idx = @readed.rindex("\n")
|
226
|
-
@char_no = idx + 1
|
227
|
-
else
|
228
|
-
@char_no = @base_char_no + @readed.size
|
229
|
-
end
|
230
|
-
else
|
231
|
-
@char_no -= 1
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
235
|
-
def peek_equal?(str)
|
236
|
-
chrs = str.split(//)
|
237
|
-
until @rests.size >= chrs.size
|
238
|
-
return false unless buf_input
|
239
|
-
end
|
240
|
-
@rests[0, chrs.size] == chrs
|
241
|
-
end
|
242
|
-
|
243
|
-
def peek_match?(regexp)
|
244
|
-
while @rests.empty?
|
245
|
-
return false unless buf_input
|
246
|
-
end
|
247
|
-
regexp =~ @rests.join("")
|
248
|
-
end
|
249
|
-
|
250
|
-
def peek(i = 0)
|
251
|
-
while @rests.size <= i
|
252
|
-
return nil unless buf_input
|
253
|
-
end
|
254
|
-
@rests[i]
|
255
|
-
end
|
256
|
-
|
257
|
-
def buf_input
|
258
|
-
prompt
|
259
|
-
line = @input.call
|
260
|
-
return nil unless line
|
261
|
-
@rests.concat line.split(//)
|
262
|
-
true
|
263
|
-
end
|
264
|
-
private :buf_input
|
265
|
-
|
266
|
-
def set_prompt(p = nil, &block)
|
267
|
-
p = block if block_given?
|
268
|
-
if p.respond_to?(:call)
|
269
|
-
@prompt = p
|
270
|
-
else
|
271
|
-
@prompt = Proc.new{print p}
|
272
|
-
end
|
273
|
-
end
|
274
|
-
|
275
|
-
def prompt
|
276
|
-
if @prompt
|
277
|
-
@prompt.call(@ltype, @indent, @continue, @line_no)
|
278
|
-
end
|
279
|
-
end
|
280
|
-
|
281
|
-
def initialize_input
|
282
|
-
@ltype = nil
|
283
|
-
@quoted = nil
|
284
|
-
@indent = 0
|
285
|
-
@indent_stack = []
|
286
|
-
@lex_state = :EXPR_BEG
|
287
|
-
@space_seen = false
|
288
|
-
@current_readed = @readed
|
289
|
-
|
290
|
-
@continue = false
|
291
|
-
prompt
|
292
|
-
|
293
|
-
@line = ""
|
294
|
-
@exp_line_no = @line_no
|
295
|
-
end
|
296
|
-
|
297
|
-
def each_top_level_statement
|
298
|
-
initialize_input
|
299
|
-
catch(:TERM_INPUT) do
|
300
|
-
loop do
|
301
|
-
begin
|
302
|
-
@continue = false
|
303
|
-
prompt
|
304
|
-
unless l = lex
|
305
|
-
throw :TERM_INPUT if @line == ''
|
306
|
-
else
|
307
|
-
#p l
|
308
|
-
@line.concat l
|
309
|
-
if @ltype or @continue or @indent > 0
|
310
|
-
next
|
311
|
-
end
|
312
|
-
end
|
313
|
-
if @line != "\n"
|
314
|
-
yield @line, @exp_line_no
|
315
|
-
end
|
316
|
-
break unless l
|
317
|
-
@line = ''
|
318
|
-
@exp_line_no = @line_no
|
319
|
-
|
320
|
-
@indent = 0
|
321
|
-
@indent_stack = []
|
322
|
-
prompt
|
323
|
-
rescue TerminateLineInput
|
324
|
-
initialize_input
|
325
|
-
prompt
|
326
|
-
get_readed
|
327
|
-
end
|
328
|
-
end
|
329
|
-
end
|
330
|
-
end
|
331
|
-
|
332
|
-
def lex
|
333
|
-
until (((tk = token).kind_of?(TkNL) || tk.kind_of?(TkEND_OF_SCRIPT)) &&
|
334
|
-
!@continue or
|
335
|
-
tk.nil?)
|
336
|
-
#p tk
|
337
|
-
#p @lex_state
|
338
|
-
#p self
|
339
|
-
end
|
340
|
-
line = get_readed
|
341
|
-
# print self.inspect
|
342
|
-
if line == "" and tk.kind_of?(TkEND_OF_SCRIPT) || tk.nil?
|
343
|
-
nil
|
344
|
-
else
|
345
|
-
line
|
346
|
-
end
|
347
|
-
end
|
348
|
-
|
349
|
-
def token
|
350
|
-
# require "tracer"
|
351
|
-
# Tracer.on
|
352
|
-
@prev_seek = @seek
|
353
|
-
@prev_line_no = @line_no
|
354
|
-
@prev_char_no = @char_no
|
355
|
-
begin
|
356
|
-
begin
|
357
|
-
tk = @OP.match(self)
|
358
|
-
@space_seen = tk.kind_of?(TkSPACE)
|
359
|
-
@first_in_method_statement = false if !@space_seen && @first_in_method_statement
|
360
|
-
rescue SyntaxError => e
|
361
|
-
raise Error, "syntax error: #{e.message}" if
|
362
|
-
@exception_on_syntax_error
|
363
|
-
|
364
|
-
tk = TkError.new(@seek, @line_no, @char_no)
|
365
|
-
end
|
366
|
-
end while @skip_space and tk.kind_of?(TkSPACE)
|
367
|
-
|
368
|
-
if @readed_auto_clean_up
|
369
|
-
get_readed
|
370
|
-
end
|
371
|
-
|
372
|
-
if TkSYMBEG === tk then
|
373
|
-
tk1 = token
|
374
|
-
set_token_position tk.seek, tk.line_no, tk.char_no
|
375
|
-
|
376
|
-
case tk1
|
377
|
-
when TkId, TkOp, TkSTRING, TkDSTRING, TkSTAR, TkAMPER then
|
378
|
-
if tk1.respond_to?(:name) then
|
379
|
-
tk = Token(TkSYMBOL, ":" + tk1.name)
|
380
|
-
else
|
381
|
-
tk = Token(TkSYMBOL, ":" + tk1.text)
|
382
|
-
end
|
383
|
-
else
|
384
|
-
tk = tk1
|
385
|
-
end
|
386
|
-
elsif (TkPLUS === tk or TkMINUS === tk) and peek(0) =~ /\d/ then
|
387
|
-
tk1 = token
|
388
|
-
set_token_position tk.seek, tk.line_no, tk.char_no
|
389
|
-
tk = Token(tk1.class, tk.text + tk1.text)
|
390
|
-
end
|
391
|
-
@after_question = false if @after_question and !(TkQUESTION === tk)
|
392
|
-
|
393
|
-
# Tracer.off
|
394
|
-
tk
|
395
|
-
end
|
396
|
-
|
397
|
-
ENINDENT_CLAUSE = [
|
398
|
-
"case", "class", "def", "do", "for", "if",
|
399
|
-
"module", "unless", "until", "while", "begin" #, "when"
|
400
|
-
]
|
401
|
-
|
402
|
-
DEINDENT_CLAUSE = ["end" #, "when"
|
403
|
-
]
|
404
|
-
|
405
|
-
PERCENT_LTYPE = {
|
406
|
-
"q" => "\'",
|
407
|
-
"Q" => "\"",
|
408
|
-
"x" => "\`",
|
409
|
-
"r" => "/",
|
410
|
-
"w" => "]",
|
411
|
-
"W" => "]",
|
412
|
-
"s" => ":",
|
413
|
-
"i" => "]",
|
414
|
-
"I" => "]"
|
415
|
-
}
|
416
|
-
|
417
|
-
PERCENT_PAREN = {
|
418
|
-
"{" => "}",
|
419
|
-
"[" => "]",
|
420
|
-
"<" => ">",
|
421
|
-
"(" => ")"
|
422
|
-
}
|
423
|
-
|
424
|
-
PERCENT_PAREN_REV = PERCENT_PAREN.invert
|
425
|
-
|
426
|
-
Ltype2Token = {
|
427
|
-
"\'" => TkSTRING,
|
428
|
-
"\"" => TkSTRING,
|
429
|
-
"\`" => TkXSTRING,
|
430
|
-
"/" => TkREGEXP,
|
431
|
-
"]" => TkDSTRING,
|
432
|
-
":" => TkSYMBOL
|
433
|
-
}
|
434
|
-
DLtype2Token = {
|
435
|
-
"\"" => TkDSTRING,
|
436
|
-
"\`" => TkDXSTRING,
|
437
|
-
"/" => TkDREGEXP,
|
438
|
-
}
|
439
|
-
|
440
|
-
def lex_init()
|
441
|
-
@OP = IRB::SLex.new
|
442
|
-
@OP.def_rules("\0", "\004", "\032") do |op, io|
|
443
|
-
Token(TkEND_OF_SCRIPT, '')
|
444
|
-
end
|
445
|
-
|
446
|
-
@OP.def_rules(" ", "\t", "\f", "\r", "\13") do |op, io|
|
447
|
-
@space_seen = true
|
448
|
-
str = op
|
449
|
-
while (ch = getc) =~ /[ \t\f\r\13]/ do
|
450
|
-
str << ch
|
451
|
-
end
|
452
|
-
ungetc
|
453
|
-
Token TkSPACE, str
|
454
|
-
end
|
455
|
-
|
456
|
-
@OP.def_rule("#") do |op, io|
|
457
|
-
identify_comment
|
458
|
-
end
|
459
|
-
|
460
|
-
@OP.def_rule("=begin",
|
461
|
-
proc{|op, io| @prev_char_no == 0 && peek(0) =~ /\s/}) do
|
462
|
-
|op, io|
|
463
|
-
@ltype = "="
|
464
|
-
res = op
|
465
|
-
until (ch = getc) == "\n" do
|
466
|
-
res << ch
|
467
|
-
end
|
468
|
-
res << ch
|
469
|
-
|
470
|
-
until ( peek_equal?("=end") && peek(4) =~ /\s/ ) do
|
471
|
-
(ch = getc)
|
472
|
-
res << ch
|
473
|
-
end
|
474
|
-
|
475
|
-
res << gets # consume =end
|
476
|
-
|
477
|
-
@ltype = nil
|
478
|
-
Token(TkRD_COMMENT, res)
|
479
|
-
end
|
480
|
-
|
481
|
-
@OP.def_rule("\n") do |op, io|
|
482
|
-
print "\\n\n" if RDoc::RubyLex.debug?
|
483
|
-
unless @heredoc_queue.empty?
|
484
|
-
info = @heredoc_queue[0]
|
485
|
-
if !info[:started] # "\n"
|
486
|
-
info[:started] = true
|
487
|
-
ungetc "\n"
|
488
|
-
elsif info[:heredoc_end].nil? # heredoc body
|
489
|
-
tk, heredoc_end = identify_here_document_body(info[:quoted], info[:lt], info[:indent])
|
490
|
-
info[:heredoc_end] = heredoc_end
|
491
|
-
ungetc "\n"
|
492
|
-
else # heredoc end
|
493
|
-
@heredoc_queue.shift
|
494
|
-
@lex_state = :EXPR_BEG
|
495
|
-
tk = Token(TkHEREDOCEND, info[:heredoc_end])
|
496
|
-
if !@heredoc_queue.empty?
|
497
|
-
@heredoc_queue[0][:started] = true
|
498
|
-
ungetc "\n"
|
499
|
-
end
|
500
|
-
end
|
501
|
-
end
|
502
|
-
unless tk
|
503
|
-
case @lex_state
|
504
|
-
when :EXPR_BEG, :EXPR_FNAME, :EXPR_DOT
|
505
|
-
@continue = true
|
506
|
-
else
|
507
|
-
@continue = false
|
508
|
-
@lex_state = :EXPR_BEG unless @escaped_nl
|
509
|
-
until (@indent_stack.empty? ||
|
510
|
-
[TkLPAREN, TkLBRACK, TkLBRACE,
|
511
|
-
TkfLPAREN, TkfLBRACK, TkfLBRACE].include?(@indent_stack.last))
|
512
|
-
@indent_stack.pop
|
513
|
-
end
|
514
|
-
end
|
515
|
-
@current_readed = @readed
|
516
|
-
@here_readed.clear
|
517
|
-
tk = Token(TkNL)
|
518
|
-
end
|
519
|
-
@escaped_nl = false
|
520
|
-
tk
|
521
|
-
end
|
522
|
-
|
523
|
-
@OP.def_rules("=") do
|
524
|
-
|op, io|
|
525
|
-
case @lex_state
|
526
|
-
when :EXPR_FNAME, :EXPR_DOT
|
527
|
-
@lex_state = :EXPR_ARG
|
528
|
-
else
|
529
|
-
@lex_state = :EXPR_BEG
|
530
|
-
end
|
531
|
-
Token(op)
|
532
|
-
end
|
533
|
-
|
534
|
-
@OP.def_rules("*", "**",
|
535
|
-
"==", "===",
|
536
|
-
"=~", "<=>",
|
537
|
-
"<", "<=",
|
538
|
-
">", ">=", ">>", "=>") do
|
539
|
-
|op, io|
|
540
|
-
case @lex_state
|
541
|
-
when :EXPR_FNAME, :EXPR_DOT
|
542
|
-
tk = Token(TkId, op)
|
543
|
-
@lex_state = :EXPR_ARG
|
544
|
-
else
|
545
|
-
tk = Token(op)
|
546
|
-
@lex_state = :EXPR_BEG
|
547
|
-
end
|
548
|
-
tk
|
549
|
-
end
|
550
|
-
|
551
|
-
@OP.def_rules("->") do
|
552
|
-
|op, io|
|
553
|
-
@lex_state = :EXPR_ENDFN
|
554
|
-
Token(op)
|
555
|
-
end
|
556
|
-
|
557
|
-
@OP.def_rules("!", "!=", "!~") do
|
558
|
-
|op, io|
|
559
|
-
case @lex_state
|
560
|
-
when :EXPR_FNAME, :EXPR_DOT
|
561
|
-
@lex_state = :EXPR_ARG
|
562
|
-
Token(TkId, op)
|
563
|
-
else
|
564
|
-
@lex_state = :EXPR_BEG
|
565
|
-
Token(op)
|
566
|
-
end
|
567
|
-
end
|
568
|
-
|
569
|
-
@OP.def_rules("<<") do
|
570
|
-
|op, io|
|
571
|
-
tk = nil
|
572
|
-
if @lex_state != :EXPR_END && @lex_state != :EXPR_CLASS &&
|
573
|
-
(@lex_state != :EXPR_ARG || @space_seen)
|
574
|
-
c = peek(0)
|
575
|
-
if /\S/ =~ c && (/["'`]/ =~ c || /\w/ =~ c || c == "-" || c == "~")
|
576
|
-
tk = identify_here_document(op)
|
577
|
-
end
|
578
|
-
end
|
579
|
-
unless tk
|
580
|
-
case @lex_state
|
581
|
-
when :EXPR_FNAME, :EXPR_DOT
|
582
|
-
tk = Token(TkId, op)
|
583
|
-
@lex_state = :EXPR_ARG
|
584
|
-
else
|
585
|
-
tk = Token(op)
|
586
|
-
@lex_state = :EXPR_BEG
|
587
|
-
end
|
588
|
-
end
|
589
|
-
tk
|
590
|
-
end
|
591
|
-
|
592
|
-
@OP.def_rules("'", '"') do
|
593
|
-
|op, io|
|
594
|
-
identify_string(op)
|
595
|
-
end
|
596
|
-
|
597
|
-
@OP.def_rules("`") do
|
598
|
-
|op, io|
|
599
|
-
if :EXPR_FNAME == @lex_state or :EXPR_DOT == @lex_state
|
600
|
-
@lex_state = :EXPR_ARG
|
601
|
-
Token(TkId, op)
|
602
|
-
else
|
603
|
-
identify_string(op)
|
604
|
-
end
|
605
|
-
end
|
606
|
-
|
607
|
-
@OP.def_rules('?') do
|
608
|
-
|op, io|
|
609
|
-
if @lex_state == :EXPR_END
|
610
|
-
@lex_state = :EXPR_BEG
|
611
|
-
@after_question = true
|
612
|
-
Token(TkQUESTION)
|
613
|
-
else
|
614
|
-
ch = getc
|
615
|
-
if @lex_state == :EXPR_ARG && ch =~ /\s/
|
616
|
-
ungetc
|
617
|
-
@lex_state = :EXPR_BEG;
|
618
|
-
Token(TkQUESTION)
|
619
|
-
else
|
620
|
-
@lex_state = :EXPR_END
|
621
|
-
ch << getc if "\\" == ch
|
622
|
-
Token(TkCHAR, "?#{ch}")
|
623
|
-
end
|
624
|
-
end
|
625
|
-
end
|
626
|
-
|
627
|
-
@OP.def_rules("&&", "||") do
|
628
|
-
|op, io|
|
629
|
-
@lex_state = :EXPR_BEG
|
630
|
-
Token(op)
|
631
|
-
end
|
632
|
-
|
633
|
-
@OP.def_rules("&", "|") do
|
634
|
-
|op, io|
|
635
|
-
case @lex_state
|
636
|
-
when :EXPR_FNAME, :EXPR_DOT
|
637
|
-
tk = Token(TkId, op)
|
638
|
-
@lex_state = :EXPR_ARG
|
639
|
-
else
|
640
|
-
tk = Token(op)
|
641
|
-
@lex_state = :EXPR_BEG
|
642
|
-
end
|
643
|
-
tk
|
644
|
-
end
|
645
|
-
|
646
|
-
@OP.def_rules("+=", "-=", "*=", "**=",
|
647
|
-
"&=", "|=", "^=", "<<=", ">>=", "||=", "&&=") do
|
648
|
-
|op, io|
|
649
|
-
@lex_state = :EXPR_BEG
|
650
|
-
op =~ /^(.*)=$/
|
651
|
-
Token(TkOPASGN, $1)
|
652
|
-
end
|
653
|
-
|
654
|
-
@OP.def_rule("+@", proc{|op, io| @lex_state == :EXPR_FNAME}) do
|
655
|
-
|op, io|
|
656
|
-
@lex_state = :EXPR_ARG
|
657
|
-
Token(TkId, op)
|
658
|
-
end
|
659
|
-
|
660
|
-
@OP.def_rule("-@", proc{|op, io| @lex_state == :EXPR_FNAME}) do
|
661
|
-
|op, io|
|
662
|
-
@lex_state = :EXPR_ARG
|
663
|
-
Token(TkId, op)
|
664
|
-
end
|
665
|
-
|
666
|
-
@OP.def_rules("+", "-") do
|
667
|
-
|op, io|
|
668
|
-
catch(:RET) do
|
669
|
-
if :EXPR_FNAME == @lex_state or :EXPR_DOT == @lex_state
|
670
|
-
tk = Token(TkId, op)
|
671
|
-
@lex_state = :EXPR_ARG
|
672
|
-
elsif @lex_state == :EXPR_ARG
|
673
|
-
if @space_seen and peek(0) =~ /[0-9]/
|
674
|
-
throw :RET, identify_number(op)
|
675
|
-
else
|
676
|
-
@lex_state = :EXPR_BEG
|
677
|
-
end
|
678
|
-
elsif @lex_state != :EXPR_END and peek(0) =~ /[0-9]/
|
679
|
-
throw :RET, identify_number(op)
|
680
|
-
else
|
681
|
-
@lex_state = :EXPR_BEG
|
682
|
-
end
|
683
|
-
tk = Token(op) unless tk
|
684
|
-
tk
|
685
|
-
end
|
686
|
-
end
|
687
|
-
|
688
|
-
@OP.def_rules(".", "&.") do
|
689
|
-
|op, io|
|
690
|
-
@lex_state = :EXPR_BEG
|
691
|
-
if peek(0) =~ /[0-9]/
|
692
|
-
ungetc
|
693
|
-
identify_number
|
694
|
-
else
|
695
|
-
# for "obj.if" or "obj&.if" etc.
|
696
|
-
@lex_state = :EXPR_DOT
|
697
|
-
Token(op)
|
698
|
-
end
|
699
|
-
end
|
700
|
-
|
701
|
-
@OP.def_rules("..", "...") do
|
702
|
-
|op, io|
|
703
|
-
@lex_state = :EXPR_BEG
|
704
|
-
Token(op)
|
705
|
-
end
|
706
|
-
|
707
|
-
lex_int2
|
708
|
-
end
|
709
|
-
|
710
|
-
def lex_int2
|
711
|
-
@OP.def_rules("]", "}", ")") do
|
712
|
-
|op, io|
|
713
|
-
@lex_state = :EXPR_END
|
714
|
-
@indent -= 1
|
715
|
-
@indent_stack.pop
|
716
|
-
Token(op)
|
717
|
-
end
|
718
|
-
|
719
|
-
@OP.def_rule(":") do
|
720
|
-
|op, io|
|
721
|
-
if @lex_state == :EXPR_END || peek(0) =~ /\s/
|
722
|
-
@lex_state = :EXPR_BEG
|
723
|
-
Token(TkCOLON)
|
724
|
-
else
|
725
|
-
@lex_state = :EXPR_FNAME;
|
726
|
-
Token(TkSYMBEG)
|
727
|
-
end
|
728
|
-
end
|
729
|
-
|
730
|
-
@OP.def_rule("::") do
|
731
|
-
|op, io|
|
732
|
-
# p @lex_state.id2name, @space_seen
|
733
|
-
if @lex_state == :EXPR_BEG or @lex_state == :EXPR_ARG && @space_seen
|
734
|
-
@lex_state = :EXPR_BEG
|
735
|
-
Token(TkCOLON3)
|
736
|
-
else
|
737
|
-
@lex_state = :EXPR_DOT
|
738
|
-
Token(TkCOLON2)
|
739
|
-
end
|
740
|
-
end
|
741
|
-
|
742
|
-
@OP.def_rule("/") do
|
743
|
-
|op, io|
|
744
|
-
if :EXPR_FNAME == @lex_state or :EXPR_DOT == @lex_state
|
745
|
-
@lex_state = :EXPR_ARG
|
746
|
-
Token(TkId, op)
|
747
|
-
elsif @lex_state == :EXPR_BEG || @lex_state == :EXPR_MID || @first_in_method_statement
|
748
|
-
identify_string(op)
|
749
|
-
elsif peek(0) == '='
|
750
|
-
getc
|
751
|
-
@lex_state = :EXPR_BEG
|
752
|
-
Token(TkOPASGN, "/") #/)
|
753
|
-
elsif @lex_state == :EXPR_ARG and @space_seen and peek(0) !~ /\s/
|
754
|
-
identify_string(op)
|
755
|
-
else
|
756
|
-
@lex_state = :EXPR_BEG
|
757
|
-
Token("/") #/)
|
758
|
-
end
|
759
|
-
end
|
760
|
-
|
761
|
-
@OP.def_rules("^") do
|
762
|
-
|op, io|
|
763
|
-
case @lex_state
|
764
|
-
when :EXPR_FNAME, :EXPR_DOT
|
765
|
-
tk = Token(TkId, op)
|
766
|
-
@lex_state = :EXPR_ARG
|
767
|
-
else
|
768
|
-
tk = Token(op)
|
769
|
-
@lex_state = :EXPR_BEG
|
770
|
-
end
|
771
|
-
tk
|
772
|
-
end
|
773
|
-
|
774
|
-
# @OP.def_rules("^=") do
|
775
|
-
# @lex_state = :EXPR_BEG
|
776
|
-
# Token(OP_ASGN, :^)
|
777
|
-
# end
|
778
|
-
|
779
|
-
@OP.def_rules(",") do
|
780
|
-
|op, io|
|
781
|
-
@lex_state = :EXPR_BEG
|
782
|
-
Token(op)
|
783
|
-
end
|
784
|
-
|
785
|
-
@OP.def_rules(";") do
|
786
|
-
|op, io|
|
787
|
-
@lex_state = :EXPR_BEG
|
788
|
-
until (@indent_stack.empty? ||
|
789
|
-
[TkLPAREN, TkLBRACK, TkLBRACE,
|
790
|
-
TkfLPAREN, TkfLBRACK, TkfLBRACE].include?(@indent_stack.last))
|
791
|
-
@indent_stack.pop
|
792
|
-
end
|
793
|
-
Token(op)
|
794
|
-
end
|
795
|
-
|
796
|
-
@OP.def_rule("~") do
|
797
|
-
|op, io|
|
798
|
-
case @lex_state
|
799
|
-
when :EXPR_FNAME, :EXPR_DOT
|
800
|
-
@lex_state = :EXPR_ARG
|
801
|
-
Token(TkId, op)
|
802
|
-
else
|
803
|
-
@lex_state = :EXPR_BEG
|
804
|
-
Token(op)
|
805
|
-
end
|
806
|
-
end
|
807
|
-
|
808
|
-
@OP.def_rule("~@", proc{|op, io| @lex_state == :EXPR_FNAME}) do
|
809
|
-
|op, io|
|
810
|
-
@lex_state = :EXPR_BEG
|
811
|
-
Token("~")
|
812
|
-
end
|
813
|
-
|
814
|
-
@OP.def_rule("(") do
|
815
|
-
|op, io|
|
816
|
-
@indent += 1
|
817
|
-
if @lex_state == :EXPR_BEG || @lex_state == :EXPR_MID
|
818
|
-
@lex_state = :EXPR_BEG
|
819
|
-
tk_c = TkfLPAREN
|
820
|
-
else
|
821
|
-
@lex_state = :EXPR_BEG
|
822
|
-
tk_c = TkLPAREN
|
823
|
-
end
|
824
|
-
@indent_stack.push tk_c
|
825
|
-
Token tk_c
|
826
|
-
end
|
827
|
-
|
828
|
-
@OP.def_rule("[]", proc{|op, io| @lex_state == :EXPR_FNAME}) do
|
829
|
-
|op, io|
|
830
|
-
@lex_state = :EXPR_ARG
|
831
|
-
Token(TkId, op)
|
832
|
-
end
|
833
|
-
|
834
|
-
@OP.def_rule("[]=", proc{|op, io| @lex_state == :EXPR_FNAME}) do
|
835
|
-
|op, io|
|
836
|
-
@lex_state = :EXPR_ARG
|
837
|
-
Token(TkId, op)
|
838
|
-
end
|
839
|
-
|
840
|
-
@OP.def_rule("[") do
|
841
|
-
|op, io|
|
842
|
-
text = nil
|
843
|
-
@indent += 1
|
844
|
-
if @lex_state == :EXPR_FNAME
|
845
|
-
tk_c = TkfLBRACK
|
846
|
-
else
|
847
|
-
if @lex_state == :EXPR_BEG || @lex_state == :EXPR_MID
|
848
|
-
tk_c = TkLBRACK
|
849
|
-
elsif @lex_state == :EXPR_ARG && @space_seen
|
850
|
-
tk_c = TkLBRACK
|
851
|
-
elsif @lex_state == :EXPR_DOT
|
852
|
-
if peek(0) == "]"
|
853
|
-
tk_c = TkIDENTIFIER
|
854
|
-
getc
|
855
|
-
if peek(0) == "="
|
856
|
-
text = "[]="
|
857
|
-
else
|
858
|
-
text = "[]"
|
859
|
-
end
|
860
|
-
else
|
861
|
-
tk_c = TkOp
|
862
|
-
end
|
863
|
-
else
|
864
|
-
tk_c = TkfLBRACK
|
865
|
-
end
|
866
|
-
@lex_state = :EXPR_BEG
|
867
|
-
end
|
868
|
-
@indent_stack.push tk_c
|
869
|
-
Token(tk_c, text)
|
870
|
-
end
|
871
|
-
|
872
|
-
@OP.def_rule("{") do
|
873
|
-
|op, io|
|
874
|
-
@indent += 1
|
875
|
-
if @lex_state != :EXPR_END && @lex_state != :EXPR_ARG
|
876
|
-
tk_c = TkLBRACE
|
877
|
-
else
|
878
|
-
tk_c = TkfLBRACE
|
879
|
-
end
|
880
|
-
@lex_state = :EXPR_BEG
|
881
|
-
@indent_stack.push tk_c
|
882
|
-
Token(tk_c)
|
883
|
-
end
|
884
|
-
|
885
|
-
@OP.def_rule('\\') do
|
886
|
-
|op, io|
|
887
|
-
if peek(0) == "\n"
|
888
|
-
@space_seen = true
|
889
|
-
@continue = true
|
890
|
-
@escaped_nl = true
|
891
|
-
end
|
892
|
-
Token("\\")
|
893
|
-
end
|
894
|
-
|
895
|
-
@OP.def_rule('%') do
|
896
|
-
|op, io|
|
897
|
-
if :EXPR_FNAME == @lex_state or :EXPR_DOT == @lex_state
|
898
|
-
@lex_state = :EXPR_ARG
|
899
|
-
Token(TkId, op)
|
900
|
-
elsif @lex_state == :EXPR_BEG || @lex_state == :EXPR_MID
|
901
|
-
identify_quotation
|
902
|
-
elsif peek(0) == '='
|
903
|
-
getc
|
904
|
-
@lex_state = :EXPR_BEG
|
905
|
-
Token(TkOPASGN, '%')
|
906
|
-
elsif @lex_state == :EXPR_ARG and @space_seen and peek(0) !~ /\s/
|
907
|
-
identify_quotation
|
908
|
-
else
|
909
|
-
@lex_state = :EXPR_BEG
|
910
|
-
Token("%") #))
|
911
|
-
end
|
912
|
-
end
|
913
|
-
|
914
|
-
@OP.def_rule('$') do
|
915
|
-
|op, io|
|
916
|
-
identify_gvar
|
917
|
-
end
|
918
|
-
|
919
|
-
@OP.def_rule('@') do
|
920
|
-
|op, io|
|
921
|
-
if peek(0) =~ /[\w@]/
|
922
|
-
ungetc
|
923
|
-
identify_identifier
|
924
|
-
else
|
925
|
-
Token("@")
|
926
|
-
end
|
927
|
-
end
|
928
|
-
|
929
|
-
# @OP.def_rule("def", proc{|op, io| /\s/ =~ io.peek(0)}) do
|
930
|
-
# |op, io|
|
931
|
-
# @indent += 1
|
932
|
-
# @lex_state = :EXPR_FNAME
|
933
|
-
# # @lex_state = :EXPR_END
|
934
|
-
# # until @rests[0] == "\n" or @rests[0] == ";"
|
935
|
-
# # rests.shift
|
936
|
-
# # end
|
937
|
-
# end
|
938
|
-
|
939
|
-
@OP.def_rule("_") do
|
940
|
-
if peek_match?(/_END__/) and @lex_state == :EXPR_BEG then
|
941
|
-
6.times { getc }
|
942
|
-
Token(TkEND_OF_SCRIPT, '__END__')
|
943
|
-
else
|
944
|
-
ungetc
|
945
|
-
identify_identifier
|
946
|
-
end
|
947
|
-
end
|
948
|
-
|
949
|
-
@OP.def_rule("") do
|
950
|
-
|op, io|
|
951
|
-
printf "MATCH: start %s: %s\n", op, io.inspect if RDoc::RubyLex.debug?
|
952
|
-
if peek(0) =~ /[0-9]/
|
953
|
-
t = identify_number
|
954
|
-
else
|
955
|
-
t = identify_identifier
|
956
|
-
end
|
957
|
-
printf "MATCH: end %s: %s\n", op, io.inspect if RDoc::RubyLex.debug?
|
958
|
-
t
|
959
|
-
end
|
960
|
-
|
961
|
-
p @OP if RDoc::RubyLex.debug?
|
962
|
-
end
|
963
|
-
|
964
|
-
def identify_gvar
|
965
|
-
@lex_state = :EXPR_END
|
966
|
-
|
967
|
-
case ch = getc
|
968
|
-
when /[~_*$?!@\/\\;,=:<>".]/ #"
|
969
|
-
Token(TkGVAR, "$" + ch)
|
970
|
-
when "-"
|
971
|
-
Token(TkGVAR, "$-" + getc)
|
972
|
-
when "&", "`", "'", "+"
|
973
|
-
Token(TkBACK_REF, "$"+ch)
|
974
|
-
when /[1-9]/
|
975
|
-
ref = ch
|
976
|
-
while (ch = getc) =~ /[0-9]/ do ref << ch end
|
977
|
-
ungetc
|
978
|
-
Token(TkNTH_REF, "$#{ref}")
|
979
|
-
when /\w/
|
980
|
-
ungetc
|
981
|
-
ungetc
|
982
|
-
identify_identifier
|
983
|
-
else
|
984
|
-
ungetc
|
985
|
-
Token("$")
|
986
|
-
end
|
987
|
-
end
|
988
|
-
|
989
|
-
IDENT_RE = eval '/[\w\u{0080}-\u{FFFFF}]/u'
|
990
|
-
|
991
|
-
def identify_identifier
|
992
|
-
token = ""
|
993
|
-
if peek(0) =~ /[$@]/
|
994
|
-
token.concat(c = getc)
|
995
|
-
if c == "@" and peek(0) == "@"
|
996
|
-
token.concat getc
|
997
|
-
end
|
998
|
-
end
|
999
|
-
|
1000
|
-
while (ch = getc) =~ IDENT_RE do
|
1001
|
-
print " :#{ch}: " if RDoc::RubyLex.debug?
|
1002
|
-
token.concat ch
|
1003
|
-
end
|
1004
|
-
|
1005
|
-
ungetc
|
1006
|
-
|
1007
|
-
if ((ch == "!" && peek(1) != "=") || ch == "?") && token[0,1] =~ /\w/
|
1008
|
-
token.concat getc
|
1009
|
-
end
|
1010
|
-
|
1011
|
-
# almost fix token
|
1012
|
-
|
1013
|
-
case token
|
1014
|
-
when /^\$/
|
1015
|
-
return Token(TkGVAR, token)
|
1016
|
-
when /^\@\@/
|
1017
|
-
@lex_state = :EXPR_END
|
1018
|
-
# p Token(TkCVAR, token)
|
1019
|
-
return Token(TkCVAR, token)
|
1020
|
-
when /^\@/
|
1021
|
-
@lex_state = :EXPR_END
|
1022
|
-
return Token(TkIVAR, token)
|
1023
|
-
end
|
1024
|
-
|
1025
|
-
if @lex_state != :EXPR_DOT
|
1026
|
-
print token, "\n" if RDoc::RubyLex.debug?
|
1027
|
-
|
1028
|
-
token_c, *trans = TkReading2Token[token]
|
1029
|
-
if token_c
|
1030
|
-
# reserved word?
|
1031
|
-
|
1032
|
-
if (@lex_state != :EXPR_BEG &&
|
1033
|
-
@lex_state != :EXPR_FNAME &&
|
1034
|
-
trans[1])
|
1035
|
-
# modifiers
|
1036
|
-
token_c = TkSymbol2Token[trans[1]]
|
1037
|
-
@lex_state = trans[0]
|
1038
|
-
else
|
1039
|
-
if @lex_state != :EXPR_FNAME
|
1040
|
-
if ENINDENT_CLAUSE.include?(token)
|
1041
|
-
valid = peek(0) != ':'
|
1042
|
-
|
1043
|
-
# check for ``class = val'' etc.
|
1044
|
-
case token
|
1045
|
-
when "class"
|
1046
|
-
valid = false unless peek_match?(/^\s*(<<|\w|::)/)
|
1047
|
-
when "def"
|
1048
|
-
valid = false if peek_match?(/^\s*(([+-\/*&\|^]|<<|>>|\|\||\&\&)=|\&\&|\|\|)/)
|
1049
|
-
when "do"
|
1050
|
-
valid = false if peek_match?(/^\s*([+-\/*]?=|\*|<|>|\&)/)
|
1051
|
-
when *ENINDENT_CLAUSE
|
1052
|
-
valid = false if peek_match?(/^\s*([+-\/*]?=|\*|<|>|\&|\|)/)
|
1053
|
-
else
|
1054
|
-
# no nothing
|
1055
|
-
end if valid
|
1056
|
-
|
1057
|
-
if valid
|
1058
|
-
if token == "do"
|
1059
|
-
if ![TkFOR, TkWHILE, TkUNTIL].include?(@indent_stack.last)
|
1060
|
-
@indent += 1
|
1061
|
-
@indent_stack.push token_c
|
1062
|
-
end
|
1063
|
-
else
|
1064
|
-
@indent += 1
|
1065
|
-
@indent_stack.push token_c
|
1066
|
-
end
|
1067
|
-
else
|
1068
|
-
token_c = TkIDENTIFIER
|
1069
|
-
end
|
1070
|
-
|
1071
|
-
elsif DEINDENT_CLAUSE.include?(token)
|
1072
|
-
@indent -= 1
|
1073
|
-
@indent_stack.pop
|
1074
|
-
end
|
1075
|
-
@lex_state = trans[0]
|
1076
|
-
else
|
1077
|
-
@lex_state = :EXPR_END
|
1078
|
-
end
|
1079
|
-
end
|
1080
|
-
if token_c.ancestors.include?(TkId) and peek(0) == ':' and !peek_match?(/^::/)
|
1081
|
-
token.concat getc
|
1082
|
-
token_c = TkSYMBOL
|
1083
|
-
end
|
1084
|
-
return Token(token_c, token)
|
1085
|
-
end
|
1086
|
-
end
|
1087
|
-
|
1088
|
-
if @lex_state == :EXPR_FNAME
|
1089
|
-
@lex_state = :EXPR_END
|
1090
|
-
if peek(0) == '=' and peek(1) != '>'
|
1091
|
-
token.concat getc
|
1092
|
-
end
|
1093
|
-
elsif @lex_state == :EXPR_BEG || @lex_state == :EXPR_DOT ||
|
1094
|
-
@lex_state == :EXPR_ARG || @lex_state == :EXPR_MID
|
1095
|
-
@lex_state = :EXPR_ARG
|
1096
|
-
else
|
1097
|
-
@lex_state = :EXPR_END
|
1098
|
-
end
|
1099
|
-
|
1100
|
-
if token[0, 1] =~ /[A-Z]/
|
1101
|
-
if token[-1] =~ /[!?]/
|
1102
|
-
token_c = TkIDENTIFIER
|
1103
|
-
else
|
1104
|
-
token_c = TkCONSTANT
|
1105
|
-
end
|
1106
|
-
elsif token[token.size - 1, 1] =~ /[!?]/
|
1107
|
-
token_c = TkFID
|
1108
|
-
else
|
1109
|
-
token_c = TkIDENTIFIER
|
1110
|
-
end
|
1111
|
-
if peek(0) == ':' and !peek_match?(/^::/)
|
1112
|
-
token.concat getc
|
1113
|
-
return Token(TkSYMBOL, token)
|
1114
|
-
else
|
1115
|
-
return Token(token_c, token)
|
1116
|
-
end
|
1117
|
-
end
|
1118
|
-
|
1119
|
-
def identify_here_document(op)
|
1120
|
-
ch = getc
|
1121
|
-
start_token = op
|
1122
|
-
# if lt = PERCENT_LTYPE[ch]
|
1123
|
-
if ch == "-" or ch == "~"
|
1124
|
-
start_token.concat ch
|
1125
|
-
ch = getc
|
1126
|
-
indent = true
|
1127
|
-
end
|
1128
|
-
if /['"`]/ =~ ch
|
1129
|
-
start_token.concat ch
|
1130
|
-
user_quote = lt = ch
|
1131
|
-
quoted = ""
|
1132
|
-
while (c = getc) && c != lt
|
1133
|
-
quoted.concat c
|
1134
|
-
end
|
1135
|
-
start_token.concat quoted
|
1136
|
-
start_token.concat lt
|
1137
|
-
else
|
1138
|
-
user_quote = nil
|
1139
|
-
lt = '"'
|
1140
|
-
quoted = ch.dup
|
1141
|
-
while (c = getc) && c =~ /\w/
|
1142
|
-
quoted.concat c
|
1143
|
-
end
|
1144
|
-
start_token.concat quoted
|
1145
|
-
ungetc
|
1146
|
-
end
|
1147
|
-
|
1148
|
-
@heredoc_queue << {
|
1149
|
-
quoted: quoted,
|
1150
|
-
lt: lt,
|
1151
|
-
indent: indent,
|
1152
|
-
started: false
|
1153
|
-
}
|
1154
|
-
@lex_state = :EXPR_END
|
1155
|
-
Token(RDoc::RubyLex::TkHEREDOCBEG, start_token)
|
1156
|
-
end
|
1157
|
-
|
1158
|
-
def identify_here_document_body(quoted, lt, indent)
|
1159
|
-
ltback, @ltype = @ltype, lt
|
1160
|
-
|
1161
|
-
doc = ""
|
1162
|
-
heredoc_end = nil
|
1163
|
-
while l = gets
|
1164
|
-
l = l.sub(/(:?\r)?\n\z/, "\n")
|
1165
|
-
if (indent ? l.strip : l.chomp) == quoted
|
1166
|
-
heredoc_end = l
|
1167
|
-
break
|
1168
|
-
end
|
1169
|
-
doc << l
|
1170
|
-
end
|
1171
|
-
raise Error, "Missing terminating #{quoted} for string" unless heredoc_end
|
1172
|
-
|
1173
|
-
@ltype = ltback
|
1174
|
-
@lex_state = :EXPR_BEG
|
1175
|
-
[Token(RDoc::RubyLex::TkHEREDOC, doc), heredoc_end]
|
1176
|
-
end
|
1177
|
-
|
1178
|
-
def identify_quotation
|
1179
|
-
type = ch = getc
|
1180
|
-
if lt = PERCENT_LTYPE[type]
|
1181
|
-
ch = getc
|
1182
|
-
elsif type =~ /\W/
|
1183
|
-
type = nil
|
1184
|
-
lt = "\""
|
1185
|
-
else
|
1186
|
-
return Token(TkMOD, '%')
|
1187
|
-
end
|
1188
|
-
# if ch !~ /\W/
|
1189
|
-
# ungetc
|
1190
|
-
# next
|
1191
|
-
# end
|
1192
|
-
#@ltype = lt
|
1193
|
-
@quoted = ch unless @quoted = PERCENT_PAREN[ch]
|
1194
|
-
identify_string(lt, @quoted, type)
|
1195
|
-
end
|
1196
|
-
|
1197
|
-
def identify_number(op = "")
|
1198
|
-
@lex_state = :EXPR_END
|
1199
|
-
|
1200
|
-
num = op
|
1201
|
-
|
1202
|
-
if peek(0) == "0" && peek(1) !~ /[.eEri]/
|
1203
|
-
num << getc
|
1204
|
-
|
1205
|
-
case peek(0)
|
1206
|
-
when /[xX]/
|
1207
|
-
ch = getc
|
1208
|
-
match = /[0-9a-fA-F_]/
|
1209
|
-
when /[bB]/
|
1210
|
-
ch = getc
|
1211
|
-
match = /[01_]/
|
1212
|
-
when /[oO]/
|
1213
|
-
ch = getc
|
1214
|
-
match = /[0-7_]/
|
1215
|
-
when /[dD]/
|
1216
|
-
ch = getc
|
1217
|
-
match = /[0-9_]/
|
1218
|
-
when /[0-7]/
|
1219
|
-
match = /[0-7_]/
|
1220
|
-
when /[89]/
|
1221
|
-
raise Error, "Illegal octal digit"
|
1222
|
-
else
|
1223
|
-
return Token(TkINTEGER, num)
|
1224
|
-
end
|
1225
|
-
|
1226
|
-
num << ch if ch
|
1227
|
-
|
1228
|
-
len0 = true
|
1229
|
-
non_digit = false
|
1230
|
-
while ch = getc
|
1231
|
-
num << ch
|
1232
|
-
if match =~ ch
|
1233
|
-
if ch == "_"
|
1234
|
-
if non_digit
|
1235
|
-
raise Error, "trailing `#{ch}' in number"
|
1236
|
-
else
|
1237
|
-
non_digit = ch
|
1238
|
-
end
|
1239
|
-
else
|
1240
|
-
non_digit = false
|
1241
|
-
len0 = false
|
1242
|
-
end
|
1243
|
-
else
|
1244
|
-
ungetc
|
1245
|
-
num[-1, 1] = ''
|
1246
|
-
if len0
|
1247
|
-
raise Error, "numeric literal without digits"
|
1248
|
-
end
|
1249
|
-
if non_digit
|
1250
|
-
raise Error, "trailing `#{non_digit}' in number"
|
1251
|
-
end
|
1252
|
-
break
|
1253
|
-
end
|
1254
|
-
end
|
1255
|
-
return Token(TkINTEGER, num)
|
1256
|
-
end
|
1257
|
-
|
1258
|
-
type = TkINTEGER
|
1259
|
-
allow_point = true
|
1260
|
-
allow_e = true
|
1261
|
-
allow_ri = true
|
1262
|
-
non_digit = false
|
1263
|
-
while ch = getc
|
1264
|
-
num << ch
|
1265
|
-
case ch
|
1266
|
-
when /[0-9]/
|
1267
|
-
non_digit = false
|
1268
|
-
when "_"
|
1269
|
-
non_digit = ch
|
1270
|
-
when allow_point && "."
|
1271
|
-
if non_digit
|
1272
|
-
raise Error, "trailing `#{non_digit}' in number"
|
1273
|
-
end
|
1274
|
-
type = TkFLOAT
|
1275
|
-
if peek(0) !~ /[0-9]/
|
1276
|
-
type = TkINTEGER
|
1277
|
-
ungetc
|
1278
|
-
num[-1, 1] = ''
|
1279
|
-
break
|
1280
|
-
end
|
1281
|
-
allow_point = false
|
1282
|
-
when allow_e && "e", allow_e && "E"
|
1283
|
-
if non_digit
|
1284
|
-
raise Error, "trailing `#{non_digit}' in number"
|
1285
|
-
end
|
1286
|
-
type = TkFLOAT
|
1287
|
-
if peek(0) =~ /[+-]/
|
1288
|
-
num << getc
|
1289
|
-
end
|
1290
|
-
allow_e = false
|
1291
|
-
allow_ri = false
|
1292
|
-
allow_point = false
|
1293
|
-
non_digit = ch
|
1294
|
-
when allow_ri && "r"
|
1295
|
-
if non_digit
|
1296
|
-
raise Error, "trailing `#{non_digit}' in number"
|
1297
|
-
end
|
1298
|
-
type = TkRATIONAL
|
1299
|
-
if peek(0) == 'i'
|
1300
|
-
type = TkIMAGINARY
|
1301
|
-
num << getc
|
1302
|
-
end
|
1303
|
-
break
|
1304
|
-
when allow_ri && "i"
|
1305
|
-
if non_digit && non_digit != "r"
|
1306
|
-
raise Error, "trailing `#{non_digit}' in number"
|
1307
|
-
end
|
1308
|
-
type = TkIMAGINARY
|
1309
|
-
break
|
1310
|
-
else
|
1311
|
-
if non_digit
|
1312
|
-
raise Error, "trailing `#{non_digit}' in number"
|
1313
|
-
end
|
1314
|
-
ungetc
|
1315
|
-
num[-1, 1] = ''
|
1316
|
-
break
|
1317
|
-
end
|
1318
|
-
end
|
1319
|
-
|
1320
|
-
Token(type, num)
|
1321
|
-
end
|
1322
|
-
|
1323
|
-
def identify_string(ltype, quoted = ltype, type = nil)
|
1324
|
-
close = PERCENT_PAREN.values.include?(quoted)
|
1325
|
-
@ltype = ltype
|
1326
|
-
@quoted = quoted
|
1327
|
-
|
1328
|
-
str = if ltype == quoted and %w[" ' / `].include? ltype and type.nil? then
|
1329
|
-
ltype.dup
|
1330
|
-
else
|
1331
|
-
"%#{type}#{PERCENT_PAREN_REV[quoted]||quoted}"
|
1332
|
-
end
|
1333
|
-
|
1334
|
-
subtype = nil
|
1335
|
-
begin
|
1336
|
-
nest = 0
|
1337
|
-
|
1338
|
-
while ch = getc
|
1339
|
-
str << ch
|
1340
|
-
|
1341
|
-
if @quoted == ch and nest <= 0
|
1342
|
-
break
|
1343
|
-
elsif @ltype != "'" && @ltype != "]" && @ltype != ":" and ch == "#"
|
1344
|
-
ch = getc
|
1345
|
-
if ch == "{" then
|
1346
|
-
subtype = true
|
1347
|
-
str << ch << skip_inner_expression
|
1348
|
-
next
|
1349
|
-
else
|
1350
|
-
ungetc
|
1351
|
-
end
|
1352
|
-
elsif ch == '\\'
|
1353
|
-
case @ltype
|
1354
|
-
when "'" then
|
1355
|
-
case ch = getc
|
1356
|
-
when "'", '\\' then
|
1357
|
-
str << ch
|
1358
|
-
else
|
1359
|
-
str << ch
|
1360
|
-
end
|
1361
|
-
else
|
1362
|
-
str << read_escape
|
1363
|
-
end
|
1364
|
-
end
|
1365
|
-
|
1366
|
-
if close then
|
1367
|
-
if PERCENT_PAREN[ch] == @quoted
|
1368
|
-
nest += 1
|
1369
|
-
elsif ch == @quoted
|
1370
|
-
nest -= 1
|
1371
|
-
end
|
1372
|
-
end
|
1373
|
-
end
|
1374
|
-
|
1375
|
-
if @ltype == "/"
|
1376
|
-
while peek(0) =~ /i|m|x|o|e|s|u|n/
|
1377
|
-
str << getc
|
1378
|
-
end
|
1379
|
-
end
|
1380
|
-
|
1381
|
-
if peek(0) == ':' and !peek_match?(/^::/) and :EXPR_BEG == @lex_state and !@after_question
|
1382
|
-
str.concat getc
|
1383
|
-
return Token(TkSYMBOL, str)
|
1384
|
-
elsif subtype
|
1385
|
-
Token(DLtype2Token[ltype], str)
|
1386
|
-
else
|
1387
|
-
Token(Ltype2Token[ltype], str)
|
1388
|
-
end
|
1389
|
-
ensure
|
1390
|
-
@ltype = nil
|
1391
|
-
@quoted = nil
|
1392
|
-
@lex_state = :EXPR_END
|
1393
|
-
end
|
1394
|
-
end
|
1395
|
-
|
1396
|
-
def skip_inner_expression
|
1397
|
-
res = ""
|
1398
|
-
nest = 0
|
1399
|
-
while ch = getc
|
1400
|
-
res << ch
|
1401
|
-
if ch == '}'
|
1402
|
-
break if nest.zero?
|
1403
|
-
nest -= 1
|
1404
|
-
elsif ch == '{'
|
1405
|
-
nest += 1
|
1406
|
-
end
|
1407
|
-
end
|
1408
|
-
res
|
1409
|
-
end
|
1410
|
-
|
1411
|
-
def identify_comment
|
1412
|
-
@ltype = "#"
|
1413
|
-
|
1414
|
-
comment = '#'
|
1415
|
-
|
1416
|
-
while ch = getc
|
1417
|
-
# if ch == "\\" #"
|
1418
|
-
# read_escape
|
1419
|
-
# end
|
1420
|
-
if ch == "\n"
|
1421
|
-
@ltype = nil
|
1422
|
-
ungetc
|
1423
|
-
break
|
1424
|
-
end
|
1425
|
-
|
1426
|
-
comment << ch
|
1427
|
-
end
|
1428
|
-
|
1429
|
-
return Token(TkCOMMENT, comment)
|
1430
|
-
end
|
1431
|
-
|
1432
|
-
def read_escape
|
1433
|
-
escape = ''
|
1434
|
-
ch = getc
|
1435
|
-
|
1436
|
-
case ch
|
1437
|
-
when "\n", "\r", "\f"
|
1438
|
-
escape << ch
|
1439
|
-
when "\\", "n", "t", "r", "f", "v", "a", "e", "b", "s" #"
|
1440
|
-
escape << ch
|
1441
|
-
when /[0-7]/
|
1442
|
-
ungetc ch
|
1443
|
-
3.times do
|
1444
|
-
ch = getc
|
1445
|
-
case ch
|
1446
|
-
when /[0-7]/
|
1447
|
-
escape << ch
|
1448
|
-
when nil
|
1449
|
-
break
|
1450
|
-
else
|
1451
|
-
ungetc
|
1452
|
-
break
|
1453
|
-
end
|
1454
|
-
end
|
1455
|
-
|
1456
|
-
when "x"
|
1457
|
-
escape << ch
|
1458
|
-
|
1459
|
-
2.times do
|
1460
|
-
ch = getc
|
1461
|
-
case ch
|
1462
|
-
when /[0-9a-fA-F]/
|
1463
|
-
escape << ch
|
1464
|
-
when nil
|
1465
|
-
break
|
1466
|
-
else
|
1467
|
-
ungetc
|
1468
|
-
break
|
1469
|
-
end
|
1470
|
-
end
|
1471
|
-
|
1472
|
-
when "M"
|
1473
|
-
escape << ch
|
1474
|
-
|
1475
|
-
ch = getc
|
1476
|
-
if ch != '-'
|
1477
|
-
ungetc
|
1478
|
-
else
|
1479
|
-
escape << ch
|
1480
|
-
|
1481
|
-
ch = getc
|
1482
|
-
if ch == "\\" #"
|
1483
|
-
ungetc
|
1484
|
-
escape << read_escape
|
1485
|
-
else
|
1486
|
-
escape << ch
|
1487
|
-
end
|
1488
|
-
end
|
1489
|
-
|
1490
|
-
when "C", "c" #, "^"
|
1491
|
-
escape << ch
|
1492
|
-
|
1493
|
-
if ch == "C"
|
1494
|
-
ch = getc
|
1495
|
-
|
1496
|
-
if ch == "-"
|
1497
|
-
escape << ch
|
1498
|
-
ch = getc
|
1499
|
-
escape << ch
|
1500
|
-
|
1501
|
-
escape << read_escape if ch == "\\"
|
1502
|
-
else
|
1503
|
-
ungetc
|
1504
|
-
end
|
1505
|
-
elsif (ch = getc) == "\\" #"
|
1506
|
-
escape << ch << read_escape
|
1507
|
-
end
|
1508
|
-
else
|
1509
|
-
escape << ch
|
1510
|
-
|
1511
|
-
# other characters
|
1512
|
-
end
|
1513
|
-
|
1514
|
-
escape
|
1515
|
-
end
|
1516
|
-
|
1517
|
-
# :startdoc:
|
1518
|
-
|
1519
|
-
end
|
1520
|
-
|
1521
|
-
#RDoc::RubyLex.debug_level = 1
|