asciidoctor-sail 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.adoc +21 -0
- data/lib/asciidoctor-sail/highlighter.rb +3 -2
- data/lib/asciidoctor-sail/macros.rb +45 -22
- data/lib/asciidoctor-sail/sources.rb +4 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64902e55e5a314105d5cf7b74686c7791c4ba72b0778f2048c51e3c0a32522f5
|
4
|
+
data.tar.gz: ec176896d3dab99ae5ceaa3fb64b88cf6dc2fadc004010edecb4e85e984c1846
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 693ece551f08ebe8385f30b2e33dc7d2dc1d8dd6b3366a4da37d5f537b4ba15c4c37e3525ebf2929fee7f0785097628e40e9f779a1ec1268ff5f44e702a5610e
|
7
|
+
data.tar.gz: b403b703dbfb130a3938c50df22c3f344031007cda868784c7af3ab4ff60a03453c475e0ce127703b4e73c5bd0c0624d4ea7bc82c04a3a4133980be4cc4e4c6d
|
data/README.adoc
CHANGED
@@ -5,3 +5,24 @@ https://github.com/rems-project/sail[Sail] ISA specifications into
|
|
5
5
|
Asciidoc documents, primarily aimed at supporting documentation for
|
6
6
|
RISC-V extensions using the
|
7
7
|
https://github.com/riscv/sail-riscv[sail-riscv] model.
|
8
|
+
|
9
|
+
== Installation
|
10
|
+
|
11
|
+
asciidoctor-sail is published on https://rubygems.org[rubygems], so it can be installed with gem install:
|
12
|
+
|
13
|
+
[source,sh]
|
14
|
+
----
|
15
|
+
gem install asciidoctor-sail
|
16
|
+
----
|
17
|
+
|
18
|
+
The requirements are simply asciidoctor itself, or asciidoctor and
|
19
|
+
asciidoctor-diagram if encoding diagrams are generated (which also
|
20
|
+
require the https://wavedrom.com[WaveDrom] editor to be installed).
|
21
|
+
asciidoctor-pdf is also supported for PDF generation.
|
22
|
+
|
23
|
+
== Documentation
|
24
|
+
|
25
|
+
Documentation is available as a PDF
|
26
|
+
https://github.com/Alasdair/asciidoctor-sail/blob/master/doc/built/sail_to_asciidoc.pdf[here]. The
|
27
|
+
PDF is itself built with asciidoctor-pdf and asciidoctor-sail, using
|
28
|
+
the various examples in `doc/examples`.
|
@@ -32,7 +32,7 @@ class SailLexer < Rouge::RegexLexer
|
|
32
32
|
@keywords ||= Set.new %w[
|
33
33
|
and as by match clause operator default end enum else forall foreach function mapping overload throw
|
34
34
|
try catch if in let var ref pure monadic register return scattered struct then type union newtype with
|
35
|
-
val outcome instantiation impl repeat until while do bitfield forwards backwards to
|
35
|
+
val outcome instantiation impl repeat until while do bitfield forwards backwards to from
|
36
36
|
]
|
37
37
|
end
|
38
38
|
|
@@ -126,8 +126,9 @@ class SailLexer < Rouge::RegexLexer
|
|
126
126
|
end
|
127
127
|
|
128
128
|
state :attribute do
|
129
|
+
rule(/\[/, Comment::Preproc, :attribute)
|
129
130
|
rule(/\]/, Comment::Preproc, :pop!)
|
130
|
-
rule(/[^\]]+/, Comment::Preproc)
|
131
|
+
rule(/[^\[\]]+/, Comment::Preproc)
|
131
132
|
end
|
132
133
|
|
133
134
|
state :pragma do
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'set'
|
4
|
+
|
3
5
|
module Asciidoctor
|
4
6
|
module Sail
|
5
7
|
module SourceMacro
|
@@ -16,7 +18,7 @@ module Asciidoctor
|
|
16
18
|
raise "#{PLUGIN_NAME}: Version does not match version in source map #{source_map}"
|
17
19
|
end
|
18
20
|
|
19
|
-
json
|
21
|
+
return json, from
|
20
22
|
end
|
21
23
|
|
22
24
|
def get_type(attrs)
|
@@ -33,13 +35,19 @@ module Asciidoctor
|
|
33
35
|
|
34
36
|
def read_source(json, part)
|
35
37
|
source = ''
|
36
|
-
|
38
|
+
|
37
39
|
if json.is_a? String
|
38
40
|
source = json
|
39
41
|
elsif json[part].is_a? String
|
40
42
|
source = json[part]
|
41
43
|
else
|
42
|
-
|
44
|
+
path = json['file']
|
45
|
+
|
46
|
+
if not File.exist?(path)
|
47
|
+
raise "#{PLUGIN_NAME}: File #{path} does not exist"
|
48
|
+
end
|
49
|
+
|
50
|
+
file = File.read(path)
|
43
51
|
loc = json[part]['loc']
|
44
52
|
|
45
53
|
# Get the source code, adjusting for the indentation of the first line of the span
|
@@ -98,7 +106,7 @@ module Asciidoctor
|
|
98
106
|
end
|
99
107
|
end
|
100
108
|
|
101
|
-
json
|
109
|
+
return json, type
|
102
110
|
end
|
103
111
|
|
104
112
|
# Compute the minimum indentation for any line in a source block
|
@@ -122,8 +130,8 @@ module Asciidoctor
|
|
122
130
|
end
|
123
131
|
|
124
132
|
def get_source(doc, target, attrs)
|
125
|
-
json = get_sourcemap doc, attrs
|
126
|
-
json = get_sail_object json, target, attrs
|
133
|
+
json, from = get_sourcemap doc, attrs
|
134
|
+
json, type = get_sail_object json, target, attrs
|
127
135
|
dedent = attrs.any? { |k, v| (k.is_a? Integer) && %w[dedent unindent].include?(v) }
|
128
136
|
strip = attrs.any? { |k, v| (k.is_a? Integer) && %w[trim strip].include?(v) }
|
129
137
|
|
@@ -136,7 +144,7 @@ module Asciidoctor
|
|
136
144
|
else
|
137
145
|
source = read_source(json, part)
|
138
146
|
end
|
139
|
-
|
147
|
+
|
140
148
|
source.strip! if strip
|
141
149
|
|
142
150
|
if dedent
|
@@ -149,7 +157,7 @@ module Asciidoctor
|
|
149
157
|
source = lines
|
150
158
|
end
|
151
159
|
|
152
|
-
source
|
160
|
+
return source, type, from
|
153
161
|
end
|
154
162
|
|
155
163
|
def match_clause(desc, json)
|
@@ -160,7 +168,7 @@ module Asciidoctor
|
|
160
168
|
if patterns.length == 1
|
161
169
|
patterns = patterns[0]
|
162
170
|
end
|
163
|
-
|
171
|
+
|
164
172
|
match_clause ::Regexp.last_match(2), patterns
|
165
173
|
elsif desc.length.positive? && desc[0] == '('
|
166
174
|
tuples = nil
|
@@ -196,10 +204,25 @@ module Asciidoctor
|
|
196
204
|
|
197
205
|
named :sail
|
198
206
|
|
207
|
+
@@ids = Set.new()
|
208
|
+
|
199
209
|
def process(parent, target, attrs)
|
200
|
-
source = get_source parent.document, target, attrs
|
210
|
+
source, type, from = get_source parent.document, target, attrs
|
201
211
|
|
202
|
-
|
212
|
+
if type == 'function' then
|
213
|
+
id = "#{from}-#{target}"
|
214
|
+
else
|
215
|
+
id = "#{from}-#{type}-#{target}"
|
216
|
+
end
|
217
|
+
|
218
|
+
if not @@ids.member?(id) then
|
219
|
+
@@ids.add(id)
|
220
|
+
block = create_listing_block parent, source, { 'id' => id, 'style' => 'source', 'language' => 'sail' }
|
221
|
+
else
|
222
|
+
block = create_listing_block parent, source, { 'style' => 'source', 'language' => 'sail' }
|
223
|
+
end
|
224
|
+
|
225
|
+
block
|
203
226
|
end
|
204
227
|
end
|
205
228
|
|
@@ -213,7 +236,7 @@ module Asciidoctor
|
|
213
236
|
def process doc, reader, target, attrs
|
214
237
|
target.delete_prefix! 'sail:'
|
215
238
|
|
216
|
-
source = get_source doc, target, attrs
|
239
|
+
source, type, from = get_source doc, target, attrs
|
217
240
|
|
218
241
|
reader.push_include source, target, target, 1, {}
|
219
242
|
reader
|
@@ -229,9 +252,9 @@ module Asciidoctor
|
|
229
252
|
|
230
253
|
def process doc, reader, target, attrs
|
231
254
|
target.delete_prefix! 'sailwavedrom:'
|
232
|
-
json = get_sourcemap doc, attrs
|
233
|
-
json = get_sail_object json, target, attrs
|
234
|
-
|
255
|
+
json, from = get_sourcemap doc, attrs
|
256
|
+
json, type = get_sail_object json, target, attrs
|
257
|
+
|
235
258
|
key = 'wavedrom'
|
236
259
|
if attrs.any? { |k, v| (k.is_a? Integer) && v == 'right' }
|
237
260
|
key = 'right_wavedrom'
|
@@ -239,12 +262,12 @@ module Asciidoctor
|
|
239
262
|
key = 'left_wavedrom'
|
240
263
|
end
|
241
264
|
|
242
|
-
if attrs.
|
265
|
+
if attrs.any? { |k, v| (k.is_a? Integer) && v == 'raw' }
|
243
266
|
diagram = json[key]
|
244
267
|
else
|
245
|
-
diagram = "[wavedrom, ,
|
268
|
+
diagram = "[wavedrom, ,]\n....\n#{json[key]}\n...."
|
246
269
|
end
|
247
|
-
|
270
|
+
|
248
271
|
reader.push_include diagram, target, target, 1, {}
|
249
272
|
reader
|
250
273
|
end
|
@@ -252,15 +275,15 @@ module Asciidoctor
|
|
252
275
|
|
253
276
|
class DocCommentIncludeProcessor < ::Asciidoctor::Extensions::IncludeProcessor
|
254
277
|
include SourceMacro
|
255
|
-
|
278
|
+
|
256
279
|
def handles? target
|
257
280
|
target.start_with? 'sailcomment:'
|
258
281
|
end
|
259
282
|
|
260
283
|
def process doc, reader, target, attrs
|
261
284
|
target.delete_prefix! 'sailcomment:'
|
262
|
-
json = get_sourcemap doc, attrs
|
263
|
-
json = get_sail_object json, target, attrs
|
285
|
+
json, from = get_sourcemap doc, attrs
|
286
|
+
json, type = get_sail_object json, target, attrs
|
264
287
|
|
265
288
|
if json.nil? || json.is_a?(Array)
|
266
289
|
raise "#{PLUGIN_NAME}: Could not find Sail object for #{target} when processing include::sailcomment. You may need to specify a clause."
|
@@ -270,7 +293,7 @@ module Asciidoctor
|
|
270
293
|
if comment.nil?
|
271
294
|
raise "#{PLUGIN_NAME}: No documentation comment for Sail object #{target}"
|
272
295
|
end
|
273
|
-
|
296
|
+
|
274
297
|
reader.push_include comment, target, target, 1, attrs
|
275
298
|
reader
|
276
299
|
end
|
@@ -10,6 +10,10 @@ module Asciidoctor
|
|
10
10
|
def self.register(key, sourcemap_path)
|
11
11
|
return if @sources.key?(key)
|
12
12
|
|
13
|
+
if not File.exist?(sourcemap_path)
|
14
|
+
raise "Sail Asciidoc plugin: File #{sourcemap_path} does not exist"
|
15
|
+
end
|
16
|
+
|
13
17
|
file = File.read(sourcemap_path)
|
14
18
|
@sources[key] = JSON.parse(file)
|
15
19
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asciidoctor-sail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alasdair Armstrong
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Asciidoctor extension for documenting Sail models
|
14
14
|
email:
|