odin_html_docs_main.odin 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292
  1. package odin_html_docs
  2. import doc "core:odin/doc-format"
  3. import "core:fmt"
  4. import "core:io"
  5. import "core:os"
  6. import "core:strings"
  7. import "core:path/slashpath"
  8. import "core:sort"
  9. import "core:slice"
  10. GITHUB_LICENSE_URL :: "https://github.com/odin-lang/Odin/tree/master/LICENSE"
  11. GITHUB_CORE_URL :: "https://github.com/odin-lang/Odin/tree/master/core"
  12. BASE_CORE_URL :: "/core"
  13. header: ^doc.Header
  14. files: []doc.File
  15. pkgs: []doc.Pkg
  16. entities: []doc.Entity
  17. types: []doc.Type
  18. pkgs_to_use: map[string]^doc.Pkg // trimmed path
  19. pkg_to_path: map[^doc.Pkg]string // trimmed path
  20. array :: proc(a: $A/doc.Array($T)) -> []T {
  21. return doc.from_array(header, a)
  22. }
  23. str :: proc(s: $A/doc.String) -> string {
  24. return doc.from_string(header, s)
  25. }
  26. errorf :: proc(format: string, args: ..any) -> ! {
  27. fmt.eprintf("%s ", os.args[0])
  28. fmt.eprintf(format, ..args)
  29. fmt.eprintln()
  30. os.exit(1)
  31. }
  32. base_type :: proc(t: doc.Type) -> doc.Type {
  33. t := t
  34. for {
  35. if t.kind != .Named {
  36. break
  37. }
  38. t = types[array(t.types)[0]]
  39. }
  40. return t
  41. }
  42. is_type_untyped :: proc(type: doc.Type) -> bool {
  43. if type.kind == .Basic {
  44. flags := transmute(doc.Type_Flags_Basic)type.flags
  45. return .Untyped in flags
  46. }
  47. return false
  48. }
  49. common_prefix :: proc(strs: []string) -> string {
  50. if len(strs) == 0 {
  51. return ""
  52. }
  53. n := max(int)
  54. for str in strs {
  55. n = min(n, len(str))
  56. }
  57. prefix := strs[0][:n]
  58. for str in strs[1:] {
  59. for len(prefix) != 0 && str[:len(prefix)] != prefix {
  60. prefix = prefix[:len(prefix)-1]
  61. }
  62. if len(prefix) == 0 {
  63. break
  64. }
  65. }
  66. return prefix
  67. }
  68. recursive_make_directory :: proc(path: string, prefix := "") {
  69. head, _, tail := strings.partition(path, "/")
  70. path_to_make := head
  71. if prefix != "" {
  72. path_to_make = fmt.tprintf("%s/%s", prefix, head)
  73. }
  74. os.make_directory(path_to_make, 0)
  75. if tail != "" {
  76. recursive_make_directory(tail, path_to_make)
  77. }
  78. }
  79. write_html_header :: proc(w: io.Writer, title: string) {
  80. fmt.wprintf(w, string(#load("header.txt.html")), title)
  81. io.write(w, #load("header-lower.txt.html"))
  82. }
  83. write_html_footer :: proc(w: io.Writer, include_directory_js: bool) {
  84. fmt.wprintf(w, "\n")
  85. io.write(w, #load("footer.txt.html"))
  86. if false && include_directory_js {
  87. io.write_string(w, `
  88. <script type="text/javascript">
  89. (function (win, doc) {
  90. 'use strict';
  91. if (!doc.querySelectorAll || !win.addEventListener) {
  92. // doesn't cut the mustard.
  93. return;
  94. }
  95. let toggles = doc.querySelectorAll('[aria-controls]');
  96. for (let i = 0; i < toggles.length; i = i + 1) {
  97. let toggleID = toggles[i].getAttribute('aria-controls');
  98. if (doc.getElementById(toggleID)) {
  99. let togglecontent = doc.getElementById(toggleID);
  100. togglecontent.setAttribute('aria-hidden', 'true');
  101. togglecontent.setAttribute('tabindex', '-1');
  102. toggles[i].setAttribute('aria-expanded', 'false');
  103. }
  104. }
  105. function toggle(ev) {
  106. ev = ev || win.event;
  107. var target = ev.target || ev.srcElement;
  108. if (target.hasAttribute('data-aria-owns')) {
  109. let toggleIDs = target.getAttribute('data-aria-owns').match(/[^ ]+/g);
  110. toggleIDs.forEach(toggleID => {
  111. if (doc.getElementById(toggleID)) {
  112. ev.preventDefault();
  113. let togglecontent = doc.getElementById(toggleID);
  114. if (togglecontent.getAttribute('aria-hidden') == 'true') {
  115. togglecontent.setAttribute('aria-hidden', 'false');
  116. target.setAttribute('aria-expanded', 'true');
  117. if (target.tagName == 'A') {
  118. togglecontent.focus();
  119. }
  120. } else {
  121. togglecontent.setAttribute('aria-hidden', 'true');
  122. target.setAttribute('aria-expanded', 'false');
  123. }
  124. }
  125. })
  126. }
  127. }
  128. doc.addEventListener('click', toggle, false);
  129. }(this, this.document));
  130. </script>`)
  131. }
  132. fmt.wprintf(w, "</body>\n</html>\n")
  133. }
  134. main :: proc() {
  135. if len(os.args) != 2 {
  136. errorf("expected 1 .odin-doc file")
  137. }
  138. data, ok := os.read_entire_file(os.args[1])
  139. if !ok {
  140. errorf("unable to read file:", os.args[1])
  141. }
  142. err: doc.Reader_Error
  143. header, err = doc.read_from_bytes(data)
  144. switch err {
  145. case .None:
  146. case .Header_Too_Small:
  147. errorf("file is too small for the file format")
  148. case .Invalid_Magic:
  149. errorf("invalid magic for the file format")
  150. case .Data_Too_Small:
  151. errorf("data is too small for the file format")
  152. case .Invalid_Version:
  153. errorf("invalid file format version")
  154. }
  155. files = array(header.files)
  156. pkgs = array(header.pkgs)
  157. entities = array(header.entities)
  158. types = array(header.types)
  159. {
  160. fullpaths: [dynamic]string
  161. defer delete(fullpaths)
  162. for pkg in pkgs[1:] {
  163. append(&fullpaths, str(pkg.fullpath))
  164. }
  165. path_prefix := common_prefix(fullpaths[:])
  166. pkgs_to_use = make(map[string]^doc.Pkg)
  167. fullpath_loop: for fullpath, i in fullpaths {
  168. path := strings.trim_prefix(fullpath, path_prefix)
  169. if !strings.has_prefix(path, "core/") {
  170. continue fullpath_loop
  171. }
  172. pkg := &pkgs[i+1]
  173. if len(array(pkg.entities)) == 0 {
  174. continue fullpath_loop
  175. }
  176. trimmed_path := strings.trim_prefix(path, "core/")
  177. if strings.has_prefix(trimmed_path, "sys") {
  178. continue fullpath_loop
  179. }
  180. pkgs_to_use[trimmed_path] = pkg
  181. }
  182. for path, pkg in pkgs_to_use {
  183. pkg_to_path[pkg] = path
  184. }
  185. }
  186. b := strings.make_builder()
  187. defer strings.destroy_builder(&b)
  188. w := strings.to_writer(&b)
  189. {
  190. strings.reset_builder(&b)
  191. write_html_header(w, "core library - pkg.odin-lang.org")
  192. write_core_directory(w)
  193. write_html_footer(w, true)
  194. os.make_directory("core", 0)
  195. os.write_entire_file("core/index.html", b.buf[:])
  196. }
  197. for path, pkg in pkgs_to_use {
  198. strings.reset_builder(&b)
  199. write_html_header(w, fmt.tprintf("package %s - pkg.odin-lang.org", path))
  200. write_pkg(w, path, pkg)
  201. write_html_footer(w, false)
  202. recursive_make_directory(path, "core")
  203. os.write_entire_file(fmt.tprintf("core/%s/index.html", path), b.buf[:])
  204. }
  205. }
  206. Dir_Node :: struct {
  207. dir: string,
  208. path: string,
  209. name: string,
  210. pkg: ^doc.Pkg,
  211. children: [dynamic]^Dir_Node,
  212. }
  213. generate_directory_tree :: proc() -> (root: ^Dir_Node) {
  214. sort_tree :: proc(node: ^Dir_Node) {
  215. slice.sort_by_key(node.children[:], proc(node: ^Dir_Node) -> string {return node.name})
  216. for child in node.children {
  217. sort_tree(child)
  218. }
  219. }
  220. root = new(Dir_Node)
  221. root.children = make([dynamic]^Dir_Node)
  222. children := make([dynamic]^Dir_Node)
  223. for path, pkg in pkgs_to_use {
  224. dir, _, inner := strings.partition(path, "/")
  225. if inner == "" {
  226. node := new_clone(Dir_Node{
  227. dir = dir,
  228. name = dir,
  229. path = path,
  230. pkg = pkg,
  231. })
  232. append(&root.children, node)
  233. } else {
  234. node := new_clone(Dir_Node{
  235. dir = dir,
  236. name = inner,
  237. path = path,
  238. pkg = pkg,
  239. })
  240. append(&children, node)
  241. }
  242. }
  243. child_loop: for child in children {
  244. dir, _, inner := strings.partition(child.path, "/")
  245. for node in root.children {
  246. if node.dir == dir {
  247. append(&node.children, child)
  248. continue child_loop
  249. }
  250. }
  251. parent := new_clone(Dir_Node{
  252. dir = dir,
  253. name = dir,
  254. path = dir,
  255. pkg = nil,
  256. })
  257. append(&root.children, parent)
  258. append(&parent.children, child)
  259. }
  260. sort_tree(root)
  261. return
  262. }
  263. write_core_directory :: proc(w: io.Writer) {
  264. root := generate_directory_tree()
  265. fmt.wprintln(w, `<div class="row odin-main">`)
  266. defer fmt.wprintln(w, `</div>`)
  267. {
  268. fmt.wprintln(w, `<article class="col-lg-12 p-4">`)
  269. fmt.wprintln(w, "<header>")
  270. fmt.wprintln(w, "<h1>Core Library Collection</h1>")
  271. fmt.wprintln(w, "<ul>")
  272. fmt.wprintf(w, "<li>License: <a href=\"{0:s}\">BSD-3-Clause</a></li>\n", GITHUB_LICENSE_URL)
  273. fmt.wprintf(w, "<li>Repository: <a href=\"{0:s}\">{0:s}</a></li>\n", GITHUB_CORE_URL)
  274. fmt.wprintln(w, "</ul>")
  275. fmt.wprintln(w, "</header>")
  276. fmt.wprintln(w, "</article>")
  277. fmt.wprintln(w, "<hr>")
  278. }
  279. fmt.wprintln(w, `<article class="col-lg-12 p-4">`)
  280. defer fmt.wprintln(w, `</article>`)
  281. fmt.wprintln(w, "<header>")
  282. fmt.wprintln(w, `<h2><i class="bi bi-folder"></i>Directories</h2>`)
  283. fmt.wprintln(w, "</header>")
  284. fmt.wprintln(w, "<div>")
  285. fmt.wprintln(w, "\t<table class=\"doc-directory mt-4 mb-4\">")
  286. fmt.wprintln(w, "\t\t<tbody>")
  287. for dir in root.children {
  288. if len(dir.children) != 0 {
  289. fmt.wprint(w, `<tr aria-controls="`)
  290. for child in dir.children {
  291. fmt.wprintf(w, "pkg-%s ", str(child.pkg.name))
  292. }
  293. fmt.wprint(w, `" class="directory-pkg"><td class="pkg-line pkg-name" data-aria-owns="`)
  294. for child in dir.children {
  295. fmt.wprintf(w, "pkg-%s ", str(child.pkg.name))
  296. }
  297. fmt.wprintf(w, `" id="pkg-%s">`, dir.dir)
  298. } else {
  299. fmt.wprintf(w, `<tr id="pkg-%s" class="directory-pkg"><td class="pkg-name">`, dir.dir)
  300. }
  301. if dir.pkg != nil {
  302. fmt.wprintf(w, `<a href="%s/%s">%s</a>`, BASE_CORE_URL, dir.path, dir.name)
  303. } else {
  304. fmt.wprintf(w, "%s", dir.name)
  305. }
  306. io.write_string(w, `</td>`)
  307. io.write_string(w, `<td class="pkg-line pkg-line-doc">`)
  308. if dir.pkg != nil {
  309. line_doc, _, _ := strings.partition(str(dir.pkg.docs), "\n")
  310. line_doc = strings.trim_space(line_doc)
  311. if line_doc != "" {
  312. write_doc_line(w, line_doc)
  313. }
  314. }
  315. io.write_string(w, `</td>`)
  316. fmt.wprintf(w, "</tr>\n")
  317. for child in dir.children {
  318. assert(child.pkg != nil)
  319. fmt.wprintf(w, `<tr id="pkg-%s" class="directory-pkg directory-child"><td class="pkg-line pkg-name">`, str(child.pkg.name))
  320. fmt.wprintf(w, `<a href="%s/%s/">%s</a>`, BASE_CORE_URL, child.path, child.name)
  321. io.write_string(w, `</td>`)
  322. line_doc, _, _ := strings.partition(str(child.pkg.docs), "\n")
  323. line_doc = strings.trim_space(line_doc)
  324. io.write_string(w, `<td class="pkg-line pkg-line-doc">`)
  325. if line_doc != "" {
  326. write_doc_line(w, line_doc)
  327. }
  328. io.write_string(w, `</td>`)
  329. fmt.wprintf(w, "</td>")
  330. fmt.wprintf(w, "</tr>\n")
  331. }
  332. }
  333. fmt.wprintln(w, "\t\t</tbody>")
  334. fmt.wprintln(w, "\t</table>")
  335. fmt.wprintln(w, "</div>")
  336. }
  337. is_entity_blank :: proc(e: doc.Entity_Index) -> bool {
  338. name := str(entities[e].name)
  339. return name == ""
  340. }
  341. write_where_clauses :: proc(w: io.Writer, where_clauses: []doc.String) {
  342. if len(where_clauses) != 0 {
  343. io.write_string(w, " where ")
  344. for clause, i in where_clauses {
  345. if i > 0 {
  346. io.write_string(w, ", ")
  347. }
  348. io.write_string(w, str(clause))
  349. }
  350. }
  351. }
  352. Write_Type_Flag :: enum {
  353. Is_Results,
  354. Variadic,
  355. Allow_Indent,
  356. Poly_Names,
  357. }
  358. Write_Type_Flags :: distinct bit_set[Write_Type_Flag]
  359. Type_Writer :: struct {
  360. w: io.Writer,
  361. pkg: doc.Pkg_Index,
  362. indent: int,
  363. generic_scope: map[string]bool,
  364. }
  365. write_type :: proc(using writer: ^Type_Writer, type: doc.Type, flags: Write_Type_Flags) {
  366. write_param_entity :: proc(using writer: ^Type_Writer, e, next_entity: ^doc.Entity, flags: Write_Type_Flags, name_width := 0) {
  367. name := str(e.name)
  368. write_padding :: proc(w: io.Writer, name: string, name_width: int) {
  369. for _ in 0..<name_width-len(name) {
  370. io.write_byte(w, ' ')
  371. }
  372. }
  373. if .Param_Using in e.flags { io.write_string(w, "using ") }
  374. if .Param_Const in e.flags { io.write_string(w, "#const ") }
  375. if .Param_Auto_Cast in e.flags { io.write_string(w, "#auto_cast ") }
  376. if .Param_CVararg in e.flags { io.write_string(w, "#c_vararg ") }
  377. if .Param_No_Alias in e.flags { io.write_string(w, "#no_alias ") }
  378. if .Param_Any_Int in e.flags { io.write_string(w, "#any_int ") }
  379. init_string := str(e.init_string)
  380. switch {
  381. case init_string == "#caller_location":
  382. assert(name != "")
  383. io.write_string(w, name)
  384. io.write_string(w, " := ")
  385. fmt.wprintf(w, `<a href="%s/runtime/#Source_Code_Location">`, BASE_CORE_URL)
  386. io.write_string(w, init_string)
  387. io.write_string(w, `</a>`)
  388. case strings.has_prefix(init_string, "context."):
  389. io.write_string(w, name)
  390. io.write_string(w, " := ")
  391. fmt.wprintf(w, `<a href="%s/runtime/#Context">`, BASE_CORE_URL)
  392. io.write_string(w, init_string)
  393. io.write_string(w, `</a>`)
  394. case:
  395. the_type := types[e.type]
  396. type_flags := flags - {.Is_Results}
  397. if .Param_Ellipsis in e.flags {
  398. type_flags += {.Variadic}
  399. }
  400. #partial switch e.kind {
  401. case .Constant:
  402. assert(name != "")
  403. io.write_byte(w, '$')
  404. io.write_string(w, name)
  405. if name != "" && init_string == "" && next_entity != nil && e.field_group_index >= 0 {
  406. if e.field_group_index == next_entity.field_group_index && e.type == next_entity.type {
  407. return
  408. }
  409. }
  410. generic_scope[name] = true
  411. if !is_type_untyped(the_type) {
  412. io.write_string(w, ": ")
  413. write_padding(w, name, name_width)
  414. write_type(writer, the_type, type_flags)
  415. io.write_string(w, " = ")
  416. io.write_string(w, init_string)
  417. } else {
  418. io.write_string(w, " := ")
  419. io.write_string(w, init_string)
  420. }
  421. return
  422. case .Variable:
  423. if name != "" && init_string == "" && next_entity != nil && e.field_group_index >= 0 {
  424. if e.field_group_index == next_entity.field_group_index && e.type == next_entity.type {
  425. io.write_string(w, name)
  426. return
  427. }
  428. }
  429. if name != "" {
  430. io.write_string(w, name)
  431. io.write_string(w, ": ")
  432. write_padding(w, name, name_width)
  433. }
  434. write_type(writer, the_type, type_flags)
  435. case .Type_Name:
  436. io.write_byte(w, '$')
  437. io.write_string(w, name)
  438. generic_scope[name] = true
  439. io.write_string(w, ": ")
  440. write_padding(w, name, name_width)
  441. if the_type.kind == .Generic {
  442. io.write_string(w, "typeid")
  443. if ts := array(the_type.types); len(ts) == 1 {
  444. io.write_byte(w, '/')
  445. write_type(writer, types[ts[0]], type_flags)
  446. }
  447. } else {
  448. write_type(writer, the_type, type_flags)
  449. }
  450. }
  451. if init_string != "" {
  452. io.write_string(w, " = ")
  453. io.write_string(w, init_string)
  454. }
  455. }
  456. }
  457. write_poly_params :: proc(using writer: ^Type_Writer, type: doc.Type, flags: Write_Type_Flags) {
  458. if type.polymorphic_params != 0 {
  459. io.write_byte(w, '(')
  460. write_type(writer, types[type.polymorphic_params], flags+{.Poly_Names})
  461. io.write_byte(w, ')')
  462. }
  463. write_where_clauses(w, array(type.where_clauses))
  464. }
  465. do_indent :: proc(using writer: ^Type_Writer, flags: Write_Type_Flags) {
  466. if .Allow_Indent not_in flags {
  467. return
  468. }
  469. for _ in 0..<indent {
  470. io.write_byte(w, '\t')
  471. }
  472. }
  473. do_newline :: proc(using writer: ^Type_Writer, flags: Write_Type_Flags) {
  474. if .Allow_Indent in flags {
  475. io.write_byte(w, '\n')
  476. }
  477. }
  478. calc_name_width :: proc(type_entities: []doc.Entity_Index) -> (name_width: int) {
  479. for entity_index in type_entities {
  480. e := &entities[entity_index]
  481. name := str(e.name)
  482. name_width = max(len(name), name_width)
  483. }
  484. return
  485. }
  486. type_entities := array(type.entities)
  487. type_types := array(type.types)
  488. switch type.kind {
  489. case .Invalid:
  490. // ignore
  491. case .Basic:
  492. type_flags := transmute(doc.Type_Flags_Basic)type.flags
  493. if is_type_untyped(type) {
  494. io.write_string(w, str(type.name))
  495. } else {
  496. fmt.wprintf(w, `<a href="">%s</a>`, str(type.name))
  497. }
  498. case .Named:
  499. e := entities[type_entities[0]]
  500. name := str(type.name)
  501. tn_pkg := files[e.pos.file].pkg
  502. if tn_pkg != pkg {
  503. fmt.wprintf(w, `%s.`, str(pkgs[tn_pkg].name))
  504. }
  505. if .Private in e.flags {
  506. io.write_string(w, name)
  507. } else if n := strings.contains_rune(name, '('); n >= 0 {
  508. fmt.wprintf(w, `<a class="code-typename" href="{2:s}/{0:s}/#{1:s}">{1:s}</a>`, pkg_to_path[&pkgs[tn_pkg]], name[:n], BASE_CORE_URL)
  509. io.write_string(w, name[n:])
  510. } else {
  511. fmt.wprintf(w, `<a class="code-typename" href="{2:s}/{0:s}/#{1:s}">{1:s}</a>`, pkg_to_path[&pkgs[tn_pkg]], name, BASE_CORE_URL)
  512. }
  513. case .Generic:
  514. name := str(type.name)
  515. if name not_in generic_scope {
  516. io.write_byte(w, '$')
  517. }
  518. io.write_string(w, name)
  519. if name not_in generic_scope && len(array(type.types)) == 1 {
  520. io.write_byte(w, '/')
  521. write_type(writer, types[type_types[0]], flags)
  522. }
  523. case .Pointer:
  524. io.write_byte(w, '^')
  525. write_type(writer, types[type_types[0]], flags)
  526. case .Array:
  527. assert(type.elem_count_len == 1)
  528. io.write_byte(w, '[')
  529. io.write_uint(w, uint(type.elem_counts[0]))
  530. io.write_byte(w, ']')
  531. write_type(writer, types[type_types[0]], flags)
  532. case .Enumerated_Array:
  533. io.write_byte(w, '[')
  534. write_type(writer, types[type_types[0]], flags)
  535. io.write_byte(w, ']')
  536. write_type(writer, types[type_types[1]], flags)
  537. case .Slice:
  538. if .Variadic in flags {
  539. io.write_string(w, "..")
  540. } else {
  541. io.write_string(w, "[]")
  542. }
  543. write_type(writer, types[type_types[0]], flags - {.Variadic})
  544. case .Dynamic_Array:
  545. io.write_string(w, "[dynamic]")
  546. write_type(writer, types[type_types[0]], flags)
  547. case .Map:
  548. io.write_string(w, "map[")
  549. write_type(writer, types[type_types[0]], flags)
  550. io.write_byte(w, ']')
  551. write_type(writer, types[type_types[1]], flags)
  552. case .Struct:
  553. type_flags := transmute(doc.Type_Flags_Struct)type.flags
  554. io.write_string(w, "struct")
  555. write_poly_params(writer, type, flags)
  556. if .Packed in type_flags { io.write_string(w, " #packed") }
  557. if .Raw_Union in type_flags { io.write_string(w, " #raw_union") }
  558. if custom_align := str(type.custom_align); custom_align != "" {
  559. io.write_string(w, " #align")
  560. io.write_string(w, custom_align)
  561. }
  562. io.write_string(w, " {")
  563. tags := array(type.tags)
  564. if len(type_entities) != 0 {
  565. do_newline(writer, flags)
  566. indent += 1
  567. name_width := calc_name_width(type_entities)
  568. for entity_index, i in type_entities {
  569. e := &entities[entity_index]
  570. next_entity: ^doc.Entity = nil
  571. if i+1 < len(type_entities) {
  572. next_entity = &entities[type_entities[i+1]]
  573. }
  574. do_indent(writer, flags)
  575. write_param_entity(writer, e, next_entity, flags, name_width)
  576. if tag := str(tags[i]); tag != "" {
  577. io.write_byte(w, ' ')
  578. io.write_quoted_string(w, tag)
  579. }
  580. io.write_byte(w, ',')
  581. do_newline(writer, flags)
  582. }
  583. indent -= 1
  584. do_indent(writer, flags)
  585. }
  586. io.write_string(w, "}")
  587. case .Union:
  588. type_flags := transmute(doc.Type_Flags_Union)type.flags
  589. io.write_string(w, "union")
  590. write_poly_params(writer, type, flags)
  591. if .No_Nil in type_flags { io.write_string(w, " #no_nil") }
  592. if .Maybe in type_flags { io.write_string(w, " #maybe") }
  593. if custom_align := str(type.custom_align); custom_align != "" {
  594. io.write_string(w, " #align")
  595. io.write_string(w, custom_align)
  596. }
  597. io.write_string(w, " {")
  598. if len(type_types) > 1 {
  599. do_newline(writer, flags)
  600. indent += 1
  601. for type_index in type_types {
  602. do_indent(writer, flags)
  603. write_type(writer, types[type_index], flags)
  604. io.write_string(w, ", ")
  605. do_newline(writer, flags)
  606. }
  607. indent -= 1
  608. do_indent(writer, flags)
  609. }
  610. io.write_string(w, "}")
  611. case .Enum:
  612. io.write_string(w, "enum")
  613. if len(type_types) != 0 {
  614. io.write_byte(w, ' ')
  615. write_type(writer, types[type_types[0]], flags)
  616. }
  617. io.write_string(w, " {")
  618. do_newline(writer, flags)
  619. indent += 1
  620. name_width := calc_name_width(type_entities)
  621. for entity_index in type_entities {
  622. e := &entities[entity_index]
  623. name := str(e.name)
  624. do_indent(writer, flags)
  625. io.write_string(w, name)
  626. if init_string := str(e.init_string); init_string != "" {
  627. for _ in 0..<name_width-len(name) {
  628. io.write_byte(w, ' ')
  629. }
  630. io.write_string(w, " = ")
  631. io.write_string(w, init_string)
  632. }
  633. io.write_string(w, ", ")
  634. do_newline(writer, flags)
  635. }
  636. indent -= 1
  637. do_indent(writer, flags)
  638. io.write_string(w, "}")
  639. case .Tuple:
  640. if len(type_entities) == 0 {
  641. return
  642. }
  643. require_parens := (.Is_Results in flags) && (len(type_entities) > 1 || !is_entity_blank(type_entities[0]))
  644. if require_parens { io.write_byte(w, '(') }
  645. for entity_index, i in type_entities {
  646. if i > 0 {
  647. io.write_string(w, ", ")
  648. }
  649. e := &entities[entity_index]
  650. next_entity: ^doc.Entity = nil
  651. if i+1 < len(type_entities) {
  652. next_entity = &entities[type_entities[i+1]]
  653. }
  654. write_param_entity(writer, e, next_entity, flags)
  655. }
  656. if require_parens { io.write_byte(w, ')') }
  657. case .Proc:
  658. type_flags := transmute(doc.Type_Flags_Proc)type.flags
  659. io.write_string(w, "proc")
  660. cc := str(type.calling_convention)
  661. if cc != "" {
  662. io.write_byte(w, ' ')
  663. io.write_quoted_string(w, cc)
  664. io.write_byte(w, ' ')
  665. }
  666. params := array(type.types)[0]
  667. results := array(type.types)[1]
  668. io.write_byte(w, '(')
  669. write_type(writer, types[params], flags)
  670. io.write_byte(w, ')')
  671. if results != 0 {
  672. assert(.Diverging not_in type_flags)
  673. io.write_string(w, " -> ")
  674. write_type(writer, types[results], flags+{.Is_Results})
  675. }
  676. if .Diverging in type_flags {
  677. io.write_string(w, " -> !")
  678. }
  679. if .Optional_Ok in type_flags {
  680. io.write_string(w, " #optional_ok")
  681. }
  682. case .Bit_Set:
  683. type_flags := transmute(doc.Type_Flags_Bit_Set)type.flags
  684. io.write_string(w, "bit_set[")
  685. if .Op_Lt in type_flags {
  686. io.write_uint(w, uint(type.elem_counts[0]))
  687. io.write_string(w, "..<")
  688. io.write_uint(w, uint(type.elem_counts[1]))
  689. } else if .Op_Lt_Eq in type_flags {
  690. io.write_uint(w, uint(type.elem_counts[0]))
  691. io.write_string(w, "..=")
  692. io.write_uint(w, uint(type.elem_counts[1]))
  693. } else {
  694. write_type(writer, types[type_types[0]], flags)
  695. }
  696. if .Underlying_Type in type_flags {
  697. write_type(writer, types[type_types[1]], flags)
  698. }
  699. io.write_string(w, "]")
  700. case .Simd_Vector:
  701. io.write_string(w, "#simd[")
  702. io.write_uint(w, uint(type.elem_counts[0]))
  703. io.write_byte(w, ']')
  704. case .SOA_Struct_Fixed:
  705. io.write_string(w, "#soa[")
  706. io.write_uint(w, uint(type.elem_counts[0]))
  707. io.write_byte(w, ']')
  708. case .SOA_Struct_Slice:
  709. io.write_string(w, "#soa[]")
  710. case .SOA_Struct_Dynamic:
  711. io.write_string(w, "#soa[dynamic]")
  712. case .Relative_Pointer:
  713. io.write_string(w, "#relative(")
  714. write_type(writer, types[type_types[1]], flags)
  715. io.write_string(w, ") ")
  716. write_type(writer, types[type_types[0]], flags)
  717. case .Relative_Slice:
  718. io.write_string(w, "#relative(")
  719. write_type(writer, types[type_types[1]], flags)
  720. io.write_string(w, ") ")
  721. write_type(writer, types[type_types[0]], flags)
  722. case .Multi_Pointer:
  723. io.write_string(w, "[^]")
  724. write_type(writer, types[type_types[0]], flags)
  725. case .Matrix:
  726. io.write_string(w, "matrix[")
  727. io.write_uint(w, uint(type.elem_counts[0]))
  728. io.write_string(w, ", ")
  729. io.write_uint(w, uint(type.elem_counts[1]))
  730. io.write_string(w, "]")
  731. write_type(writer, types[type_types[0]], flags)
  732. }
  733. }
  734. write_doc_line :: proc(w: io.Writer, text: string) {
  735. text := text
  736. for len(text) != 0 {
  737. if strings.count(text, "`") >= 2 {
  738. n := strings.index_byte(text, '`')
  739. io.write_string(w, text[:n])
  740. io.write_string(w, "<code class=\"code-inline\">")
  741. remaining := text[n+1:]
  742. m := strings.index_byte(remaining, '`')
  743. io.write_string(w, remaining[:m])
  744. io.write_string(w, "</code>")
  745. text = remaining[m+1:]
  746. } else {
  747. io.write_string(w, text)
  748. return
  749. }
  750. }
  751. }
  752. write_docs :: proc(w: io.Writer, pkg: ^doc.Pkg, docs: string) {
  753. if docs == "" {
  754. return
  755. }
  756. Block_Kind :: enum {
  757. Paragraph,
  758. Code,
  759. }
  760. Block :: struct {
  761. kind: Block_Kind,
  762. lines: []string,
  763. }
  764. lines: [dynamic]string
  765. it := docs
  766. for line_ in strings.split_iterator(&it, "\n") {
  767. line := strings.trim_right_space(line_)
  768. append(&lines, line)
  769. }
  770. curr_block_kind := Block_Kind.Paragraph
  771. start := 0
  772. blocks: [dynamic]Block
  773. for line, i in lines {
  774. text := strings.trim_space(line)
  775. switch curr_block_kind {
  776. case .Paragraph:
  777. if strings.has_prefix(line, "\t") {
  778. if i-start > 0 {
  779. append(&blocks, Block{curr_block_kind, lines[start:i]})
  780. }
  781. curr_block_kind, start = .Code, i
  782. } else if text == "" {
  783. if i-start > 0 {
  784. append(&blocks, Block{curr_block_kind, lines[start:i]})
  785. }
  786. start = i
  787. }
  788. case .Code:
  789. if text == "" || strings.has_prefix(line, "\t") {
  790. continue
  791. }
  792. if i-start > 0 {
  793. append(&blocks, Block{curr_block_kind, lines[start:i]})
  794. }
  795. curr_block_kind, start = .Paragraph, i
  796. }
  797. }
  798. if start < len(lines) {
  799. if len(lines)-start > 0 {
  800. append(&blocks, Block{curr_block_kind, lines[start:]})
  801. }
  802. }
  803. for block in &blocks {
  804. trim_amount := 0
  805. for trim_amount = 0; trim_amount < len(block.lines); trim_amount += 1 {
  806. line := block.lines[trim_amount]
  807. if strings.trim_space(line) != "" {
  808. break
  809. }
  810. }
  811. block.lines = block.lines[trim_amount:]
  812. }
  813. for block, i in blocks {
  814. if len(block.lines) == 0 {
  815. continue
  816. }
  817. prev_line := ""
  818. if i > 0 {
  819. prev_lines := blocks[i-1].lines
  820. if len(prev_lines) > 0 {
  821. prev_line = prev_lines[len(prev_lines)-1]
  822. }
  823. }
  824. prev_line = strings.trim_space(prev_line)
  825. lines := block.lines[:]
  826. end_line := block.lines[len(lines)-1]
  827. if block.kind == .Paragraph && i+1 < len(blocks) {
  828. if strings.has_prefix(end_line, "Example:") && blocks[i+1].kind == .Code {
  829. lines = lines[:len(lines)-1]
  830. }
  831. }
  832. switch block.kind {
  833. case .Paragraph:
  834. io.write_string(w, "<p>")
  835. for line, line_idx in lines {
  836. if line_idx > 0 {
  837. io.write_string(w, "\n")
  838. }
  839. io.write_string(w, line)
  840. }
  841. io.write_string(w, "</p>\n")
  842. case .Code:
  843. all_blank := len(lines) > 0
  844. for line in lines {
  845. if strings.trim_space(line) != "" {
  846. all_blank = false
  847. }
  848. }
  849. if all_blank {
  850. continue
  851. }
  852. if strings.has_prefix(prev_line, "Example:") {
  853. io.write_string(w, "<details open class=\"code-example\">\n")
  854. defer io.write_string(w, "</details>\n")
  855. io.write_string(w, "<summary>Example:</summary>\n")
  856. io.write_string(w, `<pre><code class="hljs" data-lang="odin">`)
  857. for line in lines {
  858. io.write_string(w, strings.trim_prefix(line, "\t"))
  859. io.write_string(w, "\n")
  860. }
  861. io.write_string(w, "</code></pre>\n")
  862. } else {
  863. io.write_string(w, "<pre>")
  864. for line in lines {
  865. io.write_string(w, strings.trim_prefix(line, "\t"))
  866. io.write_string(w, "\n")
  867. }
  868. io.write_string(w, "</pre>\n")
  869. }
  870. }
  871. }
  872. }
  873. write_pkg :: proc(w: io.Writer, path: string, pkg: ^doc.Pkg) {
  874. fmt.wprintln(w, `<div class="row odin-main">`)
  875. defer fmt.wprintln(w, `</div>`)
  876. fmt.wprintln(w, `<article class="col-lg-9 p-4 documentation odin-article">`)
  877. { // breadcrumbs
  878. fmt.wprintln(w, `<div class="row">`)
  879. defer fmt.wprintln(w, `</div>`)
  880. fmt.wprintln(w, `<nav aria-label="breadcrumb">`)
  881. defer fmt.wprintln(w, `</nav>`)
  882. io.write_string(w, "<ol class=\"breadcrumb\">\n")
  883. defer io.write_string(w, "</ol>\n")
  884. fmt.wprintf(w, `<li class="breadcrumb-item"><a class="breadcrumb-link" href="%s">core</a></li>`, BASE_CORE_URL)
  885. dirs := strings.split(path, "/")
  886. for dir, i in dirs {
  887. url := strings.join(dirs[:i+1], "/")
  888. short_path := strings.join(dirs[1:i+1], "/")
  889. a_class := "breadcrumb-link"
  890. is_curr := i+1 == len(dirs)
  891. if is_curr {
  892. io.write_string(w, `<li class="breadcrumb-item active" aria-current="page">`)
  893. } else {
  894. io.write_string(w, `<li class="breadcrumb-item">`)
  895. }
  896. if !is_curr && (short_path in pkgs_to_use) {
  897. fmt.wprintf(w, `<a href="%s/%s">%s</a>`, BASE_CORE_URL, url, dir)
  898. } else {
  899. io.write_string(w, dir)
  900. }
  901. io.write_string(w, "</li>\n")
  902. }
  903. }
  904. fmt.wprintf(w, "<h1>package core:%s</h1>\n", path)
  905. overview_docs := strings.trim_space(str(pkg.docs))
  906. if overview_docs != "" {
  907. fmt.wprintln(w, "<h2>Overview</h2>")
  908. fmt.wprintln(w, "<div id=\"pkg-overview\">")
  909. defer fmt.wprintln(w, "</div>")
  910. write_docs(w, pkg, overview_docs)
  911. }
  912. fmt.wprintln(w, `<h2>Index</h2>`)
  913. fmt.wprintln(w, `<div id="pkg-index">`)
  914. pkg_procs: [dynamic]^doc.Entity
  915. pkg_proc_groups: [dynamic]^doc.Entity
  916. pkg_types: [dynamic]^doc.Entity
  917. pkg_vars: [dynamic]^doc.Entity
  918. pkg_consts: [dynamic]^doc.Entity
  919. for entity_index in array(pkg.entities) {
  920. e := &entities[entity_index]
  921. name := str(e.name)
  922. if name == "" || name[0] == '_' {
  923. continue
  924. }
  925. switch e.kind {
  926. case .Invalid, .Import_Name, .Library_Name:
  927. // ignore
  928. case .Constant: append(&pkg_consts, e)
  929. case .Variable: append(&pkg_vars, e)
  930. case .Type_Name: append(&pkg_types, e)
  931. case .Procedure: append(&pkg_procs, e)
  932. case .Proc_Group: append(&pkg_proc_groups, e)
  933. }
  934. }
  935. entity_key :: proc(e: ^doc.Entity) -> string {
  936. return str(e.name)
  937. }
  938. slice.sort_by_key(pkg_procs[:], entity_key)
  939. slice.sort_by_key(pkg_proc_groups[:], entity_key)
  940. slice.sort_by_key(pkg_types[:], entity_key)
  941. slice.sort_by_key(pkg_vars[:], entity_key)
  942. slice.sort_by_key(pkg_consts[:], entity_key)
  943. write_index :: proc(w: io.Writer, name: string, entities: []^doc.Entity) {
  944. fmt.wprintln(w, `<div>`)
  945. defer fmt.wprintln(w, `</div>`)
  946. fmt.wprintf(w, `<details open class="doc-index" id="doc-index-{0:s}" aria-labelledby="#doc-index-{0:s}-header">`+"\n", name)
  947. fmt.wprintf(w, `<summary id="#doc-index-{0:s}-header">`+"\n", name)
  948. io.write_string(w, name)
  949. fmt.wprintln(w, `</summary>`)
  950. defer fmt.wprintln(w, `</details>`)
  951. if len(entities) == 0 {
  952. io.write_string(w, "<p>This section is empty.</p>\n")
  953. } else {
  954. fmt.wprintln(w, "<ul>")
  955. for e in entities {
  956. name := str(e.name)
  957. fmt.wprintf(w, "<li><a href=\"#{0:s}\">{0:s}</a></li>\n", name)
  958. }
  959. fmt.wprintln(w, "</ul>")
  960. }
  961. }
  962. entity_ordering := [?]struct{name: string, entities: []^doc.Entity} {
  963. {"Types", pkg_types[:]},
  964. {"Constants", pkg_consts[:]},
  965. {"Variables", pkg_vars[:]},
  966. {"Procedures", pkg_procs[:]},
  967. {"Procedure Groups", pkg_proc_groups[:]},
  968. }
  969. for eo in entity_ordering {
  970. write_index(w, eo.name, eo.entities)
  971. }
  972. fmt.wprintln(w, "</div>")
  973. write_entity :: proc(w: io.Writer, e: ^doc.Entity) {
  974. write_attributes :: proc(w: io.Writer, e: ^doc.Entity) {
  975. for attr in array(e.attributes) {
  976. io.write_string(w, "@(")
  977. name := str(attr.name)
  978. value := str(attr.value)
  979. io.write_string(w, name)
  980. if value != "" {
  981. io.write_string(w, "=")
  982. io.write_string(w, value)
  983. }
  984. io.write_string(w, ")\n")
  985. }
  986. }
  987. pkg_index := files[e.pos.file].pkg
  988. pkg := &pkgs[pkg_index]
  989. writer := &Type_Writer{
  990. w = w,
  991. pkg = pkg_index,
  992. }
  993. defer delete(writer.generic_scope)
  994. name := str(e.name)
  995. path := pkg_to_path[pkg]
  996. filename := slashpath.base(str(files[e.pos.file].name))
  997. fmt.wprintf(w, "<h3 id=\"{0:s}\"><span><a class=\"doc-id-link\" href=\"#{0:s}\">{0:s}", name)
  998. fmt.wprintf(w, "<span class=\"a-hidden\">&nbsp;¶</span></a></span>")
  999. if e.pos.file != 0 && e.pos.line > 0 {
  1000. src_url := fmt.tprintf("%s/%s/%s#L%d", GITHUB_CORE_URL, path, filename, e.pos.line)
  1001. fmt.wprintf(w, "<div class=\"doc-source\"><a href=\"{0:s}\"><em>Source</em></a></div>", src_url)
  1002. }
  1003. fmt.wprintf(w, "</h3>\n")
  1004. fmt.wprintln(w, `<div>`)
  1005. switch e.kind {
  1006. case .Invalid, .Import_Name, .Library_Name:
  1007. // ignore
  1008. case .Constant:
  1009. fmt.wprint(w, `<pre class="doc-code">`)
  1010. the_type := types[e.type]
  1011. init_string := str(e.init_string)
  1012. assert(init_string != "")
  1013. ignore_type := true
  1014. if the_type.kind == .Basic && is_type_untyped(the_type) {
  1015. } else {
  1016. ignore_type = false
  1017. type_name := str(the_type.name)
  1018. if type_name != "" && strings.has_prefix(init_string, type_name) {
  1019. ignore_type = true
  1020. }
  1021. }
  1022. if ignore_type {
  1023. fmt.wprintf(w, "%s :: ", name)
  1024. } else {
  1025. fmt.wprintf(w, "%s: ", name)
  1026. write_type(writer, the_type, {.Allow_Indent})
  1027. fmt.wprintf(w, " : ")
  1028. }
  1029. io.write_string(w, init_string)
  1030. fmt.wprintln(w, "</pre>")
  1031. case .Variable:
  1032. fmt.wprint(w, `<pre class="doc-code">`)
  1033. write_attributes(w, e)
  1034. fmt.wprintf(w, "%s: ", name)
  1035. write_type(writer, types[e.type], {.Allow_Indent})
  1036. init_string := str(e.init_string)
  1037. if init_string != "" {
  1038. io.write_string(w, " = ")
  1039. io.write_string(w, "…")
  1040. }
  1041. fmt.wprintln(w, "</pre>")
  1042. case .Type_Name:
  1043. fmt.wprint(w, `<pre class="doc-code">`)
  1044. fmt.wprintf(w, "%s :: ", name)
  1045. the_type := types[e.type]
  1046. type_to_print := the_type
  1047. if the_type.kind == .Named && .Type_Alias not_in e.flags {
  1048. if e.pos == entities[array(the_type.entities)[0]].pos {
  1049. bt := base_type(the_type)
  1050. #partial switch bt.kind {
  1051. case .Struct, .Union, .Proc, .Enum:
  1052. // Okay
  1053. case:
  1054. io.write_string(w, "distinct ")
  1055. }
  1056. type_to_print = bt
  1057. }
  1058. }
  1059. write_type(writer, type_to_print, {.Allow_Indent})
  1060. fmt.wprintln(w, "</pre>")
  1061. case .Procedure:
  1062. fmt.wprint(w, `<pre class="doc-code">`)
  1063. fmt.wprintf(w, "%s :: ", name)
  1064. write_type(writer, types[e.type], nil)
  1065. write_where_clauses(w, array(e.where_clauses))
  1066. fmt.wprint(w, " {…}")
  1067. fmt.wprintln(w, "</pre>")
  1068. case .Proc_Group:
  1069. fmt.wprint(w, `<pre class="doc-code">`)
  1070. fmt.wprintf(w, "%s :: proc{{\n", name)
  1071. for entity_index in array(e.grouped_entities) {
  1072. this_proc := &entities[entity_index]
  1073. this_pkg := files[this_proc.pos.file].pkg
  1074. io.write_byte(w, '\t')
  1075. if this_pkg != pkg_index {
  1076. fmt.wprintf(w, "%s.", str(pkgs[this_pkg].name))
  1077. }
  1078. name := str(this_proc.name)
  1079. fmt.wprintf(w, `<a class="code-procedure" href="{2:s}/{0:s}/#{1:s}">`, pkg_to_path[&pkgs[this_pkg]], name, BASE_CORE_URL)
  1080. io.write_string(w, name)
  1081. io.write_string(w, `</a>`)
  1082. io.write_byte(w, ',')
  1083. io.write_byte(w, '\n')
  1084. }
  1085. fmt.wprintln(w, "}")
  1086. fmt.wprintln(w, "</pre>")
  1087. }
  1088. fmt.wprintln(w, `</div>`)
  1089. the_docs := strings.trim_space(str(e.docs))
  1090. if the_docs != "" {
  1091. fmt.wprintln(w, `<details class="odin-doc-toggle" open>`)
  1092. fmt.wprintln(w, `<summary class="hideme"><span>&nbsp;</span></summary>`)
  1093. write_docs(w, pkg, the_docs)
  1094. fmt.wprintln(w, `</details>`)
  1095. }
  1096. }
  1097. write_entities :: proc(w: io.Writer, title: string, entities: []^doc.Entity) {
  1098. fmt.wprintf(w, "<h2 id=\"pkg-{0:s}\">{0:s}</h2>\n", title)
  1099. fmt.wprintln(w, `<section class="documentation">`)
  1100. if len(entities) == 0 {
  1101. io.write_string(w, "<p>This section is empty.</p>\n")
  1102. } else {
  1103. for e in entities {
  1104. fmt.wprintln(w, `<div class="pkg-entity">`)
  1105. write_entity(w, e)
  1106. fmt.wprintln(w, `</div>`)
  1107. }
  1108. }
  1109. fmt.wprintln(w, "</section>")
  1110. }
  1111. for eo in entity_ordering {
  1112. write_entities(w, eo.name, eo.entities)
  1113. }
  1114. fmt.wprintln(w, `<h2 id="pkg-source-files">Source Files</h2>`)
  1115. fmt.wprintln(w, "<ul>")
  1116. any_hidden := false
  1117. source_file_loop: for file_index in array(pkg.files) {
  1118. file := files[file_index]
  1119. filename := slashpath.base(str(file.name))
  1120. switch {
  1121. case
  1122. strings.has_suffix(filename, "_windows.odin"),
  1123. strings.has_suffix(filename, "_darwin.odin"),
  1124. strings.has_suffix(filename, "_essence.odin"),
  1125. strings.has_suffix(filename, "_freebsd.odin"),
  1126. strings.has_suffix(filename, "_wasi.odin"),
  1127. strings.has_suffix(filename, "_js.odin"),
  1128. strings.has_suffix(filename, "_freestanding.odin"),
  1129. strings.has_suffix(filename, "_amd64.odin"),
  1130. strings.has_suffix(filename, "_i386.odin"),
  1131. strings.has_suffix(filename, "_arch64.odin"),
  1132. strings.has_suffix(filename, "_wasm32.odin"),
  1133. strings.has_suffix(filename, "_wasm64.odin"),
  1134. false:
  1135. any_hidden = true
  1136. continue source_file_loop
  1137. }
  1138. fmt.wprintf(w, `<li><a href="%s/%s/%s">%s</a></li>`, GITHUB_CORE_URL, path, filename, filename)
  1139. fmt.wprintln(w)
  1140. }
  1141. if any_hidden {
  1142. fmt.wprintln(w, "<li><em>(hidden platform specific files)</em></li>")
  1143. }
  1144. fmt.wprintln(w, "</ul>")
  1145. fmt.wprintln(w, `</article>`)
  1146. {
  1147. write_link :: proc(w: io.Writer, id, text: string) {
  1148. fmt.wprintf(w, `<li><a href="#%s">%s</a>`, id, text)
  1149. }
  1150. fmt.wprintln(w, `<div class="col-lg-3 odin-toc-border navbar-light"><div class="sticky-top odin-below-navbar py-3">`)
  1151. fmt.wprintln(w, `<nav id="TableOfContents">`)
  1152. fmt.wprintln(w, `<ul>`)
  1153. if overview_docs != "" {
  1154. write_link(w, "pkg-overview", "Overview")
  1155. }
  1156. for eo in entity_ordering do if len(eo.entities) != 0 {
  1157. fmt.wprintf(w, `<li><a href="#pkg-{0:s}">{0:s}</a>`, eo.name)
  1158. fmt.wprintln(w, `<ul>`)
  1159. for e in eo.entities {
  1160. fmt.wprintf(w, "<li><a href=\"#{0:s}\">{0:s}</a></li>\n", str(e.name))
  1161. }
  1162. fmt.wprintln(w, "</ul>")
  1163. fmt.wprintln(w, "</li>")
  1164. }
  1165. write_link(w, "pkg-source-files", "Source Files")
  1166. fmt.wprintln(w, `</ul>`)
  1167. fmt.wprintln(w, `</nav>`)
  1168. fmt.wprintln(w, `</div></div>`)
  1169. }
  1170. }