1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510
|
//===----------------------------------------------------------*- swift -*-===//
//
// This source file is part of the Swift Argument Parser open source project
//
// Copyright (c) 2021 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
//===----------------------------------------------------------------------===//
//===--------------------------------------------------------*- openbsd -*-===//
//
// This source file contains descriptions of mandoc syntax tree nodes derived
// from their original descriptions in the mandoc source found here:
// https://github.com/openbsd/src/blob/master/share/man/man7/mdoc.7
//
// $Id: LICENSE,v 1.22 2021/09/19 11:02:09 schwarze Exp $
//
// With the exceptions noted below, all non-trivial files contained
// in the mandoc toolkit are protected by the Copyright of the following
// developers:
//
// Copyright (c) 2008-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
// Copyright (c) 2010-2021 Ingo Schwarze <schwarze@openbsd.org>
// Copyright (c) 1999, 2004, 2017 Marc Espie <espie@openbsd.org>
// Copyright (c) 2009, 2010, 2011, 2012 Joerg Sonnenberger <joerg@netbsd.org>
// Copyright (c) 2013 Franco Fichtner <franco@lastsummer.de>
// Copyright (c) 2014 Baptiste Daroussin <bapt@freebsd.org>
// Copyright (c) 2016 Ed Maste <emaste@freebsd.org>
// Copyright (c) 2017 Michael Stapelberg <stapelberg@debian.org>
// Copyright (c) 2017 Anthony Bentley <bentley@openbsd.org>
// Copyright (c) 1998, 2004, 2010, 2015 Todd C. Miller <Todd.Miller@courtesan.com>
// Copyright (c) 2008, 2017 Otto Moerbeek <otto@drijf.net>
// Copyright (c) 2004 Ted Unangst <tedu@openbsd.org>
// Copyright (c) 1994 Christos Zoulas <christos@netbsd.org>
// Copyright (c) 2003, 2007, 2008, 2014 Jason McIntyre <jmc@openbsd.org>
//
// See the individual files for information about who contributed
// to which file during which years.
//
//
// The mandoc distribution as a whole is distributed by its developers
// under the following license:
//
// Permission to use, copy, modify, and distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
//
//
// The following files included from outside sources are protected by
// other people's Copyright and are distributed under various 2-clause
// and 3-clause BSD licenses; see these individual files for details.
//
// soelim.c, soelim.1:
// Copyright (c) 2014 Baptiste Daroussin <bapt@freebsd.org>
//
// compat_err.c, compat_fts.c, compat_fts.h,
// compat_getsubopt.c, compat_strcasestr.c, compat_strsep.c,
// man.1:
// Copyright (c) 1989,1990,1993,1994 The Regents of the University of California
//
// compat_stringlist.c, compat_stringlist.h:
// Copyright (c) 1994 Christos Zoulas <christos@netbsd.org>
//
// See https://mandoc.bsd.lv/LICENSE for license information
//
//===----------------------------------------------------------------------===//
fileprivate extension Array {
mutating func append(optional newElement: Element?) {
if let newElement = newElement {
append(newElement)
}
}
}
/// `MDocMacroProtocol` defines the properties required to serialize a
/// strongly-typed mdoc macro to the raw format.
public protocol MDocMacroProtocol: MDocASTNode {
/// The underlying `mdoc` macro string; used during serialization.
static var kind: String { get }
/// The arguments passed to the underlying `mdoc` macro; used during
/// serialization.
var arguments: [MDocASTNode] { get set }
}
extension MDocMacroProtocol {
/// Append unchecked arguments to a `MDocMacroProtocol`.
public func withUnsafeChildren(nodes: [MDocASTNode]) -> Self {
var copy = self
copy.arguments.append(contentsOf: nodes)
return copy
}
}
extension MDocMacroProtocol {
public func _serialized(context: MDocSerializationContext) -> String {
var result = ""
// Prepend a dot if we aren't already in a macroLine context
if !context.macroLine {
result += "."
}
result += Self.kind
if !arguments.isEmpty {
var context = context
context.macroLine = true
result += " "
result += arguments
.map { $0._serialized(context: context) }
.joined(separator: " ")
}
return result
}
}
/// `MDocMacro` is a namespace for types conforming to ``MDocMacroProtocol``.
public enum MDocMacro {
/// Comment placed inline in the manual page.
///
/// Comment are not displayed by tools consuming serialized manual pages.
///
/// __Example Usage__:
/// ```swift
/// Comment("WIP: History section...")
/// ```
public struct Comment: MDocMacroProtocol {
public static let kind = #"\""#
public var arguments: [MDocASTNode]
/// Creates a new `Comment` macro.
///
/// - Parameters:
/// - comment: A string to insert as an inline comment.
public init(_ comment: String) {
self.arguments = [comment]
}
}
// MARK: - Document preamble and NAME section macros
/// Document date displayed in the manual page footer.
///
/// This must be the first macro in any `mdoc` document.
///
/// __Example Usage__:
/// ```swift
/// DocumentDate(day: 9, month: "September", year: 2014)
/// ```
public struct DocumentDate: MDocMacroProtocol {
public static let kind = "Dd"
public var arguments: [MDocASTNode]
/// Creates a new `DocumentDate` macro.
///
/// - Parameters:
/// - day: An integer number day of the month the manual was written.
/// - month: The full English month name the manual was written.
/// - year: The four digit year the manual was written.
public init(day: Int, month: String, year: Int) {
arguments = [month, "\(day),", year]
}
}
/// Document title displayed in the manual page header.
///
/// This must be the second macro in any `mdoc` document.
///
/// __Example Usage__:
/// ```swift
/// DocumentTitle(title: "swift", section: 1)
/// DocumentTitle(title: "swift", section: 1, arch: "arm64e")
/// ```
public struct DocumentTitle: MDocMacroProtocol {
public static let kind = "Dt"
public var arguments: [MDocASTNode]
/// Creates a new `DocumentTitle` macro.
///
/// - Parameters:
/// - title: The document's title or name. By convention the title should
/// be all caps.
/// - section: The manual section. The section should match the manual
/// page's file extension. Must be one of the following values:
/// 1. General Commands
/// 2. System Calls
/// 3. Library Functions
/// 4. Device Drivers
/// 5. File Formats
/// 6. Games
/// 7. Miscellaneous Information
/// 8. System Manager's Manual
/// 9. Kernel Developer's Manual
/// - arch: The machine architecture the manual page applies to, for
/// example: `alpha`, `i386`, `x86_64` or `arm64e`.
public init(title: String, section: Int, arch: String? = nil) {
precondition((1...9).contains(section))
self.arguments = [title, section]
self.arguments.append(optional: arch)
}
}
/// Operating system and version displayed in the manual page footer.
///
/// This must be the third macro in any `mdoc` document.
///
/// __Example Usage__:
/// ```swift
/// OperatingSystem()
/// OperatingSystem(name: "macOS")
/// OperatingSystem(name: "macOS", version: "10.13")
/// ```
public struct OperatingSystem: MDocMacroProtocol {
public static let kind = "Os"
public var arguments: [MDocASTNode]
/// Creates a new `OperatingSystem` macro.
///
/// - Note: The `version` parameter must not be specified without the `name`
/// parameter.
///
/// - Parameters:
/// - name: The operating system the manual page contents is valid for.
/// Omitting `name` is recommended and will result in the user's
/// operating system name being used.
/// - version: The version the of the operating system specified by `name`
/// the manual page contents is valid for. Omitting `version` is
/// recommended.
public init(name: String? = nil, version: String? = nil) {
precondition(!(name == nil && version != nil))
self.arguments = []
self.arguments.append(optional: name)
self.arguments.append(optional: version)
}
}
/// The name of the manual page.
///
/// The first use of ``DocumentName`` is typically in the "NAME" section. The
/// name provided to the created ``DocumentName`` will be remembered and
/// subsequent uses of the ``DocumentName`` can omit the name argument.
///
/// - Note: Manual pages in sections 1, 6, and 8 may use the name of command
/// or feature documented in the manual page as the name.
///
/// In sections 2, 3, and 9 use the ``FunctionName`` macro instead of the
/// ``DocumentName`` macro to indicate the name of the document.
///
/// __Example Usage__:
/// ```swift
/// SectionHeader(title: "SYNOPSIS")
/// DocumentName(name: "swift")
/// OptionalCommandLineComponent(arguments: CommandArgument(arguments: ["h"]))
/// ```
public struct DocumentName: MDocMacroProtocol {
public static let kind = "Nm"
public var arguments: [MDocASTNode]
/// Creates a new `DocumentName` macro.
///
/// - Parameters:
/// - name: The name of the manual page.
public init(name: String? = nil) {
self.arguments = []
self.arguments.append(optional: name)
}
}
/// Single line description of the manual page.
///
/// This must be the last macro in the "NAME" section `mdoc` document and
/// should not appear in any other section.
///
/// __Example Usage__:
/// ```swift
/// DocumentDescription(description: "Safe, fast, and expressive general-purpose programming language")
/// ```
public struct DocumentDescription: MDocMacroProtocol {
public static let kind = "Nd"
public var arguments: [MDocASTNode]
/// Creates a new `DocumentDescription` macro.
///
/// - Parameters:
/// - description: The description of the manual page.
public init(description: String) {
self.arguments = [description]
}
}
// MARK: - Sections and cross references
/// Start a new manual section.
///
/// See [Manual Structure](http://mandoc.bsd.lv/man/mdoc.7.html#MANUAL_STRUCTURE)
/// for a list of standard sections. Custom sections should be avoided though
/// can be used.
///
/// - Note: Section names should be unique so they can be referenced using a
/// ``SectionReference``.
///
/// __Example Usage__:
/// ```swift
/// SectionHeader(title: "NAME")
/// ```
public struct SectionHeader: MDocMacroProtocol {
public static let kind = "Sh"
public var arguments: [MDocASTNode]
/// Creates a new `SectionHeader` macro.
///
/// - Parameters:
/// - title: The title of the section.
public init(title: String) {
self.arguments = [title]
}
}
/// Start a new manual subsection.
///
/// There is no standard naming convention of subsections.
///
/// - Note: Subsection names should be unique so they can be referenced using
/// a ``SectionReference``.
///
/// __Example Usage__:
/// ```swift
/// SubsectionHeader(title: "DETAILS")
/// ```
public struct SubsectionHeader: MDocMacroProtocol {
public static let kind = "Ss"
public var arguments: [MDocASTNode]
/// Creates a new `SubsectionHeader` macro.
///
/// - Parameters:
/// - title: The title of the subsection.
public init(title: String) {
self.arguments = [title]
}
}
/// Reference a section or subsection in the same manual page.
///
/// The section or subsection title must exactly match the title passed to
/// ``SectionReference``.
///
/// __Example Usage__:
/// ```swift
/// SectionReference(title: "NAME")
/// ```
public struct SectionReference: MDocMacroProtocol {
public static let kind = "Sx"
public var arguments: [MDocASTNode]
/// Creates a new `SectionReference` macro.
///
/// - Parameters:
/// - title: The title of the section or subsection to reference.
public init(title: String) {
self.arguments = [title]
}
}
/// Reference another manual page.
///
/// __Example Usage__:
/// ```swift
/// CrossManualReference(title: "swift", section: 1)
/// ```
public struct CrossManualReference: MDocMacroProtocol {
public static let kind = "Xr"
public var arguments: [MDocASTNode]
/// Creates a new `CrossManualReference` macro.
///
/// - Parameters:
/// - title: The title of the section or subsection to reference.
public init(title: String, section: Int) {
precondition((1...9).contains(section))
self.arguments = [title, section]
}
}
/// Whitespace break between paragaphs.
///
/// Breaks should not be inserted immeediately before or after
/// ``SectionHeader``, ``SubsectionHeader``, and ``BeginList`` macros.
public struct ParagraphBreak: MDocMacroProtocol {
public static let kind = "Pp"
public var arguments: [MDocASTNode]
/// Creates a new `ParagraphBreak` macro.
public init() {
self.arguments = []
}
}
// MARK: - Displays and lists
// Display block: -type [-offset width] [-compact].
// TODO: "Ed"
// Indented display (one line).
// TODO: "D1"
// Indented literal display (one line).
// TODO: "Dl"
// In-line literal display: ‘text’.
// TODO: "Ql"
// FIXME: Documentation
/// Open a list scope.
///
/// Closed by an ``EndList`` macro.
///
/// Lists are made of ``ListItem``s which are displayed in a variety of styles
/// depending on the ``ListStyle`` used to create the list scope.
/// List scopes can be nested in other list scopes, however nesting `.column`
/// and `ListStyle.enum` lists is not recommended as they may display inconsistently
/// between tools.
///
/// __Example Usage__:
/// ```swift
/// BeginList(style: .tag, width: 6)
/// ListItem(title: "Hello, Swift!")
/// "Welcome to the Swift programming language."
/// ListItem(title: "Goodbye!")
/// EndList()
/// ```
public struct BeginList: MDocMacroProtocol {
/// Enumeration of styles supported by the ``BeginList`` macro.
public enum ListStyle: String {
/// A bulleted list.
///
/// Item titles should not be provided, instead item bodies are displayed
/// indented from a preceding bullet point using the specified width.
case bullet
// TODO: case column
// /// A columnated list.
// case column
/// A dashed list.
///
/// Identical to `.bullet` except dashes precede each item.
case dash
/// An unindented list without newlines following important item titles
/// without macro parsing.
///
/// Identical to `.inset` except item titles are displayed with importance
/// and are not parsed for macros. `.diag` is typically used in the
/// "DIAGNOSTICS" section with errors as the item titles.
case diag
/// An enumerated list.
///
/// Identical to `.bullet` except increasing numbers starting at 1 precede
/// each item.
case `enum`
/// An indented list without joined item titles and bodies.
///
/// Identical to `.tag` except item bodies always on the line after the
/// item title.
case hang
/// Alias for `.dash`.
case hyphen
/// An unindented list without newlines following item titles.
///
/// Identical to `.ohang` except item titles are not followed by newlines.
case inset
/// An unindented list without item titles.
///
/// Identical to `.ohang` except item titles should not be provided and
/// are not displayed.
case item
/// An unindented list.
///
/// Item titles are displayed on a single line, with unindented item
/// bodies on the succeeding lines.
case ohang
/// An indented list.
///
/// Item titles are displayed on a single line with item bodies indented
/// using the specified width on succeeding lines. If the item title is
/// shorter than the indentation width, item bodies are displayed on the
/// same as the title.
case tag
}
public static let kind = "Bl"
public var arguments: [MDocASTNode]
/// Creates a new `BeginList` macro.
///
/// - Parameters:
/// - style: Display style.
/// - width: Number of characters to indent item bodies from titles.
/// - offset: Number of characters to indent both the item titles and bodies.
/// - compact: Disable vertical spacing between list items.
public init(style: ListStyle, width: Int? = nil, offset: Int? = nil, compact: Bool = false) {
self.arguments = ["-\(style)"]
switch style {
case .bullet, .dash, .`enum`, .hang, .hyphen, .tag:
if let width = width {
self.arguments.append(contentsOf: ["-width", "\(width)n"])
}
case /*.column, */.diag, .inset, .item, .ohang:
assert(width == nil, "`width` should be nil for style: \(style)")
}
if let offset = offset {
self.arguments.append(contentsOf: ["-offset", "\(offset)n"])
}
if compact {
self.arguments.append(contentsOf: ["-compact"])
}
}
}
/// A list item.
///
/// ``ListItem`` begins a list item scope continuing until another
/// ``ListItem`` is encountered or the enclosing list scope is closed by
/// ``EndList``. ``ListItem``s may include a title if the the enclosing list
/// scope was constructed with one of the following styles:
/// - `.bullet`
/// - `.dash`
/// - `.enum`
/// - `.hang`
/// - `.hyphen`
/// - `.tag`
///
/// __Example Usage__:
/// ```swift
/// BeginList(style: .tag, width: 6)
/// ListItem(title: "Hello, Swift!")
/// "Welcome to the Swift programming language."
/// ListItem(title: "Goodbye!")
/// EndList()
/// ```
public struct ListItem: MDocMacroProtocol {
public static let kind = "It"
public var arguments: [MDocASTNode]
/// Creates a new `ListItem` macro.
///
/// - Parameters:
/// - title: List item title, only valid depending on the ``ListStyle``.
public init(title: MDocASTNode? = nil) {
arguments = []
arguments.append(optional: title)
}
}
// Table cell separator in Bl -column lists.
// TODO: "Ta"
/// Close a list scope opened by a ``BeginList`` macro.
public struct EndList: MDocMacroProtocol {
public static let kind = "El"
public var arguments: [MDocASTNode]
/// Creates a new `EndList` macro.
public init() {
self.arguments = []
}
}
// Bibliographic block (references).
// TODO: "Re"
// MARK: Spacing control
/// Text without a trailing space.
///
/// __Example Usage__:
/// ```swift
/// WithoutTrailingSpace(text: "swift")
/// ```
public struct WithoutTrailingSpace: MDocMacroProtocol {
public static let kind = "Pf"
public var arguments: [MDocASTNode]
/// Creates a new `WithoutTrailingSpace` macro.
///
/// - Parameters:
/// - text: The text to display without a trailing space.
public init(text: String) {
self.arguments = [text]
}
}
/// Text without a leading space.
///
/// __Example Usage__:
/// ```swift
/// WithoutLeadingSpace(text: "swift")
/// ```
public struct WithoutLeadingSpace: MDocMacroProtocol {
public static let kind = "Ns"
public var arguments: [MDocASTNode]
/// Creates a new `WithoutLeadingSpace` macro.
///
/// - Parameters:
/// - text: The text to display without a trailing space.
public init(text: String) {
self.arguments = [text]
}
}
/// An apostrophe without leading and trailing spaces.
///
/// __Example Usage__:
/// ```swift
/// Apostrophe()
/// ```
public struct Apostrophe: MDocMacroProtocol {
public static let kind = "Ap"
public var arguments: [MDocASTNode]
/// Creates a new `Apostrophe` macro.
public init() {
self.arguments = []
}
}
// TODO: HorizontalSpacing
// /// Switch horizontal spacing mode: [on | off].
// public struct HorizontalSpacing: MDocMacroProtocol {
// public static let kind = "Sm"
// public var arguments: [MDocASTNode]
// public init() {
// self.arguments = []
// }
// }
// Keep block: -words.
// TODO: "Ek"
// MARK: - Semantic markup for command-line utilities
/// Command-line flags and options.
///
/// Displays a hyphen (`-`) before each argument. ``CommandOption`` is
/// typically used in the "SYNOPSIS" and "DESCRIPTION" sections when listing
/// and describing options in a manual page.
///
/// __Example Usage__:
/// ```swift
/// CommandOption(arguments: ["-version"])
/// .withUnsafeChildren(CommandArgument(arguments: "version"))
/// ```
public struct CommandOption: MDocMacroProtocol {
public static let kind = "Fl"
public var arguments: [MDocASTNode]
/// Creates a new `CommandOption` macro.
///
/// - Parameters:
/// - arguments: Command-line flags and options.
public init(options: [MDocASTNode]) {
self.arguments = options
}
}
/// Command-line modifiers.
///
/// ``CommandModifier`` is typically used to denote strings exactly passed as
/// arguments, if and only if, ``CommandOption`` is not appropriate.
/// ``CommandModifier`` can also be used to specify configuration options and
/// keys.
///
/// __Example Usage__:
/// ```swift
/// CommandModifier(modifiers: ["Configuration File"])
/// .withUnsafeChildren(nodes: [FilePath(path: "$HOME/.swiftpm")])
/// ```
public struct CommandModifier: MDocMacroProtocol {
public static let kind = "Cm"
public var arguments: [MDocASTNode]
/// Creates a new `CommandModifier` macro.
///
/// - Parameters:
/// - modifiers: Command-line modifiers.
public init(modifiers: [MDocASTNode]) {
self.arguments = modifiers
}
}
/// Command-line placeholders.
///
/// ``CommandArgument`` displays emphasized placeholders for command-line
/// flags, options and arguments. Flag and option names must use
/// ``CommandOption`` or `CommandModifier` macros. If no arguments are
/// provided to ``CommandArgument``, the string `"file ..."` is used.
///
/// __Example Usage__:
/// ```swift
/// CommandArgument()
/// CommandArgument(arguments: [arg1, ",", arg2, "."])
/// CommandOption(arguments: ["-version"])
/// .withUnsafeChildren(CommandArgument(arguments: "version"))
/// ```
public struct CommandArgument: MDocMacroProtocol {
public static let kind = "Ar"
public var arguments: [MDocASTNode]
/// Creates a new `CommandArgument` macro.
///
/// - Parameters:
/// - arguments: Command-line argument placeholders.
public init(arguments: [MDocASTNode]) {
self.arguments = arguments
}
}
/// Single-line optional command-line components.
///
/// Displays the arguments in `[squareBrackets]`.
/// ``OptionalCommandLineComponent`` is typically used in the "SYNOPSIS"
/// section.
///
/// __Example Usage__:
/// ```swift
/// SectionHeader(title: "SYNOPSIS")
/// DocumentName(name: "swift")
/// OptionalCommandLineComponent(arguments: CommandArgument(arguments: ["h"]))
/// ```
public struct OptionalCommandLineComponent: MDocMacroProtocol {
public static let kind = "Op"
public var arguments: [MDocASTNode]
/// Creates a new `OptionalCommandLineComponent` macro.
///
/// - Parameters:
/// - arguments: Command-line components to enclose.
public init(arguments: [MDocASTNode]) {
self.arguments = arguments
}
}
/// Begin a multi-line optional command-line comment scope.
///
/// Displays the scope contents in `[squareBrackets]`.
/// ``BeginOptionalCommandLineComponent`` is typically used in the "SYNOPSIS"
/// section.
///
/// Closed by an ``EndOptionalCommandLineComponent`` macro.
///
/// __Example Usage__:
/// ```swift
/// BeginOptionalCommandLineComponent()
/// "Hello, Swift!"
/// EndOptionalCommandLineComponent()
/// ```
public struct BeginOptionalCommandLineComponent: MDocMacroProtocol {
public static let kind = "Oo"
public var arguments: [MDocASTNode]
/// Creates a new `BeginOptionalCommandLineComponent` macro.
public init() {
self.arguments = []
}
}
/// Close a ```BeginOptionalCommandLineComponent``` block.
public struct EndOptionalCommandLineComponent: MDocMacroProtocol {
public static let kind = "Oc"
public var arguments: [MDocASTNode]
/// Creates a new `EndOptionalCommandLineComponent` macro.
public init() {
self.arguments = []
}
}
/// An interactive command.
///
/// ``InteractiveCommand`` is similar to ``CommandModifier`` but should be used
/// to describe commands instead of arguments. For example,
/// ``InteractiveCommand`` can be used to describe the commands to editors
/// like `emacs` and `vim` or shells like `bash` or `fish`.
///
/// __Example Usage__:
/// ```swift
/// InteractiveCommand(name: "print")
/// InteractiveCommand(name: "save")
/// InteractiveCommand(name: "quit")
/// ```
public struct InteractiveCommand: MDocMacroProtocol {
public static let kind = "Ic"
public var arguments: [MDocASTNode]
/// Creates a new `InteractiveCommand` macro.
///
/// - Parameters:
/// - name: Name of the interactive command.
public init(name: String) {
self.arguments = [name]
}
}
/// An environment variable.
///
/// __Example Usage__:
/// ```swift
/// EnvironmentVariable(variable: "DISPLAY")
/// EnvironmentVariable(variable: "PATH")
/// ```
public struct EnvironmentVariable: MDocMacroProtocol {
public static let kind = "Ev"
public var arguments: [MDocASTNode]
/// Creates a new `EnvironmentVariable` macro.
///
/// - Parameters:
/// - name: Name of the environment variable.
public init(name: String) {
self.arguments = [name]
}
}
/// A file path.
///
/// __Example Usage__:
/// ```swift
/// FilePath()
/// FilePath(path: "/usr/bin/swift")
/// FilePath(path: "/usr/share/man/man1/swift.1")
/// ```
public struct FilePath: MDocMacroProtocol {
public static let kind = "Pa"
public var arguments: [MDocASTNode]
/// Creates a new `FilePath` macro.
///
/// - Parameters:
/// - path: An optional absolute or relative path or a file or directory.
/// Tilde (`~`) will be used, if no path is used.
public init(path: String? = nil) {
self.arguments = []
self.arguments.append(optional: path)
}
}
// MARK: - Semantic markup for function libraries
// Function library (one argument).
// TODO: "Lb"
// Include file (one argument).
// TODO: "In"
// Other preprocessor directive (>0 arguments).
// TODO: "Fd"
// Function type (>0 arguments).
// TODO: "Ft"
// Function block: funcname.
// TODO: "Fc"
// Function name: funcname [argument ...].
// TODO: "Fn"
// Function argument (>0 arguments).
// TODO: "Fa"
// Variable type (>0 arguments).
// TODO: "Vt"
// Variable name (>0 arguments).
// TODO: "Va"
/// Defined variable or preprocessor constant (>0 arguments).
// TODO: "Dv"
/// Error constant (>0 arguments).
// TODO: "Er"
/// Environmental variable (>0 arguments).
// TODO: "Ev"
// MARK: - Various semantic markup
/// An author's name.
///
/// ``Author`` can be used to designate any author. Specifying an author of
/// the manual page itself should only occur in the "AUTHORS" section.
///
/// ``Author`` also controls the display mode of authors. In the split mode,
/// a new-line will be inserted before each author, otherwise authors will
/// appear inline with other macros and text. Outside of the "AUTHORS"
/// section, the default display mode is unsplit. The display mode is reset at
/// the start of the "AUTHORS" section. In the "AUTHORS" section, the first
/// use of ``Author`` will use the unsplit mode and subsequent uses with use
/// the split mode. This behavior can be overridden by inserting an author
/// display mode macro before the normal author macro.
///
/// __Example Usage__:
/// ```swift
/// Author(split: false)
/// Author(name: "Rauhul Varma")
/// ```
public struct Author: MDocMacroProtocol {
public static let kind = "An"
public var arguments: [MDocASTNode]
/// Creates a new `Author` macro.
///
/// - Parameters:
/// - name: The author name to display.
public init(name: String) {
self.arguments = [name]
}
/// Creates a new `Author` macro.
///
/// - Parameters:
/// - split: The split display mode to use for subsequent uses of
/// ``Author``.
public init(split: Bool) {
self.arguments = [split ? "-split" : "-nosplit"]
}
}
/// A website hyperlink.
///
/// __Example Usage__:
/// ```swift
/// Hyperlink(url: "http://swift.org")
/// Hyperlink(url: "http://swift.org", displayText: "Programming in Swift")
/// ```
public struct Hyperlink: MDocMacroProtocol {
public static let kind = "Lk"
public var arguments: [MDocASTNode]
/// Creates a new `Hyperlink` macro.
///
/// - Parameters:
/// - url: The website address to link.
/// - displayText: Optional title text accompanying the url.
public init(url: String, displayText: String? = nil) {
self.arguments = [url]
self.arguments.append(optional: displayText)
}
}
/// An email hyperlink.
///
/// __Example Usage__:
/// ```swift
/// MailTo(email: "swift+evolution-discuss@forums.swift.org")
/// ```
public struct MailTo: MDocMacroProtocol {
public static let kind = "Mt"
public var arguments: [MDocASTNode]
/// Creates a new `MailTo` macro.
///
/// - Parameters:
/// - email: The email address to link.
public init(email: String) {
self.arguments = [email]
}
}
// TODO: KernelConfiguration
// /// Kernel configuration declaration (>0 arguments).
// public struct KernelConfiguration: MDocMacroProtocol {
// public static let kind = "Cd"
// public var arguments: [MDocASTNode]
// public init() {
// self.arguments = []
// }
// }
// TODO: MemoryAddress
// /// Memory address (>0 arguments).
// public struct MemoryAddress: MDocMacroProtocol {
// public static let kind = "Ad"
// public var arguments: [MDocASTNode]
// public init() {
// self.arguments = []
// }
// }
// TODO: MathematicalSymbol
// /// Mathematical symbol (>0 arguments).
// public struct MathematicalSymbol: MDocMacroProtocol {
// public static let kind = "Ms"
// public var arguments: [MDocASTNode]
// public init() {
// self.arguments = []
// }
// }
// MARK: - Physical markup
/// Emphasize single-line text.
///
/// ``Emphasis`` should only be used when no other semantic macros are
/// appropriate. ``Emphasis`` is used to express "emphasis"; for example:
/// ``Emphasis`` can be used to highlight technical terms and placeholders,
/// except when they appear in syntactic elements. ``Emphasis`` should not be
/// conflated with "importance" which should be expressed using ``Boldface``.
///
/// - Note: Emphasizes text is usually italicized. If the output program does
/// not support italicizing text, it is underlined instead.
///
/// __Example Usage__:
/// ```swift
/// Emphasis(arguments: ["Hello", ", "Swift!"])
/// ```
public struct Emphasis: MDocMacroProtocol {
public static let kind = "Em"
public var arguments: [MDocASTNode]
/// Creates a new `Emphasis` macro.
///
/// - Parameters:
/// - arguments: Text to emphasize.
public init(arguments: [MDocASTNode]) {
self.arguments = arguments
}
}
/// Embolden single-line text.
///
/// ``Boldface`` should only be used when no other semantic macros are
/// appropriate. ``Boldface`` is used to express "importance"; for example:
/// ``Boldface`` can be used to highlight required arguments and exact text.
/// ``Boldface`` should not be conflated with "emphasis" which
/// should be expressed using ``Emphasis``.
///
/// __Example Usage__:
/// ```swift
/// Boldface(arguments: ["Hello,", " Swift!"])
/// ```
public struct Boldface: MDocMacroProtocol {
public static let kind = "Sy"
public var arguments: [MDocASTNode]
/// Creates a new `Boldface` macro.
///
/// - Parameters:
/// - arguments: Text to embolden.
public init(arguments: [MDocASTNode]) {
self.arguments = arguments
}
}
/// Reset the font style, set by a single-line text macro.
///
/// __Example Usage__:
/// ```swift
/// Boldface(arguments: ["Hello,"])
/// .withUnsafeChildren(nodes: [NormalText(), " Swift!"])
/// ```
public struct NormalText: MDocMacroProtocol {
public static let kind = "No"
public var arguments: [MDocASTNode]
/// Creates a new `NormalText` macro.
public init() {
self.arguments = []
}
}
/// Open a font scope with a font style.
///
/// Closed by a ``EndFont`` macro.
///
/// __Example Usage__:
/// ```swift
/// BeginFont(style: .boldface)
/// "Hello, Swift!"
/// EndFont()
/// ```
public struct BeginFont: MDocMacroProtocol {
/// Enumeration of font styles supported by `mdoc`.
public enum FontStyle {
/// Italic font style.
case emphasis
/// Typewriter font style.
///
/// `literal` should not be used because it is visually identical to
/// normal text.
case literal
/// Bold font style.
case boldface
}
public static let kind = "Bf"
public var arguments: [MDocASTNode]
/// Creates a new `BeginFont` macro.
///
/// - Parameters:
/// - style: The style of font scope the macro opens.
public init(style: FontStyle) {
switch style {
case .emphasis:
self.arguments = ["-emphasis"]
case .literal:
self.arguments = ["-literal"]
case .boldface:
self.arguments = ["-symbolic"]
}
}
}
/// Close a font scope opened by a ``BeginFont`` macro.
public struct EndFont: MDocMacroProtocol {
public static let kind = "Ef"
public var arguments: [MDocASTNode]
/// Creates a new `EndFont` macro.
public init() {
self.arguments = []
}
}
// MARK: - Physical enclosures
/// Open a scope enclosed by `“typographic”` double-quotes.
///
/// Closed by a ``EndTypographicDoubleQuotes`` macro.
///
/// __Example Usage__:
/// ```swift
/// BeginTypographicDoubleQuotes()
/// "Hello, Swift!"
/// EndTypographicDoubleQuotes()
/// ```
public struct BeginTypographicDoubleQuotes: MDocMacroProtocol {
public static let kind = "Do"
public var arguments: [MDocASTNode]
/// Creates a new `BeginTypographicDoubleQuotes` macro.
public init() {
self.arguments = []
}
}
/// Close a scope opened by a ``BeginTypographicDoubleQuotes`` macro.
public struct EndTypographicDoubleQuotes: MDocMacroProtocol {
public static let kind = "Dc"
public var arguments: [MDocASTNode]
/// Creates a new `EndTypographicDoubleQuotes` macro.
public init() {
self.arguments = []
}
}
/// Open a scope enclosed by `"typewriter"` double-quotes.
///
/// Closed by a ``EndTypewriterDoubleQuotes`` macro.
///
/// __Example Usage__:
/// ```swift
/// BeginTypewriterDoubleQuotes()
/// "Hello, Swift!"
/// EndTypewriterDoubleQuotes()
/// ```
public struct BeginTypewriterDoubleQuotes: MDocMacroProtocol {
public static let kind = "Qo"
public var arguments: [MDocASTNode]
/// Creates a new `BeginTypewriterDoubleQuotes` macro.
public init() {
self.arguments = []
}
}
/// Close a scope opened by a ``BeginTypewriterDoubleQuotes`` macro.
public struct EndTypewriterDoubleQuotes: MDocMacroProtocol {
public static let kind = "Qc"
public var arguments: [MDocASTNode]
/// Creates a new `EndTypewriterDoubleQuotes` macro.
public init() {
self.arguments = []
}
}
/// Open a scope enclosed by `'single'` quotes.
///
/// Closed by a ``EndSingleQuotes`` macro.
///
/// __Example Usage__:
/// ```swift
/// BeginSingleQuotes()
/// "Hello, Swift!"
/// EndSingleQuotes()
/// ```
public struct BeginSingleQuotes: MDocMacroProtocol {
public static let kind = "So"
public var arguments: [MDocASTNode]
/// Creates a new `BeginSingleQuotes` macro.
public init() {
self.arguments = []
}
}
/// Close a scope opened by a ``BeginSingleQuotes`` macro.
public struct EndSingleQuotes: MDocMacroProtocol {
public static let kind = "Sc"
public var arguments: [MDocASTNode]
/// Creates a new `EndSingleQuotes` macro.
public init() {
self.arguments = []
}
}
/// Open a scope enclosed by `(parentheses)`.
///
/// Closed by a ``EndParentheses`` macro.
///
/// __Example Usage__:
/// ```swift
/// BeginParentheses()
/// "Hello, Swift!"
/// EndParentheses()
/// ```
public struct BeginParentheses: MDocMacroProtocol {
public static let kind = "Po"
public var arguments: [MDocASTNode]
/// Creates a new `BeginParentheses` macro.
public init() {
self.arguments = []
}
}
/// Close a scope opened by a ``BeginParentheses`` macro.
public struct EndParentheses: MDocMacroProtocol {
public static let kind = "Pc"
public var arguments: [MDocASTNode]
/// Creates a new `EndParentheses` macro.
public init() {
self.arguments = []
}
}
/// Open a scope enclosed by `[squareBrackets]`.
///
/// Closed by a ``EndSquareBrackets`` macro.
///
/// __Example Usage__:
/// ```swift
/// BeginSquareBrackets()
/// "Hello, Swift!"
/// EndSquareBrackets()
/// ```
public struct BeginSquareBrackets: MDocMacroProtocol {
public static let kind = "Bo"
public var arguments: [MDocASTNode]
/// Creates a new `BeginSquareBrackets` macro.
public init() {
self.arguments = []
}
}
/// Close a scope opened by a ``BeginSquareBrackets`` macro.
public struct EndSquareBrackets: MDocMacroProtocol {
public static let kind = "Bc"
public var arguments: [MDocASTNode]
/// Creates a new `EndSquareBrackets` macro.
public init() {
self.arguments = []
}
}
/// Open a scope enclosed by `{curlyBraces}`.
///
/// Closed by a ``EndCurlyBraces`` macro.
///
/// __Example Usage__:
/// ```swift
/// BeginCurlyBraces()
/// "Hello, Swift!"
/// EndCurlyBraces()
/// ```
public struct BeginCurlyBraces: MDocMacroProtocol {
public static let kind = "Bro"
public var arguments: [MDocASTNode]
/// Creates a new `BeginCurlyBraces` macro.
public init() {
self.arguments = []
}
}
/// Close a scope opened by a ``BeginCurlyBraces`` macro.
public struct EndCurlyBraces: MDocMacroProtocol {
public static let kind = "Brc"
public var arguments: [MDocASTNode]
/// Creates a new `EndCurlyBraces` macro.
public init() {
self.arguments = []
}
}
/// Open a scope enclosed by `<angleBrackets>`.
///
/// Closed by a ``EndAngleBrackets`` macro.
///
/// __Example Usage__:
/// ```swift
/// BeginAngleBrackets()
/// "Hello, Swift!"
/// EndAngleBrackets()
/// ```
public struct BeginAngleBrackets: MDocMacroProtocol {
public static let kind = "Ao"
public var arguments: [MDocASTNode]
/// Creates a new `BeginAngleBrackets` macro.
public init() {
self.arguments = []
}
}
/// Close a scope opened by a ``BeginAngleBrackets`` macro.
public struct EndAngleBrackets: MDocMacroProtocol {
public static let kind = "Ac"
public var arguments: [MDocASTNode]
/// Creates a new `EndAngleBrackets` macro.
public init() {
self.arguments = []
}
}
// TODO: GenericEnclosure
// /// Enclose another element generically.
// case genericEnclosure(MDocLowLevelASTNode)
// MARK: - Text production
/// Display a standard line about the exit code of specified utilities.
///
/// This macro indicates the specified utilities exit 0 on success and other
/// values on failure. ``ExitStandard``` should be only included in the
/// "EXIT STATUS" section.
///
/// ``ExitStandard`` should only be used in sections 1, 6, and 8.
public struct ExitStandard: MDocMacroProtocol {
public static let kind = "Ex"
public var arguments: [MDocASTNode]
/// Creates a new `ExitStandard` macro.
///
/// - Parameters:
/// - utilities: A list of utilities the exit standard applies to. If no
/// utilities are specified the document's name set by ``DocumentName``
/// is used.
public init(utilities: [String] = []) {
self.arguments = ["-std"] + utilities
}
}
// TODO: ReturnStandard
// /// Insert a standard sentence regarding a function call's return value of 0 on success and -1 on error, with the errno libc global variable set on error.
// ///
// /// If function is not specified, the document's name set by ``DocumentName`` is used. Multiple function arguments are treated as separate functions.
// public struct ReturnStandard: MDocMacroProtocol {
// public static let kind = "Rv"
// public var arguments: [MDocASTNode]
// public init() {
// self.arguments = []
// }
// }
// TODO: StandardsReference
// /// Reference to a standards document (one argument).
// public struct StandardsReference: MDocMacroProtocol {
// public static let kind = "St"
// public var arguments: [MDocASTNode]
// public init() {
// self.arguments = []
// }
// }
/// Display a formatted version of AT&T UNIX.
///
/// __Example Usage__:
/// ```swift
/// AttUnix()
/// AttUnix(version: "V.1")
/// ```
public struct AttUnix: MDocMacroProtocol {
public static let kind = "At"
public var arguments: [MDocASTNode]
/// Creates a new `AttUnix` macro.
///
/// - Parameters:
/// - version: The version of Att Unix to stylize. Omitting
/// `version` will result in an unversioned OS being displayed.
/// `version` should be one of the following values;
/// - `v[1-7] | 32v` - A version of AT&T UNIX.
/// - `III` - AT&T System III UNIX.
/// - `V | V.[1-4]` - A version of AT&T System V UNIX.
public init(version: String? = nil) {
self.arguments = []
self.arguments.append(optional: version)
}
}
/// Display a formatted variant and version of BSD.
///
/// __Example Usage__:
/// ```swift
/// BSD()
/// BSD(name: "Ghost")
/// BSD(name: "Ghost", version: "21.04.27")
/// ```
public struct BSD: MDocMacroProtocol {
public static let kind = "Bx"
public var arguments: [MDocASTNode]
/// Creates a new `BSD` macro.
///
/// - Note: The `version` parameter must not be specified without
/// the `name` parameter.
///
/// - Parameters:
/// - name: The name of the BSD variant to stylize.
/// - version: The version `name` to stylize. Omitting `version`
/// will result in an unversioned OS being displayed.
public init(name: String? = nil, version: String? = nil) {
precondition(!(name == nil && version != nil))
self.arguments = []
self.arguments.append(optional: name)
self.arguments.append(optional: version)
}
}
/// Display a formatted version of BSD/OS.
///
/// __Example Usage__:
/// ```swift
/// BSDOS()
/// BSDOS(version: "5.1")
/// ```
public struct BSDOS: MDocMacroProtocol {
public static let kind = "Bsx"
public var arguments: [MDocASTNode]
/// Creates a new `BSDOS` macro.
///
/// - Parameters:
/// - version: The version of BSD/OS to stylize. Omitting
/// `version` will result in an unversioned OS being displayed.
public init(version: String? = nil) {
self.arguments = []
self.arguments.append(optional: version)
}
}
/// Display a formatted version of NetBSD.
///
/// __Example Usage__:
/// ```swift
/// NetBSD()
/// NetBSD(version: "9.2")
/// ```
public struct NetBSD: MDocMacroProtocol {
public static let kind = "Nx"
public var arguments: [MDocASTNode]
/// Creates a new `NetBSD` macro.
///
/// - Parameters:
/// - version: The version of NetBSD to stylize. Omitting
/// `version` will result in an unversioned OS being displayed.
public init(version: String? = nil) {
self.arguments = []
self.arguments.append(optional: version)
}
}
/// Display a formatted version of FreeBSD.
///
/// __Example Usage__:
/// ```swift
/// FreeBSD()
/// FreeBSD(version: "13.0")
/// ```
public struct FreeBSD: MDocMacroProtocol {
public static let kind = "Fx"
public var arguments: [MDocASTNode]
/// Creates a new `FreeBSD` macro.
///
/// - Parameters:
/// - version: The version of FreeBSD to stylize. Omitting
/// `version` will result in an unversioned OS being displayed.
public init(version: String? = nil) {
self.arguments = []
self.arguments.append(optional: version)
}
}
/// Display a formatted version of OpenBSD.
///
/// __Example Usage__:
/// ```swift
/// OpenBSD()
/// OpenBSD(version: "6.9")
/// ```
public struct OpenBSD: MDocMacroProtocol {
public static let kind = "Ox"
public var arguments: [MDocASTNode]
/// Creates a new `OpenBSD` macro.
///
/// - Parameters:
/// - version: The version of OpenBSD to stylize. Omitting
/// `version` will result in an unversioned OS being displayed.
public init(version: String? = nil) {
self.arguments = []
self.arguments.append(optional: version)
}
}
/// Display a formatted version of DragonFly.
///
/// __Example Usage__:
/// ```swift
/// DragonFly()
/// DragonFly(version: "6.0")
/// ```
public struct DragonFly: MDocMacroProtocol {
public static let kind = "Dx"
public var arguments: [MDocASTNode]
/// Creates a new `DragonFly` macro.
///
/// - Parameters:
/// - version: The version of DragonFly to stylize. Omitting
/// `version` will result in an unversioned OS being displayed.
public init(version: String? = nil) {
self.arguments = []
self.arguments.append(optional: version)
}
}
}
|