From: Lady Date: Sat, 15 Jul 2023 21:53:34 +0000 (-0700) Subject: Initial commit X-Git-Tag: 0.1.0~1 X-Git-Url: https://git.ladys.computer/Sutra/commitdiff_plain/86748e0641f8c4d833cf2cca4873925a6f6c64e8 Initial commit Includes all X·S·D datatype productions and operators and initial setup for X·S·D functions (but no functions yet). --- 86748e0641f8c4d833cf2cca4873925a6f6c64e8 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ee6256c --- /dev/null +++ b/LICENSE @@ -0,0 +1,373 @@ +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at https://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. diff --git a/README.markdown b/README.markdown new file mode 100644 index 0000000..0a28e52 --- /dev/null +++ b/README.markdown @@ -0,0 +1,36 @@ +# ♓️🪡 सूत्र + +**X·D·M for Ecmascript.** + +♓️🪡 सूत्र is an implementation of the +[X·Path and X·Query Data Model (X·D·M)][XDM] for Ecmascript. It +includes an implementation of the +[X·M·L Schema Definition Language][XSD-1] in the [`xsd`](./xsd) +directory. + +This module depends heavily on [♓️🧩 Piscēs][Pisces]. + +## Nomenclature + +सूत्र (sūtra) is a Sanskrit word +meaning “thread”. + +In Ascii, ♓️🪡 सूत्र should be represented as `Sutra`, the Anglicized +form of the name. + +## Current Status + +Prospective. The immediate goal is to have a working impelentation of +the [X·M·L Schema Definition Datatypes][XSD-2]. Other components will +be added later. + +## License + +Source files are licensed under the terms of the Mozilla Public +License, version 2.0. For more information, see +[LICENSE](./LICENSE). + +[Pisces]: +[XSD-1]: +[XSD-2]: +[XDM]: diff --git a/deno.json b/deno.json new file mode 100644 index 0000000..d00db95 --- /dev/null +++ b/deno.json @@ -0,0 +1 @@ +{ "fmt": { "lineWidth": 71 } } diff --git a/deno.lock b/deno.lock new file mode 100644 index 0000000..7688268 --- /dev/null +++ b/deno.lock @@ -0,0 +1,19 @@ +{ + "version": "2", + "remote": { + "https://deno.land/std@0.192.0/fmt/colors.ts": "d67e3cd9f472535241a8e410d33423980bec45047e343577554d3356e1f0ef4e", + "https://deno.land/std@0.192.0/testing/_diff.ts": "1a3c044aedf77647d6cac86b798c6417603361b66b54c53331b312caeb447aea", + "https://deno.land/std@0.192.0/testing/_format.ts": "a69126e8a469009adf4cf2a50af889aca364c349797e63174884a52ff75cf4c7", + "https://deno.land/std@0.192.0/testing/_test_suite.ts": "30f018feeb3835f12ab198d8a518f9089b1bcb2e8c838a8b615ab10d5005465c", + "https://deno.land/std@0.192.0/testing/asserts.ts": "e16d98b4d73ffc4ed498d717307a12500ae4f2cbe668f1a215632d19fcffc22f", + "https://git.ladys.computer/Pisces/blob_plain/0.4.0:/binary.js": "4dd2ba7bc3c0d7b31b24fdd8350f3d976ae8c916b283cedc06dd3b768bbcb812", + "https://git.ladys.computer/Pisces/blob_plain/0.4.0:/collection.js": "3d9f2f9817273aeffd6735ecf5cd2a00ed7a9327859fb026e729b434ab98c59b", + "https://git.ladys.computer/Pisces/blob_plain/0.4.0:/function.js": "0ca111c31ff3694822082e785c52d71c079c0269f3fb3b97c0d145a4a4ca31d1", + "https://git.ladys.computer/Pisces/blob_plain/0.4.0:/iri.js": "8dcb861befecff5897c489b73cc077453a857cda899844ebc6f5f3f3cd6c03f2", + "https://git.ladys.computer/Pisces/blob_plain/0.4.0:/mod.js": "835746ed65fa23c87235343e88945ee5a6cbb5c7baa74f197ff5f9cd280dd506", + "https://git.ladys.computer/Pisces/blob_plain/0.4.0:/numeric.js": "3c46c43c6d15d91d54363320e19f3cb32beaf9779419bd05b8988a030bd68410", + "https://git.ladys.computer/Pisces/blob_plain/0.4.0:/object.js": "e611a5aad46ca1525cd6a9e55eb00fee4c62012464b087bd04f38754a6eded84", + "https://git.ladys.computer/Pisces/blob_plain/0.4.0:/string.js": "64e6e2ed922b927db720b38cb1c4f781617fbd15fcf0bf285a90c12ff5619a62", + "https://git.ladys.computer/Pisces/blob_plain/0.4.0:/value.js": "96d2e2c347ea76f191b78a622e8bf04ac31213184f72a5d1247aa4c381304d88" + } +} diff --git a/deps.js b/deps.js new file mode 100644 index 0000000..471ec38 --- /dev/null +++ b/deps.js @@ -0,0 +1,33 @@ +// ♓️🪡 सूत्र ∷ deps.js +// ==================================================================== +// +// Copyright © 2023 Lady [@ Lady’s Computer]. +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at . + +export { + bind, + call, + floor, + getPrototype, + isArrayBuffer, + isFiniteNumber, + isIntegralNumber, + ITERATOR, + Matcher, + NAN, + NEGATIVE_INFINITY, + NEGATIVE_ZERO, + objectCreate, + POSITIVE_INFINITY, + POSITIVE_ZERO, + rawString, + sameValue, + stringSplit, + substring, + toFloat32, + type, + UNDEFINED, +} from "https://git.ladys.computer/Pisces/blob_plain/0.4.0:/mod.js"; diff --git a/dev-deps.js b/dev-deps.js new file mode 100644 index 0000000..3b374d6 --- /dev/null +++ b/dev-deps.js @@ -0,0 +1,13 @@ +// ♓️🪡 सूत् ∷ dev-deps.js +// ==================================================================== +// +// Copyright © 2023 Lady [@ Lady’s Computer]. +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at . + +export { + assert, + assertStrictEquals, +} from "https://deno.land/std@0.192.0/testing/asserts.ts"; diff --git a/xsd/README.markdown b/xsd/README.markdown new file mode 100644 index 0000000..0ed60ea --- /dev/null +++ b/xsd/README.markdown @@ -0,0 +1,73 @@ +# ♓️🪡 सूत्र ∷ X·S·D + +♓️🪡 सूत्र ∷ X·S·D provides an implementation of the +[X·M·L Schema Definition Language][XSD-1], including the +[X·M·L Schema Definition Datatypes][XSD-2], for Ecmascript. + +## Notes + +### Typechecking + +All of the functions provided by `./functions.js` will throw an error +if they are given arguments which do not match the expectations +established by the X·S·D spec. No type coersion occurs. + +### Efficiency + +♓️🪡 सूत्र ∷ X·S·D emphasizes algorithm correctness and takes a somewhat +extreme stance with regards to spec adherence. This means that the +algorithms used may be somewhat slow, although native platform features +will be leveraged when possible. + +### Numeric values + +♓️🪡 सूत्र ∷ X·S·D treats all numeric values as native Ecmascript +numbers. This may lead to rounding errors for decimals and extreme +values. + +This behaviour may change in the future; see + for progress on getting a +more precise decimal type into Ecmascript. + +### Positive and Negative Zero + +X·S·D only formally distinguishes positive and negative zero for floats +and doubles, but it allows them to be represented lexically in all +other signed numeric types. ♓️🪡 सूत्र ∷ X·S·D silently coerces negative +zero to positive zero for numeric datatypes in which it is not an +explicit part of the value space, as well as for numeric components of +other datatypes (e·g durations). + +### Date∕times and Durations + +♓️🪡 सूत्र ∷ X·S·D does not provide actual classes for X·S·D +date/timeSevenPropertyModel values or durations, treatings both as +simple objects. This approach was taken to maximize compatibility with +other modules. Formally :— + +1. A duration is any object for which getting the `months` property + returns an integer, getting the `seconds` property returns a finite + number, and these two values have the same sign. (Positive and + negative zero are treated as having the same sign for this + comparison.) + + Note that `months` and `seconds` **must not** be undefined. + +2. A date/timeSevenPropertyModel value is any object for which getting + the `year`, `month`, `day`, `hour`, `minute`, `second`, and + `timezoneOffset` properties returns values within the bounds + specified in the X·S·D specification. Absent values can be + represented with undefined, and need not actually be defined on the + object). + +Functions which return durations or date/timeSevenPropertyModel values +will always return a plain, extensible object which :— + +- Inherits from `%ObjectPrototype%`, +- Has all of the applicable properties defined as enumerable, + configurable, writable own data properties (absent properties will be + defined with a value of undefined), and +- Has no other own properties. + +[XSD-1]: +[XSD-2]: diff --git a/xsd/functions.js b/xsd/functions.js new file mode 100644 index 0000000..4ad5b5c --- /dev/null +++ b/xsd/functions.js @@ -0,0 +1,440 @@ +// ♓️🪡 सूत्र ∷ xsd/functions.js +// ==================================================================== +// +// Copyright © 2023 Lady [@ Lady’s Computer]. +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at . + +import { + bind, + call, + getPrototype, + isArrayBuffer, + isFiniteNumber, + isIntegralNumber, + ITERATOR, + objectCreate, + sameValue, + toFloat32, + type, +} from "../deps.js"; +import { div, mod } from "./operators.js"; +import { + booleanRep, + dateLexicalRep, + dateTimeLexicalRep, + dayFrag, + dayTimeDurationLexicalRep, + decimalLexicalRep, + decimalPtNumeral, + digit as lexicalDigit, + doubleRep, + duDayFrag, + duDayTimeFrag, + duHourFrag, + duMinuteFrag, + duMonthFrag, + durationLexicalRep, + duSecondFrag, + duTimeFrag, + duYearFrag, + duYearMonthFrag, + floatRep, + fracFrag, + gDayLexicalRep, + gMonthDayLexicalRep, + gMonthLexicalRep, + gYearLexicalRep, + gYearMonthLexicalRep, + hexBinary, + hexDigit, + hexOctet, + hourFrag, + minuteFrag, + monthFrag, + noDecimalPtNumeral, + numericalSpecialRep, + scientificNotationNumeral, + secondFrag, + stringRep, + timeLexicalRep, + timezoneFrag, + unsignedDecimalPtNumeral, + unsignedNoDecimalPtNumeral, + yearFrag, + yearMonthDurationLexicalRep, +} from "./productions.js"; +import { + absent, + negativeInfinity, + negativeZero, + notANumber, + positiveInfinity, + positiveZero, +} from "./values.js"; + +const stringToFloat = parseFloat; + +/** + * Ensures that the provided matcher matches the provided value and + * returns it. + * + * ☡ This function throws if the matcher does not match. + * + * ※ This function is not exposed. + */ +const ensureMatches = (matcher, $) => { + if (matcher($)) { + return $; + } else { + throw new TypeError( + `सूत्र: Expected a ${matcher.name}, but got: ${$}.`, + ); + } +}; + +/** + * Ensures that the provided value with the provided name is present or + * absent. + * + * ☡ This function throws if the presence of the value is not correct. + * + * ※ This function is not exposed. + */ +const ensurePresence = (name, value, present = true) => { + if ((value !== absent) === !present) { + throw new TypeError( + `सूत्र: Expected ${name} to be ${ + present ? "present" : "absent" + }, but got: ${value}.`, + ); + } else { + return value; + } +}; + +/** + * Ensures that the provided value is a valid, complete duration and + * returns an object with its months and seconds. + * + * ☡ This function throws if the provided value is not a valid, + * complete duration. + * + * ※ This function is not exposed. + */ +const duration = ($) => { + const { months, seconds } = $; + if (!isIntegralNumber(months)) { + throw new TypeError( + `सूत्र: Expected duration to have an integer for months, but got: ${months}.`, + ); + } else if (!isFiniteNumber(seconds)) { + throw new TypeError( + `सूत्र: Expected duration to have a finite number for seconds, but got: ${seconds}.`, + ); + } else if (months > 0 && seconds < 0 || months < 0 && seconds > 0) { + throw new TypeError( + `सूत्र: Expected seconds in duration to match polarity of months, but got: ${seconds}.`, + ); + } else { + return { months, seconds }; + } +}; + +/** + * Ensures that the provided value is a valid + * date/timeSevenPropertyModel value and returns an object with its + * year, month, day, hour, minute, second, and timezoneOffset. + * + * ☡ This function throws if the provided value is not a valid + * date/timeSevenPropertyModel value. + * + * ※ This function is not exposed. + */ +const date·timeSevenPropertyModel = ($) => { + if (type($) !== "object") { + throw new TypeError( + `सूत्र: Expected a date/timeSevenPropertyModel value, but got: ${$}.`, + ); + } else { + const { year, month, day, hour, minute, second, timezoneOffset } = + $; + if (year !== absent && !isIntegralNumber(year)) { + throw new TypeError( + `सूत्र: Expected year to be an optional integer, but got: ${year}.`, + ); + } else if ( + month !== absent && + !(isIntegralNumber(month) && month >= 1 && month <= 12) + ) { + throw new TypeError( + `सूत्र: Expected month to be an optional integer between 1 and 12 inclusive, but got: ${month}.`, + ); + } else if ( + day !== absent && + !(isIntegralNumber(day) && day >= 1 && day <= 31) + ) { + throw new TypeError( + `सूत्र: Expected day to be an optional integer between 1 and 31 inclusive, but got: ${day}.`, + ); + } else if ( + hour !== absent && + !(isIntegralNumber(hour) && hour >= 0 && hour <= 24) + ) { + throw new TypeError( + `सूत्र: Expected hour to be an optional integer between 0 and 24 inclusive, but got: ${hour}.`, + ); + } else if ( + minute !== absent && + !(isIntegralNumber(minute) && minute >= 0 && minute <= 59) + ) { + throw new TypeError( + `सूत्र: Expected minute to be an optional integer between 0 and 59 inclusive, but got: ${minute}.`, + ); + } else if ( + second !== absent && + !(isFiniteNumber(second) && second >= 0 && second < 60) + ) { + throw new TypeError( + `सूत्र: Expected second to be an optional finite number greater than or equal to 0 and less than 60, but got: ${second}.`, + ); + } else if ( + timezoneOffset !== absent && + !(isIntegralNumber(timezoneOffset) && timezoneOffset >= -840 && + timezoneOffset <= 840) + ) { + throw new TypeError( + `सूत्र: Expected timezoneOffset to be an optional integer between -840 and 840 inclusive, but got: ${timezoneOffset}.`, + ); + } else if ( + month !== absent && day !== absent && !( + month === 2 && day === 29 + ) && day > daysInMonth(year, month) + ) { + throw new TypeError( + `सूत्र: The provided day violates the day‐of‐month constraint for month ${month}: ${day}.`, + ); + } else { + return { + year, + month, + day, + hour, + minute, + second, + timezoneOffset, + }; + } + } +}; + +/** + * Ensures that the provided value is an integer and returns it. + * + * ☡ This function throws if the provided value is not an integer. + * + * ※ This function is not exposed. + */ +const integer = ($) => { + if (!isIntegralNumber($)) { + throw new TypeError(`सूत्र: Expected an integer, but got: ${$}.`); + } else { + return $; + } +}; + +/** + * Ensures that the provided value is a nonnegative integer and returns + * it. + * + * ☡ This function throws if the provided value is not a nonnegative + * integer. + * + * ※ This function is not exposed. + */ +const nonnegativeInteger = ($) => { + if (!(isIntegralNumber($) && $ >= 0)) { + throw new TypeError( + `सूत्र: Expected a nonnegative integer, but got: ${$}.`, + ); + } else { + return $; + } +}; + +/** + * Ensures that the provided value is a finite number and returns it. + * + * ☡ This function throws if the provided value is not a finite number. + * + * ※ This function is not exposed. + */ +const decimalNumber = ($) => { + if (!(isFiniteNumber($))) { + throw new TypeError( + `सूत्र: Expected a finite number, but got: ${$}.`, + ); + } else { + return $; + } +}; + +/** + * Ensures that the provided value is a nonnegative finite number and + * returns it. + * + * ☡ This function throws if the provided value is not a nonnegative + * finite number. + * + * ※ This function is not exposed. + */ +const nonnegativeDecimalNumber = ($) => { + if (!(isFiniteNumber($) && $ >= 0)) { + throw new TypeError( + `सूत्र: Expected a nonnegative finite number, but got: ${$}.`, + ); + } else { + return $; + } +}; + +/** + * Ensures that the provided value is a 32‐bit float and returns it. + * + * ☡ This function throws if the provided value is not a 32‐bit float. + * + * ※ This function is not exposed. + */ +const float = ($) => { + if (typeof $ !== "number" || !sameValue(toFloat32($), $)) { + throw new TypeError( + `सूत्र: Expected a float value, but got: ${$}.`, + ); + } else { + return $; + } +}; + +/** + * Ensures that the provided value is a number and returns it. + * + * ☡ This function throws if the provided value is not a number. + * + * ※ This function is not exposed. + */ +const double = ($) => { + if (typeof $ !== "number") { + throw new TypeError( + `सूत्र: Expected a double value, but got: ${$}.`, + ); + } else { + return $; + } +}; + +/** + * Ensures that the provided value is a hexBinary value, i·e a sequence + * of binary octets. + * + * ☡ This function throws if the provided value is not an array buffer. + * + * ※ This function is not exposed. + */ +const hexBinaryValue = ($) => { + if (!isArrayBuffer($)) { + throw new TypeError( + `सूत्र: Expected a hexBinary value, but got: ${$}.`, + ); + } else { + return $; + } +}; + +const { + /** + * Converts a string of 0’s and 1’s into a sequence of binary digits. + * + * ※ This function is not exposed. + */ + binaryDigitSequence, + + /** + * Converts a generator iterator into a sequence of values. + * + * ※ This function is not exposed. + */ + generatorSequence, + + /** + * Converts a string into a sequence of characters. + * + * ※ This function is not exposed. + */ + literalSequence, +} = (() => { + const { + next: generatorIteratorNext, + } = getPrototype(function* () {}.prototype); + const { [ITERATOR]: stringIterator } = String.prototype; + const { + next: stringIteratorNext, + } = getPrototype(""[ITERATOR]()); + const binaryDigitIterator = function* () { + for (const digit of literalSequence(this)) { + yield digit === "0" ? 0 : 1; + } + }; + const binaryDigitSequenceIterablePrototype = { + [ITERATOR]() { + return { + next: bind( + generatorIteratorNext, + call(binaryDigitIterator, this.binaryDigits, []), + [], + ), + }; + }, + }; + const generatorSequenceIterablePrototype = { + [ITERATOR]() { + return { + next: bind( + generatorIteratorNext, + this.generator(), + [], + ), + }; + }, + }; + const literalSequenceIterablePrototype = { + [ITERATOR]() { + return { + next: bind( + stringIteratorNext, + call(stringIterator, this.literal, []), + [], + ), + }; + }, + }; + + return { + binaryDigitSequence: (digits) => + objectCreate( + binaryDigitSequenceIterablePrototype, + { binaryDigits: { value: digits } }, + ), + generatorSequence: (generator) => + objectCreate( + generatorSequenceIterablePrototype, + { generator: { value: generator } }, + ), + literalSequence: (literal) => + objectCreate( + literalSequenceIterablePrototype, + { literal: { value: literal } }, + ), + }; +})(); diff --git a/xsd/mod.js b/xsd/mod.js new file mode 100644 index 0000000..6c69de3 --- /dev/null +++ b/xsd/mod.js @@ -0,0 +1,13 @@ +// ♓️🪡 सूत्र ∷ xsd/mod.js +// ==================================================================== +// +// Copyright © 2023 Lady [@ Lady’s Computer]. +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at . + +export * from "./functions.js"; +export * from "./operators.js"; +export * from "./productions.js"; +export * from "./values.js"; diff --git a/xsd/operators.js b/xsd/operators.js new file mode 100644 index 0000000..0ef157c --- /dev/null +++ b/xsd/operators.js @@ -0,0 +1,28 @@ +// ♓️🪡 सूत्र ∷ xsd/operators.js +// ==================================================================== +// +// Copyright © 2023 Lady [@ Lady’s Computer]. +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at . + +import { floor } from "../deps.js"; + +/** + * For the provided arguments m & n, the greatest integer less than or + * equal to m ∕ n. + * + * See . + */ +export const div = (m, n) => floor(m / n); + +/** + * For the provided arguments m & n, m − n × (m ·div· n). + * + * See . + * + * ☡ This function may suffer from floating‐point rounding errors if + * the provided arguments are not integers. + */ +export const mod = (m, n) => m - n * div(m, n); diff --git a/xsd/productions.js b/xsd/productions.js new file mode 100644 index 0000000..86a8e2f --- /dev/null +++ b/xsd/productions.js @@ -0,0 +1,485 @@ +// ♓️🪡 सूत्र ∷ xsd/productions.js +// ==================================================================== +// +// Copyright © 2023 Lady [@ Lady’s Computer]. +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at . + +import { + Matcher, + objectCreate, + rawString, + stringSplit, + substring, +} from "../deps.js"; + +const dayOfMonthValuesConstraint = (day, month, year = "1972") => { + const d = +day; + const m = +month; + const y = +year; + return m === 4 || m === 6 || m === 9 || m === 11 + ? d <= 30 + : m === 2 && (y % 4 || !(y % 100) && y % 400) + ? d <= 28 + : m === 2 && (!(y % 400) || !(y % 4) && y % 100) + ? d <= 29 + : true; +}; + +export const { + /** `[1] stringRep ::= Char*` */ + stringRep, + + /** `[2] booleanRep ::= 'true' | 'false' | '1' | '0'` */ + booleanRep, + + /** `[3] decimalLexicalRep ::= decimalPtNumeral | noDecimalPtNumeral` */ + decimalLexicalRep, + + /** `[4] floatRep ::= noDecimalPtNumeral | decimalPtNumeral | scientificNotationNumeral | numericalSpecialRep` */ + floatRep, + + /** `[5] doubleRep ::= noDecimalPtNumeral | decimalPtNumeral | scientificNotationNumeral | numericalSpecialRep` */ + doubleRep, + + /** `[6] duYearFrag ::= unsignedNoDecimalPtNumeral 'Y'` */ + duYearFrag, + + /** `[7] duMonthFrag ::= unsignedNoDecimalPtNumeral 'M'` */ + duMonthFrag, + + /** `[8] duDayFrag ::= unsignedNoDecimalPtNumeral 'D'` */ + duDayFrag, + + /** `[9] duHourFrag ::= unsignedNoDecimalPtNumeral 'H'` */ + duHourFrag, + + /** `[10] duMinuteFrag ::= unsignedNoDecimalPtNumeral 'M'` */ + duMinuteFrag, + + /** + * `[11] duSecondFrag ::= (unsignedNoDecimalPtNumeral | unsignedFullDecimalPtNumeral) 'S'` + * + * ※ The X·S·D specification specifies unsignedDecimalPtNumeral, not + * unsignedFullDecimalPtNumeral, but the specification text and + * provided regular expressions imply that the latter was intended. + */ + duSecondFrag, + + /** `[12] duYearMonthFrag ::= (duYearFrag duMonthFrag?) | duMonthFrag` */ + duYearMonthFrag, + + /** `[13] duTimeFrag ::= 'T' ((duHourFrag duMinuteFrag? duSecondFrag?) | (duMinuteFrag duSecondFrag?) | duSecondFrag)` */ + duTimeFrag, + + /** `[14] duDayTimeFrag ::= (duDayFrag duTimeFrag?) | duTimeFrag` */ + duDayTimeFrag, + + /** `[15] durationLexicalRep ::= '-'? 'P' ((duYearMonthFrag duDayTimeFrag?) | duDayTimeFrag)` */ + durationLexicalRep, + + /** + * `[16] dateTimeLexicalRep ::= yearFrag '-' monthFrag '-' dayFrag 'T' ((hourFrag ':' minuteFrag ':' secondFrag) | endOfDayFrag) timezoneFrag?` + * + * **Constraint: Day-of-month Values** + * + * The ·day· value must be no more than 30 if ·month· is one of 4, 6, + * 9, or 11; no more than 28 if ·month· is 2 and ·year· is not + * divisible by 4, or is divisible by 100 but not by 400; and no more + * than 29 if ·month· is 2 and ·year· is divisible by 400, or by 4 + * but not by 100. + * + * **Constraint: Day-of-month Representations** + * + * Within a dateTimeLexicalRep, a dayFrag must not begin with the + * digit '3' or be '29' unless the value to which it would map would + * satisfy the value constraint on ·day· values ("Constraint: + * Day-of-month Values") given above. + */ + dateTimeLexicalRep, + + /** `[17] timeLexicalRep ::= ((hourFrag ':' minuteFrag ':' secondFrag) | endOfDayFrag) timezoneFrag?` */ + timeLexicalRep, + + /** + * `[18] dateLexicalRep ::= yearFrag '-' monthFrag '-' dayFrag timezoneFrag?` + * + * **Constraint: Day-of-month Values** + * + * The ·day· value must be no more than 30 if ·month· is one of 4, 6, + * 9, or 11; no more than 28 if ·month· is 2 and ·year· is not + * divisible by 4, or is divisible by 100 but not by 400; and no more + * than 29 if ·month· is 2 and ·year· is divisible by 400, or by 4 + * but not by 100. + * + * **Constraint: Day-of-month Representations** + * + * Within a dateLexicalRep, a dayFrag must not begin with the digit + * '3' or be '29' unless the value to which it would map would + * satisfy the value constraint on ·day· values ("Constraint: + * Day-of-month Values") given above. + */ + dateLexicalRep, + + /** `[19] gYearMonthLexicalRep ::= yearFrag '-' monthFrag timezoneFrag?` */ + gYearMonthLexicalRep, + + /** `[20] gYearLexicalRep ::= yearFrag timezoneFrag?` */ + gYearLexicalRep, + + /** + * `[21] gMonthDayLexicalRep ::= '--' monthFrag '-' dayFrag timezoneFrag?` + * + * **Constraint: Day-of-month Values** + * + * The ·day· value must be no more than 30 if ·month· is one of 4, 6, + * 9, or 11, and no more than 29 if ·month· is 2. + * + * **Constraint: Day-of-month Representations** + * + * Within a gMonthDayLexicalRep, a dayFrag must not begin with the + * digit '3' or be '29' unless the value to which it would map would + * satisfy the value constraint on ·day· values ("Constraint: + * Day-of-month Values") given above. + */ + gMonthDayLexicalRep, + + /** `[22] gDayLexicalRep ::= '---' dayFrag timezoneFrag?` */ + gDayLexicalRep, + + /** `[23] gMonthLexicalRep ::= '--' monthFrag timezoneFrag?` */ + gMonthLexicalRep, + + /** `[24] hexDigit ::= [0-9a-fA-F]` */ + hexDigit, + + /** `[25] hexOctet ::= hexDigit hexDigit` */ + hexOctet, + + /** `[26] hexBinary ::= hexOctet*` */ + hexBinary, + + /** `[27] Base64Binary ::= (B64quad* B64final)?` */ + Base64Binary, + + /** `[28] B64quad ::= (B64 B64 B64 B64)` */ + B64quad, + + /** `[29] B64final ::= B64finalquad | Padded16 | Padded8` */ + B64final, + + /** `[30] B64finalquad ::= (B64 B64 B64 B64char)` */ + B64finalquad, + + /** `[31] Padded16 ::= B64 B64 B16 '='` */ + Padded16, + + /** `[32] Padded8 ::= B64 B04 '=' #x20? '='` */ + Padded8, + + /** `[33] B64 ::= B64char #x20?` */ + B64, + + /** `[34] B64char ::= [A-Za-z0-9+/]` */ + B64char, + + /** `[35] B16 ::= B16char #x20?` */ + B16, + + /** `[36] B16char ::= [AEIMQUYcgkosw048]` */ + B16char, + + /** `[37] B04 ::= B04char #x20?` */ + B04, + + /** `[38] B04char ::= [AQgw]` */ + B04char, + + /** `[39] Canonical-base64Binary ::= CanonicalQuad* CanonicalPadded?` */ + Canonical·base64Binary, + + /** `[40] CanonicalQuad ::= B64char B64char B64char B64char` */ + CanonicalQuad, + + /** `[41] CanonicalPadded ::= B64char B64char B16char '=' | B64char B04char '=='` */ + CanonicalPadded, + + /** `[42] yearMonthDurationLexicalRep ::= '-'? 'P' duYearMonthFrag` */ + yearMonthDurationLexicalRep, + + /** `[43] dayTimeDurationLexicalRep ::= '-'? 'P' duDayTimeFrag` */ + dayTimeDurationLexicalRep, + + /** + * `[44] dateTimeStampLexicalRep ::= yearFrag '-' monthFrag '-' dayFrag 'T' ((hourFrag ':' minuteFrag ':' secondFrag) | endOfDayFrag) timezoneFrag` + * + * **Constraint: Day-of-month Values** + * + * The ·day· value must be no more than 30 if ·month· is one of 4, 6, + * 9, or 11; no more than 28 if ·month· is 2 and ·year· is not + * divisible by 4, or is divisible by 100 but not by 400; and no more + * than 29 if ·month· is 2 and ·year· is divisible by 400, or by 4 + * but not by 100. + * + * **Constraint: Day-of-month Representations** + * + * Within a dateTimeStampLexicalRep, a dayFrag must not begin with + * the digit '3' or be '29' unless the value to which it would map + * would satisfy the value constraint on ·day· values ("Constraint: + * Day-of-month Values") given above. + */ + dateTimeStampLexicalRep, + + /** `[45] digit ::= [0-9]` */ + digit, + + /** `[46] unsignedNoDecimalPtNumeral ::= digit+` */ + unsignedNoDecimalPtNumeral, + + /** `[47] noDecimalPtNumeral ::= ('+' | '-')? unsignedNoDecimalPtNumeral` */ + noDecimalPtNumeral, + + /** `[48] fracFrag ::= digit+` */ + fracFrag, + + /** `[49] unsignedDecimalPtNumeral ::= (unsignedNoDecimalPtNumeral '.' fracFrag?) | ('.' fracFrag)` */ + unsignedDecimalPtNumeral, + + /** `[50] unsignedFullDecimalPtNumeral ::= unsignedNoDecimalPtNumeral '.' fracFrag` */ + unsignedFullDecimalPtNumeral, + + /** `[51] decimalPtNumeral ::= ('+' | '-')? unsignedDecimalPtNumeral` */ + decimalPtNumeral, + + /** `[52] unsignedScientificNotationNumeral ::= (unsignedNoDecimalPtNumeral | unsignedDecimalPtNumeral) ('e' | 'E') noDecimalPtNumeral` */ + unsignedScientificNotationNumeral, + + /** `[53] scientificNotationNumeral ::= ('+' | '-')? unsignedScientificNotationNumeral` */ + scientificNotationNumeral, + + /** `[54] minimalNumericalSpecialRep ::= 'INF' | '-INF' | 'NaN'` */ + minimalNumericalSpecialRep, + + /** `[55] numericalSpecialRep ::= ('+' | '-')? unsignedScientificNotationNumeral` */ + numericalSpecialRep, + + /** `[56] yearFrag ::= '-'? (([1-9] digit digit digit+)) | ('0' digit digit digit))` */ + yearFrag, + + /** `[57] monthFrag ::= ('0' [1-9]) | ('1' [0-2])` */ + monthFrag, + + /** `[58] dayFrag ::= ('0' [1-9]) | ([12] digit) | ('3' [01])` */ + dayFrag, + + /** `[59] hourFrag ::= ([01] digit) | ('2' [0-3])` */ + hourFrag, + + /** `[60] minuteFrag ::= [0-5] digit` */ + minuteFrag, + + /** `[61] secondFrag ::= ([0-5] digit) ('.' digit+)?` */ + secondFrag, + + /** `[62] endOfDayFrag ::= '24:00:00' ('.' '0'+)?` */ + endOfDayFrag, + + /** `[63] timezoneFrag ::= 'Z' | ('+' | '-') (('0' digit | '1' [0-3]) ':' minuteFrag | '14:00')` */ + timezoneFrag, +} = (() => { + const matchers = objectCreate(null); + const match = + (name, constraint = null) => (strings, ...substitutions) => { + const source = `(?:${rawString(strings, ...substitutions)})`; + matchers[name] = new Matcher(`^${source}$`, name, constraint); + return source; + }; + + const stringRep = match( + "stringRep", + )`[^\u{0}\u{D800}-\u{DFFF}\u{FFFE}\u{FFFF}]*`; + const booleanRep = match("booleanRep")`true|false|1|0`; + const digit = match("digit")`[0-9]`; + const unsignedNoDecimalPtNumeral = match( + "unsignedNoDecimalPtNumeral", + )`${digit}+`; + const noDecimalPtNumeral = match( + "noDecimalPtNumeral", + )`[+-]?${unsignedNoDecimalPtNumeral}`; + const fracFrag = match("fracFrag")`${digit}+`; + const unsignedDecimalPtNumeral = match( + "unsignedDecimalPtNumeral", + )`${unsignedNoDecimalPtNumeral}\.${fracFrag}?|\.${fracFrag}`; + const unsignedFullDecimalPtNumeral = match( + "unsignedFullDecimalPtNumeral", + )`${unsignedNoDecimalPtNumeral}\.${fracFrag}`; + const decimalPtNumeral = match( + "decimalPtNumeral", + )`[+-]?${unsignedDecimalPtNumeral}`; + const unsignedScientificNotationNumeral = match( + "unsignedScientificNotationNumeral", + )`(?:${unsignedNoDecimalPtNumeral}|${unsignedDecimalPtNumeral})[eE]${noDecimalPtNumeral}`; + const scientificNotationNumeral = match( + "scientificNotationNumeral", + )`[+-]?${unsignedScientificNotationNumeral}`; + const minimalNumericalSpecialRep = match( + "minimalNumericalSpecialRep", + )`INF|-INF|NaN`; + const numericalSpecialRep = match( + "numericalSpecialRep", + )`\+INF|${minimalNumericalSpecialRep}`; + const decimalLexicalRep = match( + "decimalLexicalRep", + )`${decimalPtNumeral}|${noDecimalPtNumeral}`; + const floatRep = match( + "floatRep", + )`${noDecimalPtNumeral}|${decimalPtNumeral}|${scientificNotationNumeral}|${numericalSpecialRep}`; + const doubleRep = match( + "doubleRep", + )`${noDecimalPtNumeral}|${decimalPtNumeral}|${scientificNotationNumeral}|${numericalSpecialRep}`; + const duYearFrag = match( + "duYearFrag", + )`${unsignedNoDecimalPtNumeral}Y`; + const duMonthFrag = match( + "duMonthFrag", + )`${unsignedNoDecimalPtNumeral}M`; + const duDayFrag = match("duDayFrag")`${unsignedNoDecimalPtNumeral}D`; + const duHourFrag = match( + "duHourFrag", + )`${unsignedNoDecimalPtNumeral}H`; + const duMinuteFrag = match( + "duMinuteFrag", + )`${unsignedNoDecimalPtNumeral}M`; + const duSecondFrag = match( + "duSecondFrag", + )`(?:${unsignedNoDecimalPtNumeral}|${unsignedFullDecimalPtNumeral})S`; + const duYearMonthFrag = match( + "duYearMonthFrag", + )`${duYearFrag}${duMonthFrag}?|${duMonthFrag}`; + const duTimeFrag = match( + "duTimeFrag", + )`T(?:${duHourFrag}${duMinuteFrag}?${duSecondFrag}?|${duMinuteFrag}${duSecondFrag}?|${duSecondFrag})`; + const duDayTimeFrag = match( + "duDayTimeFrag", + )`${duDayFrag}${duTimeFrag}?|${duTimeFrag}`; + const durationLexicalRep = match( + "durationLexicalRep", + )`-?P(?:${duYearMonthFrag}${duDayTimeFrag}?|${duDayTimeFrag})`; + const yearFrag = match( + "yearFrag", + )`-?(?:[1-9]${digit}{3,}|0${digit}{3})`; + const monthFrag = match("monthFrag")`0[1-9]|1[0-2]`; + const dayFrag = match("dayFrag")`0[1-9]|[12]${digit}|3[01]`; + const hourFrag = match("hourFrag")`[01]${digit}|2[0-3]`; + const minuteFrag = match("minuteFrag")`[0-5]${digit}`; + const secondFrag = match( + "secondFrag", + )`[0-5]${digit}(?:\.${digit}+)?`; + const endOfDayFrag = match("endOfDayFrag")`24:00:00(?:\.0+)?`; + const timezoneFrag = match( + "timezoneFrag", + )`Z|[+-](?:(?:0${digit}|1[0-3]):${minuteFrag}|14:00)`; + const dateTimeLexicalRep = match("dateTimeLexicalRep", ($) => { + const components = stringSplit($, "-"); + return components[0] === "" + ? dayOfMonthValuesConstraint( + substring(components[3], 0, 2), + components[2], + `-${components[1]}`, + ) + : dayOfMonthValuesConstraint( + substring(components[2], 0, 2), + components[1], + components[0], + ); + })`${yearFrag}-${monthFrag}-${dayFrag}T(?:${hourFrag}:${minuteFrag}:${secondFrag}|${endOfDayFrag})${timezoneFrag}?`; + const timeLexicalRep = match( + "timeLexicalRep", + )`(?:${hourFrag}:${minuteFrag}:${secondFrag}|${endOfDayFrag})${timezoneFrag}?`; + const dateLexicalRep = match("dateLexicalRep", ($) => { + const components = stringSplit($, "-"); + return components[0] === "" + ? dayOfMonthValuesConstraint( + substring(components[3], 0, 2), + components[2], + `-${components[1]}`, + ) + : dayOfMonthValuesConstraint( + substring(components[2], 0, 2), + components[1], + components[0], + ); + })`${yearFrag}-${monthFrag}-${dayFrag}${timezoneFrag}?`; + const gYearMonthLexicalRep = match( + "gYearMonthLexicalRep", + )`${yearFrag}-${monthFrag}${timezoneFrag}?`; + const gYearLexicalRep = match( + "gYearLexicalRep", + )`${yearFrag}${timezoneFrag}?`; + const gMonthDayLexicalRep = match("gMonthDayLexicalRep", ($) => { + const components = stringSplit(substring($, 2), "-"); + return dayOfMonthValuesConstraint( + substring(components[1], 0, 2), + components[0], + ); + })`--${monthFrag}-${dayFrag}${timezoneFrag}?`; + const gDayLexicalRep = match( + "gDayLexicalRep", + )`---${dayFrag}${timezoneFrag}?`; + const gMonthLexicalRep = match( + "gMonthLexicalRep", + )`--${monthFrag}${timezoneFrag}?`; + const hexDigit = match("hexDigit")`[0-9a-fA-F]`; + const hexOctet = match("hexOctet")`${hexDigit}{2}`; + const hexBinary = match("hexBinary")`${hexOctet}*`; + const B04char = match("B04char")`[AQgw]`; + const B04 = match("B04")`${B04char}\u{20}?`; + const B16char = match("B16char")`[AEIMQUYcgkosw048]`; + const B16 = match("B16")`${B16char}\u{20}?`; + const B64char = match("B64char")`[A-Za-z0-9+/]`; + const B64 = match("B64")`${B64char}\u{20}?`; + const Padded8 = match("Padded8")`${B64}${B04}=\u{20}?=`; + const Padded16 = match("Padded16")`${B64}{2}${B16}=`; + const B64finalquad = match("B64finalquad")`${B64}{3}${B64char}`; + const B64final = match( + "B64final", + )`${B64finalquad}|${Padded16}|${Padded8}`; + const B64quad = match("B64quad")`${B64}{4}`; + const Base64Binary = match( + "Base64Binary", + )`(?:${B64quad}*${B64final})?`; + const CanonicalPadded = match( + "CanonicalPadded", + )`${B64char}{2}${B16char}=|${B64char}${B04char}==`; + const CanonicalQuad = match("CanonicalQuad")`${B64char}{4}`; + const Canonical·base64Binary = match( + "Canonical·base64Binary", + )`${CanonicalQuad}*${CanonicalPadded}?`; + const yearMonthDurationLexicalRep = match( + "yearMonthDurationLexicalRep", + )`-?P${duYearMonthFrag}`; + const dayTimeDurationLexicalRep = match( + "dayTimeDurationLexicalRep", + )`-?P${duDayTimeFrag}`; + const dateTimeStampLexicalRep = match( + "dateTimeStampLexicalRep", + ($) => { + const components = stringSplit($, "-"); + return components[0] === "" + ? dayOfMonthValuesConstraint( + substring(components[3], 0, 2), + components[2], + `-${components[1]}`, + ) + : dayOfMonthValuesConstraint( + substring(components[2], 0, 2), + components[1], + components[0], + ); + }, + )`${yearFrag}-${monthFrag}-${dayFrag}T(?:${hourFrag}:${minuteFrag}:${secondFrag}|${endOfDayFrag})${timezoneFrag}`; + + return matchers; +})(); diff --git a/xsd/productions.test.js b/xsd/productions.test.js new file mode 100644 index 0000000..351bc25 --- /dev/null +++ b/xsd/productions.test.js @@ -0,0 +1,18 @@ +// ♓️🪡 सूत्र ∷ xsd/productions.test.js +// ==================================================================== +// +// Copyright © 2023 Lady [@ Lady’s Computer]. +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at . + +import { assert, assertStrictEquals } from "../dev-deps.js"; +import * as productions from "./productions.js"; + +Deno.test("Exports a correctly‐named value for each production", () => { + for (const [name, matcher] of Object.entries(productions)) { + assert(matcher != null, name); + assertStrictEquals(matcher.name, name); + } +}); diff --git a/xsd/values.js b/xsd/values.js new file mode 100644 index 0000000..ca5eb5b --- /dev/null +++ b/xsd/values.js @@ -0,0 +1,17 @@ +// ♓️🪡 सूत्र ∷ xsd/values.js +// ==================================================================== +// +// Copyright © 2023 Lady [@ Lady’s Computer]. +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at . + +export { + NAN as notANumber, + NEGATIVE_INFINITY as negativeInfinity, + NEGATIVE_ZERO as negativeZero, + POSITIVE_INFINITY as positiveInfinity, + POSITIVE_ZERO as positiveZero, + UNDEFINED as absent, +} from "../deps.js";