Compare commits
No commits in common. "main" and "keyring" have entirely different histories.
|
@ -1,4 +0,0 @@
|
|||
.DS_Store
|
||||
.idea
|
||||
*.log
|
||||
tmp/
|
|
@ -1,8 +0,0 @@
|
|||
(authorizations
|
||||
(version 0)
|
||||
(("1086 326D E207 068C 1C02 5129 A64F 4134 5C74 00AF"
|
||||
(name "takev"))))
|
||||
|
||||
;;; Local Variables:
|
||||
;;; mode: scheme
|
||||
;;; End:
|
|
@ -1,8 +0,0 @@
|
|||
(channel
|
||||
(version 0)
|
||||
(directory ".guix/modules"))
|
||||
|
||||
|
||||
;;; Local Variables:
|
||||
;;; mode: scheme
|
||||
;;; End:
|
|
@ -1,39 +0,0 @@
|
|||
(define-module (guix-toml)
|
||||
#:use-module (guix)
|
||||
#:use-module (guix git-download)
|
||||
#:use-module (guix packages)
|
||||
#:use-module ((guix licenses) #:prefix license:)
|
||||
#:use-module (guix build-system guile)
|
||||
#:use-module (gnu packages)
|
||||
#:use-module (gnu packages guile)
|
||||
#:use-module (gnu packages pkg-config))
|
||||
|
||||
(define vcs-file?
|
||||
(or (git-predicate "../..")
|
||||
(const #t)))
|
||||
|
||||
(define-public guile-toml
|
||||
(package
|
||||
(name "guix-toml")
|
||||
(version "0.1-src")
|
||||
(source (local-file "../.." "guile-toml"
|
||||
#:recursive? #t
|
||||
#:select? vcs-file?))
|
||||
(arguments
|
||||
(list
|
||||
#:phases
|
||||
#~(modify-phases %standard-phases
|
||||
(add-after 'unpack 'remove-guix
|
||||
(lambda _
|
||||
(begin
|
||||
(delete-file "guix.scm")
|
||||
(delete-file ".guix/modules/guix-toml.scm")))))))
|
||||
(build-system guile-build-system)
|
||||
(native-inputs (list pkg-config guile-3.0 guile-json-4))
|
||||
(propagated-inputs (list guile-json-4))
|
||||
(synopsis "")
|
||||
(description "")
|
||||
(home-page "")
|
||||
(license license:gpl3+)))
|
||||
|
||||
guile-toml
|
674
LICENSE
674
LICENSE
|
@ -1,674 +0,0 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
103
README.org
103
README.org
|
@ -1,103 +0,0 @@
|
|||
|
||||
|
||||
* guile-toml
|
||||
|
||||
TOML for Guile; v1.0.0 compliant.
|
||||
|
||||
** Installation
|
||||
|
||||
For now: add this folder to your ~GUILE_LOAD_PATH~.
|
||||
|
||||
** Usage
|
||||
|
||||
When parsing and building TOML documents, guile-toml follows [[https://github.com/aconchillo/guile-json][guile-json]] as close as possible. TOML types correspond to Guile types according to the following table:
|
||||
|
||||
| TOML | Guile |
|
||||
|----------------+---------------------|
|
||||
| string | string [0] |
|
||||
| key-value pair | alist |
|
||||
| array | vector |
|
||||
| integer/float | real |
|
||||
| true | #t |
|
||||
| false | #f |
|
||||
| datetime | SRFI-19 date [1] |
|
||||
| nan | +nan.0 |
|
||||
| ±inf | ±inf.0 |
|
||||
|
||||
To start using guile-toml:
|
||||
#+begin_src scheme
|
||||
(use-modules (toml))
|
||||
#+end_src
|
||||
|
||||
[0]: TOML's default behaviour for invalid UTF-8 is to fail, whereas [[https://www.gnu.org/software/guile/manual/html_node/Encoding.html][Guile's default behavior]] is to replace invalid UTF-8 with the replacement character <20>. If you prefer TOML's behavior, use ~(set-port-conversion-strategy! (current-input-port) 'error)~.
|
||||
|
||||
[1]: TOML's ~time-local~ is parsed same as a ~datetime-local~ on the date of ~1970-01-01~.
|
||||
|
||||
*** Reading TOML documents
|
||||
|
||||
- ~(toml->scm str)~
|
||||
|
||||
Reads a TOML document from the given string. Guile-toml's parsing is implemented with ~(ice-9 peg)~, which unfortunately does not support ports. See below for how to use this with a TOML file.
|
||||
|
||||
*** Building TOML documents
|
||||
- ~(scm->toml native #:optional port)~
|
||||
|
||||
Creates a TOML document from the given native Guile value. The TOML document is written into the given port, or to the current output port if none is given.
|
||||
|
||||
** Examples
|
||||
- Basic ~toml->scm~ usage:
|
||||
#+begin_src scheme
|
||||
> (toml->scm "[a]\n b.c = \"hi world\"")
|
||||
|
||||
(("a" ("b" ("c" . "hi world"))))
|
||||
#+end_src
|
||||
|
||||
- Read a TOML file and parse it (example from [[https://toml.io][toml.io]]):
|
||||
#+begin_src scheme
|
||||
> (use-modules (toml) (ice-9 textual-ports))
|
||||
> (toml->scm (call-with-input-file "example.toml" get-string-all))
|
||||
|
||||
(("servers"
|
||||
("beta" ("role" . "backend") ("ip" . "10.0.0.2"))
|
||||
("alpha"
|
||||
("role" . "frontend")
|
||||
("ip" . "10.0.0.1")))
|
||||
("database"
|
||||
("temp_targets" ("case" . 72.0) ("cpu" . 79.5))
|
||||
("data" . #(#("delta" "phi") #(3.14)))
|
||||
("ports" . #(8000 8001 8002))
|
||||
("enabled" . #t))
|
||||
("owner"
|
||||
("dob"
|
||||
.
|
||||
#<date nanosecond: 0 second: 0 minute: 32 hour: 7 day: 27 month: 5 year: 1979 zone-offset: -28800>)
|
||||
("name" . "Tom Preston-Werner"))
|
||||
("title" . "TOML Example"))
|
||||
#+end_src
|
||||
|
||||
~example.toml~:
|
||||
#+begin_src toml
|
||||
# This is a TOML document
|
||||
|
||||
title = "TOML Example"
|
||||
|
||||
[owner]
|
||||
name = "Tom Preston-Werner"
|
||||
dob = 1979-05-27T07:32:00-08:00
|
||||
|
||||
[database]
|
||||
enabled = true
|
||||
ports = [ 8000, 8001, 8002 ]
|
||||
data = [ ["delta", "phi"], [3.14] ]
|
||||
temp_targets = { cpu = 79.5, case = 72.0 }
|
||||
|
||||
[servers]
|
||||
|
||||
[servers.alpha]
|
||||
ip = "10.0.0.1"
|
||||
role = "frontend"
|
||||
|
||||
[servers.beta]
|
||||
ip = "10.0.0.2"
|
||||
role = "backend"
|
||||
#+end_src
|
|
@ -1,29 +0,0 @@
|
|||
#+title: guile-toml tests
|
||||
|
||||
|
||||
* toml-test suite
|
||||
|
||||
To run the ~toml-test~ suite, install ~toml-test~ by following the instructions [[https://github.com/BurntSushi/toml-test/#installation][here]]. Running the tests also depends on [[https://github.com/aconchillo/guile-json][guile-json]], so make sure to have it installed.
|
||||
|
||||
To test the decoder, run:
|
||||
#+begin_src shell
|
||||
$ toml-test ./test-decoder.scm
|
||||
#+end_src
|
||||
|
||||
To test the encoder, run:
|
||||
#+begin_src shell
|
||||
$ toml-test -encoder ./test-encoder.scm
|
||||
#+end_src
|
||||
|
||||
* tests for Guile's datatypes
|
||||
|
||||
The ~toml-test~ suite tests TOML's structure extensively, but since it relies on JSON and a different encoding of values, we still need to test whether Guile's datatypes are decoded and encoded correctly.
|
||||
|
||||
To run the tests for the decoder:
|
||||
#+begin_src shell
|
||||
$ guile test-datatypes.scm
|
||||
#+end_src
|
||||
|
||||
The files ~decoder.scm~ and ~encoder.scm~ serve as manual testing utilities:
|
||||
- ~decoder.scm~ takes TOML input from STDIN and outputs pretty-printed SCM to STDOUT.
|
||||
- ~encoder.scm~ takes JSON input from STDIN and outputs TOML to STDOUT.
|
|
@ -1,11 +0,0 @@
|
|||
#!/usr/bin/env -S guile -s
|
||||
!#
|
||||
(use-modules
|
||||
(toml)
|
||||
(ice-9 pretty-print)
|
||||
(ice-9 textual-ports))
|
||||
|
||||
(define str (get-string-all (current-input-port)))
|
||||
(define scm (toml->scm str))
|
||||
|
||||
(pretty-print scm)
|
|
@ -1,9 +0,0 @@
|
|||
#!/usr/bin/env -S guile -s
|
||||
!#
|
||||
(use-modules
|
||||
(toml builder)
|
||||
(json))
|
||||
|
||||
(define scm (json->scm (current-input-port)))
|
||||
|
||||
(scm->toml scm)
|
|
@ -1,40 +0,0 @@
|
|||
(use-modules (srfi srfi-64)
|
||||
(srfi srfi-19)
|
||||
(toml))
|
||||
|
||||
(test-begin "decoder-datatypes-test")
|
||||
|
||||
(define date (make-date 0 1 1 1 1 1 2000 0))
|
||||
(define toml-datetime "datetime = 2000-01-01T01:01:01Z")
|
||||
(define scm-datetime (toml->scm toml-datetime))
|
||||
(test-equal scm-datetime `(("datetime" . ,date)))
|
||||
|
||||
(define toml-float "float = 0.1")
|
||||
(define scm-float (toml->scm toml-float))
|
||||
(test-equal scm-float '(("float" . 0.1)))
|
||||
|
||||
(define toml-nan "nan = nan")
|
||||
(define scm-nan (toml->scm toml-nan))
|
||||
(test-equal scm-nan '(("nan" . +nan.0)))
|
||||
|
||||
(define toml-inf "inf = inf")
|
||||
(define scm-inf (toml->scm toml-inf))
|
||||
(test-equal scm-inf '(("inf" . +inf.0)))
|
||||
|
||||
(define toml-positive-inf "positive-inf = +inf")
|
||||
(define scm-positive-inf (toml->scm toml-positive-inf))
|
||||
(test-equal scm-positive-inf '(("positive-inf" . +inf.0)))
|
||||
|
||||
(define toml-negative-inf "negative-inf = -inf")
|
||||
(define scm-negative-inf (toml->scm toml-negative-inf))
|
||||
(test-equal scm-negative-inf '(("negative-inf" . -inf.0)))
|
||||
|
||||
(define toml-true "true = true")
|
||||
(define scm-true (toml->scm toml-true))
|
||||
(test-equal scm-true '(("true" . #t)))
|
||||
|
||||
(define toml-false "false = false")
|
||||
(define scm-false (toml->scm toml-false))
|
||||
(test-equal scm-false '(("false" . #f)))
|
||||
|
||||
(test-end "decoder-datatypes-test")
|
|
@ -1,60 +0,0 @@
|
|||
#!/usr/bin/env -S guile -s
|
||||
!#
|
||||
(use-modules
|
||||
(toml parser)
|
||||
(json)
|
||||
(ice-9 match)
|
||||
(ice-9 textual-ports)
|
||||
(ice-9 pretty-print))
|
||||
|
||||
(define test-value->scm
|
||||
(lambda (v)
|
||||
(match v
|
||||
(('array vs ...)
|
||||
(list->vector (map test-value->scm (flatten-array vs))))
|
||||
(('string ys ...)
|
||||
`(("value" . ,(read-string ys)) ("type" . "string")))
|
||||
('string
|
||||
`(("value" . "") ("type" . "string")))
|
||||
(('integer x)
|
||||
`(("value" . ,(number->string (read-int x))) ("type" . "integer")))
|
||||
(('datetime v)
|
||||
(validate-date-time `(datetime ,v))
|
||||
`(("value" . ,v) ("type" . "datetime")))
|
||||
(('datetime-local v)
|
||||
(validate-date-time `(datetime-local ,v))
|
||||
`(("value" . ,v) ("type" . "datetime-local")))
|
||||
(('date-local v)
|
||||
(validate-date-time `(date-local ,v))
|
||||
`(("value" . ,v) ("type" . "date-local")))
|
||||
(('time-local v)
|
||||
(validate-date-time `(time-local ,v))
|
||||
`(("value" . ,v) ("type" . "time-local")))
|
||||
(('inline-table "")
|
||||
'())
|
||||
(('inline-table xs ...)
|
||||
(peg-tree->scm (flatten-tree xs)))
|
||||
((x y)
|
||||
`(("value" . ,y) ("type" . ,(symbol->string x))))
|
||||
('()
|
||||
'())
|
||||
(_ (error "err: ~a" v)))))
|
||||
|
||||
(define test-value?
|
||||
(lambda (expr)
|
||||
(and
|
||||
(string? (car expr))
|
||||
(or
|
||||
(vector? (cdr expr))
|
||||
(equal? (map car (cdr expr)) '("value" "type"))))))
|
||||
|
||||
|
||||
(set-port-conversion-strategy! (current-input-port) 'error)
|
||||
|
||||
(define str (get-string-all (current-input-port)))
|
||||
|
||||
(define scm (parameterize ((value->scm test-value->scm)
|
||||
(value? test-value?))
|
||||
(toml->scm str)))
|
||||
|
||||
(define json (scm->json scm #:pretty #t #:unicode #t))
|
|
@ -1,58 +0,0 @@
|
|||
#!/usr/bin/env -S guile -s
|
||||
!#
|
||||
(use-modules
|
||||
(toml builder)
|
||||
(json)
|
||||
(srfi srfi-1)
|
||||
(ice-9 textual-ports)
|
||||
(ice-9 match)
|
||||
(ice-9 pretty-print))
|
||||
|
||||
(define test-value?
|
||||
(lambda (expr)
|
||||
(or
|
||||
(vector? expr)
|
||||
(and
|
||||
(list? expr)
|
||||
(or (equal? (map car expr) '("type" "value"))
|
||||
(equal? (map car expr) '("value" "type")))))))
|
||||
|
||||
(define (build-atomic-value scm port)
|
||||
(define (find-cdr-by-car s lst)
|
||||
(cdr (find (lambda (x) (equal? (car x) s)) lst)))
|
||||
(define type (find-cdr-by-car "type" scm))
|
||||
(define value (find-cdr-by-car "value" scm))
|
||||
(match type
|
||||
("string"
|
||||
(toml-build-string value port))
|
||||
("float"
|
||||
(put-string port (string-append value
|
||||
(if (or
|
||||
(string-contains value "n")
|
||||
(string-contains value "."))
|
||||
""
|
||||
".0"))))
|
||||
(_
|
||||
(put-string port value))))
|
||||
;; ("integer")))
|
||||
|
||||
|
||||
(define* (test-toml-build-value scm port #:key (newline? #t) (inline? #t))
|
||||
(cond
|
||||
((vector? scm)
|
||||
(toml-build-array scm port))
|
||||
(else
|
||||
(build-atomic-value scm port))))
|
||||
|
||||
(set-port-conversion-strategy! (current-input-port) 'error)
|
||||
|
||||
(define scm (json->scm (current-input-port)))
|
||||
|
||||
;; (pretty-print scm)
|
||||
;; (test-value? '())
|
||||
|
||||
;;(value->scm test-value->scm)
|
||||
(define x (parameterize ((toml-build-value test-toml-build-value)
|
||||
(value? test-value?))
|
||||
(scm->toml scm)))
|
||||
;; (scm->toml scm)
|
4
toml.scm
4
toml.scm
|
@ -1,4 +0,0 @@
|
|||
(define-module (toml)
|
||||
#:use-module (toml parser)
|
||||
#:use-module (toml builder)
|
||||
#:re-export (toml->scm scm->toml))
|
270
toml/builder.scm
270
toml/builder.scm
|
@ -1,270 +0,0 @@
|
|||
(define-module (toml builder)
|
||||
#:use-module (srfi srfi-1)
|
||||
#:use-module (json)
|
||||
#:use-module (srfi srfi-19)
|
||||
#:use-module (ice-9 textual-ports)
|
||||
#:use-module (ice-9 receive)
|
||||
#:use-module (ice-9 string-fun)
|
||||
#:export (scm->toml value? toml-build-value toml-build-array toml-build-string))
|
||||
|
||||
(define-syntax-rule (log-exprs exp ...) (begin (format (current-error-port) "~a: ~S\n" (quote exp) exp) ...))
|
||||
|
||||
;; we want to be able to dynamically bind this functin in test-decoder.scm
|
||||
;; TODO fix duplicate
|
||||
(define value?
|
||||
(make-parameter
|
||||
(lambda (expr) (not (list? expr)))))
|
||||
|
||||
(define (value-pair? scm)
|
||||
(and (string? (car scm))
|
||||
((value?) (cdr scm))))
|
||||
|
||||
(define (table-or-array-table? scm)
|
||||
(or (not (value-pair? scm))
|
||||
(array-table? (cdr scm))))
|
||||
|
||||
(define (array-table? v)
|
||||
(and (vector? v) (not (any (value?) (vector->list v)))))
|
||||
|
||||
(define (array-table-pair? scm)
|
||||
(array-table? (cdr scm)))
|
||||
;; (define scm->value
|
||||
;; (lambda))
|
||||
(define (build-newline port newline?)
|
||||
(when newline?
|
||||
(newline port)))
|
||||
|
||||
(define (toml-build-array-table-header keys port)
|
||||
(put-string port "[[")
|
||||
(build-keys keys port)
|
||||
(put-string port "]]"))
|
||||
|
||||
(define* (toml-build-array-table scm port #:optional (current-table '()))
|
||||
(define header (car scm))
|
||||
(define keys (append current-table (list header)))
|
||||
(define entries (vector->list (cdr scm)))
|
||||
(let loop ((entries entries))
|
||||
(unless (null? entries)
|
||||
(toml-build-array-table-header keys port)
|
||||
(build-newline port #t)
|
||||
(toml-build (car entries) port keys)
|
||||
(loop (cdr entries)))))
|
||||
|
||||
(define* (build-object-pair p port #:optional (current-table '())#:key (newline? #t) (inline? #f))
|
||||
(if (array-table? (cdr p))
|
||||
(toml-build-array-table p port current-table)
|
||||
(build-keyval p port #:newline? newline? #:inline? inline?)))
|
||||
|
||||
(define* (build-keyval p port #:key (newline? #t) (inline? #f))
|
||||
(build-key (car p) port)
|
||||
(put-string port " = ")
|
||||
(toml-build (cdr p) port #:newline? newline? #:inline? inline?))
|
||||
|
||||
(define* (escape-control-characters s #:optional (literal-nl? #f))
|
||||
(define (char->unicode-hex c)
|
||||
(define hex-unpadded (number->string (char->integer c) 16))
|
||||
(define zeroes (make-string (- 4 (string-length hex-unpadded)) #\0))
|
||||
(string-append "\\u" zeroes hex-unpadded))
|
||||
(apply string-append (map (lambda (c)
|
||||
(cond
|
||||
((and literal-nl? (eq? c #\newline))
|
||||
"\n")
|
||||
((eq? 'Cc (char-general-category c))
|
||||
(char->unicode-hex c))
|
||||
(else (string c))))
|
||||
(string->list s))))
|
||||
|
||||
(define (toml-build-string s port)
|
||||
(define quote-type (if (or
|
||||
(string-contains s "\\")
|
||||
(string-contains s "\"")) #\' #\"))
|
||||
(define surround (if (string-contains s "\n")
|
||||
(make-string 3 quote-type)
|
||||
(string quote-type)))
|
||||
;; (define surround (make-string 1 quote-type))
|
||||
(put-string port surround)
|
||||
(put-string port (escape-control-characters s #t))
|
||||
(put-string port surround))
|
||||
|
||||
(define (toml-build-key-string s port)
|
||||
(define quote-type (if (or
|
||||
(string-contains s "\\")
|
||||
(string-contains s "\"")) #\' #\"))
|
||||
(define surround (make-string 1 quote-type))
|
||||
(put-string port surround)
|
||||
(put-string port (escape-control-characters s))
|
||||
(put-string port surround))
|
||||
|
||||
(define (build-keys lst port)
|
||||
;; TODO unicode keys
|
||||
;; (put-string port (string-join lst "."))
|
||||
;; (toml-build-string (string-join lst ".") port))
|
||||
(let loop ((lst lst))
|
||||
(if (null? (cdr lst))
|
||||
(build-key (car lst) port)
|
||||
(begin
|
||||
(build-key (car lst) port)
|
||||
(put-string port ".")
|
||||
(loop (cdr lst))))))
|
||||
|
||||
(define (build-key s port)
|
||||
(toml-build-key-string s port))
|
||||
|
||||
(define (build-table scm port current-table)
|
||||
(define new-table (append current-table (list (car scm))))
|
||||
(put-string port "[")
|
||||
(build-keys new-table port)
|
||||
(put-string port "]")
|
||||
(newline port)
|
||||
(toml-build (cdr scm) port new-table))
|
||||
|
||||
(define (values-then-array-tables a b)
|
||||
(let ((av? (array-table? (cdr a)))
|
||||
(bv? (array-table? (cdr b))))
|
||||
(cond
|
||||
((and av? bv?) #t)
|
||||
(av? #f)
|
||||
(bv? #t))))
|
||||
|
||||
(define (toml-build-tree scm port current-table)
|
||||
(define pairs scm)
|
||||
(unless (null? pairs)
|
||||
(receive (tables keyvals)
|
||||
(partition table-or-array-table? pairs)
|
||||
;; (log-exprs "." tables keyvals ".")
|
||||
(for-each (lambda (kv)
|
||||
(build-object-pair kv port current-table))
|
||||
keyvals)
|
||||
(receive (array-tables std-tables)
|
||||
(partition array-table-pair? tables)
|
||||
;; (log-exprs "_" array-tables std-tables "_")
|
||||
(for-each (lambda (t)
|
||||
(build-table t port current-table))
|
||||
std-tables)
|
||||
(for-each (lambda (kv)
|
||||
(build-object-pair kv port current-table))
|
||||
array-tables)))))
|
||||
|
||||
(define (build-delimited lst port)
|
||||
(unless (null? lst)
|
||||
(let loop ((lst lst))
|
||||
(if (null? (cdr lst))
|
||||
(toml-build (car lst) port #:newline? #f #:inline? #t)
|
||||
(begin (toml-build (car lst) port #:newline? #f #:inline? #t)
|
||||
(put-string port ", ")
|
||||
(loop (cdr lst)))))))
|
||||
|
||||
(define (build-delimited-pairs lst port)
|
||||
(unless (null? lst)
|
||||
(let loop ((lst lst))
|
||||
(if (null? (cdr lst))
|
||||
(build-object-pair (car lst) port #:newline? #f #:inline? #t)
|
||||
(begin (build-object-pair (car lst) port #:newline? #f #:inline? #t)
|
||||
(put-string port ", ")
|
||||
(loop (cdr lst)))))))
|
||||
|
||||
(define (toml-build-inline-tree scm port)
|
||||
(define pairs scm)
|
||||
(put-string port "{")
|
||||
(unless (null? pairs)
|
||||
(build-delimited-pairs pairs port))
|
||||
;; (build-delimited pairs port))
|
||||
(put-string port "}"))
|
||||
|
||||
;; (build-object-pair (car pairs) port)
|
||||
;; (for-each (lambda (p)
|
||||
;; (build-object-pair p port))
|
||||
;; (cdr pairs))
|
||||
;; (newline port))))
|
||||
|
||||
(define (toml-build-array v port)
|
||||
(put-string port "[")
|
||||
(build-delimited (vector->list v) port)
|
||||
(put-string port "]"))
|
||||
|
||||
;; (define x (make-date 0 0 1 1 1 1 0 0))
|
||||
;; (date->toml-datetime x)
|
||||
|
||||
(define (date->toml-datetime date)
|
||||
(define format (string-append
|
||||
"~Y-~m-~dT~H:~M:~S"
|
||||
(if (< 0 (date-nanosecond date)) ".~N" "")
|
||||
"~z"))
|
||||
(date->string date format))
|
||||
|
||||
(define toml-build-value
|
||||
(make-parameter
|
||||
(lambda*
|
||||
(scm port #:key (newline? #t) (inline? #f))
|
||||
(cond
|
||||
;; ((eq? scm null) (toml-build-null port))
|
||||
;; ((boolean? scm) (toml-build-boolean scm port))
|
||||
;; ((symbol? scm) (toml-build-string (symbol->string scm) port))
|
||||
|
||||
;; TODO float (nan, inf)
|
||||
((date? scm) (put-string port (date->toml-datetime scm)))
|
||||
((vector? scm) (toml-build-array scm port))
|
||||
((string? scm) (toml-build-string scm port))
|
||||
(else (display scm port)))
|
||||
(build-newline port newline?))))
|
||||
|
||||
(define* (toml-build scm port #:optional (current-table '())
|
||||
#:key (newline? #t) (inline? #f))
|
||||
;; (log-exprs scm)
|
||||
(cond
|
||||
;; ((eq? scm null) (toml-build-null port))
|
||||
;; ((boolean? scm) (toml-build-boolean scm port))
|
||||
;; ((toml-number? scm) (toml-build-number scm port))
|
||||
;; ((symbol? scm) (toml-build-string (symbol->string scm) port))
|
||||
((null? scm)
|
||||
(and inline? (toml-build-inline-tree '() port)))
|
||||
(((value?) scm)
|
||||
((toml-build-value) scm port #:newline? newline? #:inline? inline?))
|
||||
((array-table? (and (list? scm) (cdr scm)))
|
||||
(toml-build-array-table scm port))
|
||||
((or (pair? scm) (null? scm))
|
||||
(if inline?
|
||||
(toml-build-inline-tree scm port)
|
||||
(toml-build-tree scm port current-table))))
|
||||
|
||||
(build-newline port newline?))
|
||||
;; (else (throw 'toml-invalid scm))))
|
||||
|
||||
(define* (scm->toml scm
|
||||
#:optional (port (current-output-port)))
|
||||
(toml-build scm port))
|
||||
|
||||
;; (scm->toml '(("a" . "b") ("c" . "d")))
|
||||
;; (scm->toml '(("yo" ("a" . "b"))))
|
||||
;; (scm->toml '(("hi"
|
||||
;; ("yo" ("a" . "b") ("c" . "d"))
|
||||
;; ;; ("e" . #("f" "b" (("a" . "b")))) TODO inline-tables
|
||||
;; ("e" . #("f" "b" "g")))
|
||||
;; ("g" . "p")))
|
||||
|
||||
;; '(("servers"
|
||||
;; ("beta" ("role" . "backend") ("ip" . "10.0.0.2"))
|
||||
;; ("alpha"
|
||||
;; ("role" . "frontend")
|
||||
;; ("ip" . "10.0.0.1")))
|
||||
;; ("database"
|
||||
;; ("temp_targets" ("case" . 72.0) ("cpu" . 79.5))
|
||||
;; ("data" . #(#("delta" "phi") #(3.14)))
|
||||
;; ("ports" . #(8000 8001 8002))
|
||||
;; ("enabled" . #t))
|
||||
;; ("owner"
|
||||
;; ("dob"
|
||||
;; . "date")
|
||||
;; ("name" . "Tom Preston-Werner"))
|
||||
;; ("title" . "TOML Example"))
|
||||
|
||||
;; '()
|
||||
|
||||
|
||||
;; (define (values-first a b)
|
||||
;; (let ((av? ((value?) a))
|
||||
;; (bv? ((value?) b)))
|
||||
;; (cond
|
||||
;; ((and av? bv?) #t)
|
||||
;; (av? #t)
|
||||
;; (bv? #f))))
|
|
@ -1,307 +0,0 @@
|
|||
(define-module (toml parser-peg)
|
||||
#:use-module (ice-9 peg)
|
||||
#:use-module (ice-9 pretty-print)
|
||||
#:export (parse))
|
||||
|
||||
;; Built-in ABNF terms, reproduced here for clarity
|
||||
(define-peg-string-patterns
|
||||
"ALPHA <- [A-Z] / [a-z]
|
||||
DIGIT <- [0-9]
|
||||
HEXDIG <- DIGIT / [A-Fa-f]
|
||||
")
|
||||
;; T-Newline
|
||||
(define-peg-string-patterns
|
||||
"t-newline < '\n' / '\r\n'")
|
||||
|
||||
(define-peg-string-patterns
|
||||
"toml <- (t-expression t-newline)* t-expression
|
||||
t-expression <- ((ws keyval ws) / (ws table ws) / ws) comment?
|
||||
")
|
||||
|
||||
;; Whitespace
|
||||
(define-peg-string-patterns
|
||||
"ws < wschar*
|
||||
wschar < ' ' / '\t'
|
||||
")
|
||||
;; Comment
|
||||
;; non-ascii <- %x80-D7FF / %xE000-10FFFF
|
||||
;; non-eol <- %x09 / %x20-7F / non-ascii
|
||||
|
||||
(define-peg-pattern non-ascii body
|
||||
(or (range #\x80 #\xD7FF) (range #\xE000 #\x10FFFF)))
|
||||
(define-peg-pattern non-eol body
|
||||
;; TODO report abnf is wrong here?
|
||||
(or "\t" (range #\x20 #\x7E) non-ascii))
|
||||
|
||||
(define-peg-string-patterns
|
||||
"comment-start-symbol <- '#'
|
||||
|
||||
comment < comment-start-symbol non-eol*
|
||||
")
|
||||
;; Key-Value pairs
|
||||
|
||||
(define-peg-string-patterns
|
||||
"keyval <-- key keyval-sep val
|
||||
key <- dotted-key / simple-key
|
||||
simple-key <-- quoted-key / unquoted-key
|
||||
|
||||
unquoted-key <- (ALPHA / DIGIT / '-' / '_')+
|
||||
quoted-key <- basic-string / literal-string
|
||||
dotted-key <- simple-key ( dot-sep simple-key )+
|
||||
|
||||
dot-sep <- ws dot ws
|
||||
dot < '.'
|
||||
keyval-sep <- ws eq ws
|
||||
eq < '='
|
||||
val <- string / bool / array / inline-table / date-time / float / integer
|
||||
|
||||
")
|
||||
;; String
|
||||
(define-peg-string-patterns
|
||||
"string <-- ml-basic-string / basic-string / ml-literal-string / literal-string
|
||||
")
|
||||
;; Basic String
|
||||
(define-peg-string-patterns
|
||||
"basic-string <- quotation-mark basic-char* quotation-mark
|
||||
|
||||
quotation-mark < '\"'
|
||||
|
||||
basic-char <- basic-unescaped / escaped
|
||||
")
|
||||
|
||||
;; basic-unescaped <- wschar / %x21 / %x23-5B / %x5D-7E / non-ascii
|
||||
(define-peg-pattern basic-unescaped body
|
||||
(or body-wschar (range #\x21 #\x21) (range #\x23 #\x5B) (range #\x5D #\x7E) non-ascii))
|
||||
(define-peg-string-patterns
|
||||
"escaped <-- escape escape-seq-char
|
||||
|
||||
escape <- '\\'
|
||||
")
|
||||
|
||||
(define-peg-pattern escape-seq-char body
|
||||
(or
|
||||
"\""
|
||||
"\\"
|
||||
"b"
|
||||
"f"
|
||||
"n"
|
||||
"r"
|
||||
"t"
|
||||
(and (range #\u #\u) HEXDIG HEXDIG HEXDIG HEXDIG)
|
||||
(and (range #\U #\U) HEXDIG HEXDIG HEXDIG HEXDIG HEXDIG HEXDIG HEXDIG HEXDIG)))
|
||||
|
||||
;; escape-seq-char <- %x22 ; quotation mark U+0022
|
||||
;; escape-seq-char =/ %x5C ; reverse solidus U+005C
|
||||
;; escape-seq-char =/ %x62 ; b backspace U+0008
|
||||
;; escape-seq-char =/ %x66 ; f form feed U+000C
|
||||
;; escape-seq-char =/ %x6E ; n line feed U+000A
|
||||
;; escape-seq-char =/ %x72 ; r carriage return U+000D
|
||||
;; escape-seq-char =/ %x74 ; t tab U+0009
|
||||
;; escape-seq-char =/ %x75 4HEXDIG ; uXXXX U+XXXX
|
||||
;; escape-seq-char =/ %x55 8HEXDIG ; UXXXXXXXX U+XXXXXXXX
|
||||
;; ))
|
||||
|
||||
|
||||
|
||||
|
||||
;; Multiline Basic String
|
||||
(define-peg-string-patterns
|
||||
"ml-basic-string <- ml-basic-string-delim t-newline? ml-basic-body ml-basic-string-delim
|
||||
ml-basic-string-delim <- quotation-mark quotation-mark quotation-mark
|
||||
ml-basic-body <- mlb-content* (mlb-quotes mlb-content+)* mlb-quotes-end?
|
||||
|
||||
mlb-quotes-end <- mlb-quotes-end-2 / mlb-quotes-end-1
|
||||
mlb-quotes-end-1 <- body-quot &ml-basic-string-delim
|
||||
mlb-quotes-end-2 <- body-quot body-quot &ml-basic-string-delim
|
||||
|
||||
body-newline <- '\n' / '\r\n'
|
||||
body-ws <- body-wschar*
|
||||
body-wschar <- ' ' / '\t'
|
||||
body-quot <- '\"'
|
||||
|
||||
mlb-content <- mlb-escaped-nl / mlb-char / body-newline
|
||||
mlb-char <- mlb-unescaped / escaped
|
||||
mlb-quotes <- !ml-basic-string-delim body-quot body-quot?
|
||||
mlb-escaped-nl < escape ws body-newline (wschar / body-newline)*
|
||||
")
|
||||
;; mlb-unescaped <- wschar / %x21 / %x23-5B / %x5D-7E / non-ascii
|
||||
(define-peg-pattern mlb-unescaped body
|
||||
(or body-wschar (range #\x21 #\x21) (range #\x23 #\x5B) (range #\x5D #\x7E) non-ascii))
|
||||
|
||||
;; Literal String
|
||||
(define-peg-string-patterns
|
||||
"literal-string <- apostrophe literal-char* apostrophe
|
||||
")
|
||||
|
||||
;; apostrophe <- '\x27' ; apostrophe
|
||||
;; literal-char <- %x09 / %x20-26 / %x28-7E / non-ascii
|
||||
(define-peg-pattern apostrophe none "'")
|
||||
(define-peg-pattern body-apostrophe body "'")
|
||||
(define-peg-pattern literal-char body
|
||||
(or "\t" (range #\x20 #\x26) (range #\x28 #\x7E) non-ascii))
|
||||
|
||||
;; Multiline Literal String
|
||||
(define-peg-string-patterns
|
||||
"mll-quotes <- !ml-literal-string-delim body-apostrophe body-apostrophe?
|
||||
|
||||
mll-quotes-end <- mll-quotes-end-2 / mll-quotes-end-1
|
||||
mll-quotes-end-1 <- body-apostrophe &ml-literal-string-delim
|
||||
mll-quotes-end-2 <- body-apostrophe body-apostrophe &ml-literal-string-delim
|
||||
|
||||
ml-literal-string <- ml-literal-string-delim t-newline? ml-literal-body ml-literal-string-delim
|
||||
ml-literal-string-delim <- apostrophe apostrophe apostrophe
|
||||
ml-literal-body <- mll-content* (mll-quotes mll-content+ )* mll-quotes-end?
|
||||
|
||||
mll-content <- mll-char / body-newline
|
||||
")
|
||||
|
||||
(define-peg-pattern mll-char body
|
||||
(or "\t" (range #\x20 #\x26) (range #\x28 #\x7E) non-ascii))
|
||||
;; Integer
|
||||
(define-peg-string-patterns
|
||||
"integer <-- hex-int / oct-int / bin-int / dec-int
|
||||
|
||||
minus <- '-'
|
||||
plus < '+'
|
||||
underscore < '_'
|
||||
digit1-9 <- [1-9]
|
||||
digit0-7 <- [0-9]
|
||||
digit0-1 <- [0-1]
|
||||
|
||||
hex-prefix <- '0x'
|
||||
oct-prefix <- '0o'
|
||||
bin-prefix <- '0b'
|
||||
|
||||
dec-int <- (minus / plus)? unsigned-dec-int
|
||||
unsigned-dec-int <- (digit1-9 ( DIGIT / (underscore DIGIT))+) / DIGIT
|
||||
|
||||
hex-int <- hex-prefix HEXDIG (HEXDIG / underscore HEXDIG)*
|
||||
oct-int <- oct-prefix digit0-7 (digit0-7 / underscore digit0-7)*
|
||||
bin-int <- bin-prefix digit0-1 (digit0-1 / underscore digit0-1)*
|
||||
")
|
||||
;; Float
|
||||
(define-peg-string-patterns
|
||||
"float <-- (float-int-part ( t-exp / frac t-exp?)) / special-float
|
||||
|
||||
float-dec-int <- (minus / plus)? unsigned-dec-int
|
||||
float-int-part <- float-dec-int
|
||||
frac <- decimal-point zero-prefixable-int
|
||||
decimal-point <- '.'
|
||||
zero-prefixable-int <- DIGIT (DIGIT / underscore DIGIT)*
|
||||
|
||||
t-exp <- [eE] float-t-exp-part
|
||||
float-t-exp-part <- (minus / plus)? zero-prefixable-int
|
||||
|
||||
minus-none < '-'
|
||||
plus-none < '+'
|
||||
t-nan <- 'nan'
|
||||
t-inf <- 'inf'
|
||||
|
||||
special-float <- ((minus / plus)? t-inf) / ((minus-none / plus-none)? t-nan)
|
||||
|
||||
")
|
||||
;; Boolean
|
||||
(define-peg-string-patterns
|
||||
"bool <-- 'true' / 'false'
|
||||
|
||||
")
|
||||
;; true <- %x74.72.75.65 ; true
|
||||
;; false <- %x66.61.6C.73.65 ; false
|
||||
|
||||
;; Date and Time (as defined in RFC 3339)
|
||||
(define-peg-string-patterns
|
||||
"date-time <- datetime / datetime-local / date-local / time-local
|
||||
|
||||
date-fullyear <- DIGIT DIGIT DIGIT DIGIT
|
||||
date-month <- DIGIT DIGIT
|
||||
date-mday <- DIGIT DIGIT
|
||||
time-delim <- 'T' / 't' / ' '
|
||||
time-hour <- DIGIT DIGIT
|
||||
time-minute <- DIGIT DIGIT
|
||||
time-second <- DIGIT DIGIT
|
||||
time-secfrac <- '.' DIGIT+
|
||||
time-numoffset <- ( '+' / '-' ) time-hour ':' time-minute
|
||||
time-offset <- 'Z' / 'z' / time-numoffset
|
||||
|
||||
partial-time <- time-hour ':' time-minute ':' time-second time-secfrac?
|
||||
full-date <- date-fullyear '-' date-month '-' date-mday
|
||||
full-time <- partial-time time-offset
|
||||
")
|
||||
;; time-delim <- 'T' / ' ' ; T, t, or space
|
||||
|
||||
;; Offset Date-Time
|
||||
(define-peg-string-patterns
|
||||
"datetime <-- full-date time-delim full-time
|
||||
")
|
||||
;; Local Date-Time
|
||||
(define-peg-string-patterns
|
||||
"datetime-local <-- full-date time-delim partial-time
|
||||
")
|
||||
;; Local Date
|
||||
(define-peg-string-patterns
|
||||
"date-local <-- full-date
|
||||
")
|
||||
;; Local Time
|
||||
(define-peg-string-patterns
|
||||
"time-local <-- partial-time
|
||||
")
|
||||
;; Array
|
||||
;; array-values <- ws-comment-t-newline val ws-comment-t-newline array-sep array-values / ws-comment-t-newline val ws-comment-t-newline array-sep?
|
||||
;; array-values <- (ws-comment-t-newline val ws-comment-t-newline array-sep)* ws-comment-t-newline val ws-comment-t-newline array-sep?
|
||||
(define-peg-string-patterns
|
||||
"array <-- array-open array-values? ws-comment-t-newline array-close
|
||||
|
||||
array-open < '['
|
||||
array-close < ']'
|
||||
|
||||
array-values <- array-values-1 / array-values-2
|
||||
array-values-1 <- ws-comment-t-newline val ws-comment-t-newline array-sep array-values
|
||||
array-values-2 <- ws-comment-t-newline val ws-comment-t-newline array-sep?
|
||||
|
||||
array-sep < ','
|
||||
|
||||
ws-comment-t-newline <- ((comment? t-newline) / wschar)*
|
||||
")
|
||||
;; Table
|
||||
(define-peg-string-patterns
|
||||
"table <- std-table / array-table
|
||||
")
|
||||
;; Standard Table
|
||||
(define-peg-string-patterns
|
||||
"std-table <-- std-table-open key std-table-close
|
||||
|
||||
std-table-open < '[' ws
|
||||
std-table-close < ws ']'
|
||||
")
|
||||
;; Inline Table
|
||||
(define-peg-string-patterns
|
||||
"inline-table <-- inline-table-open (inline-table-keyvals / empty) inline-table-close
|
||||
|
||||
empty <- ''
|
||||
inline-table-open < '{' ws
|
||||
inline-table-close < ws '}'
|
||||
inline-table-sep < ws ',' ws
|
||||
|
||||
inline-table-keyvals <- keyval (inline-table-sep inline-table-keyvals)?
|
||||
")
|
||||
;; Array Table
|
||||
(define-peg-string-patterns
|
||||
"array-table <-- array-table-open key array-table-close
|
||||
|
||||
array-table-open < '[[' ws
|
||||
array-table-close < ws ']]'
|
||||
")
|
||||
|
||||
|
||||
(define (parse str)
|
||||
;; (define record (keyword-flatten
|
||||
;; '(keyval std-table inline-table)
|
||||
;; (match-pattern toml str)))
|
||||
(define peg (match-pattern toml str))
|
||||
(if (eq? (string-length str) (peg:end peg))
|
||||
(begin
|
||||
;; (pretty-print (peg:tree record))
|
||||
(peg:tree peg))
|
||||
(begin
|
||||
(pretty-print (peg:tree peg))
|
||||
(error "guile-toml: parsing failed\n" (peg:substring peg)))))
|
415
toml/parser.scm
415
toml/parser.scm
|
@ -1,415 +0,0 @@
|
|||
(define-module (toml parser)
|
||||
#:use-module (toml parser-peg)
|
||||
#:use-module (ice-9 peg)
|
||||
#:use-module (ice-9 textual-ports)
|
||||
#:use-module (ice-9 pretty-print)
|
||||
#:use-module (ice-9 match)
|
||||
#:use-module (ice-9 regex)
|
||||
#:use-module (srfi srfi-19)
|
||||
#:use-module (json)
|
||||
#:use-module (srfi srfi-1)
|
||||
#:export (toml->scm peg-tree->scm flatten-tree flatten-array value->scm validate-date-time read-string read-int value?))
|
||||
|
||||
|
||||
(define-syntax-rule (log-exprs exp ...) (begin (format #t "~a: ~S\n" (quote exp) exp) ...))
|
||||
|
||||
(define (flatten-array l)
|
||||
(keyword-flatten '(string bool array inline-table datetime float integer) l))
|
||||
|
||||
(define (get-keys l)
|
||||
(map (lambda (k) (read-string (cdr k))) (keyword-flatten '(simple-key) l)))
|
||||
|
||||
(define (unicode-point->string s)
|
||||
(string (integer->char (string->number (substring s 2) 16))))
|
||||
|
||||
(define (unescape-escaped s)
|
||||
(if (list? s)
|
||||
(match (string-ref (cadr s) 1)
|
||||
(#\\ "\\")
|
||||
(#\" "\"")
|
||||
(#\b "\b")
|
||||
(#\f "\f")
|
||||
(#\n "\n")
|
||||
(#\r "\r")
|
||||
(#\t "\t")
|
||||
(#\u (unicode-point->string (cadr s)))
|
||||
(#\U (unicode-point->string (cadr s)))
|
||||
(_ (error "guile-toml: unsupported escape char:" (cadr s))))
|
||||
s))
|
||||
|
||||
(define (read-string lst)
|
||||
(string-join (map unescape-escaped (keyword-flatten '(escaped) lst)) ""))
|
||||
|
||||
(define (read-int str)
|
||||
(define base (false-if-exception (substring str 0 2)))
|
||||
(define data (false-if-exception (substring str 2)))
|
||||
(match base
|
||||
("0b" (string->number data 2))
|
||||
("0o" (string->number data 8))
|
||||
("0x" (string->number data 16))
|
||||
(_ (string->number str 10))))
|
||||
|
||||
;; we want to be able to dynamically bind this function in test-decoder.scm
|
||||
(define value->scm
|
||||
(make-parameter
|
||||
(lambda (value-pair)
|
||||
;; (log-exprs value-pair)
|
||||
(match value-pair
|
||||
(('array value-pairs ...)
|
||||
;; (log-exprs value-pairs (flatten-array value-pairs))
|
||||
;; (pretty-print value-pairs)
|
||||
;; (newline)
|
||||
;; (pretty-print (flatten-array value-pairs))
|
||||
(list->vector (map (value->scm) (flatten-array value-pairs))))
|
||||
(('integer v)
|
||||
(read-int v))
|
||||
(('float v)
|
||||
;; could make this nicer by tagging nan/inf already in PEGs
|
||||
(cond
|
||||
((string-contains v "nan") #i+nan.0)
|
||||
((string-contains v "-inf") #i-inf.0)
|
||||
((string-contains v "inf") #i+inf.0)
|
||||
(else (string->number v))))
|
||||
(('string vs ...)
|
||||
(read-string vs))
|
||||
('string
|
||||
"")
|
||||
(('bool v)
|
||||
(equal? v "true"))
|
||||
(('datetime v)
|
||||
(validate-date-time `(datetime ,v))
|
||||
(datetime->date v))
|
||||
(('datetime-local v)
|
||||
(validate-date-time `(datetime-local ,v))
|
||||
(datetime-local->date v))
|
||||
(('date-local v)
|
||||
(validate-date-time `(date-local ,v))
|
||||
(date-local->date v))
|
||||
(('time-local v)
|
||||
(validate-date-time `(time-local ,v))
|
||||
(time-local->date v))
|
||||
(('inline-table "")
|
||||
'())
|
||||
(('inline-table xs ...)
|
||||
(peg-tree->scm (flatten-tree xs)))
|
||||
((x y)
|
||||
(format #f "~a: ~a" x y))
|
||||
('()
|
||||
'())
|
||||
('(())
|
||||
(error "redef"))
|
||||
;; ('inline-table
|
||||
;; '())
|
||||
(_ (error "err:" value-pair))))))
|
||||
|
||||
(define (normalize-date-time s)
|
||||
(define s-with-T (string-replace s "T" 10 11)) ;; could be t, T, or " ", so we can't just upcase all
|
||||
(define s-upcased (string-upcase s-with-T))
|
||||
(define s-without-colon (if (string-match "[+-][0-9][0-9]:[0-9][0-9]$" s)
|
||||
(regexp-substitute #f (string-match ":([0-9][0-9])$" s-with-T) 'pre "" 1 'post)
|
||||
s-upcased))
|
||||
s-without-colon)
|
||||
|
||||
(define (datetime->date s)
|
||||
(define format (string-append
|
||||
"~Y-~m-~dT~H:~M:~S"
|
||||
(if (string-contains s ".") ".~N" "")
|
||||
"~z"))
|
||||
(string->date (normalize-date-time s) format))
|
||||
|
||||
(define (datetime-local->date s)
|
||||
(string->date (normalize-date-time s) "~Y-~m-~dT~H:~M:~S"))
|
||||
|
||||
(define (date-local->date s)
|
||||
(string->date s "~Y~m~d"))
|
||||
|
||||
(define (time-local->date s)
|
||||
(datetime-local->date (string-append "1970-01-01T" s)))
|
||||
|
||||
(define (remove-nanos s)
|
||||
(define nanos (string-match "\\.[0-9]+" s))
|
||||
(define region (and nanos (vector-ref nanos 1)))
|
||||
(if region
|
||||
(string-replace s "" (car region) (cdr region))
|
||||
s))
|
||||
|
||||
(define (validate-date-time v)
|
||||
(let ((result (match v
|
||||
(('datetime s)
|
||||
(strptime "%FT%T%z" (normalize-date-time (remove-nanos s))))
|
||||
(('datetime-local s)
|
||||
(strptime "%FT%T" (normalize-date-time (remove-nanos s))))
|
||||
(('date-local s)
|
||||
(strptime "%F" s))
|
||||
(('time-local s)
|
||||
(strptime "%T" (remove-nanos s))))))
|
||||
(when (and result (< 60 (tm:sec (car result))))
|
||||
(error "guile-toml: invalid date-time"))))
|
||||
|
||||
;; (define s "1987-12-21")
|
||||
;; (tm:sec (car (strptime "%F" s)))
|
||||
;; (validate-date-time `(datetime ,s))
|
||||
|
||||
|
||||
|
||||
;; (datetime-string->date "1987-12-21T18:23:23+08:00")
|
||||
;; (car (strptime "%FT%T%z" "1987-18-83T18:28:60+08:00"))
|
||||
;; (tm:gmtoff (car (strptime "%FT%T%z" "1987-12-13T18:28:60+9100")))
|
||||
;; (date->string (rfc3339-string->date "1987-12-83T18:28:60+08:00"))
|
||||
|
||||
(define (keyval->scm keys value array-table-index)
|
||||
(let loop ((keys keys))
|
||||
(cond
|
||||
;; ((and array-table-index (eq? 2 (length keys)))
|
||||
;; (cons (first keys) (list->vector (list (list (cons (second keys) ((value->scm) (car value))))))))
|
||||
|
||||
((null? (cdr keys))
|
||||
(cons (car keys) ((value->scm) (car value))))
|
||||
(else
|
||||
(list (car keys) (loop (cdr keys)))))))
|
||||
|
||||
;; we want to be able to dynamically bind this functin in test-decoder.scm
|
||||
(define value?
|
||||
(make-parameter
|
||||
(lambda (expr) (not (list? expr)))))
|
||||
|
||||
(define (find-subtree tree key)
|
||||
(let ((k (list-index (lambda (x) (equal? x key))
|
||||
(map car tree))))
|
||||
(and k (cons k (list-ref tree k)))))
|
||||
|
||||
(find-subtree '(("x" ("y"))) "x")
|
||||
(find-subtree '(("a" . 2) ("b" . 2)) '("c"))
|
||||
;; (map car '(("x")))
|
||||
|
||||
|
||||
|
||||
(define (add-to-tree tree table-keys keys value array-table-index)
|
||||
(if array-table-index
|
||||
(add-kv-to-tree-in-array tree table-keys keys value array-table-index)
|
||||
(add-kv-to-tree tree (append table-keys keys) value)))
|
||||
|
||||
(define (init-array-table keys value)
|
||||
(cons (first keys) (list->vector `((,(cons (second keys) value))))))
|
||||
|
||||
;; adds kv to the tree within array[(length array)], always in the last position of the array
|
||||
(define (add-kv-to-array array keys value index)
|
||||
(define l (vector->list array))
|
||||
(define k (1- (length l)))
|
||||
(if (eq? '() value)
|
||||
(extend-array-table array)
|
||||
(begin (list-set! l
|
||||
k
|
||||
(add-kv-to-tree (vector-ref array k) keys value))
|
||||
(list->vector l))))
|
||||
|
||||
;; (add-kv-to-array #((("a" . 2) ("b" . 2)) (("d" . 2))) '("c") '((integer "3")) 0)
|
||||
(define (extend-array-table array)
|
||||
(list->vector (append (vector->list array) '(()))))
|
||||
|
||||
|
||||
|
||||
;; replaces keys at position k in tree (probably could just use list-set! here)
|
||||
(define (replace-in-tree tree keyname k new)
|
||||
;; (log-exprs "repla" tree keyname k new)
|
||||
(append
|
||||
(take tree k)
|
||||
(list (cons
|
||||
keyname
|
||||
new))
|
||||
(drop tree (1+ k))))
|
||||
|
||||
|
||||
|
||||
;; adds kv pair which is within an array table (needs a better name)
|
||||
(define (add-kv-to-tree-in-array tree table-keys keys value index)
|
||||
;; (pretty-print value)
|
||||
;; (log-exprs tree table-keys keys ".")
|
||||
(if (null? (cdr table-keys))
|
||||
(begin
|
||||
;; (log-exprs "/////////////" tree table-keys keys value "///////////////")
|
||||
(if (or (null? tree) (null? (car tree)))
|
||||
;; (list (cons (car table-keys) (add-kv-to-array (if (null? tree) #(()) (cdr tree)) keys value index)))
|
||||
(list (cons (car table-keys) (make-vector 1 '())))
|
||||
(let ((k (list-index (lambda (x) (equal? x (car table-keys))) (map car tree))))
|
||||
;; (log-exprs tree keys value k)
|
||||
(if k
|
||||
(let ((e (list-ref tree k)))
|
||||
(replace-in-tree tree (car e) k (add-kv-to-array (cdr e) keys value 0)))
|
||||
(cons (cons (car table-keys) (make-vector 1 '())) tree)))))
|
||||
;; (cons (cons (car table-keys) (add-kv-to-array #(()) keys value index)) tree)))))
|
||||
(let ((f (find-subtree tree (car table-keys))))
|
||||
;; (log-exprs f table-keys keys value)
|
||||
(cond
|
||||
((and f (vector? (cddr f)))
|
||||
;; (log-exprs "-----" tree table-keys keys value f "------------")
|
||||
(let* ((k (car f)) (e (cdr f))
|
||||
(array (cdr e))
|
||||
(len (1- (vector-length array)))
|
||||
(el-of-array (vector-ref array len))
|
||||
(new-el (add-kv-to-tree-in-array el-of-array (cdr table-keys) keys value index)))
|
||||
;; (log-exprs "~~~" array el-of-array new-el "~~~")
|
||||
(vector-set! array len new-el)
|
||||
tree))
|
||||
(f
|
||||
(let* ((k (car f)) (e (cdr f)))
|
||||
(replace-in-tree tree (car e) k (add-kv-to-tree-in-array (cdr e) (cdr table-keys) keys value index))))
|
||||
(else
|
||||
(cons (cons (car table-keys) (add-kv-to-tree-in-array '()
|
||||
(cdr table-keys) keys value index))
|
||||
tree))))))
|
||||
|
||||
(define (add-kv-to-tree tree keys value)
|
||||
;; (pretty-print value)
|
||||
;; (log-exprs tree keys value)
|
||||
(let ((k (and (not (null? keys))
|
||||
(list-index (lambda (x) (equal? x (car keys))) (map car tree)))))
|
||||
;; (log-exprs k "!")
|
||||
(if k
|
||||
(let ((e (list-ref tree k)))
|
||||
(cond
|
||||
((vector? (cdr e))
|
||||
;; (cons (add-kv-to-array (cdr e) keys value #f))
|
||||
(replace-in-tree tree (car e) k (add-kv-to-array (cdr e) (cdr keys) value #f)))
|
||||
(((value?) e)
|
||||
(error "guile-toml: redefinition not allowed"))
|
||||
(else
|
||||
(replace-in-tree tree (car e) k (add-kv-to-tree (cdr e) (cdr keys) value)))))
|
||||
(if (and (null? keys) (null? (car value)))
|
||||
tree
|
||||
(cons (keyval->scm keys value #f) tree)))))
|
||||
|
||||
;; '(a b c) -> '((a) (a b) (a b c))
|
||||
(define (heads lst)
|
||||
(map (lambda (k) (list-head lst k)) (iota (length lst) 1)))
|
||||
|
||||
(define (check-keyval-keys keylist explicit-keyval-keys)
|
||||
;; (log-exprs keylist explicit-keyval-keys)
|
||||
(let ((heads (map (lambda (k) (list-head keylist k))
|
||||
(iota (length keylist) 1))))
|
||||
(when (any (lambda (x) (member x explicit-keyval-keys))
|
||||
heads)
|
||||
(begin
|
||||
(error "guile-toml: redefinition not allowed" keylist explicit-keyval-keys)))))
|
||||
|
||||
;; a drop that doesn't error out when k is too big
|
||||
(define (safe-drop lst k)
|
||||
(match (false-if-exception (drop lst k))
|
||||
(#f '())
|
||||
(x x)))
|
||||
|
||||
;; (define* (check-explicit-table-keys keylist explicit-table-keys #:optional (current-table-length 0))
|
||||
;; (when (and (not (null? keylist))
|
||||
;; (or
|
||||
;; (member keylist explicit-table-keys)
|
||||
;; (any (lambda (x) (member x explicit-table-keys)) (safe-drop (heads keylist) current-table-length))))
|
||||
;; (error "guile-toml: redefinition not allowed" keylist explicit-table-keys current-table-length)))
|
||||
|
||||
;; we check all heads of keylist, and drop the keys containing only the current table before
|
||||
(define* (check-explicit-table-keys keylist explicit-table-keys #:optional (current-table-length 0))
|
||||
;; (log-exprs keylist explicit-table-keys current-table-length "____")
|
||||
(when (and (not (null? keylist))
|
||||
(or
|
||||
(member keylist explicit-table-keys)
|
||||
(any (lambda (x) (member x explicit-table-keys)) (safe-drop (heads keylist) current-table-length))))
|
||||
(error "guile-toml: redefinition not allowed" keylist explicit-table-keys current-table-length)))
|
||||
|
||||
;; (check-explicit-table-keys '("x") '(("x" "c" "s")) 2)
|
||||
(define (all-keys-but-last l) (reverse (cdr (reverse l))))
|
||||
|
||||
;; (define (car-or-last-of-vector lv)
|
||||
;; (if (vector? lv)
|
||||
;; (vector-ref lv (vector-length lv))
|
||||
;; (car lv)))
|
||||
(define (tree-or-last-of-vector tree)
|
||||
(if (vector? tree)
|
||||
(vector-ref tree (1- (vector-length tree)))
|
||||
tree))
|
||||
|
||||
(define (find-key tree keys)
|
||||
;; (log-exprs tree keys)
|
||||
(let* ((tree (tree-or-last-of-vector tree))
|
||||
(k (list-index (lambda (x) (equal? x (car keys)))
|
||||
(map car tree))))
|
||||
(cond
|
||||
((and k (null? (cdr keys))) (list-ref tree k))
|
||||
(k (find-key (cdr (list-ref tree k)) (cdr keys)))
|
||||
(else #f))))
|
||||
|
||||
(define (toml->scm s)
|
||||
(define tree (parse s))
|
||||
(peg-tree->scm (flatten-tree tree)))
|
||||
|
||||
(define (flatten-tree tree)
|
||||
(keyword-flatten '(keyval array-table std-table inline-table) tree))
|
||||
|
||||
;; could refactor to have one 'keyval match, then match the rest again
|
||||
(define (peg-tree->scm tree)
|
||||
;; (pretty-print tree)
|
||||
(let loop ((tree (cond ((null? tree) '(()))
|
||||
((symbol? (car tree)) (list tree))
|
||||
(else tree)))
|
||||
(result '())
|
||||
(current-table '())
|
||||
(explicit-keyval-keys '())
|
||||
(explicit-table-keys '())
|
||||
(explicit-array-table-keys '())
|
||||
(new-explicit-table-keys '())
|
||||
(array-table-index #f))
|
||||
(match (car tree)
|
||||
(('keyval ('simple-key value)) ;; special case for key being empty string
|
||||
(let* ((keylist (append current-table '(""))))
|
||||
(if (not array-table-index)
|
||||
(check-keyval-keys keylist explicit-keyval-keys))
|
||||
(set! result (add-to-tree result current-table '("") (list value) array-table-index))))
|
||||
|
||||
(('keyval keys value ...)
|
||||
(let* ((keylist (append current-table (get-keys keys)))
|
||||
(keylist-all-but-last (all-keys-but-last keylist)))
|
||||
(when (not (eq? 1 (length (get-keys keys))))
|
||||
(check-explicit-table-keys keylist-all-but-last explicit-table-keys (length current-table))
|
||||
(set! new-explicit-table-keys (cons keylist-all-but-last new-explicit-table-keys)))
|
||||
(set! explicit-keyval-keys (cons keylist explicit-keyval-keys))
|
||||
(set! result (add-to-tree result current-table (get-keys keys) value array-table-index))))
|
||||
|
||||
(('std-table keys ...)
|
||||
(let ((keylist (get-keys keys)))
|
||||
(set! explicit-table-keys (append new-explicit-table-keys explicit-table-keys))
|
||||
(set! new-explicit-table-keys '())
|
||||
(if (not array-table-index)
|
||||
(check-keyval-keys keylist explicit-keyval-keys))
|
||||
(if array-table-index
|
||||
(when (find-key result keylist)
|
||||
(check-explicit-table-keys keylist
|
||||
(append explicit-array-table-keys explicit-table-keys)
|
||||
(length current-table)))
|
||||
(check-explicit-table-keys keylist
|
||||
(append explicit-array-table-keys explicit-table-keys)
|
||||
(length current-table)))
|
||||
(set! array-table-index #f)
|
||||
(set! explicit-table-keys (cons keylist explicit-table-keys))
|
||||
;; (log-exprs array-table-index explicit-table-keys)
|
||||
;; (unless (find-key result keylist)
|
||||
(set! result (add-to-tree result '() keylist '(()) array-table-index))
|
||||
(set! current-table keylist)))
|
||||
|
||||
(('array-table keys ...)
|
||||
(set! array-table-index 0)
|
||||
(let ((keylist (get-keys keys)))
|
||||
(check-explicit-table-keys keylist (remove (lambda (x) (equal? x keylist)) explicit-table-keys))
|
||||
(set! explicit-array-table-keys (cons keylist explicit-array-table-keys))
|
||||
(set! current-table keylist)
|
||||
(set! result (add-to-tree result current-table '() '() array-table-index))))
|
||||
('() '())
|
||||
(x (error x)))
|
||||
|
||||
(if (null? (cdr tree))
|
||||
result
|
||||
(loop (cdr tree)
|
||||
result
|
||||
current-table
|
||||
explicit-keyval-keys
|
||||
explicit-table-keys
|
||||
explicit-array-table-keys
|
||||
new-explicit-table-keys
|
||||
array-table-index))))
|
Loading…
Reference in New Issue