• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2016-2021 The Khronos Group Inc.
2#
3# SPDX-License-Identifier: Apache-2.0
4
5require 'asciidoctor/extensions' unless RUBY_ENGINE == 'opal'
6
7include ::Asciidoctor
8
9# This is the generated map of API interfaces in this spec build
10require 'api.rb'
11$apiNames = APInames.new
12
13class SpecInlineMacroBase < Extensions::InlineMacroProcessor
14    use_dsl
15    using_format :short
16end
17
18class NormativeInlineMacroBase < SpecInlineMacroBase
19    def text
20        'normative'
21    end
22
23    def process parent, target, attributes
24        create_inline parent, :quoted, '<strong class="purple">' + text + '</strong>'
25    end
26end
27
28class LinkInlineMacroBase < SpecInlineMacroBase
29    # Check if a link macro target exists - overridden by specific macros
30    # Default assumption is that it does exist
31    def exists? target
32      return true
33    end
34
35    def process parent, target, attributes
36      if not exists? target
37        # If the macro target isn't in this build, but has an alias,
38        # substitute that alias as the argument.
39        # Otherwise, turn the (attempted) link into text, and complain.
40        if $apiNames.nonexistent.has_key? target
41          oldtarget = target
42          target = $apiNames.nonexistent[oldtarget]
43          msg = 'Rewriting nonexistent link macro target: ' + @name.to_s + ':' + oldtarget + ' to ' + target
44          Asciidoctor::LoggerManager.logger.info msg
45          # Fall through
46        else
47          # Suppress warnings for apiext: macros as this is such a common case
48          if @name.to_s != 'apiext'
49            msg = 'Textifying unknown link macro target: ' + @name.to_s + ':' + target
50            Asciidoctor::LoggerManager.logger.warn msg
51          end
52          return create_inline parent, :quoted, '<code>' + target + '</code>'
53        end
54      end
55
56      if parent.document.attributes['cross-file-links']
57        return Inline.new(parent, :anchor, target, :type => :link, :target => (target + '.html'))
58      else
59        return Inline.new(parent, :anchor, target, :type => :xref, :target => ('#' + target), :attributes => {'fragment' => target, 'refid' => target})
60      end
61    end
62end
63
64class CodeInlineMacroBase < SpecInlineMacroBase
65    def process parent, target, attributes
66        create_inline parent, :quoted, '<code>' + target.gsub('&#8594;', '-&gt;') + '</code>'
67    end
68end
69
70class StrongInlineMacroBase < SpecInlineMacroBase
71    def process parent, target, attributes
72        create_inline parent, :quoted, '<code>' + target.gsub('&#8594;', '-&gt;') + '</code>'
73    end
74end
75
76class ParamInlineMacroBase < SpecInlineMacroBase
77    def process parent, target, attributes
78         create_inline parent, :quoted, '<code>' + target.gsub('&#8594;', '-&gt;') + '</code>'
79    end
80end
81
82class CanInlineMacro < NormativeInlineMacroBase
83    named :can
84    match /can:(\w*)/
85
86    def text
87        'can'
88    end
89end
90
91class CannotInlineMacro < NormativeInlineMacroBase
92    named :cannot
93    match /cannot:(\w*)/
94
95    def text
96        'cannot'
97    end
98end
99
100class MayInlineMacro < NormativeInlineMacroBase
101    named :may
102    match /may:(\w*)/
103
104    def text
105        'may'
106    end
107end
108
109class MustInlineMacro < NormativeInlineMacroBase
110    named :must
111    match /must:(\w*)/
112
113    def text
114        'must'
115    end
116end
117
118class OptionalInlineMacro < NormativeInlineMacroBase
119    named :optional
120    match /optional:(\w*)/
121
122    def text
123        'optional'
124    end
125end
126
127class OptionallyInlineMacro < NormativeInlineMacroBase
128    named :optionally
129    match /optionally:(\w*)/
130
131    def text
132        'optionally'
133    end
134end
135
136class RequiredInlineMacro < NormativeInlineMacroBase
137    named :required
138    match /required:(\w*)/
139
140    def text
141        'required'
142    end
143end
144
145class ShouldInlineMacro < NormativeInlineMacroBase
146    named :should
147    match /should:(\w*)/
148
149    def text
150        'should'
151    end
152end
153
154# Generic reference page link to any entity with an anchor/refpage
155class ReflinkInlineMacro < LinkInlineMacroBase
156    named :reflink
157    match /reflink:(\w+)/
158end
159
160# Link to an extension appendix/refpage
161class ApiextInlineMacro < LinkInlineMacroBase
162    named :apiext
163    match /apiext:(\w+)/
164
165    def exists? target
166        $apiNames.features.has_key? target
167    end
168end
169
170class FlinkInlineMacro < LinkInlineMacroBase
171    named :flink
172    match /flink:(\w+)/
173
174    def exists? target
175        $apiNames.protos.has_key? target
176    end
177end
178
179class FnameInlineMacro < CodeInlineMacroBase
180    named :fname
181    match /fname:(\w+)/
182end
183
184class FtextInlineMacro < CodeInlineMacroBase
185    named :ftext
186    match /ftext:([\w\*]+)/
187end
188
189class SnameInlineMacro < CodeInlineMacroBase
190    named :sname
191    match /sname:(\w+)/
192end
193
194class SlinkInlineMacro < LinkInlineMacroBase
195    named :slink
196    match /slink:(\w+)/
197
198    def exists? target
199        $apiNames.structs.has_key? target or $apiNames.handles.has_key? target
200    end
201end
202
203class StextInlineMacro < CodeInlineMacroBase
204    named :stext
205    match /stext:([\w\*]+)/
206end
207
208class EnameInlineMacro < CodeInlineMacroBase
209    named :ename
210    match /ename:(\w+)/
211
212    def exists? target
213        $apiNames.consts.has_key? target
214    end
215end
216
217class ElinkInlineMacro < LinkInlineMacroBase
218    named :elink
219    match /elink:(\w+)/
220
221    def exists? target
222        $apiNames.enums.has_key? target
223    end
224end
225
226class EtextInlineMacro < CodeInlineMacroBase
227    named :etext
228    match /etext:([\w\*]+)/
229end
230
231# this does not handle any [] at the moment
232
233class PnameInlineMacro < ParamInlineMacroBase
234    named :pname
235    match /pname:(\w+((\.|&#8594;)\w+)*)/
236end
237
238class PtextInlineMacro < ParamInlineMacroBase
239    named :ptext
240    match /ptext:([\w\*]+((\.|&#8594;)[\w\*]+)*)/
241end
242
243class DnameInlineMacro < CodeInlineMacroBase
244    named :dname
245    match /dname:(\w+)/
246end
247
248class DlinkInlineMacro < LinkInlineMacroBase
249    named :dlink
250    match /dlink:(\w+)/
251
252    def exists? target
253        $apiNames.defines.has_key? target
254    end
255end
256
257class TnameInlineMacro < CodeInlineMacroBase
258    named :tname
259    match /tname:(\w+)/
260end
261
262class TlinkInlineMacro < LinkInlineMacroBase
263    named :tlink
264    match /tlink:(\w+)/
265
266    def exists? target
267        $apiNames.flags.has_key? target or
268            $apiNames.funcpointers.has_key? target or
269            $apiNames.defines.has_key? target
270    end
271end
272
273class BasetypeInlineMacro < CodeInlineMacroBase
274    named :basetype
275    match /basetype:(\w+)/
276end
277
278# This doesn't include the full range of code: use
279# It allows imbedded periods (field separators) and wildcards if followed by
280# another word, and an ending wildcard.
281
282class CodeInlineMacro < CodeInlineMacroBase
283    named :code
284    match /code:(\w+([.*]\w+)*\**)/
285end
286
287# The tag: and attr: macros are only used in registry.txt
288
289class TagInlineMacro < StrongInlineMacroBase
290    named :tag
291    match /tag:(\w+)/
292end
293
294class AttrInlineMacro < StrongInlineMacroBase
295    named :attr
296    match /attr:(\w+)/
297end
298
299# Does nothing - just markup that we've considered the use case
300class UndefinedInlineMacro < SpecInlineMacroBase
301    named :undefined
302    match /undefined:/
303
304    def process parent, target, attributes
305        create_inline parent, :quoted, 'undefined'
306    end
307end
308