Skip to content

Commit 156721d

Browse files
authored
Add docs-resources pdf theme, IDL highlighting (#10)
* Add riscv pdf template, IDL syntax highlighting
1 parent 2526359 commit 156721d

File tree

9 files changed

+239
-34
lines changed

9 files changed

+239
-34
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "ext/riscv-opcodes"]
22
path = ext/riscv-opcodes
33
url = https://github.com/riscv/riscv-opcodes.git
4+
[submodule "ext/docs-resources"]
5+
path = ext/docs-resources
6+
url = https://github.com/riscv/docs-resources.git

Gemfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ ruby "3.2.3"
55
source "https://rubygems.org"
66

77
gem "asciidoctor-diagram", "~> 2.2"
8-
gem "asciidoctor-multipage"
98
gem "asciidoctor-pdf"
109
gem "base64"
1110
gem "bigdecimal"
1211
gem "json_schemer", "~> 1.0"
1312
gem "minitest"
13+
gem "pygments.rb"
1414
gem "rake", "~> 13.0"
15-
gem "slim", "~> 5.1"
15+
gem "rouge"
1616
gem "treetop", "1.6.12"
1717
gem "webrick"
1818
gem "yard"

Gemfile.lock

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ GEM
1515
asciidoctor-diagram-ditaamini (1.0.3)
1616
asciidoctor-diagram-plantuml (1.2024.5)
1717
asciidoctor-diagram-batik (~> 1.17)
18-
asciidoctor-multipage (0.0.19)
19-
asciidoctor (>= 2.0.11, < 2.1)
2018
asciidoctor-pdf (2.3.14)
2119
asciidoctor (~> 2.0)
2220
concurrent-ruby (~> 1.1)
@@ -82,6 +80,7 @@ GEM
8280
pdf-reader (~> 2.0)
8381
prawn (~> 2.2)
8482
public_suffix (6.0.0)
83+
pygments.rb (3.0.0)
8584
racc (1.8.0)
8685
rainbow (3.1.1)
8786
rake (13.2.1)
@@ -91,6 +90,7 @@ GEM
9190
nokogiri
9291
rexml (3.2.8)
9392
strscan (>= 3.0.9)
93+
rouge (4.3.0)
9494
rubocop (1.64.1)
9595
json (~> 2.3)
9696
language_server-protocol (>= 3.17.0)
@@ -111,9 +111,6 @@ GEM
111111
ruby-progressbar (1.13.0)
112112
ruby-rc4 (0.1.5)
113113
simpleidn (0.2.3)
114-
slim (5.2.1)
115-
temple (~> 0.10.0)
116-
tilt (>= 2.1.0)
117114
solargraph (0.50.0)
118115
backport (~> 1.2)
119116
benchmark
@@ -131,7 +128,6 @@ GEM
131128
tilt (~> 2.0)
132129
yard (~> 0.9, >= 0.9.24)
133130
strscan (3.1.0)
134-
temple (0.10.3)
135131
thor (1.3.1)
136132
tilt (2.3.0)
137133
treetop (1.6.12)
@@ -147,16 +143,16 @@ PLATFORMS
147143

148144
DEPENDENCIES
149145
asciidoctor-diagram (~> 2.2)
150-
asciidoctor-multipage
151146
asciidoctor-pdf
152147
base64
153148
bigdecimal
154149
json_schemer (~> 1.0)
155150
minitest
151+
pygments.rb
156152
rake (~> 13.0)
153+
rouge
157154
rubocop-minitest
158155
ruby-prof
159-
slim (~> 5.1)
160156
solargraph
161157
treetop (= 1.6.12)
162158
webrick

arch/ext/Zbs.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ Zbs:
99
company:
1010
name: RISC-V International
1111
url: https://riscv.org
12+
doc_license:
13+
name: Creative Commons Attribution 4.0 International License (CC-BY 4.0)
14+
url: https://creativecommons.org/licenses/by/4.0/
1215
versions:
1316
- version: 1.0
1417
state: ratified
1518
ratification_date: 2021-06
19+
url: https://drive.google.com/drive/u/0/folders/1_wqb-rXOVkGa6rqmugN3kwCftWDf1daU
1620
repositories:
1721
- url: https://github.com/riscv/riscv-bitmanip
1822
branch: main

backends/ext_pdf_doc/idl_lexer.rb

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
require "rouge"
2+
3+
module Rouge
4+
module Lexers
5+
class Idl < RegexLexer
6+
tag "idl"
7+
filenames "idl", "isa"
8+
9+
title "IDL"
10+
desc "ISA Description Language"
11+
12+
ws = /[ \n]+/
13+
id = /[a-zA-Z_][a-zA-Z0-9_]*/
14+
15+
def self.keywords
16+
@keywords ||= Set.new %w[
17+
if else for return returns arguments description body function builtin enum bitfield
18+
]
19+
end
20+
21+
def self.keywords_type
22+
@keywords_type ||= Set.new %w[
23+
Bits XReg U32 U64 String Boolean
24+
]
25+
end
26+
27+
# start { push :bol }
28+
29+
state :bol do
30+
rule(//) { pop! }
31+
end
32+
33+
state :root do
34+
rule ws, Text::Whitespace
35+
rule %r{#.*}, Comment::Single
36+
rule %r{"[^"]*"}, Str::Double
37+
rule %r{[A-Z][a-zA-Z0-9]*}, Name::Constant
38+
rule %r{(?:(?:[0-9]+)|(?:XLEN))?'s?[bodh]?[0-9_a-fA-F]+}, Num
39+
rule %r/0x[0-9a-f]+[lu]*/i, Num::Hex
40+
rule %r/0[0-7]+[lu]*/i, Num::Oct
41+
rule %r{\d+}, Num::Integer
42+
rule %r{(?:true|false|\$encoding|\$pc)}, Name::Builtin
43+
rule %r{[.,;:\[\]\(\)\}\{]}, Punctuation
44+
rule %r([~!%^&*+=\|?:<>/-]), Operator
45+
rule id do |m|
46+
name = m[0]
47+
48+
if self.class.keywords.include? name
49+
token Keyword
50+
elsif self.class.keywords_type.include? name
51+
token Keyword::Type
52+
else
53+
token Name
54+
end
55+
end
56+
end
57+
end
58+
end
59+
end

backends/ext_pdf_doc/tasks.rake

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,15 @@ module AsciidocUtils
4848
end
4949
end
5050

51+
file "#{$root}/ext/docs-resources/themes/riscv-pdf.yml" => "#{$root}/.gitmodules" do |t|
52+
system "git submodule update --init ext/docs-resources"
53+
end
54+
5155
rule %r{#{$root}/gen/ext_pdf_doc/.*/pdf/.*_extension\.pdf} => proc { |tname|
5256
config_name = Pathname.new(tname).relative_path_from("#{$root}/gen/ext_pdf_doc").to_s.split("/")[0]
5357
ext_name = Pathname.new(tname).basename(".pdf").to_s.split("_")[0..-2].join("_")
5458
[
59+
"#{$root}/ext/docs-resources/themes/riscv-pdf.yml",
5560
"#{$root}/gen/ext_pdf_doc/#{config_name}/adoc/#{ext_name}_extension.adoc"
5661
]
5762
} do |t|
@@ -60,7 +65,20 @@ rule %r{#{$root}/gen/ext_pdf_doc/.*/pdf/.*_extension\.pdf} => proc { |tname|
6065
adoc_file = "#{$root}/gen/ext_pdf_doc/#{config_name}/adoc/#{ext_name}_extension.adoc"
6166

6267
FileUtils.mkdir_p File.dirname(t.name)
63-
Asciidoctor.convert_file(adoc_file, backend: "pdf", safe: :safe, to_file: t.name)
68+
sh [
69+
"asciidoctor-pdf",
70+
"-w",
71+
"-v",
72+
"-a toc",
73+
"-a compress",
74+
"-a pdf-theme=#{$root}/ext/docs-resources/themes/riscv-pdf.yml",
75+
"-a pdf-fontsdir=#{$root}/ext/docs-resources/fonts",
76+
"-a imagesdir=#{$root}/ext/docs-resources/images",
77+
"-r asciidoctor-diagram",
78+
"-r #{$root}/backends/ext_pdf_doc/idl_lexer",
79+
"-o #{t.name}",
80+
adoc_file
81+
].join(" ")
6482

6583
puts
6684
puts "Success!! File written to #{t.name}"
@@ -102,6 +120,8 @@ rule %r{#{$root}/gen/ext_pdf_doc/.*/adoc/.*_extension\.adoc} => proc { |tname|
102120
erb.filename = template_path.to_s
103121

104122
ext = arch_def.extension(ext_name)
123+
version_num = ENV.key?("EXT_VERSION") ? ENV["EXT_VERSION"] : ext.versions.sort { |v| Gem::Version.new(v["version"]) }.last["version"]
124+
ext_version = ext.versions.find { |v| v["version"] == version_num }
105125
FileUtils.mkdir_p File.dirname(t.name)
106126
File.write t.name, AsciidocUtils.resolve_links(arch_def.find_replace_links(erb.result(binding)))
107127
end
@@ -120,6 +140,8 @@ namespace :gen do
120140

121141
desc <<~DESC
122142
Generate PDF documentation for :extension that is defined or overlayed in :cfg
143+
144+
The latest version will be used, but can be overloaded by setting the EXT_VERSION environment variable.
123145
DESC
124146
task :cfg_ext_pdf, [:extension, :cfg] do |_t, args|
125147
raise ArgumentError, "Missing required argument :extension" if args[:extension].nil?

0 commit comments

Comments
 (0)