bitclust-core 1.7.0 → 1.9.0
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.
- checksums.yaml +4 -4
- data/data/bitclust/template/class-index +0 -1
- data/data/bitclust/template.epub/class +5 -5
- data/data/bitclust/template.epub/class-index +0 -1
- data/data/bitclust/template.epub/contents +7 -4
- data/data/bitclust/template.epub/layout +4 -4
- data/data/bitclust/template.offline/class-index +0 -1
- data/lib/bitclust/generators/epub.rb +69 -5
- data/lib/bitclust/irb.rb +14 -8
- data/lib/bitclust/markdown_bridge.rb +11 -6
- data/lib/bitclust/markdown_tree.rb +128 -11
- data/lib/bitclust/methoddatabase.rb +15 -4
- data/lib/bitclust/nameutils.rb +13 -0
- data/lib/bitclust/preprocessor.rb +0 -36
- data/lib/bitclust/remote.rb +405 -0
- data/lib/bitclust/runner.rb +5 -10
- data/lib/bitclust/screen.rb +2 -1
- data/lib/bitclust/searcher.rb +43 -24
- data/lib/bitclust/subcommands/chm_command.rb +1 -1
- data/lib/bitclust/subcommands/epub_command.rb +2 -2
- data/lib/bitclust/subcommands/extract_command.rb +7 -0
- data/lib/bitclust/subcommands/htmlfile_command.rb +73 -1
- data/lib/bitclust/subcommands/methods_command.rb +5 -28
- data/lib/bitclust/subcommands/query_command.rb +1 -0
- data/lib/bitclust/subcommands/server_command.rb +21 -10
- data/lib/bitclust/subcommands/setup_command.rb +28 -10
- data/lib/bitclust/syntax_highlighter.rb +65 -4
- data/lib/bitclust/user_dirs.rb +62 -0
- data/lib/bitclust/version.rb +1 -1
- data/test/test_chm_command.rb +22 -0
- data/test/test_epub_command.rb +60 -0
- data/test/test_epub_generator.rb +330 -0
- data/test/test_extract_command.rb +34 -0
- data/test/test_htmlfile_command.rb +211 -0
- data/test/test_irb_plugin.rb +100 -6
- data/test/test_markdown_bridge.rb +35 -0
- data/test/test_markdown_tree.rb +144 -0
- data/test/test_mdparser.rb +39 -0
- data/test/test_methods_command.rb +32 -0
- data/test/test_opensearchdescription_screen.rb +39 -0
- data/test/test_query_command.rb +30 -0
- data/test/test_remote.rb +374 -0
- data/test/test_runner.rb +61 -1
- data/test/test_searcher.rb +63 -0
- data/test/test_server_command.rb +41 -0
- data/test/test_setup_command.rb +143 -0
- data/test/test_syntax_highlighter.rb +124 -0
- data/test/test_user_dirs.rb +62 -0
- metadata +39 -2
- data/lib/bitclust/ridatabase.rb +0 -359
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c926bbf2b56a9b2553e97487db023f2ac8aac329ab1af22d2f8b56fa09afc8d5
|
|
4
|
+
data.tar.gz: 072201ad18fc53aac71ac620388018469fe618299f0af50bc5abf0a553e596ab
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 419ddb1ee1e46be729fc87e957a9aebd56a490810f8134b26617654986b77a5f1aef9b0599ecb7b6c9342dcb57c1417510cf93d9a7169614b36f195f67bd7d43
|
|
7
|
+
data.tar.gz: d683d676ce9daa86aa4544730f38898eb21ffdcd4e604711b01db22416531fe080685e5b6eddb533cafa8c71b135f7453f20fd42b58771f86faf762a8d7b602e
|
|
@@ -24,20 +24,20 @@
|
|
|
24
24
|
<% end %>
|
|
25
25
|
|
|
26
26
|
<% unless @entry.extended.empty? %>
|
|
27
|
-
<br
|
|
27
|
+
<br />extend: <%= @entry.extended.map {|c| class_link(c.name) }.join(', ') %>
|
|
28
28
|
<% end %>
|
|
29
29
|
<% unless @entry.aliases.empty? %>
|
|
30
|
-
<br
|
|
30
|
+
<br />aliases: <%=h @entry.aliases.map{|c| c.name}.join(', ') %>
|
|
31
31
|
<% end %>
|
|
32
32
|
<% unless @entry.dynamically_included.empty? %>
|
|
33
|
-
<br
|
|
33
|
+
<br /> dynamic include:
|
|
34
34
|
<%= @entry.dynamically_included.map{|m|
|
|
35
35
|
class_link(m.name) + " (by " + library_link(m.library.name) + ")"
|
|
36
36
|
}.join(", ")
|
|
37
37
|
%>
|
|
38
38
|
<% end %>
|
|
39
39
|
<% unless @entry.dynamically_extended.empty? %>
|
|
40
|
-
<br
|
|
40
|
+
<br /> dynamic extend:
|
|
41
41
|
<%= @entry.dynamically_extended.map{|m|
|
|
42
42
|
class_link(m.name) + " (by " + library_link(m.library.name) + ")"
|
|
43
43
|
}.join(", ")
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
entries.each do |m|
|
|
73
73
|
m.names.each do |mname|
|
|
74
74
|
%>
|
|
75
|
-
<a href="#<%= m.index_id %>"><%= "#{prefix}#{mname}" %></a>
|
|
75
|
+
<a href="#<%= m.index_id %>"><%= escape_html "#{prefix}#{mname}" %></a>
|
|
76
76
|
<%
|
|
77
77
|
end
|
|
78
78
|
end
|
|
@@ -8,15 +8,18 @@
|
|
|
8
8
|
</metadata>
|
|
9
9
|
<manifest>
|
|
10
10
|
<item id="toc" properties="nav" href="nav.xhtml" media-type="application/xhtml+xml" />
|
|
11
|
-
<item id="index" href="OEBPS/doc/index.
|
|
12
|
-
<%
|
|
13
|
-
<item id="<%= item[:id] %>" href="<%= item[:path] %>" media-type="
|
|
11
|
+
<item id="index" href="OEBPS/doc/index.xhtml" media-type="application/xhtml+xml" />
|
|
12
|
+
<% class_items.each do |item| -%>
|
|
13
|
+
<item id="<%= item[:id] %>" href="<%= item[:path] %>" media-type="<%= item[:media_type] %>" />
|
|
14
|
+
<% end -%>
|
|
15
|
+
<% other_items.each do |item| -%>
|
|
16
|
+
<item id="<%= item[:id] %>" href="<%= item[:path] %>" media-type="<%= item[:media_type] %>" />
|
|
14
17
|
<% end -%>
|
|
15
18
|
</manifest>
|
|
16
19
|
<spine>
|
|
17
20
|
<itemref idref="toc" />
|
|
18
21
|
<itemref idref="index" />
|
|
19
|
-
<%
|
|
22
|
+
<% class_items.each do |item| -%>
|
|
20
23
|
<itemref idref="<%= item[:id] %>" />
|
|
21
24
|
<% end -%>
|
|
22
25
|
</spine>
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
<!DOCTYPE html>
|
|
3
3
|
<html lang="ja-JP">
|
|
4
4
|
<head>
|
|
5
|
-
<meta http-equiv="Content-Type" content="text/html; charset=<%=h charset() %>"
|
|
6
|
-
<meta http-equiv="Content-Language" content="ja-JP"
|
|
7
|
-
<link rel="stylesheet" type="text/css" href="<%=h css_url() %>"
|
|
8
|
-
<link rel="icon" type="image/png" href="<%=h favicon_url() %>"
|
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=<%=h charset() %>" />
|
|
6
|
+
<meta http-equiv="Content-Language" content="ja-JP" />
|
|
7
|
+
<link rel="stylesheet" type="text/css" href="<%=h css_url() %>" />
|
|
8
|
+
<link rel="icon" type="image/png" href="<%=h favicon_url() %>" />
|
|
9
9
|
<title><%=h @title %> (Ruby <%=h ruby_version %>)</title>
|
|
10
10
|
</head>
|
|
11
11
|
<body>
|
|
@@ -24,11 +24,17 @@ module BitClust
|
|
|
24
24
|
|
|
25
25
|
CONTENTS_DIR_NAME = 'OEBPS'
|
|
26
26
|
|
|
27
|
+
# StatichtmlCommand が出力ルートに書く 2 行のリダイレクト用スタブ
|
|
28
|
+
# (<meta http-equiv="refresh"> と <a>)。ルート要素が無く XHTML として
|
|
29
|
+
# 整形式でない。EPUB の入口は nav.xhtml なのでスタブは同梱せず削除する
|
|
30
|
+
INDEX_STUB_NAME = 'index.xhtml'
|
|
31
|
+
|
|
27
32
|
def generate
|
|
28
33
|
make_epub_directory do |epub_directory|
|
|
29
34
|
contents_directory = epub_directory + CONTENTS_DIR_NAME
|
|
30
35
|
copy_static_files(epub_directory)
|
|
31
36
|
generate_xhtml_files(contents_directory)
|
|
37
|
+
remove_index_stub(contents_directory)
|
|
32
38
|
generate_contents_opf(epub_directory)
|
|
33
39
|
pack_epub(epub_directory)
|
|
34
40
|
end
|
|
@@ -71,15 +77,45 @@ module BitClust
|
|
|
71
77
|
cmd.exec(argv, options)
|
|
72
78
|
end
|
|
73
79
|
|
|
80
|
+
# manifest に id="index" で固定的に載せる doc/index ページの href
|
|
81
|
+
# (epub_directory 相対)。other_items からは除いて二重掲載を避ける
|
|
82
|
+
INDEX_PATH = Pathname.new("#{CONTENTS_DIR_NAME}/doc/index.xhtml")
|
|
83
|
+
|
|
84
|
+
MEDIA_TYPES = {
|
|
85
|
+
'.xhtml' => 'application/xhtml+xml',
|
|
86
|
+
'.css' => 'text/css',
|
|
87
|
+
'.js' => 'application/javascript',
|
|
88
|
+
'.png' => 'image/png',
|
|
89
|
+
'.jpg' => 'image/jpeg',
|
|
90
|
+
'.jpeg' => 'image/jpeg',
|
|
91
|
+
'.gif' => 'image/gif',
|
|
92
|
+
'.svg' => 'image/svg+xml',
|
|
93
|
+
}.freeze
|
|
94
|
+
|
|
74
95
|
def generate_contents_opf(epub_directory)
|
|
75
|
-
|
|
96
|
+
class_items = [] #: Array[{:id => String, :path => Pathname, :media_type => String}]
|
|
76
97
|
glob_relative_path(epub_directory, "#{CONTENTS_DIR_NAME}/class/*.xhtml").each do |path|
|
|
77
|
-
|
|
78
|
-
:id => decodename_package(path.basename(".*").to_s),
|
|
79
|
-
:path => path
|
|
98
|
+
class_items << {
|
|
99
|
+
:id => "class-#{decodename_package(path.basename(".*").to_s)}",
|
|
100
|
+
:path => path,
|
|
101
|
+
:media_type => media_type_for(path),
|
|
80
102
|
}
|
|
81
103
|
end
|
|
82
|
-
|
|
104
|
+
class_items.sort_by!{|item| item[:path] }
|
|
105
|
+
|
|
106
|
+
excluded_paths = class_items.map{|item| item[:path] } + [INDEX_PATH]
|
|
107
|
+
other_items = [] #: Array[{:id => String, :path => Pathname, :media_type => String}]
|
|
108
|
+
oebps_file_paths(epub_directory).each do |path|
|
|
109
|
+
next if excluded_paths.include?(path)
|
|
110
|
+
|
|
111
|
+
other_items << {
|
|
112
|
+
:id => manifest_id_for(path),
|
|
113
|
+
:path => path,
|
|
114
|
+
:media_type => media_type_for(path),
|
|
115
|
+
}
|
|
116
|
+
end
|
|
117
|
+
other_items.sort_by!{|item| item[:path] }
|
|
118
|
+
|
|
83
119
|
template = (@templatedir + "contents").read
|
|
84
120
|
if ::ERB.instance_method(:initialize).parameters.last.first == :key
|
|
85
121
|
erb = ::ERB.new(template, trim_mode: '-')
|
|
@@ -92,6 +128,34 @@ module BitClust
|
|
|
92
128
|
end
|
|
93
129
|
end
|
|
94
130
|
|
|
131
|
+
# OEBPS 配下の通常ファイル全部(method/library/doc/function ページと、
|
|
132
|
+
# statichtml がコピーした CSS・画像)を epub_directory 相対で返す。
|
|
133
|
+
# class ページも含む(呼び出し側で class_items と重複排除する)
|
|
134
|
+
def oebps_file_paths(epub_directory)
|
|
135
|
+
glob_relative_path(epub_directory, "#{CONTENTS_DIR_NAME}/**/*").select do |relative_path|
|
|
136
|
+
(epub_directory + relative_path).file?
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def media_type_for(path)
|
|
141
|
+
MEDIA_TYPES[path.extname.downcase] || 'application/octet-stream'
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
# class ページ以外("OEBPS/method/Array/i/each.xhtml" 等)の manifest
|
|
145
|
+
# item id。XML の NCName として妥当で一意になるよう、使えない文字は "-" に
|
|
146
|
+
# 置き換え、ディレクトリ境界は "--" にして encodename 由来の "-" と
|
|
147
|
+
# 区別する
|
|
148
|
+
def manifest_id_for(path)
|
|
149
|
+
relative = path.to_s.sub(%r{\A#{Regexp.escape(CONTENTS_DIR_NAME)}/}, "")
|
|
150
|
+
segments = relative.split("/").map{|segment| segment.gsub(/[^A-Za-z0-9_.-]/, "-") }
|
|
151
|
+
"item-#{segments.join('--')}"
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def remove_index_stub(contents_directory)
|
|
155
|
+
stub_path = contents_directory + INDEX_STUB_NAME
|
|
156
|
+
FileUtils.rm_f(stub_path.to_s, :verbose => @verbose) if stub_path.file?
|
|
157
|
+
end
|
|
158
|
+
|
|
95
159
|
def pack_epub(epub_directory)
|
|
96
160
|
epub_filename = @outputdir + @filename
|
|
97
161
|
Dir.chdir(epub_directory.to_s) do
|
data/lib/bitclust/irb.rb
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
#
|
|
3
3
|
# irb からるりま(Ruby リファレンスマニュアル)を引く refe コマンド。
|
|
4
4
|
# ~/.irbrc に `require "bitclust/irb"` と書くと irb に `refe` コマンドが
|
|
5
|
-
# 登録される。検索対象の DB は refe コマンドと同じ場所
|
|
6
|
-
#
|
|
5
|
+
# 登録される。検索対象の DB は refe コマンドと同じ場所(bitclust setup が
|
|
6
|
+
# 作る設定ファイル)から探し、DB が無ければ docs.ruby-lang.org の検索索引と
|
|
7
|
+
# Markdown 配信から取得する(BitClust::Remote)。
|
|
7
8
|
|
|
8
9
|
require 'stringio'
|
|
9
10
|
require 'bitclust'
|
|
@@ -18,15 +19,18 @@ module BitClust
|
|
|
18
19
|
refe String#gsub インスタンスメソッド
|
|
19
20
|
refe Array.new 特異メソッド
|
|
20
21
|
refe Comparable クラス・モジュール
|
|
21
|
-
refe
|
|
22
|
+
refe each 名前だけでの検索(該当が複数なら一覧)
|
|
22
23
|
|
|
23
|
-
DB が無い場合は
|
|
24
|
+
DB が無い場合は docs.ruby-lang.org から取得します(1 日キャッシュ)。
|
|
25
|
+
`bitclust setup` で DB を作ると手元で検索できます。
|
|
24
26
|
USAGE
|
|
25
27
|
|
|
26
28
|
# pattern を検索して整形済みテキストを io へ書く。db が nil なら
|
|
27
|
-
#
|
|
28
|
-
#
|
|
29
|
-
|
|
29
|
+
# 既定の場所から探し、そこにも無ければ remote(省略時は
|
|
30
|
+
# Remote.default。nil ならフォールバックしない)で検索する。
|
|
31
|
+
# 検索の失敗は例外にせず io へメッセージを書く(irb セッションを
|
|
32
|
+
# 止めないため)
|
|
33
|
+
def self.lookup(pattern, io: $stdout, db: nil, remote: Remote.default)
|
|
30
34
|
words = pattern.to_s.split
|
|
31
35
|
if words.empty?
|
|
32
36
|
io.puts USAGE
|
|
@@ -35,7 +39,9 @@ module BitClust
|
|
|
35
39
|
view = TerminalView.new(Plain.new,
|
|
36
40
|
{ describe_all: false, line: false, encoding: nil },
|
|
37
41
|
io: io)
|
|
38
|
-
Searcher.new
|
|
42
|
+
searcher = Searcher.new
|
|
43
|
+
searcher.remote = remote
|
|
44
|
+
searcher.run_query(db, words, view)
|
|
39
45
|
rescue BitClust::UserError => err
|
|
40
46
|
io.puts err.message
|
|
41
47
|
end
|
|
@@ -134,12 +134,17 @@ module BitClust
|
|
|
134
134
|
reopen_only = members[path][:kinds].all? { |kind, _| %w[reopen redefine].include?(kind) }
|
|
135
135
|
[reopen_only ? 1 : 0, path]
|
|
136
136
|
end
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
137
|
+
# 同じライブラリへの membership が複数ある(#%version A...B の #%else =
|
|
138
|
+
# A 未満と B 以上)ときは、それぞれのゲートで include サイトを繰り返す
|
|
139
|
+
"\n" + sorted.flat_map { |path|
|
|
140
|
+
members[path][:memberships].select { |mm| mm[:library] == libname }.map { |m|
|
|
141
|
+
inc = "\#@include(#{relative(emitted[path], base)})\n"
|
|
142
|
+
inc = "\#@since #{m[:since]}\n#{inc}\#@end\n" if m[:since]
|
|
143
|
+
inc = "\#@until #{m[:until]}\n#{inc}\#@end\n" if m[:until]
|
|
144
|
+
inc = "\#@if (version == \"#{m[:version]}\")\n#{inc}\#@end\n" if m[:version]
|
|
145
|
+
(m[:except] || []).each { |x| inc = "\#@if (version != \"#{x}\")\n#{inc}\#@end\n" }
|
|
146
|
+
inc
|
|
147
|
+
}
|
|
143
148
|
}.join
|
|
144
149
|
end
|
|
145
150
|
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'bitclust/exception'
|
|
4
|
+
require 'bitclust/preprocessor'
|
|
5
|
+
|
|
3
6
|
module BitClust
|
|
4
7
|
# 新パイプラインのファイル発見(MARKUP_SPEC §1.1)。
|
|
5
8
|
#
|
|
@@ -29,6 +32,11 @@ module BitClust
|
|
|
29
32
|
new(root).scan
|
|
30
33
|
end
|
|
31
34
|
|
|
35
|
+
# 1 ファイル分の front matter と本文の情報(scan が各ファイルで読むもの)
|
|
36
|
+
def self.file_info(path)
|
|
37
|
+
new(File.dirname(path)).file_info(File.basename(path))
|
|
38
|
+
end
|
|
39
|
+
|
|
32
40
|
attr_reader :libraries, :entities, :fragments, :warnings
|
|
33
41
|
|
|
34
42
|
def initialize(root)
|
|
@@ -84,6 +92,11 @@ module BitClust
|
|
|
84
92
|
self
|
|
85
93
|
end
|
|
86
94
|
|
|
95
|
+
# root 相対の path を 1 ファイルだけ読む
|
|
96
|
+
def file_info(path)
|
|
97
|
+
parse_file(path)
|
|
98
|
+
end
|
|
99
|
+
|
|
87
100
|
private
|
|
88
101
|
|
|
89
102
|
def validate(path, info)
|
|
@@ -116,36 +129,45 @@ module BitClust
|
|
|
116
129
|
if lines[0] =~ /\A---\s*\z/
|
|
117
130
|
i = 1
|
|
118
131
|
in_library_block = false
|
|
119
|
-
gate_stack = [] #: Array[
|
|
132
|
+
gate_stack = [] #: Array[list_gate]
|
|
120
133
|
while i < lines.length && lines[i] !~ /\A---\s*\z/
|
|
121
134
|
line = lines[i]
|
|
122
135
|
if in_library_block
|
|
123
|
-
# 多重所属のゲート付きリスト(MARKUP_SPEC §1.2)。
|
|
136
|
+
# 多重所属のゲート付きリスト(MARKUP_SPEC §1.2.1)。
|
|
124
137
|
# 項目は積まれているゲートをすべてまとって membership になる
|
|
125
138
|
case line
|
|
126
139
|
when /\A\s+- (\S+)/
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
140
|
+
info[:memberships].concat gated_memberships($1 || raise, gate_stack)
|
|
141
|
+
i += 1; next
|
|
142
|
+
when /\A\#[@%]\#/ # 前処理コメント(Preprocessor と同じく無視)
|
|
143
|
+
i += 1; next
|
|
144
|
+
when /\A\#[@%]/
|
|
145
|
+
list_directive(line, gate_stack, path, i + 1)
|
|
146
|
+
i += 1; next
|
|
147
|
+
when /\A\s+\#[@%]/
|
|
148
|
+
# 列 0 でない #% 行は Preprocessor でも指令にならない(YAML の
|
|
149
|
+
# コメント扱い)。ゲートが無音で無視されないようエラーにする
|
|
150
|
+
raise ParseError, "#{path}:#{i + 1}: preprocessor directive must start at column 0: #{line.strip}"
|
|
151
|
+
when /\A\s+\#/ # YAML コメント
|
|
130
152
|
i += 1; next
|
|
131
|
-
when /\A\#[@%]since\s+(\S+)/ then gate_stack.push([:since, $1]); i += 1; next
|
|
132
|
-
when /\A\#[@%]until\s+(\S+)/ then gate_stack.push([:until, $1]); i += 1; next
|
|
133
|
-
when /\A\#[@%]end\s*\z/ then gate_stack.pop; i += 1; next
|
|
134
153
|
else
|
|
135
|
-
|
|
154
|
+
# ブロック終端。この行は通常キーとして処理
|
|
155
|
+
list_end(gate_stack, path, i + 1)
|
|
156
|
+
in_library_block = false
|
|
136
157
|
end
|
|
137
158
|
end
|
|
138
159
|
case line
|
|
139
160
|
when /\Atype:\s*library\s*\z/ then info[:library_file] = true
|
|
140
161
|
when /\Aname:\s*(\S+)/ then info[:name] = $1
|
|
141
|
-
when /\Alibrary:\s*\z/ then in_library_block = true; gate_stack = [] #: Array[
|
|
142
|
-
when /\Alibrary:\s*(\S+)/ then info[:memberships] << { library: $1 }
|
|
162
|
+
when /\Alibrary:\s*\z/ then in_library_block = true; gate_stack = [] #: Array[list_gate]
|
|
163
|
+
when /\Alibrary:\s*(\S+)/ then info[:memberships] << { library: $1 || raise }
|
|
143
164
|
when /\Asince:\s*"?([^"\s]+)"?/ then info[:since] = $1
|
|
144
165
|
when /\Auntil:\s*"?([^"\s]+)"?/ then info[:until] = $1
|
|
145
166
|
when RELATION_KEY_RE then info[:front_matter_relations] = true
|
|
146
167
|
end
|
|
147
168
|
i += 1
|
|
148
169
|
end
|
|
170
|
+
list_end(gate_stack, path, i + 1) if in_library_block
|
|
149
171
|
i += 1
|
|
150
172
|
end
|
|
151
173
|
info[:library] = info[:memberships].dig(0, :library)
|
|
@@ -190,6 +212,101 @@ module BitClust
|
|
|
190
212
|
info
|
|
191
213
|
end
|
|
192
214
|
|
|
215
|
+
# --- front matter ゲート付きリストのディレクティブ ---
|
|
216
|
+
# 本文側 Preprocessor と同じ集合のうち #%since/#%until/#%version/#%else/#%end
|
|
217
|
+
# を解釈する。#%if(任意の条件式)は非対応。解釈できない行は無音で
|
|
218
|
+
# リストを打ち切らず ParseError にする(本文側の unknown directive と同じ扱い)。
|
|
219
|
+
#
|
|
220
|
+
# ゲート1段は clause の選言。clause は since(以上)/until(未満)/
|
|
221
|
+
# version(その版のみ)/except(その版以外)の交差で、#%else は直前ゲートの
|
|
222
|
+
# 補集合(#%version A...B なら「A 未満」または「B 以上」の 2 clause)
|
|
223
|
+
|
|
224
|
+
def list_directive(line, stack, path, lineno)
|
|
225
|
+
err = ->(msg) { raise ParseError, "#{path}:#{lineno}: #{msg}: #{line.strip}" }
|
|
226
|
+
case line
|
|
227
|
+
when /\A\#[@%](since|until)\b(.*)/
|
|
228
|
+
kind, raw = $1, $2 || raise
|
|
229
|
+
ver = version_literal(raw.strip) or err.("wrong conditional expr")
|
|
230
|
+
clause = kind == 'since' ? { since: ver } : { until: ver } #: gate_clause
|
|
231
|
+
stack.push({ clauses: [clause], elsed: false })
|
|
232
|
+
when /\A\#[@%]version\b(.*)/
|
|
233
|
+
clause = version_range(($1 || raise).strip) or
|
|
234
|
+
err.("wrong version range (expected V / A...B / A... / ...B)")
|
|
235
|
+
stack.push({ clauses: [clause], elsed: false })
|
|
236
|
+
when /\A\#[@%]if\b/
|
|
237
|
+
err.("#%if is not supported in front matter library list (use #%since/#%until/#%version/#%else)")
|
|
238
|
+
when /\A\#[@%]else\s*\z/
|
|
239
|
+
gate = stack.last or err.("no matching #%since/#%until/#%version")
|
|
240
|
+
err.("duplicate #%else") if gate[:elsed]
|
|
241
|
+
stack[-1] = { clauses: gate[:clauses].flat_map { |c| complement(c) }, elsed: true }
|
|
242
|
+
when /\A\#[@%]end\s*\z/
|
|
243
|
+
stack.pop or err.("no matching #%since/#%until/#%version")
|
|
244
|
+
else
|
|
245
|
+
err.("unknown preprocessor directive")
|
|
246
|
+
end
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
def list_end(stack, path, lineno)
|
|
250
|
+
return if stack.empty?
|
|
251
|
+
raise ParseError, "#{path}:#{lineno}: unterminated #%since/#%until/#%version in front matter library list"
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
VERSION_LITERAL = Preprocessor::VERSION_LITERAL
|
|
255
|
+
|
|
256
|
+
def version_literal(raw)
|
|
257
|
+
raw =~ /\A#{VERSION_LITERAL}\z/o ? ($1 || $2) : nil
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
# #%version の版範囲(Preprocessor#build_cond_by_range と同じ記法)
|
|
261
|
+
def version_range(raw)
|
|
262
|
+
case raw
|
|
263
|
+
when /\A#{VERSION_LITERAL}\.\.\.#{VERSION_LITERAL}\z/o
|
|
264
|
+
{ since: $1 || $2 || raise, until: $3 || $4 || raise }
|
|
265
|
+
when /\A#{VERSION_LITERAL}\.\.\.\z/o then { since: $1 || $2 || raise }
|
|
266
|
+
when /\A\.\.\.#{VERSION_LITERAL}\z/o then { until: $1 || $2 || raise }
|
|
267
|
+
when /\A#{VERSION_LITERAL}\z/o then { version: $1 || $2 || raise }
|
|
268
|
+
end
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
def complement(clause)
|
|
272
|
+
return [{ except: [clause[:version] || raise] }] if clause[:version]
|
|
273
|
+
alts = [] #: Array[gate_clause]
|
|
274
|
+
alts << { until: clause[:since] || raise } if clause[:since]
|
|
275
|
+
alts << { since: clause[:until] || raise } if clause[:until]
|
|
276
|
+
alts
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
# 積まれた全ゲートの交差。各段が選言なので組合せごとに1つの membership
|
|
280
|
+
# (矛盾する組合せ = 異なる単一版どうしは捨てる)
|
|
281
|
+
def gated_memberships(library, stack)
|
|
282
|
+
seed = [{}] #: Array[gate_clause]
|
|
283
|
+
combos = stack.inject(seed) { |acc, gate|
|
|
284
|
+
acc.product(gate[:clauses]).filter_map { |a, b| intersect(a, b) }
|
|
285
|
+
}
|
|
286
|
+
combos.map { |c|
|
|
287
|
+
m = { library: library } #: membership
|
|
288
|
+
m[:since] = c[:since] || raise if c[:since]
|
|
289
|
+
m[:until] = c[:until] || raise if c[:until]
|
|
290
|
+
m[:version] = c[:version] || raise if c[:version]
|
|
291
|
+
m[:except] = c[:except] || raise if c[:except]
|
|
292
|
+
m
|
|
293
|
+
}
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
def intersect(a, b)
|
|
297
|
+
r = {} #: gate_clause
|
|
298
|
+
sinces = [a[:since], b[:since]].compact
|
|
299
|
+
r[:since] = sinces.max_by { |v| Gem::Version.new(v) } || raise unless sinces.empty?
|
|
300
|
+
untils = [a[:until], b[:until]].compact
|
|
301
|
+
r[:until] = untils.min_by { |v| Gem::Version.new(v) } || raise unless untils.empty?
|
|
302
|
+
versions = [a[:version], b[:version]].compact.uniq
|
|
303
|
+
return nil if versions.size > 1
|
|
304
|
+
r[:version] = versions.first if versions.size == 1
|
|
305
|
+
excepts = (a[:except] || []) + (b[:except] || [])
|
|
306
|
+
r[:except] = excepts.uniq unless excepts.empty?
|
|
307
|
+
r
|
|
308
|
+
end
|
|
309
|
+
|
|
193
310
|
# 大文字小文字のみが異なる名前は macOS/Windows の case-insensitive FS で
|
|
194
311
|
# チェックアウト不能になるため、衝突を警告する(途中のディレクトリ名も見る)
|
|
195
312
|
def warn_case_collisions(files)
|
|
@@ -186,7 +186,7 @@ module BitClust
|
|
|
186
186
|
# membership を持つライブラリだけがメンバーとして取り込む
|
|
187
187
|
members = tree.entities.select { |_, e|
|
|
188
188
|
e[:memberships].any? { |m|
|
|
189
|
-
m[:library] == libname &&
|
|
189
|
+
m[:library] == libname && md_gate_covers?(version, m)
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
192
|
sorted = members.keys.sort_by { |path|
|
|
@@ -211,12 +211,23 @@ module BitClust
|
|
|
211
211
|
# since は「その版以降」、until は「その版未満」(ブリッジの
|
|
212
212
|
# #@since/#@until ラッパーと同じ意味論)
|
|
213
213
|
def md_version_covers?(version, since_version, until_version)
|
|
214
|
+
gate = {} #: MarkdownTree::gate_clause
|
|
215
|
+
gate[:since] = since_version if since_version
|
|
216
|
+
gate[:until] = until_version if until_version
|
|
217
|
+
md_gate_covers?(version, gate)
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
# membership のゲート(MarkdownTree の since/until/version/except)がこの版を
|
|
221
|
+
# 含むか。version は「その版のみ」、except は「その版以外」(#%version V と
|
|
222
|
+
# その #%else)。比較は Gem::Version なので 3.4 と 3.4.0 は同じ版
|
|
223
|
+
def md_gate_covers?(version, gate)
|
|
214
224
|
v = Gem::Version.new(version)
|
|
215
|
-
return false if
|
|
216
|
-
return false if
|
|
225
|
+
return false if (s = gate[:since]) && v < Gem::Version.new(s)
|
|
226
|
+
return false if (u = gate[:until]) && v >= Gem::Version.new(u)
|
|
227
|
+
return false if (only = gate[:version]) && v != Gem::Version.new(only)
|
|
228
|
+
return false if (except = gate[:except]) && except.any? { |x| v == Gem::Version.new(x) }
|
|
217
229
|
true
|
|
218
230
|
end
|
|
219
|
-
private :md_version_covers?
|
|
220
231
|
|
|
221
232
|
def refs
|
|
222
233
|
@refs ||= RefsDatabase.load(realpath('refs'))
|
data/lib/bitclust/nameutils.rb
CHANGED
|
@@ -222,6 +222,19 @@ module BitClust
|
|
|
222
222
|
Gem::Version.new(version) >= Gem::Version.new('4.0') ? '?.' : mark
|
|
223
223
|
end
|
|
224
224
|
|
|
225
|
+
# refe の検索パターン("String#gsub"・"Array.new"・"Kernel.#printf" や
|
|
226
|
+
# "," を "#" の代用にした "String,gsub" など)を [クラス名, typemark,
|
|
227
|
+
# メソッド名] に分ける。区切りは反転文字列上で探す。"?." は 4.0 以降の
|
|
228
|
+
# module function の表示形式(反転すると ".?")で、内部表記の ".#" に
|
|
229
|
+
# 正規化する
|
|
230
|
+
def parse_method_spec_pattern(pat)
|
|
231
|
+
_m, _t, _c = pat.reverse.split(/([\#,]\.|\.[\#,]|\.\?|[\#\.\,])/, 2)
|
|
232
|
+
c = (_c || raise).reverse
|
|
233
|
+
t = (_t || raise).tr(',', '#').sub(/\#\.|\.\?/, '.#')
|
|
234
|
+
m = (_m || raise).reverse
|
|
235
|
+
return c, t, m
|
|
236
|
+
end
|
|
237
|
+
|
|
225
238
|
def functionname?(n)
|
|
226
239
|
/\A\w+\z/ =~ n ? true : false
|
|
227
240
|
end
|
|
@@ -343,40 +343,4 @@ module BitClust
|
|
|
343
343
|
end
|
|
344
344
|
end
|
|
345
345
|
end
|
|
346
|
-
|
|
347
|
-
# Used by tools/stattodo.rb
|
|
348
|
-
class LineCollector < LineFilter
|
|
349
|
-
|
|
350
|
-
def LineCollector.process(path)
|
|
351
|
-
fopen(path) {|f|
|
|
352
|
-
return wrap(f).to_a
|
|
353
|
-
}
|
|
354
|
-
end
|
|
355
|
-
|
|
356
|
-
def LineCollector.wrap(f)
|
|
357
|
-
new(LineStream.new(f))
|
|
358
|
-
end
|
|
359
|
-
|
|
360
|
-
private
|
|
361
|
-
|
|
362
|
-
def next_line(f)
|
|
363
|
-
while line = f.gets
|
|
364
|
-
if /\A\#[@%]include\s*\((.*?)\)/ =~ line
|
|
365
|
-
begin
|
|
366
|
-
file = ($1 || raise).strip
|
|
367
|
-
basedir = File.dirname(line.location.file || raise)
|
|
368
|
-
@buf.concat LineCollector.process("#{basedir}/#{file}")
|
|
369
|
-
rescue Errno::ENOENT => _err
|
|
370
|
-
raise WrongInclude, "#{line.location}: \#@include'ed file not exist: #{file}"
|
|
371
|
-
end
|
|
372
|
-
else
|
|
373
|
-
@buf.push line
|
|
374
|
-
end
|
|
375
|
-
break unless @buf.empty?
|
|
376
|
-
end
|
|
377
|
-
@buf.shift
|
|
378
|
-
end
|
|
379
|
-
|
|
380
|
-
end
|
|
381
|
-
|
|
382
346
|
end
|