pax_global_header 0000666 0000000 0000000 00000000064 13566611474 0014527 g ustar 00root root 0000000 0000000 52 comment=568aea87e7649ce91ec43721d668b8d2c8ec65e2
sedparse-0.1.2/ 0000775 0000000 0000000 00000000000 13566611474 0013335 5 ustar 00root root 0000000 0000000 sedparse-0.1.2/.gitignore 0000664 0000000 0000000 00000001142 13566611474 0015323 0 ustar 00root root 0000000 0000000 # Text editor
.vscode/
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/
# Sphinx documentation
docs/_build/
# pyenv
.python-version
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
sedparse-0.1.2/.pylintrc 0000664 0000000 0000000 00000000771 13566611474 0015207 0 ustar 00root root 0000000 0000000 [MESSAGES CONTROL]
# Run all checks except those
enable=all
disable=
fixme,
locally-disabled,
locally-enabled,
suppressed-message,
missing-docstring,
bad-continuation, # incompatible with black
duplicate-code, # test_commands_with_no_args() commands list
[VARIABLES]
allow-global-unused-variables=no
[FORMAT]
max-line-length=88 # black compatible
expected-line-ending-format=LF # enforce Unix \n
# No reports, please
[MASTER]
persistent=no
[REPORTS]
reports=no
score=no
sedparse-0.1.2/.travis.yml 0000664 0000000 0000000 00000001615 13566611474 0015451 0 ustar 00root root 0000000 0000000 language: python
# Supported Python versions
python:
- "2.7"
- "3.4"
- "3.5"
- "3.6"
- "3.7"
- "3.8"
install:
# Download clitest
- curl -sOL https://raw.githubusercontent.com/aureliojargas/clitest/master/clitest
- chmod +x clitest
- mv clitest ~/bin
# Only run pylint/black in newer Python versions
- case $TRAVIS_PYTHON_VERSION in 3.[6-9])
pip install --quiet -r requirements-dev.txt;;
esac
# Install sedparse itself
- pip install -e .
script:
- ./ci.sh
# This is not included in ci.sh because it needs the 'sedparse' executable
- clitest --progress none README.md
### Environment
# Ubuntu 14.04.5 LTS
# uid=2000(travis) groups=2000(travis),999(docker)
# PWD=/home/travis/build/aureliojargas/sedparse
# PATH=/home/travis/bin
# /home/travis/.local/bin
# /usr/local/sbin
# /usr/local/bin
# /usr/sbin
# /usr/bin
# /sbin
# /bin
sedparse-0.1.2/CONTRIBUTING.md 0000664 0000000 0000000 00000003576 13566611474 0015601 0 ustar 00root root 0000000 0000000 # Contributing to sedparse
Please follow the usual GitHub workflow to contribute to this project:
- Use [GitHub issues](https://github.com/aureliojargas/sedparse/issues) for bug reports and feature requests.
- Use GitHub pull requests to submit code.
## Development environment
To create (and update in the future):
python3 -m venv env
source env/bin/activate
pip install -r requirements-dev.txt
To use it while developing:
source env/bin/activate
To leave it when done developing:
deactivate
More info at https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/
## Code check and formatting
The sedparse code is checked by pylint and formatted by [black](https://github.com/psf/black), so make sure you run both after every change.
Black is used with the default settings (no command line options) and the pylint configuration file is in the root of this repository.
Just run them over the Python files:
pylint *.py tests/*.py
black *.py tests/*.py
or better yet, just run `ci.sh` after every change.
## Testing
Code is tested by the standard `unittest` and `doctest` Python modules, and full command lines are tested by [clitest](https://github.com/aureliojargas/clitest).
The commands to run all of those are inside the [ci.sh](https://github.com/aureliojargas/sedparse/blob/master/ci.sh) script. Just run it locally after every change:
./ci.sh
This script is also automatically executed by Travis CI for every new push to the repository.
## Packaging
To locally install (and uninstall) the package directly from this repository into the virtual env and test the `sedparse` executable:
pip install -e .
pip uninstall sedparse
To install the required software for the packaging:
pip install -r requirements-pkg.txt
To build and upload the packages:
python3 setup.py sdist bdist_wheel
twine upload dist/*
sedparse-0.1.2/LICENSE 0000664 0000000 0000000 00000104515 13566611474 0014350 0 ustar 00root root 0000000 0000000 GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
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.
Copyright (C)
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 .
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:
Copyright (C)
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
.
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
.
sedparse-0.1.2/README.md 0000664 0000000 0000000 00000014154 13566611474 0014621 0 ustar 00root root 0000000 0000000 # sedparse
- Author: Aurelio Jargas
- License: GPLv3
- Tested with Python 2.7, 3.4, 3.5, 3.6, 3.7 and 3.8 (see [.travis.yml](https://github.com/aureliojargas/sedparse/blob/master/.travis.yml))
A translation from C to Python of GNU sed's parser for sed scripts.
After running sedparse in your sed script, the resulting "[AST](https://en.wikipedia.org/wiki/Abstract_syntax_tree)" is available in different formats:
- List of objects (translated C structs)
- List of dictionaries
- JSON
For a complete reference on how the different sed commands are mapped by the parser, see:
- [tests/reference.sed](https://github.com/aureliojargas/sedparse/blob/master/tests/reference.sed) - original sed script
- [tests/reference.json](https://github.com/aureliojargas/sedparse/blob/master/tests/reference.json) - JSON generated by sedparse
## About the translation
I copied the original code in C and translated everything to Python, line by line.
To make it feasible to keep this code updated with future GNU sed code, this is a literal translation, trying to mimic as much as possible of the original code. That includes using the same API, same logic, same variable and method names and same data structures. Pythonic code? Sorry, not here.
The accuracy of the parser is checked by extensive unit tests in [tests/](https://github.com/aureliojargas/sedparse/tree/master/tests).
Sedparse was translated from this GNU sed version:
http://git.savannah.gnu.org/cgit/sed.git/commit/?id=a9cb52bcf39f0ee307301ac73c11acb24372b9d8
commit a9cb52bcf39f0ee307301ac73c11acb24372b9d8
Author: Assaf Gordon
Date: Sun Jun 2 01:14:00 2019 -0600
> Note that this is not a full GNU sed implementation.
> Only the parser for sed scripts was translated.
> Check https://github.com/GillesArcas/PythonSed for a working sed in Python.
## Sedparse extensions to the original parser
- Preserves comments
- Preserves blank lines between commands
- Preserves original flags for the `s` command
- Preserves original flags for regex addresses
## Installation
pip install --user sedparse
sedparse --help
Alternatively, you can just download and run the [sedparse.py](https://raw.githubusercontent.com/aureliojargas/sedparse/master/sedparse.py) file, since it is self-contained with no external dependencies.
## Usage from the command line
The informed sed script will be parsed and checked for syntax errors. If everything is fine, a JSON representation of the script is sent to STDOUT.
Just like in sed, you can inform the sed script using one or more `-e` options:
```console
$ sedparse -e "s/foo/bar/g" -e "5d"
[
{
"cmd": "s",
"line": 1,
"x": {
"cmd_subst": {
"regx": {
"flags": "g",
"pattern": "foo",
"slash": "/"
},
"replacement": {
"text": "bar"
}
}
}
},
{
"a1": {
"addr_number": 5,
"addr_type": 3
},
"cmd": "d",
"line": 1
}
]
$
```
Or you can inform the sed script as a file argument using `-f`:
```console
$ echo '1,10!d' > head.sed
$ sedparse -f head.sed
[
{
"a1": {
"addr_number": 1,
"addr_type": 3
},
"a2": {
"addr_number": 10,
"addr_type": 3
},
"addr_bang": true,
"cmd": "d",
"line": 1
}
]
$ rm head.sed
$
```
Or even as text coming from STDIN when using the special `-` file:
```console
$ echo '\EXTREMITIES' | sedparse -f -
[
{
"a1": {
"addr_regex": {
"flags": "MI",
"pattern": "XTR",
"slash": "E"
},
"addr_type": 2
},
"cmd": "T",
"line": 1,
"x": {
"label_name": "IES"
}
}
]
$
```
## Usage as a Python module
Use `sedparse.compile_string()` to parse a string as a sed script. You must inform a list that will be appended in-place with the parsed commands.
```python
>>> import sedparse
>>> sedscript = """\
... 11,/foo/ {
... $!N
... s/\\n/-/gi
... }
... """
>>> parsed = []
>>> sedparse.compile_string(parsed, sedscript)
>>>
```
Each sed command is represented by a `struct_sed_cmd` instance.
```python
>>> import pprint
>>> pprint.pprint(parsed) # doctest:+ELLIPSIS
[struct_sed_cmd(line=1, cmd='{', ...),
struct_sed_cmd(line=2, cmd='N', ...),
struct_sed_cmd(line=3, cmd='s', ...),
struct_sed_cmd(line=4, cmd='}', ...)]
>>>
```
You can `str()` each command, or any of its inner structs, to get their "human readable" representation.
```python
>>> [str(x) for x in parsed]
['11,/foo/ {', '$ !N', 's/\\n/-/gi', '}']
>>> str(parsed[0])
'11,/foo/ {'
>>> str(parsed[0].a1)
'11'
>>> str(parsed[0].a2)
'/foo/'
>>>
```
Use `.to_dict()` to convert a command into a Python dictionary.
```python
>>> cmd_n = parsed[1]
>>> str(cmd_n)
'$ !N'
>>> pprint.pprint(cmd_n.to_dict())
{'a1': {'addr_type': 7}, 'addr_bang': True, 'cmd': 'N', 'line': 2}
>>>
>>> pprint.pprint(cmd_n.to_dict(remove_empty=False))
{'a1': {'addr_number': 0, 'addr_regex': None, 'addr_step': 0, 'addr_type': 7},
'a2': None,
'addr_bang': True,
'cmd': 'N',
'line': 2,
'x': {'cmd_subst': {'outf': {'name': ''},
'regx': {'flags': '', 'pattern': '', 'slash': ''},
'replacement': {'text': ''}},
'cmd_txt': {'text': []},
'comment': '',
'fname': '',
'int_arg': -1,
'label_name': ''}}
>>>
```
Use `.to_json()` to convert a command into JSON.
```python
>>> print(cmd_n.to_json())
{
"a1": {
"addr_type": 7
},
"addr_bang": true,
"cmd": "N",
"line": 2
}
>>>
```
Have fun!
```python
>>> [x.cmd for x in parsed] # list of commands
['{', 'N', 's', '}']
>>> [str(x) for x in parsed if x.a1 is None] # commands with no address
['s/\\n/-/gi', '}']
>>> [str(x) for x in parsed if x.addr_bang] # commands with bang !
['$ !N']
>>> [x.x.comment for x in parsed if x.x.comment] # extract all comments
[]
>>> [x.x.fname for x in parsed if x.cmd in "rRwW"] # list of read/write filenames
[]
>>>
```
sedparse-0.1.2/ci.sh 0000775 0000000 0000000 00000001503 13566611474 0014266 0 ustar 00root root 0000000 0000000 #!/bin/bash
set -euo pipefail
has_clitest() {
command -v clitest > /dev/null
}
is_python36() {
python --version 2>&1 | grep '^Python 3\.[6-9]' > /dev/null
}
if is_python36
then
echo pylint
pylint ./*.py tests/*.py
echo black
black --check --quiet ./*.py tests/*.py
else
echo pylint - SKIPPED
echo black - SKIPPED
fi
if has_clitest
then
echo cli tests
clitest --progress none --prefix 4 tests/test_cmdline.md
else
echo cli tests - SKIPPED
fi
echo doc tests
python -m doctest README.md
echo unit tests
python -m unittest discover -s tests/
echo parse reference file
python sedparse.py -f tests/reference.sed > tests/reference.json
python sedparse.py --verbose --full -f tests/reference.sed > tests/reference.full.json 2> tests/reference.verbose
git diff --exit-code tests/reference.*
sedparse-0.1.2/requirements-dev.txt 0000664 0000000 0000000 00000000040 13566611474 0017367 0 ustar 00root root 0000000 0000000 pylint == 2.4.0
black == 19.3b0
sedparse-0.1.2/requirements-pkg.txt 0000664 0000000 0000000 00000000255 13566611474 0017402 0 ustar 00root root 0000000 0000000 # Requirements for packaging
# Minimal versions from https://packaging.python.org/guides/making-a-pypi-friendly-readme/
setuptools >= 38.6.0
wheel >= 0.31.0
twine >= 1.11.0
sedparse-0.1.2/sedparse.py 0000664 0000000 0000000 00000142741 13566611474 0015526 0 ustar 00root root 0000000 0000000 # sedparse
# GNU sed's parser translated from C to Python
# https://github.com/aureliojargas/sedparse
#
# HOW IT WORKS
#
# The original sed script can be specified via strings (option -e) or via files
# (option -f). The main functions to handle them are compile_string() and
# compile_file(), respectively. Both are entrypoints to prepare the input for
# the real parsing which occurs in compile_program().
#
# The parser reads the sed script character by character (see inchar()). The
# opposite function is savchar(), which goes back one character, when necessary.
# There are also some specialized input reading functions, for example
# in_integer() to read a sequence of integers and in_nonblank() to skip a
# sequence of white space chars.
#
# The normal flow is reading the chars forward with inchar() to detect the
# addresses, commands and their arguments. When the end of the current structure
# is only detected after reading the next char, which is not part of that
# structure (for example, getting any non number while reading integers in
# in_integer()), then savchar() is called to give that char back so the main
# parser will handle it.
#
# The data for every successfully parsed command is saved as an instance of the
# struct_sed_cmd class, which is appended in-place to the cur_program list,
# specified as an argument when calling compile_string() or compile_file().
#
# Any detected syntax error aborts the parsing immediately and a ParseError
# exception is raised (see bad_prog()).
#
# The code uses some global variables to save state:
#
# prog
#
# A class to hold information about the input script. If it is a file,
# `prog.file` will hold the open file descriptor (which during the parsing
# is read using fd.seek() and fd.tell()). If it the input came from a string
# (-e option), `prog.base`, `prog.cur` and `prog.end` will be used to save
# state about where the cursor is currently pointing in the string. See more
# details in the `prog_info` class comments.
#
# cur_input
#
# A class to keep information used in error messages. We have the script
# file name and line number saved in `cur_input.name` and `cur_input.line`,
# and if it's not a file, `cur_input.string_expr_count` holds the index of
# the command line "-e" expression.
#
# blocks
#
# An integer describing the current depth of the script. Any new block "{"
# adds a new depth level and its respective "}" remove a level. A script
# like "$ { /foo/ { p;};}" will have blocks=2 when reading the "p" command,
# but will become blocks=0 when reading the last "}".
#
# pending_text
# old_text_buf
#
# Those two variables are temporary data holders so the parser can
# "remember" data from the previous parsed script. This allows for scripts
# like "sed -e 'i\' -e foo", where a single "i" command is specified in two
# chunks (by using the -e option twice).
# STILL NOT TRANSLATED
# - Check if command only accepts one address
# if (cur_cmd->a2) bad_prog (_(ONE_ADDR))
# - Check POSIX compatibility (all GNU sed extensions are supported here)
# if (posixicity == POSIXLY_BASIC)
# Since sedparse is a literal translation, maintaining the same code, variables
# and method names, I have to disable the following checks.
# pylint: disable=global-statement
# pylint: disable=invalid-name
# pylint: disable=no-else-break
# pylint: disable=no-else-return
# pylint: disable=too-few-public-methods
# pylint: disable=too-many-branches
# pylint: disable=too-many-lines
# pylint: disable=too-many-statements
from __future__ import print_function # pylint: disable=unused-variable
import argparse
import json
import os
import sys
import tempfile
__version__ = "0.1.2"
# Adapt some C entities to Python
NULL = None
EOF = ""
# Default options when dumping JSON
# The separators argument is required in python2 https://bugs.python.org/issue16333
JSON_OPTS = {"indent": 4, "sort_keys": True, "separators": (",", ": ")}
# Base class to handle translated C structs
class struct:
def to_dict(self, remove_empty=True):
"""
Return the struct data as a dict.
Using plain self.__dict__ works only for a single level. This function
is recursive and converts all the nested structs.
When using remove_empty, keys that have empty or default values are removed.
Note that the structs use no dictionaries to store their data, so we
don't need to check for it in this code.
"""
d = {}
for key, val in self.__dict__.items():
if isinstance(val, struct):
val = val.to_dict(remove_empty)
if remove_empty:
if val is None or val in ("", (), [], {}):
continue
if key == "int_arg" and val == -1:
continue
if key == "addr_bang" and not val:
continue
if key == "addr_step" and val == 0:
continue
if (
key == "addr_number"
and val == 0
and self.__dict__["addr_type"] in (ADDR_IS_REGEX, ADDR_IS_LAST)
):
continue
d[key] = val
return d
def to_json(self, remove_empty=True):
return json.dumps(self, default=lambda x: x.to_dict(remove_empty), **JSON_OPTS)
class ParseError(Exception):
# pylint: disable=too-many-arguments
def __init__(self, message="", file="", line=0, column=0, expression=0, exitcode=1):
# https://stackoverflow.com/a/38857736
super(ParseError, self).__init__(message)
self.message = message
self.file = file
self.line = line
self.column = column
self.expression = expression
self.exitcode = exitcode
######################################## translated from sed.c
program_name = "sedparse"
######################################## translated from basicdefs.h
def ISBLANK(c):
return c in (" ", "\t")
def ISDIGIT(ch):
return ch in "0123456789"
def ISSPACE(c):
# https://github.com/gcc-mirror/gcc/blob/master/include/safe-ctype.h
return c in (" ", "\t", "\n", "\v", "\f", "\r")
######################################## translated from sed.h
# The translation of the following was not necessary:
# - struct vector
# - enum replacement_types
# - enum text_types
# - enum posixicity_types
# - enum addr_state
# sedparse: The original code handles file open/read/write/close operations,
# but here we only care about the filename.
class struct_output(struct):
def __init__(self):
self.name = ""
# sedparse: not used
# missing_newline = False
# fp = None
# link = None
def __repr__(self):
return "%s(name=%r)" % (self.__class__.__name__, self.name)
def __str__(self):
return self.name
class struct_text_buf(struct):
def __init__(self):
self.text = []
# text_length = 0 # sedparse: not used
def __repr__(self):
return "%s(text=%r)" % (self.__class__.__name__, self.text)
def __str__(self):
return "".join(self.text)[:-1] # remove trailing \n
class struct_regex(struct):
def __init__(self):
self.pattern = ""
# In the original this was an integer, a bitwise OR for address flags.
# In sedparse it is a string with all the found flags, in their
# original order, and even repetition is preserved. It is also used
# to save both regex address flags and "s" command flags.
self.flags = "" # sedparse: was 0 in the original
# This is used to save the slash char used as delimiter in: regex
# addresses (/foo/p) and in "s" and "y" commands (s///).
self.slash = "" # sedparse extension
# sedparse: not used
# sz = 0
# dfa = None # struct_dfa()
# begline = False
# endline = False
# re = ""
def __repr__(self):
return "%s(slash=%r, pattern=%r, flags=%r)" % (
self.__class__.__name__,
self.slash,
self.pattern,
self.flags,
)
def __str__(self):
return self.escape() + self.slash + self.pattern + self.slash + self.flags
def escape(self): # sedparse extension
return "\\" if self.slash != "/" else ""
# enum addr_types
# fmt: off
ADDR_IS_NULL = 1 # null address
ADDR_IS_REGEX = 2 # a.addr_regex is valid
ADDR_IS_NUM = 3 # a.addr_number is valid
ADDR_IS_NUM_MOD = 4 # a.addr_number is valid, addr_step is modulo
ADDR_IS_STEP = 5 # address is +N (only valid for addr2)
ADDR_IS_STEP_MOD = 6 # address is ~N (only valid for addr2)
ADDR_IS_LAST = 7 # address is $
# fmt: on
class struct_addr(struct):
def __init__(self):
self.addr_type = ADDR_IS_NULL # enum addr_types
self.addr_number = 0
self.addr_step = 0
self.addr_regex = struct_regex()
def __repr__(self):
return "%s(addr_type=%r, addr_number=%r, addr_step=%r, addr_regex=%r)" % (
self.__class__.__name__,
self.addr_type,
self.addr_number,
self.addr_step,
self.addr_regex,
)
def __str__(self):
ret = ""
if self.addr_type == ADDR_IS_REGEX:
ret = str(self.addr_regex)
elif self.addr_type == ADDR_IS_NUM:
ret = str(self.addr_number)
elif self.addr_type == ADDR_IS_NUM_MOD:
ret = "%s~%s" % (self.addr_number, self.addr_step)
elif self.addr_type == ADDR_IS_STEP:
ret = "+%s" % self.addr_step
elif self.addr_type == ADDR_IS_STEP_MOD:
ret = "~%s" % self.addr_step
elif self.addr_type == ADDR_IS_LAST:
ret = "$"
else: # sedparse: this condition should not happen
ret = "" % self.addr_type
return ret
class struct_replacement(struct):
def __init__(self):
self.text = "" # sedparse extension
# sedparse: not used
# prefix = ""
# prefix_length = 0
# subst_id = 0
# repl_type = REPL_ASIS # enum replacement_types
# next_ = None # struct_replacement
def __repr__(self):
return "%s(text=%r)" % (self.__class__.__name__, self.text)
def __str__(self):
return self.text
class struct_subst(struct):
def __init__(self):
self.regx = struct_regex()
self.replacement = struct_replacement()
self.outf = struct_output() # "w" option given
# sedparse: not used
# Note that instead of using those attributes to save the found flags,
# sedparse saves them to self.regx.flags as a single string, preserving
# the original order and possible repetition.
# numb = 0 # if >0, only substitute for match number "numb"
# global_ = False # "g" option given
# print_ = False # "p" option given (before/after eval)
# eval_ = False # "e" option given
# max_id = 0 # maximum backreference on the RHS
# replacement_buffer = "" # ifdef lint
def __repr__(self):
return "%s(regx=%r, replacement=%r, outf=%r)" % (
self.__class__.__name__,
self.regx,
self.replacement,
self.outf,
)
def __str__(self):
return (
self.regx.slash
+ str(self.regx.pattern)
+ self.regx.slash
+ str(self.replacement.text)
+ self.regx.slash
+ self.regx.flags
+ (" " + self.outf.name if "w" in self.regx.flags else "")
)
# sedparse: In the original this was a 'union' inside 'struct sed_cmd'
class struct_sed_cmd_x(struct):
"auxiliary data for various commands"
def __init__(self):
# This structure is used for a, i, and c commands.
self.cmd_txt = struct_text_buf()
# This is used for the l, q and Q commands.
self.int_arg = -1
# This is used for the r command. (sedparse: and R w W)
self.fname = ""
# This is used for the hairy s command. (sedparse: and y)
self.cmd_subst = struct_subst()
# This is used for the ":" command.
self.label_name = ""
# This is used for the command comment.
self.comment = "" # sedparse extension
# sedparse: not used
# # This is used for the {}, b, and t commands.
# jump_index = 0
# # This is used for the w command.
# outf = struct_output()
# # This is used for the R command.
# # (despite the struct name, it is used for both in and out files).
# inf = struct_output()
# # This is used for the y command.
# translate = ""
# translatemb = ""
def __repr__(self):
return (
"%s(int_arg=%r, label_name=%r, fname=%r, comment=%r,"
" cmd_txt=%r, cmd_subst=%r)"
% (
self.__class__.__name__,
self.int_arg,
self.label_name,
self.fname,
self.comment,
self.cmd_txt,
self.cmd_subst,
)
)
class struct_sed_cmd(struct):
def __init__(self):
# Command addresses
self.a1 = struct_addr()
self.a2 = struct_addr()
# Non-zero if command is to be applied to non-matches.
self.addr_bang = False # sedparse: using bool
# The actual command character.
self.cmd = ""
# auxiliary data for various commands
self.x = struct_sed_cmd_x()
# The original line number where this command was found
self.line = 0 # sedparse extension
# sedparse: not used
# range_state = RANGE_INACTIVE # See enum addr_state
def __repr__(self):
return "%s(line=%r, cmd=%r, addr_bang=%r, a1=%r, a2=%r, x=%r)" % (
self.__class__.__name__,
self.line,
self.cmd,
self.addr_bang,
self.a1,
self.a2,
self.x,
)
def __str__(self):
ret = []
if self.a1:
ret.append(str(self.a1))
if self.a2:
ret.append(",%s" % self.a2)
if ret:
ret.append(" ")
if self.addr_bang:
ret.append("!")
ret.append(self.cmd)
if self.cmd == "\n":
pass
elif self.cmd == "#":
ret.append(self.x.comment)
elif self.cmd == ":":
ret.append(self.x.label_name)
elif self.cmd in ("s", "y"):
ret.append(str(self.x.cmd_subst))
elif self.x.label_name:
ret.append(" " + self.x.label_name)
elif self.x.fname:
ret.append(" " + self.x.fname)
elif self.x.int_arg > -1:
ret.append(" %s" % self.x.int_arg)
elif self.x.cmd_txt.text: # a i c
ret.append("\\\n%s" % self.x.cmd_txt)
return "".join(ret)
# This is defined in sed.h, but calls is_mb_char() from mbcs.c, where the real
# implementation is.
# XXX sedparse: maybe the translation is wrong or incomplete. It seems to work,
# but I'm not sure if there are some unhandled edge cases here.
def IS_MB_CHAR(ch):
"""Return True if ch is EOF or a valid single-byte character"""
# sedparse: the first condition is necessary because our EOF constant is a
# string.
return ch != EOF and ord(ch) > 127
######################################## translated from regexp.c
# sedparse: no need to compile the regex, just save the collected strings
def compile_regex(pattern, flags):
r = struct_regex()
r.pattern = "".join(pattern)
r.flags = "".join(flags)
return r
######################################## translated from utils.h
# enum exit_codes
EXIT_SUCCESS = 0
EXIT_BAD_USAGE = 1 # bad program syntax, invalid command-line options
# EXIT_BAD_INPUT = 2 # failed to open some of the input files (sedparse: not used)
EXIT_PANIC = 4 # PANIC during program execution
######################################## translated from utils.c
# Print an error message and exit
def panic(msg):
raise ParseError(exitcode=EXIT_PANIC, message="%s: %s" % (program_name, msg))
# In Python we have lists, so all the buffer-related C code is not necessary.
# Only the very minimal set of buffer functions were translated, to avoid having
# to change the logic in the caller code.
def init_buffer():
return []
def add1_buffer(buffer, ch):
if ch != EOF:
buffer.append(ch) # in-place
# the return is never used
def free_buffer(b):
del b
######################################## translated from compile.c
OPEN_BRACKET = "["
CLOSE_BRACKET = "]"
CLOSE_BRACE = "}"
class prog_info:
# When we're reading a script command from a string, `prog.base' points to
# the first character in the string, 'prog.cur' points to the current
# character in the string, and 'prog.end' points to the end of the string.
# This allows us to compile script strings that contain nulls.
base = None # int
cur = None # int
end = None # int
# This is the current script file. If it is NULL, we are reading from a
# string stored at `prog.cur' instead. If both `prog.file' and `prog.cur'
# are NULL, we're in trouble!
file = None # file descriptor
# Using None because some code checks for "is not None" to detect unset state
text = None # sedparse extension
class error_info:
"""Information used to give out useful and informative error messages."""
# This is the name of the current script file.
name = ""
# This is the number of the current script line that we're compiling.
line = 0
# This is the index of the "-e" expressions on the command line.
string_expr_count = 0
# Where we are in the processing of the input.
class prog(prog_info):
pass
class cur_input(error_info):
pass
# Allow for scripts like "sed -e 'i\' -e foo"
pending_text = NULL
old_text_buf = NULL
# sedparse: this is a sed_label struct in the original code. Here it is just an
# integer, because we only care about the indenting levels.
blocks = 0
# Various error messages we may want to print
# sedparse: not used messages are commented
BAD_BANG = "multiple `!'s"
BAD_COMMA = "unexpected `,'"
BAD_STEP = "invalid usage of +N or ~N as first address"
EXCESS_OPEN_BRACE = "unmatched `{'"
EXCESS_CLOSE_BRACE = "unexpected `}'"
EXCESS_JUNK = "extra characters after command"
EXPECTED_SLASH = "expected \\ after `a', `c' or `i'"
NO_CLOSE_BRACE_ADDR = "`}' doesn't want any addresses"
# NO_COLON_ADDR = ": doesn't want any addresses"
# NO_SHARP_ADDR = "comments don't accept any addresses"
NO_COMMAND = "missing command"
# ONE_ADDR = "command only uses one address"
UNTERM_ADDR_RE = "unterminated address regex"
UNTERM_S_CMD = "unterminated `s' command"
UNTERM_Y_CMD = "unterminated `y' command"
UNKNOWN_S_OPT = "unknown option to `s'"
EXCESS_P_OPT = "multiple `p' options to `s' command"
EXCESS_G_OPT = "multiple `g' options to `s' command"
EXCESS_N_OPT = "multiple number options to `s' command"
ZERO_N_OPT = "number option to `s' command may not be zero"
# Y_CMD_LEN = "strings for `y' command are different lengths"
BAD_DELIM = "delimiter character is not a single-byte character"
# ANCIENT_VERSION = "expected newer version of sed"
INVALID_LINE_0 = "invalid usage of line address 0"
UNKNOWN_CMD = "unknown command: `%c'"
# INCOMPLETE_CMD = "incomplete command"
COLON_LACKS_LABEL = '":" lacks a label'
# RECURSIVE_ESCAPE_C = "recursive escaping after \\c not allowed"
# DISALLOWED_CMD = "e/r/w commands disabled in sandbox mode"
MISSING_FILENAME = "missing filename in r/R/w/W commands"
# Complain about an unknown command and exit.
def bad_command(ch):
bad_prog(UNKNOWN_CMD % ch)
# Complain about a programming error and exit.
def bad_prog(why):
if cur_input.name:
msg = "%s: file %s line %d: %s" % (
program_name,
cur_input.name,
cur_input.line,
why,
)
else:
msg = "%s: -e expression #%d, char %d: %s" % (
program_name,
cur_input.string_expr_count,
(prog.cur or 0) - (prog.base or 0),
why,
)
# sedparse extension
# The following exception can be caught and this module can be used again.
# Reset to make sure data from one execution won't affect the next.
reset_globals()
# sedparse extension
# In this point, the original code shows the error message and exits. Doing
# it here would break the usage of sedparse as a Python module. So we raise
# an exception instead, and the calling code decides what to do.
raise ParseError(
message=msg,
file=cur_input.name,
expression=cur_input.string_expr_count,
line=cur_input.line,
column=(prog.cur - prog.base) if prog.cur else 0,
exitcode=EXIT_BAD_USAGE,
)
# Read the next character from the program. Return EOF if there isn't anything
# to read. Keep cur_input.line up to date, so error messages can be meaningful.
def inchar():
ch = EOF
if prog.cur is not None:
if prog.cur < prog.end:
# Original: ch = *prog.cur++;
ch = prog.text[prog.cur]
prog.cur += 1
elif prog.file:
# Original: if (!feof (prog.file)) ch = getc (prog.file);
# https://stackoverflow.com/a/15599780
ch = prog.file.read(1)
if not ch:
ch = EOF
if ch == "\n":
cur_input.line += 1
debug(ch, stats=True)
return ch
# unget `ch' so the next call to inchar will return it.
def savchar(ch):
debug("savchar(%s)" % ch, stats=True)
if ch == EOF:
return
if ch == "\n" and cur_input.line > 0:
cur_input.line -= 1
if prog.cur:
# Original: if (prog.cur <= prog.base || *--prog.cur != ch)
prog.cur -= 1
if prog.cur <= prog.base or prog.text[prog.cur] != ch:
panic(
# sedparse: original code only shows `ch` in this error message
"Called savchar with unexpected pushback (curr=%s %s!=%s)"
% (prog.cur, prog.text[prog.cur], ch)
)
else:
# Original: ungetc(ch, prog.file)
try:
# Go back one *character* in prog.file file descriptor pointer.
# Since one Unicode character can be composed of multiple bytes,
# we need that encoding to know how many bytes we should rewind.
# Note that tell() does not work when reading from STDIN, see
# the temporary file workaround in compile_file().
prog.file.seek(prog.file.tell() - len(ch.encode("utf-8")))
except ValueError: # negative seek position -1
pass
# Read the next non-blank character from the program.
def in_nonblank():
while True:
ch = inchar()
if not ISBLANK(ch):
break
return ch
# sedparse extension
# Ignore multiple trailing blanks and ; until EOC/EOL/EOF. Skipping those chars
# avoids \n incorrectly being considered a new command and producing a new
# undesired blank line in the output.
def ignore_trailing_fluff():
while True:
ch = in_nonblank()
if ch == ";": # skip it
pass
elif ch in (EOF, "\n"): # EOF, EOL
return
else: # start of a new command
savchar(ch)
return
# Consume script input until a valid end of command marker is found: comment,
# closing brace, newline, semicolon or EOF. If any other character is found, die
# with 'extra characters after command' error.
def read_end_of_cmd():
ch = in_nonblank()
if ch in (CLOSE_BRACE, "#"):
savchar(ch)
elif ch not in (EOF, "\n", ";"):
bad_prog(EXCESS_JUNK)
# sedparse extension: Ignore trailing blanks and ; until EOC/EOL/EOF
elif ch == ";":
ignore_trailing_fluff()
# Read an integer value from the program.
# sedparse: original code uses math, we use list append.
def in_integer(ch):
num = []
while ISDIGIT(ch):
num.append(ch)
ch = inchar()
savchar(ch)
return int("".join(num))
def add_then_next(buffer, ch):
add1_buffer(buffer, ch)
return inchar()
# convert_number() - Translation not needed
# sedparse extension
# This is a copy of read_filename, but preserving blanks.
def read_comment():
b = init_buffer()
ch = inchar()
while ch not in (EOF, "\n"):
ch = add_then_next(b, ch)
return b
# Read in a filename for a `r', `w', or `s///w' command.
def read_filename():
b = init_buffer()
ch = in_nonblank()
while ch not in (EOF, "\n"):
ch = add_then_next(b, ch)
# add1_buffer(b, "\0"); # not necessary in Python
return b
# get_openfile() - Translation not needed
def next_cmd_entry(vector):
# sedparse: in the original there's some of vector handling code. Here the
# equivalent is the next line and `vector.append()` at the end.
cmd = struct_sed_cmd()
cmd.a1 = NULL
cmd.a2 = NULL
# cmd.range_state = RANGE_INACTIVE # sedparse: not used
cmd.addr_bang = False
cmd.cmd = "\0" # something invalid, to catch bugs early
vector.append(cmd)
return cmd
def snarf_char_class(b): # sedparse: cur_stat argument not necessary
state = 0
delim = None # delim IF_LINT( = 0)
ch = inchar()
if ch == "^":
ch = add_then_next(b, ch)
if ch == CLOSE_BRACKET:
ch = add_then_next(b, ch)
# States are:
# 0 outside a collation element, character class or collation class
# 1 after the bracket
# 2 after the opening ./:/=
# 3 after the closing ./:/=
# Original: for (;; ch = add_then_next(b, ch)) {
first_loop_run = True
while True:
if not first_loop_run:
ch = add_then_next(b, ch)
first_loop_run = False
mb_char = IS_MB_CHAR(ch)
if ch in (EOF, "\n"):
return ch
if ch in (".", ":", "="):
if mb_char:
continue
if state == 1:
delim = ch
state = 2
elif state == 2 and ch == delim:
state = 3
# else:
# break # break from C-switch not necessary in Python
continue
if ch == OPEN_BRACKET:
if mb_char:
continue
if state == 0:
state = 1
continue
if ch == CLOSE_BRACKET:
if mb_char:
continue
if state in (0, 1):
return ch
if state == 3:
state = 0
# Getting a character different from .=: whilst in state 1
# goes back to state 0, getting a character different from ]
# whilst in state 3 goes back to state 2.
#
# Original: state &= ~1
# sedparse: Instead of following the original (tricky &= right after a
# switch inside a loop), I've opted to implement literally what the
# comment says.
if ch not in (".", ":", "=") and state == 1:
state = 0
elif ch != CLOSE_BRACKET and state == 3:
state = 2
def match_slash(slash, regex): # char, bool
# We allow only 1 byte characters for a slash.
if IS_MB_CHAR(slash):
bad_prog(BAD_DELIM)
b = init_buffer()
# Original: while ((ch = inchar ()) != EOF && ch != '\n')
while True:
ch = inchar()
if ch in (EOF, "\n"):
break
if not IS_MB_CHAR(ch):
if ch == slash:
return b
elif ch == "\\":
ch = inchar()
if ch == EOF:
break
# sedparse: GNU sed interprets \n here, we don't
# elif ch == "n" and regex:
# ch = "\n"
# sedparse: GNU sed remove the leading \ from \\n, \/, \&.
# We don't since we keep the original user text.
# elif (ch != "\n" and (ch != slash or (not regex and ch == "&"))):
else:
add1_buffer(b, "\\")
elif ch == OPEN_BRACKET and regex:
add1_buffer(b, ch)
ch = snarf_char_class(b)
if ch != CLOSE_BRACKET:
break
add1_buffer(b, ch)
if ch == "\n":
savchar(ch) # for proper line number in error report
free_buffer(b)
return NULL
# sedparse: this function works differently from the original.
# In GNU sed, there's no return, since it just sets all the flags as properties
# of "cmd_s". Here it collects and returns the flags as a list.
def mark_subst_opts(cmd_s):
flags = []
numb = False
while True:
ch = in_nonblank()
debug("s flag candidate: %r" % ch)
# sedparse: just append the flags to the list
if ch in ("i", "I", "m", "M", "e"): # GNU extensions
flags.append(ch)
elif ch == "p":
if ch in flags:
bad_prog(EXCESS_P_OPT)
flags.append(ch)
elif ch == "g":
if ch in flags:
bad_prog(EXCESS_G_OPT)
flags.append(ch)
elif ch == "w":
flags.append(ch)
# sedparse: This flag will always be at the end of the list, since
# after w cannot exist any other flag because the filename consumes
# everything until the end of the line.
b = read_filename()
if not b:
bad_prog(MISSING_FILENAME)
cmd_s.outf.name = "".join(b)
debug("s flag filename: %r" % cmd_s.outf.name)
return flags
elif ch in "0123456789":
if numb:
bad_prog(EXCESS_N_OPT)
n = in_integer(ch)
if int(n) == 0:
bad_prog(ZERO_N_OPT)
flags.append(str(n))
numb = True
elif ch in (CLOSE_BRACE, "#"):
savchar(ch)
return flags
elif ch in (EOF, "\n"):
return flags
# sedparse extension: Ignore trailing blanks and ; until EOC/EOL/EOF
elif ch == ";":
ignore_trailing_fluff()
return flags
elif ch == "\r":
if inchar() == "\n":
return flags
bad_prog(UNKNOWN_S_OPT)
else:
bad_prog(UNKNOWN_S_OPT)
# read in a label for a `:', `b', or `t' command
def read_label():
b = init_buffer()
ch = in_nonblank()
while ch not in (EOF, "\n", ";", CLOSE_BRACE, "#") and not ISBLANK(ch):
ch = add_then_next(b, ch)
savchar(ch)
# sedparse extension: Ignore trailing blanks and ; until EOC/EOL/EOF
ignore_trailing_fluff()
# add1_buffer(b, "\0") # not necessary in Python
ret = "".join(b)
free_buffer(b)
return ret
# setup_label() - Translation not needed
# release_label() - Translation not needed
# new_replacement() - Translation not needed
# setup_replacement() - Translation not needed
def read_text(buf, leadin_ch):
global pending_text
global old_text_buf
# Should we start afresh (as opposed to continue a partial text)?
if buf:
if pending_text:
free_buffer(pending_text)
pending_text = init_buffer()
buf.text = []
old_text_buf = buf
if leadin_ch == EOF:
return
if leadin_ch != "\n":
add1_buffer(pending_text, leadin_ch)
ch = inchar()
while ch not in (EOF, "\n"):
if ch == "\\":
ch = inchar()
if ch != EOF:
add1_buffer(pending_text, "\\")
if ch == EOF:
add1_buffer(pending_text, "\n")
return
ch = add_then_next(pending_text, ch)
add1_buffer(pending_text, "\n")
if not buf:
buf = old_text_buf
buf.text = pending_text[:]
free_buffer(pending_text)
pending_text = NULL
# Try to read an address for a sed command. If it succeeds, return non-zero and
# store the resulting address in `*addr'. If the input doesn't look like an
# address read nothing and return zero.
def compile_address(addr, ch): # struct_addr, str
addr.addr_type = ADDR_IS_NULL
addr.addr_step = 0
addr.addr_number = 0 # extremely unlikely to ever match
addr.addr_regex = NULL
if ch in ("/", "\\"):
# sedparse: Instead of using bit flags as in regex.c, we just save the
# flags into a list
flags = []
addr.addr_type = ADDR_IS_REGEX
if ch == "\\":
ch = inchar()
b = match_slash(ch, True)
if b == NULL:
bad_prog(UNTERM_ADDR_RE)
# sedparse extension: we save the slash char
slash = ch
while True:
ch = in_nonblank()
# if posixicity == POSIXLY_BASIC:
# goto posix_address_modifier
if ch == "I": # GNU extension
flags.append(ch)
elif ch == "M": # GNU extension
flags.append(ch)
else:
# posix_address_modifier: # GOTO label
savchar(ch)
addr.addr_regex = compile_regex(b, flags)
addr.addr_regex.slash = slash
free_buffer(b)
return True
elif ISDIGIT(ch):
addr.addr_number = in_integer(ch)
addr.addr_type = ADDR_IS_NUM
ch = in_nonblank()
if ch != "~": # or posixicity == POSIXLY_BASIC:
savchar(ch)
else:
step = in_integer(in_nonblank())
if step > 0:
addr.addr_step = step
addr.addr_type = ADDR_IS_NUM_MOD
elif ch in ("+", "~"): # and posixicity != POSIXLY_BASIC:
addr.addr_step = in_integer(in_nonblank())
# sedparse: skipping this to match and save 1,~0p and 1,+0p
# if addr.addr_step == 0:
# pass # default to ADDR_IS_NULL; forces matching to stop on next line
# elif ch == "+":
if ch == "+":
addr.addr_type = ADDR_IS_STEP
else:
addr.addr_type = ADDR_IS_STEP_MOD
elif ch == "$":
addr.addr_type = ADDR_IS_LAST
else:
return False
return True
# Read a program in and store the compiled form in `vector'.
# Original:
# Read a program (or a subprogram within `{' `}' pairs) in and store the
# compiled form in `*vector'. Return a pointer to the new vector.
def compile_program(vector):
global blocks
if pending_text:
read_text(NULL, "\n")
while True:
a = struct_addr()
# while ((ch=inchar ()) == ';' || ISSPACE (ch))
# ;
# if (ch == EOF)
# break;
while True:
ch = inchar()
# sedparse extension:
# GNU sed parser discards the \n used as command separator.
# Sedsed keeps all cosmetic line breaks (i.e. \n\n) when formatting
# code. So here sedparse creates the concept of the \n command, to
# identify and preserve those breaks.
if ch == "\n":
break
if ch != ";" and not ISSPACE(ch):
break
if ch == EOF:
break
cur_cmd = next_cmd_entry(vector)
cur_cmd.line = cur_input.line # sedparse extension
if compile_address(a, ch):
if a.addr_type == ADDR_IS_STEP or a.addr_type == ADDR_IS_STEP_MOD:
bad_prog(BAD_STEP)
cur_cmd.a1 = a
debug("----- Found address 1: %r" % cur_cmd.a1)
a = struct_addr() # reset a
ch = in_nonblank()
if ch == ",":
if not compile_address(a, in_nonblank()):
bad_prog(BAD_COMMA)
cur_cmd.a2 = a
debug("----- Found address 2: %r" % cur_cmd.a2)
ch = in_nonblank()
# sedparse: removed: or posixicity == POSIXLY_BASIC)):
if cur_cmd.a1.addr_type == ADDR_IS_NUM and cur_cmd.a1.addr_number == 0:
if not cur_cmd.a2 or cur_cmd.a2.addr_type != ADDR_IS_REGEX:
bad_prog(INVALID_LINE_0)
if ch == "!":
cur_cmd.addr_bang = True
debug("----- Found negation: !")
ch = in_nonblank()
if ch == "!":
bad_prog(BAD_BANG)
# Do not accept extended commands in --posix mode. Also,
# a few commands only accept one address in that mode.
# sedparse: SKIPPED
cur_cmd.cmd = ch
debug("----- Found command: %r" % ch)
# sedparse extension
if ch == "\n":
# Adjust the line number for the empty lines, because they're just
# detected in the next line
cur_cmd.line -= 1
# Detect cases like 1\n, an address with no "real" command
if cur_cmd.a1:
bad_prog(NO_COMMAND)
elif ch == "#":
# if (cur_cmd->a1)
# bad_prog (_(NO_SHARP_ADDR));
# sedparse: no #n detection, it will be considered a normal comment.
# It's up to the caller code to decide if this should be special.
# sedparse: GNU sed discards the comment contents, but we must save it
# while ch != EOF and ch != "\n":
# ch = inchar()
# continue
b = read_comment()
cur_cmd.x.comment = "".join(b)
debug("comment: %r" % cur_cmd.x.comment)
free_buffer(b)
# sedparse: we just save the "v" command contents, no processing
elif ch == "v":
# sedparse extension: using label_name to store "v" argument
cur_cmd.x.label_name = read_label()
debug("argument: %s" % cur_cmd.x.label_name)
elif ch == "{":
blocks += 1
# sedparse extension: Ignore trailing blanks and ; until EOC/EOL/EOF
ignore_trailing_fluff()
# cur_cmd.addr_bang = not cur_cmd.addr_bang # ?
elif ch == "}":
if not blocks:
bad_prog(EXCESS_CLOSE_BRACE)
if cur_cmd.a1:
bad_prog(NO_CLOSE_BRACE_ADDR)
read_end_of_cmd()
blocks -= 1 # done with this entry
# sedparse: "e" handling was moved here (original code uses GOTO)
elif ch in ("a", "i", "c", "e"):
ch = in_nonblank()
# sedparse: Empty "e" at EOF is allowed
if ch == EOF and cur_cmd.cmd == "e":
break
if ch == EOF:
bad_prog(EXPECTED_SLASH)
if ch == "\\":
ch = inchar()
else:
# if posixicity == POSIXLY_BASIC:
# bad_prog(EXPECTED_SLASH)
savchar(ch)
ch = "\n"
read_text(cur_cmd.x.cmd_txt, ch)
debug("text: %r" % cur_cmd.x.cmd_txt)
elif ch in (":", "T", "b", "t"):
# if (cur_cmd->a1)
# bad_prog (_(NO_COLON_ADDR));
label = read_label()
if ch == ":" and not label:
bad_prog(COLON_LACKS_LABEL)
cur_cmd.x.label_name = label
debug("label: %r" % cur_cmd.x.label_name)
# The "L" command was added in GNU sed v3.95 (Oct 2002) and was removed
# in v4.3 (Dec 2016). It used to format paragraphs like the "fmt" Unix
# command does and accepted an optional integer argument. In those 14
# years present in GNU sed, many users could have written scripts using
# it, so sedparse will keep supporting this command.
elif ch in ("Q", "q", "L", "l"):
# if ch in ("Q", "q") and cur_cmd.a2:
# bad_prog(ONE_ADDR)
ch = in_nonblank()
if ISDIGIT(ch): # and posixicity != POSIXLY_BASIC
cur_cmd.x.int_arg = in_integer(ch)
debug("int_arg: %r" % cur_cmd.x.int_arg)
else:
cur_cmd.x.int_arg = -1
debug("int_arg: -1")
savchar(ch)
read_end_of_cmd()
elif ch in (
"=",
"d",
"D",
"F",
"g",
"G",
"h",
"H",
"n",
"N",
"p",
"P",
"z",
"x",
):
read_end_of_cmd()
# sedparse: we just read the filename, nothing else
elif ch in ("r", "R", "w", "W"):
b = read_filename()
if not b:
bad_prog(MISSING_FILENAME)
cur_cmd.x.fname = "".join(b)
debug("filename: %r" % cur_cmd.x.fname)
free_buffer(b)
elif ch == "s":
slash = inchar()
b = match_slash(slash, True)
if b == NULL:
bad_prog(UNTERM_S_CMD)
# sedparse extension: we save the slash and the pattern
cur_cmd.x.cmd_subst.regx.slash = slash
cur_cmd.x.cmd_subst.regx.pattern = "".join(b)
debug("s pattern: %r" % cur_cmd.x.cmd_subst.regx.pattern)
free_buffer(b) # sedparse: freeing earlier than in original code
b2 = match_slash(slash, False)
if b2 == NULL:
bad_prog(UNTERM_S_CMD)
# sedparse: we just save the replacement text
cur_cmd.x.cmd_subst.replacement.text = "".join(b2)
debug("s replacement: %r" % cur_cmd.x.cmd_subst.replacement.text)
free_buffer(b2)
# sedparse: here GNU compiles the regex, we just save the flags
flags = "".join(mark_subst_opts(cur_cmd.x.cmd_subst))
cur_cmd.x.cmd_subst.regx.flags = flags
debug("s flags: %r" % cur_cmd.x.cmd_subst.regx.flags)
# if cur_cmd.x.cmd_subst.eval and sandbox:
# bad_prog(_(DISALLOWED_CMD))
elif ch == "y":
# sedparse extension: original code uses cur_cmd.x.translate and
# cur_cmd.x.translatemb to save the translation tables for "y". We
# instead, overload cur_cmd.x.cmd_subst to save the "y" unprocessed
# data.
slash = inchar()
b = match_slash(slash, False)
if b == NULL:
bad_prog(UNTERM_Y_CMD)
# sedparse extension: we save the slash and the pattern
cur_cmd.x.cmd_subst.regx.slash = slash
cur_cmd.x.cmd_subst.regx.pattern = "".join(b)
debug("y pattern: %r" % cur_cmd.x.cmd_subst.regx.pattern)
b2 = match_slash(slash, False)
if b2 == NULL:
bad_prog(UNTERM_Y_CMD)
# sedparse: we just save the replacement text
cur_cmd.x.cmd_subst.replacement.text = "".join(b2)
debug("y replacement: %r" % cur_cmd.x.cmd_subst.replacement.text)
# sedparse: Since we do not perform the de-escaping of \/, \\ and \\n
# (see match_slash()), the length check is turned off.
#
# if len(normalize_text(b)) != len(normalize_text(b2)):
# bad_prog(Y_CMD_LEN)
read_end_of_cmd()
free_buffer(b)
free_buffer(b2)
elif ch == EOF:
bad_prog(NO_COMMAND)
# /*NOTREACHED*/
else:
bad_command(ch)
# /*NOTREACHED*/
# if posixicity == POSIXLY_BASIC and pending_text:
# bad_prog (INCOMPLETE_CMD)
# no return, vector is edited in place
# normalize_text() - Translation not needed
# `str' is a string (from the command line) that contains a sed command.
# Compile the command, and add it to the end of `cur_program'.
def compile_string(cur_program, string):
# string_expr_count = 0
# prog and cur_input are global classes
prog.file = NULL
prog.base = 0 # first char of the string (will be 1-based)
prog.cur = prog.base
prog.end = prog.cur + len(string)
prog.text = string # sedparse extension
cur_input.line = 1 # sedparse: original was zero
cur_input.name = NULL
# string_expr_count += 1
cur_input.string_expr_count += 1
compile_program(cur_program)
prog.base = NULL
prog.cur = NULL
prog.end = NULL
prog.text = NULL
# no return, cur_program is edited in place
# `cmdfile' is the name of a file containing sed commands.
# Read them in and add them to the end of `cur_program'.
def compile_file(cur_program, cmdfile):
# prog and cur_input are global classes
if cmdfile == "-":
# sedparse extension
# My version of savchar() does not work when reading from STDIN. To
# workaround that, read STDIN now into a temporary file and only handle
# that file from now on.
with tempfile.NamedTemporaryFile(mode="w", delete=False) as file:
file.write(sys.stdin.read())
temp_filename = file.name
prog.file = open(temp_filename, "r")
else:
prog.file = open(cmdfile, "r")
cur_input.line = 1
cur_input.name = cmdfile
cur_input.string_expr_count = 0
compile_program(cur_program)
prog.file.close()
prog.file = NULL
# sedparse extension
if cmdfile == "-":
os.remove(temp_filename)
# no return, cur_program is edited in place
# cleanup_program_filenames() - Translation not needed
# Make any checks which require the whole program to have been read.
# In particular: this backpatches the jump targets. (sedparse: we don't)
# Any cleanup which can be done after these checks is done here also.
def check_final_program(): # program):
global old_text_buf
global pending_text
# do all "{"s have a corresponding "}"?
if blocks:
bad_prog(EXCESS_OPEN_BRACE)
# was the final command an unterminated a/c/i command?
if pending_text:
debug("pending_text: %r" % pending_text)
old_text_buf.text = pending_text[:]
free_buffer(pending_text)
pending_text = NULL
# rewind_read_files() - Translation not needed
# finish_program() - Translation not needed
######################################## end of translations
# From now on it's all sedparse exclusive code
PARSER_DEBUG = False
def debug(msg, stats=False):
if PARSER_DEBUG:
if stats:
print(
"exp=%s line=%s cur=%s end=%s text=%r ch=%r"
% (
cur_input.string_expr_count,
cur_input.line,
prog.cur,
prog.end,
prog.text,
msg,
),
file=sys.stderr,
)
else:
print(msg, file=sys.stderr)
def reset_globals():
"""
In the original C code, any error aborts the program. Here, we throw an
exception. This can be caught and at that point, the module globals are
still holding data from the previous parsing. We need to clean up everything
so the next call to `compile_*()` will act on fresh, uncontaminated data.
"""
global blocks
global old_text_buf
global pending_text
blocks = 0
old_text_buf = NULL
pending_text = NULL
# Reset compile_string()-related data
prog.base = NULL
prog.cur = NULL
prog.end = NULL
prog.text = NULL
# Reset compile_file()-related data
if prog.file:
prog.file.close()
prog.file = NULL
def to_json(obj, remove_empty=True):
return json.dumps(obj, default=lambda x: x.to_dict(remove_empty), **JSON_OPTS)
def print_program(compiled_program): # pylint: disable=unused-variable
indent_level = 0
indent_prefix = " " * 4
for x in compiled_program:
if x.cmd == "}":
indent_level -= 1
if x.cmd == "\n":
print()
else:
print("%s%s" % ((indent_prefix * indent_level), x))
if x.cmd == "{":
indent_level += 1
def get_argparser():
argparser = argparse.ArgumentParser(
description="Parse a sed script and show its JSON representation in STDOUT."
)
# For -e and -f we use the same name, metavar and help as in GNU sed
argparser.add_argument(
"-e",
"--expression",
metavar="script",
dest="inputs",
action="append",
type=lambda x: ("e", x), # becomes a ("e", expression) tuple
help="add the script to the commands to be parsed",
)
argparser.add_argument(
"-f",
"--file",
metavar="script-file",
dest="inputs",
action="append",
type=lambda x: ("f", x), # becomes a ("f", filename) tuple
help="add the contents of script-file to the commands to be parsed",
)
argparser.add_argument(
"--full", action="store_true", help="show full JSON (has empty values)"
)
argparser.add_argument(
"-v", "--verbose", action="store_true", help="turn on verbose mode"
)
argparser.add_argument(
"-V", "--version", action="version", version="%(prog)s " + __version__
)
return argparser
def main(arguments=None):
global PARSER_DEBUG
args = get_argparser().parse_args(arguments)
PARSER_DEBUG = args.verbose
if not args.inputs:
raise RuntimeError("No sed script to be parsed. Use -e and/or -f.")
# Read and parse the sed script informed in -e and/or -f, respecting the
# original argument order
the_program = []
for input_type, input_val in args.inputs:
if input_type == "e":
debug("\n===== Will parse expression: %s" % input_val)
compile_string(the_program, input_val)
elif input_type == "f":
debug("\n===== Will parse file: %s" % input_val)
compile_file(the_program, input_val)
else:
raise RuntimeError("Unknown input type '%s'" % input_type)
check_final_program()
return to_json(the_program, not args.full)
def entrypoint():
try:
print(main())
sys.exit(EXIT_SUCCESS)
except ParseError as err:
print(err.message, file=sys.stderr)
sys.exit(err.exitcode)
except RuntimeError as err:
sys.exit("%s: %s" % (program_name, err))
if __name__ == "__main__":
entrypoint()
sedparse-0.1.2/setup.cfg 0000664 0000000 0000000 00000000530 13566611474 0015154 0 ustar 00root root 0000000 0000000 # LICENSE file is already included by default
# https://wheel.readthedocs.io/en/stable/user_guide.html#including-license-files-in-the-generated-wheel-file
[bdist_wheel]
# This flag says to generate wheels that support both Python 2 and Python 3.
# https://packaging.python.org/guides/distributing-packages-using-setuptools/#wheels
universal=1
sedparse-0.1.2/setup.py 0000664 0000000 0000000 00000003760 13566611474 0015055 0 ustar 00root root 0000000 0000000 # Guides:
# https://packaging.python.org/tutorials/packaging-projects/
# https://packaging.python.org/guides/distributing-packages-using-setuptools/
# References:
# https://github.com/jendrikseipp/txt2tags/blob/master/setup.py
# https://github.com/mystor/git-revise/blob/master/setup.py
# https://github.com/docopt/docopt/blob/master/setup.py
# https://github.com/psf/requests/blob/master/setup.py
# https://github.com/psf/black/blob/master/setup.py
# https://github.com/pypa/pip/blob/master/setup.py
import setuptools
import sedparse
with open("README.md", "r") as fh:
LONG_DESCRIPTION = fh.read()
setuptools.setup(
name="sedparse",
version=sedparse.__version__,
author="Aurelio Jargas",
author_email="aurelio@aurelio.net",
description="GNU sed's parser translated from C to Python",
long_description=LONG_DESCRIPTION,
long_description_content_type="text/markdown",
url="https://github.com/aureliojargas/sedparse",
project_urls={
"Bug Tracker": "https://github.com/aureliojargas/sedparse/issues",
"Source Code": "https://github.com/aureliojargas/sedparse",
},
classifiers=[
"Development Status :: 4 - Beta",
"Environment :: Console",
"Intended Audience :: Developers",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Operating System :: OS Independent",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python",
"Topic :: Software Development",
],
py_modules=["sedparse"],
python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*",
entry_points={"console_scripts": ["sedparse = sedparse:entrypoint"]},
)
sedparse-0.1.2/tests/ 0000775 0000000 0000000 00000000000 13566611474 0014477 5 ustar 00root root 0000000 0000000 sedparse-0.1.2/tests/context.py 0000664 0000000 0000000 00000000524 13566611474 0016536 0 ustar 00root root 0000000 0000000 # Workaround to make ../sedparse.py importable from all test scripts.
# Idea from https://www.kennethreitz.org/essays/repository-structure-and-python
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
# pylint: disable=wrong-import-position,unused-import,unused-variable
import sedparse
sedparse-0.1.2/tests/reference.full.json 0000664 0000000 0000000 00000155312 13566611474 0020300 0 ustar 00root root 0000000 0000000 [
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "#",
"line": 1,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": " Addresses",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": {
"addr_number": 11,
"addr_regex": null,
"addr_step": 0,
"addr_type": 3
},
"a2": null,
"addr_bang": false,
"cmd": "p",
"line": 2,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": {
"addr_number": 21,
"addr_regex": null,
"addr_step": 0,
"addr_type": 3
},
"a2": {
"addr_number": 22,
"addr_regex": null,
"addr_step": 0,
"addr_type": 3
},
"addr_bang": false,
"cmd": "p",
"line": 3,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": {
"addr_number": 31,
"addr_regex": null,
"addr_step": 32,
"addr_type": 4
},
"a2": null,
"addr_bang": false,
"cmd": "p",
"line": 4,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": {
"addr_number": 41,
"addr_regex": null,
"addr_step": 0,
"addr_type": 3
},
"a2": {
"addr_number": 0,
"addr_regex": null,
"addr_step": 42,
"addr_type": 6
},
"addr_bang": false,
"cmd": "p",
"line": 5,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": {
"addr_number": 51,
"addr_regex": null,
"addr_step": 0,
"addr_type": 3
},
"a2": {
"addr_number": 0,
"addr_regex": null,
"addr_step": 52,
"addr_type": 5
},
"addr_bang": false,
"cmd": "p",
"line": 6,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": {
"addr_number": 0,
"addr_regex": null,
"addr_step": 0,
"addr_type": 7
},
"a2": null,
"addr_bang": false,
"cmd": "p",
"line": 7,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": {
"addr_number": 0,
"addr_regex": {
"flags": "",
"pattern": "regex-without-flags",
"slash": "/"
},
"addr_step": 0,
"addr_type": 2
},
"a2": null,
"addr_bang": false,
"cmd": "p",
"line": 8,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": {
"addr_number": 0,
"addr_regex": {
"flags": "IM",
"pattern": "regex-with-flags",
"slash": "/"
},
"addr_step": 0,
"addr_type": 2
},
"a2": null,
"addr_bang": false,
"cmd": "p",
"line": 9,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": {
"addr_number": 0,
"addr_regex": {
"flags": "",
"pattern": "",
"slash": "/"
},
"addr_step": 0,
"addr_type": 2
},
"a2": null,
"addr_bang": false,
"cmd": "p",
"line": 10,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "\n",
"line": 11,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "#",
"line": 12,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": " Bang to invert addresses",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": {
"addr_number": 0,
"addr_regex": null,
"addr_step": 0,
"addr_type": 7
},
"a2": null,
"addr_bang": true,
"cmd": "p",
"line": 13,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "\n",
"line": 14,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "#",
"line": 15,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": " Commands with no arguments",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "=",
"line": 16,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "b",
"line": 17,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "d",
"line": 18,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "D",
"line": 19,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "F",
"line": 20,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "g",
"line": 21,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "G",
"line": 22,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "h",
"line": 23,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "H",
"line": 24,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "l",
"line": 25,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "L",
"line": 26,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "n",
"line": 27,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "N",
"line": 28,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "p",
"line": 29,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "P",
"line": 30,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "q",
"line": 31,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "Q",
"line": 32,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "t",
"line": 33,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "T",
"line": 34,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "x",
"line": 35,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "z",
"line": 36,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "\n",
"line": 37,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "#",
"line": 38,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": " Commands with numeric argument",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "q",
"line": 39,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": 1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "Q",
"line": 40,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": 22,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "l",
"line": 41,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": 333,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "L",
"line": 42,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": 4444,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "\n",
"line": 43,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "#",
"line": 44,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": " Commands with labels",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": ":",
"line": 45,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": "label"
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "b",
"line": 46,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": "label_b"
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "t",
"line": 47,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": "label_t"
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "T",
"line": 48,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": "label_T"
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "\n",
"line": 49,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "#",
"line": 50,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": " Command v (label-like)",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "v",
"line": 51,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": "4.2"
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "\n",
"line": 52,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "#",
"line": 53,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": " Commands with files",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "r",
"line": 54,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "file_r",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "R",
"line": 55,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "file_R",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "w",
"line": 56,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "file_w",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "W",
"line": 57,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "file_W",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "\n",
"line": 58,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "#",
"line": 59,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": " Commands with text",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "a",
"line": 60,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": [
"t",
"e",
"x",
"t",
"_",
"a",
"\n"
]
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "i",
"line": 61,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": [
"t",
"e",
"x",
"t",
"_",
"i",
"\n"
]
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "c",
"line": 63,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": [
"t",
"e",
"x",
"t",
"_",
"c",
"1",
" ",
"\\",
"\n",
"t",
"e",
"x",
"t",
"_",
"c",
"2",
"\n"
]
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "\n",
"line": 66,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "#",
"line": 67,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": " Command e (text-like)",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "e",
"line": 68,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": [
"d",
"a",
"t",
"e",
"\n"
]
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "\n",
"line": 69,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "#",
"line": 70,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": " Command y",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "y",
"line": 71,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "abc",
"slash": "/"
},
"replacement": {
"text": "123"
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "y",
"line": 72,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "abc",
"slash": "@"
},
"replacement": {
"text": "123"
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "\n",
"line": 73,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "#",
"line": 74,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": " Command s",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "s",
"line": 75,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": "/"
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "s",
"line": 76,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "3",
"pattern": "",
"slash": "|"
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "s",
"line": 77,
"x": {
"cmd_subst": {
"outf": {
"name": "filew"
},
"regx": {
"flags": "gipw",
"pattern": "patt",
"slash": "/"
},
"replacement": {
"text": "repl"
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "\n",
"line": 78,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "#",
"line": 79,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": " Blocks",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": {
"addr_number": 0,
"addr_regex": null,
"addr_step": 0,
"addr_type": 7
},
"a2": null,
"addr_bang": false,
"cmd": "{",
"line": 80,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "p",
"line": 81,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
},
{
"a1": null,
"a2": null,
"addr_bang": false,
"cmd": "}",
"line": 82,
"x": {
"cmd_subst": {
"outf": {
"name": ""
},
"regx": {
"flags": "",
"pattern": "",
"slash": ""
},
"replacement": {
"text": ""
}
},
"cmd_txt": {
"text": []
},
"comment": "",
"fname": "",
"int_arg": -1,
"label_name": ""
}
}
]
sedparse-0.1.2/tests/reference.json 0000664 0000000 0000000 00000023051 13566611474 0017331 0 ustar 00root root 0000000 0000000 [
{
"cmd": "#",
"line": 1,
"x": {
"comment": " Addresses"
}
},
{
"a1": {
"addr_number": 11,
"addr_type": 3
},
"cmd": "p",
"line": 2
},
{
"a1": {
"addr_number": 21,
"addr_type": 3
},
"a2": {
"addr_number": 22,
"addr_type": 3
},
"cmd": "p",
"line": 3
},
{
"a1": {
"addr_number": 31,
"addr_step": 32,
"addr_type": 4
},
"cmd": "p",
"line": 4
},
{
"a1": {
"addr_number": 41,
"addr_type": 3
},
"a2": {
"addr_number": 0,
"addr_step": 42,
"addr_type": 6
},
"cmd": "p",
"line": 5
},
{
"a1": {
"addr_number": 51,
"addr_type": 3
},
"a2": {
"addr_number": 0,
"addr_step": 52,
"addr_type": 5
},
"cmd": "p",
"line": 6
},
{
"a1": {
"addr_type": 7
},
"cmd": "p",
"line": 7
},
{
"a1": {
"addr_regex": {
"pattern": "regex-without-flags",
"slash": "/"
},
"addr_type": 2
},
"cmd": "p",
"line": 8
},
{
"a1": {
"addr_regex": {
"flags": "IM",
"pattern": "regex-with-flags",
"slash": "/"
},
"addr_type": 2
},
"cmd": "p",
"line": 9
},
{
"a1": {
"addr_regex": {
"slash": "/"
},
"addr_type": 2
},
"cmd": "p",
"line": 10
},
{
"cmd": "\n",
"line": 11
},
{
"cmd": "#",
"line": 12,
"x": {
"comment": " Bang to invert addresses"
}
},
{
"a1": {
"addr_type": 7
},
"addr_bang": true,
"cmd": "p",
"line": 13
},
{
"cmd": "\n",
"line": 14
},
{
"cmd": "#",
"line": 15,
"x": {
"comment": " Commands with no arguments"
}
},
{
"cmd": "=",
"line": 16
},
{
"cmd": "b",
"line": 17
},
{
"cmd": "d",
"line": 18
},
{
"cmd": "D",
"line": 19
},
{
"cmd": "F",
"line": 20
},
{
"cmd": "g",
"line": 21
},
{
"cmd": "G",
"line": 22
},
{
"cmd": "h",
"line": 23
},
{
"cmd": "H",
"line": 24
},
{
"cmd": "l",
"line": 25
},
{
"cmd": "L",
"line": 26
},
{
"cmd": "n",
"line": 27
},
{
"cmd": "N",
"line": 28
},
{
"cmd": "p",
"line": 29
},
{
"cmd": "P",
"line": 30
},
{
"cmd": "q",
"line": 31
},
{
"cmd": "Q",
"line": 32
},
{
"cmd": "t",
"line": 33
},
{
"cmd": "T",
"line": 34
},
{
"cmd": "x",
"line": 35
},
{
"cmd": "z",
"line": 36
},
{
"cmd": "\n",
"line": 37
},
{
"cmd": "#",
"line": 38,
"x": {
"comment": " Commands with numeric argument"
}
},
{
"cmd": "q",
"line": 39,
"x": {
"int_arg": 1
}
},
{
"cmd": "Q",
"line": 40,
"x": {
"int_arg": 22
}
},
{
"cmd": "l",
"line": 41,
"x": {
"int_arg": 333
}
},
{
"cmd": "L",
"line": 42,
"x": {
"int_arg": 4444
}
},
{
"cmd": "\n",
"line": 43
},
{
"cmd": "#",
"line": 44,
"x": {
"comment": " Commands with labels"
}
},
{
"cmd": ":",
"line": 45,
"x": {
"label_name": "label"
}
},
{
"cmd": "b",
"line": 46,
"x": {
"label_name": "label_b"
}
},
{
"cmd": "t",
"line": 47,
"x": {
"label_name": "label_t"
}
},
{
"cmd": "T",
"line": 48,
"x": {
"label_name": "label_T"
}
},
{
"cmd": "\n",
"line": 49
},
{
"cmd": "#",
"line": 50,
"x": {
"comment": " Command v (label-like)"
}
},
{
"cmd": "v",
"line": 51,
"x": {
"label_name": "4.2"
}
},
{
"cmd": "\n",
"line": 52
},
{
"cmd": "#",
"line": 53,
"x": {
"comment": " Commands with files"
}
},
{
"cmd": "r",
"line": 54,
"x": {
"fname": "file_r"
}
},
{
"cmd": "R",
"line": 55,
"x": {
"fname": "file_R"
}
},
{
"cmd": "w",
"line": 56,
"x": {
"fname": "file_w"
}
},
{
"cmd": "W",
"line": 57,
"x": {
"fname": "file_W"
}
},
{
"cmd": "\n",
"line": 58
},
{
"cmd": "#",
"line": 59,
"x": {
"comment": " Commands with text"
}
},
{
"cmd": "a",
"line": 60,
"x": {
"cmd_txt": {
"text": [
"t",
"e",
"x",
"t",
"_",
"a",
"\n"
]
}
}
},
{
"cmd": "i",
"line": 61,
"x": {
"cmd_txt": {
"text": [
"t",
"e",
"x",
"t",
"_",
"i",
"\n"
]
}
}
},
{
"cmd": "c",
"line": 63,
"x": {
"cmd_txt": {
"text": [
"t",
"e",
"x",
"t",
"_",
"c",
"1",
" ",
"\\",
"\n",
"t",
"e",
"x",
"t",
"_",
"c",
"2",
"\n"
]
}
}
},
{
"cmd": "\n",
"line": 66
},
{
"cmd": "#",
"line": 67,
"x": {
"comment": " Command e (text-like)"
}
},
{
"cmd": "e",
"line": 68,
"x": {
"cmd_txt": {
"text": [
"d",
"a",
"t",
"e",
"\n"
]
}
}
},
{
"cmd": "\n",
"line": 69
},
{
"cmd": "#",
"line": 70,
"x": {
"comment": " Command y"
}
},
{
"cmd": "y",
"line": 71,
"x": {
"cmd_subst": {
"regx": {
"pattern": "abc",
"slash": "/"
},
"replacement": {
"text": "123"
}
}
}
},
{
"cmd": "y",
"line": 72,
"x": {
"cmd_subst": {
"regx": {
"pattern": "abc",
"slash": "@"
},
"replacement": {
"text": "123"
}
}
}
},
{
"cmd": "\n",
"line": 73
},
{
"cmd": "#",
"line": 74,
"x": {
"comment": " Command s"
}
},
{
"cmd": "s",
"line": 75,
"x": {
"cmd_subst": {
"regx": {
"slash": "/"
}
}
}
},
{
"cmd": "s",
"line": 76,
"x": {
"cmd_subst": {
"regx": {
"flags": "3",
"slash": "|"
}
}
}
},
{
"cmd": "s",
"line": 77,
"x": {
"cmd_subst": {
"outf": {
"name": "filew"
},
"regx": {
"flags": "gipw",
"pattern": "patt",
"slash": "/"
},
"replacement": {
"text": "repl"
}
}
}
},
{
"cmd": "\n",
"line": 78
},
{
"cmd": "#",
"line": 79,
"x": {
"comment": " Blocks"
}
},
{
"a1": {
"addr_type": 7
},
"cmd": "{",
"line": 80
},
{
"cmd": "p",
"line": 81
},
{
"cmd": "}",
"line": 82
}
]
sedparse-0.1.2/tests/reference.sed 0000664 0000000 0000000 00000001154 13566611474 0017133 0 ustar 00root root 0000000 0000000 # Addresses
11 p
21,22 p
31~32 p
41,~42 p
51,+52 p
$ p
/regex-without-flags/ p
/regex-with-flags/IM p
// p
# Bang to invert addresses
$ ! p
# Commands with no arguments
=
b
d
D
F
g
G
h
H
l
L
n
N
p
P
q
Q
t
T
x
z
# Commands with numeric argument
q 1
Q 22
l 333
L 4444
# Commands with labels
: label
b label_b
t label_t
T label_T
# Command v (label-like)
v 4.2
# Commands with files
r file_r
R file_R
w file_w
W file_W
# Commands with text
a text_a
i\
text_i
c\
text_c1 \
text_c2
# Command e (text-like)
e date
# Command y
y/abc/123/
y@abc@123@
# Command s
s///
s|||3
s/patt/repl/gipw filew
# Blocks
$ {
p
}
sedparse-0.1.2/tests/reference.verbose 0000664 0000000 0000000 00000114366 13566611474 0020037 0 ustar 00root root 0000000 0000000
===== Will parse file: tests/reference.sed
exp=0 line=1 cur=None end=None text=None ch='#'
----- Found command: '#'
exp=0 line=1 cur=None end=None text=None ch=' '
exp=0 line=1 cur=None end=None text=None ch='A'
exp=0 line=1 cur=None end=None text=None ch='d'
exp=0 line=1 cur=None end=None text=None ch='d'
exp=0 line=1 cur=None end=None text=None ch='r'
exp=0 line=1 cur=None end=None text=None ch='e'
exp=0 line=1 cur=None end=None text=None ch='s'
exp=0 line=1 cur=None end=None text=None ch='s'
exp=0 line=1 cur=None end=None text=None ch='e'
exp=0 line=1 cur=None end=None text=None ch='s'
exp=0 line=2 cur=None end=None text=None ch='\n'
comment: ' Addresses'
exp=0 line=2 cur=None end=None text=None ch='1'
exp=0 line=2 cur=None end=None text=None ch='1'
exp=0 line=2 cur=None end=None text=None ch=' '
exp=0 line=2 cur=None end=None text=None ch='savchar( )'
exp=0 line=2 cur=None end=None text=None ch=' '
exp=0 line=2 cur=None end=None text=None ch='p'
exp=0 line=2 cur=None end=None text=None ch='savchar(p)'
----- Found address 1: struct_addr(addr_type=3, addr_number=11, addr_step=0, addr_regex=None)
exp=0 line=2 cur=None end=None text=None ch='p'
----- Found command: 'p'
exp=0 line=3 cur=None end=None text=None ch='\n'
exp=0 line=3 cur=None end=None text=None ch='2'
exp=0 line=3 cur=None end=None text=None ch='1'
exp=0 line=3 cur=None end=None text=None ch=','
exp=0 line=3 cur=None end=None text=None ch='savchar(,)'
exp=0 line=3 cur=None end=None text=None ch=','
exp=0 line=3 cur=None end=None text=None ch='savchar(,)'
----- Found address 1: struct_addr(addr_type=3, addr_number=21, addr_step=0, addr_regex=None)
exp=0 line=3 cur=None end=None text=None ch=','
exp=0 line=3 cur=None end=None text=None ch='2'
exp=0 line=3 cur=None end=None text=None ch='2'
exp=0 line=3 cur=None end=None text=None ch=' '
exp=0 line=3 cur=None end=None text=None ch='savchar( )'
exp=0 line=3 cur=None end=None text=None ch=' '
exp=0 line=3 cur=None end=None text=None ch='p'
exp=0 line=3 cur=None end=None text=None ch='savchar(p)'
----- Found address 2: struct_addr(addr_type=3, addr_number=22, addr_step=0, addr_regex=None)
exp=0 line=3 cur=None end=None text=None ch='p'
----- Found command: 'p'
exp=0 line=4 cur=None end=None text=None ch='\n'
exp=0 line=4 cur=None end=None text=None ch='3'
exp=0 line=4 cur=None end=None text=None ch='1'
exp=0 line=4 cur=None end=None text=None ch='~'
exp=0 line=4 cur=None end=None text=None ch='savchar(~)'
exp=0 line=4 cur=None end=None text=None ch='~'
exp=0 line=4 cur=None end=None text=None ch='3'
exp=0 line=4 cur=None end=None text=None ch='2'
exp=0 line=4 cur=None end=None text=None ch=' '
exp=0 line=4 cur=None end=None text=None ch='savchar( )'
----- Found address 1: struct_addr(addr_type=4, addr_number=31, addr_step=32, addr_regex=None)
exp=0 line=4 cur=None end=None text=None ch=' '
exp=0 line=4 cur=None end=None text=None ch='p'
----- Found command: 'p'
exp=0 line=5 cur=None end=None text=None ch='\n'
exp=0 line=5 cur=None end=None text=None ch='4'
exp=0 line=5 cur=None end=None text=None ch='1'
exp=0 line=5 cur=None end=None text=None ch=','
exp=0 line=5 cur=None end=None text=None ch='savchar(,)'
exp=0 line=5 cur=None end=None text=None ch=','
exp=0 line=5 cur=None end=None text=None ch='savchar(,)'
----- Found address 1: struct_addr(addr_type=3, addr_number=41, addr_step=0, addr_regex=None)
exp=0 line=5 cur=None end=None text=None ch=','
exp=0 line=5 cur=None end=None text=None ch='~'
exp=0 line=5 cur=None end=None text=None ch='4'
exp=0 line=5 cur=None end=None text=None ch='2'
exp=0 line=5 cur=None end=None text=None ch=' '
exp=0 line=5 cur=None end=None text=None ch='savchar( )'
----- Found address 2: struct_addr(addr_type=6, addr_number=0, addr_step=42, addr_regex=None)
exp=0 line=5 cur=None end=None text=None ch=' '
exp=0 line=5 cur=None end=None text=None ch='p'
----- Found command: 'p'
exp=0 line=6 cur=None end=None text=None ch='\n'
exp=0 line=6 cur=None end=None text=None ch='5'
exp=0 line=6 cur=None end=None text=None ch='1'
exp=0 line=6 cur=None end=None text=None ch=','
exp=0 line=6 cur=None end=None text=None ch='savchar(,)'
exp=0 line=6 cur=None end=None text=None ch=','
exp=0 line=6 cur=None end=None text=None ch='savchar(,)'
----- Found address 1: struct_addr(addr_type=3, addr_number=51, addr_step=0, addr_regex=None)
exp=0 line=6 cur=None end=None text=None ch=','
exp=0 line=6 cur=None end=None text=None ch='+'
exp=0 line=6 cur=None end=None text=None ch='5'
exp=0 line=6 cur=None end=None text=None ch='2'
exp=0 line=6 cur=None end=None text=None ch=' '
exp=0 line=6 cur=None end=None text=None ch='savchar( )'
----- Found address 2: struct_addr(addr_type=5, addr_number=0, addr_step=52, addr_regex=None)
exp=0 line=6 cur=None end=None text=None ch=' '
exp=0 line=6 cur=None end=None text=None ch='p'
----- Found command: 'p'
exp=0 line=7 cur=None end=None text=None ch='\n'
exp=0 line=7 cur=None end=None text=None ch='$'
----- Found address 1: struct_addr(addr_type=7, addr_number=0, addr_step=0, addr_regex=None)
exp=0 line=7 cur=None end=None text=None ch=' '
exp=0 line=7 cur=None end=None text=None ch='p'
----- Found command: 'p'
exp=0 line=8 cur=None end=None text=None ch='\n'
exp=0 line=8 cur=None end=None text=None ch='/'
exp=0 line=8 cur=None end=None text=None ch='r'
exp=0 line=8 cur=None end=None text=None ch='e'
exp=0 line=8 cur=None end=None text=None ch='g'
exp=0 line=8 cur=None end=None text=None ch='e'
exp=0 line=8 cur=None end=None text=None ch='x'
exp=0 line=8 cur=None end=None text=None ch='-'
exp=0 line=8 cur=None end=None text=None ch='w'
exp=0 line=8 cur=None end=None text=None ch='i'
exp=0 line=8 cur=None end=None text=None ch='t'
exp=0 line=8 cur=None end=None text=None ch='h'
exp=0 line=8 cur=None end=None text=None ch='o'
exp=0 line=8 cur=None end=None text=None ch='u'
exp=0 line=8 cur=None end=None text=None ch='t'
exp=0 line=8 cur=None end=None text=None ch='-'
exp=0 line=8 cur=None end=None text=None ch='f'
exp=0 line=8 cur=None end=None text=None ch='l'
exp=0 line=8 cur=None end=None text=None ch='a'
exp=0 line=8 cur=None end=None text=None ch='g'
exp=0 line=8 cur=None end=None text=None ch='s'
exp=0 line=8 cur=None end=None text=None ch='/'
exp=0 line=8 cur=None end=None text=None ch=' '
exp=0 line=8 cur=None end=None text=None ch='p'
exp=0 line=8 cur=None end=None text=None ch='savchar(p)'
----- Found address 1: struct_addr(addr_type=2, addr_number=0, addr_step=0, addr_regex=struct_regex(slash='/', pattern='regex-without-flags', flags=''))
exp=0 line=8 cur=None end=None text=None ch='p'
----- Found command: 'p'
exp=0 line=9 cur=None end=None text=None ch='\n'
exp=0 line=9 cur=None end=None text=None ch='/'
exp=0 line=9 cur=None end=None text=None ch='r'
exp=0 line=9 cur=None end=None text=None ch='e'
exp=0 line=9 cur=None end=None text=None ch='g'
exp=0 line=9 cur=None end=None text=None ch='e'
exp=0 line=9 cur=None end=None text=None ch='x'
exp=0 line=9 cur=None end=None text=None ch='-'
exp=0 line=9 cur=None end=None text=None ch='w'
exp=0 line=9 cur=None end=None text=None ch='i'
exp=0 line=9 cur=None end=None text=None ch='t'
exp=0 line=9 cur=None end=None text=None ch='h'
exp=0 line=9 cur=None end=None text=None ch='-'
exp=0 line=9 cur=None end=None text=None ch='f'
exp=0 line=9 cur=None end=None text=None ch='l'
exp=0 line=9 cur=None end=None text=None ch='a'
exp=0 line=9 cur=None end=None text=None ch='g'
exp=0 line=9 cur=None end=None text=None ch='s'
exp=0 line=9 cur=None end=None text=None ch='/'
exp=0 line=9 cur=None end=None text=None ch='I'
exp=0 line=9 cur=None end=None text=None ch='M'
exp=0 line=9 cur=None end=None text=None ch=' '
exp=0 line=9 cur=None end=None text=None ch='p'
exp=0 line=9 cur=None end=None text=None ch='savchar(p)'
----- Found address 1: struct_addr(addr_type=2, addr_number=0, addr_step=0, addr_regex=struct_regex(slash='/', pattern='regex-with-flags', flags='IM'))
exp=0 line=9 cur=None end=None text=None ch='p'
----- Found command: 'p'
exp=0 line=10 cur=None end=None text=None ch='\n'
exp=0 line=10 cur=None end=None text=None ch='/'
exp=0 line=10 cur=None end=None text=None ch='/'
exp=0 line=10 cur=None end=None text=None ch=' '
exp=0 line=10 cur=None end=None text=None ch='p'
exp=0 line=10 cur=None end=None text=None ch='savchar(p)'
----- Found address 1: struct_addr(addr_type=2, addr_number=0, addr_step=0, addr_regex=struct_regex(slash='/', pattern='', flags=''))
exp=0 line=10 cur=None end=None text=None ch='p'
----- Found command: 'p'
exp=0 line=11 cur=None end=None text=None ch='\n'
exp=0 line=12 cur=None end=None text=None ch='\n'
----- Found command: '\n'
exp=0 line=12 cur=None end=None text=None ch='#'
----- Found command: '#'
exp=0 line=12 cur=None end=None text=None ch=' '
exp=0 line=12 cur=None end=None text=None ch='B'
exp=0 line=12 cur=None end=None text=None ch='a'
exp=0 line=12 cur=None end=None text=None ch='n'
exp=0 line=12 cur=None end=None text=None ch='g'
exp=0 line=12 cur=None end=None text=None ch=' '
exp=0 line=12 cur=None end=None text=None ch='t'
exp=0 line=12 cur=None end=None text=None ch='o'
exp=0 line=12 cur=None end=None text=None ch=' '
exp=0 line=12 cur=None end=None text=None ch='i'
exp=0 line=12 cur=None end=None text=None ch='n'
exp=0 line=12 cur=None end=None text=None ch='v'
exp=0 line=12 cur=None end=None text=None ch='e'
exp=0 line=12 cur=None end=None text=None ch='r'
exp=0 line=12 cur=None end=None text=None ch='t'
exp=0 line=12 cur=None end=None text=None ch=' '
exp=0 line=12 cur=None end=None text=None ch='a'
exp=0 line=12 cur=None end=None text=None ch='d'
exp=0 line=12 cur=None end=None text=None ch='d'
exp=0 line=12 cur=None end=None text=None ch='r'
exp=0 line=12 cur=None end=None text=None ch='e'
exp=0 line=12 cur=None end=None text=None ch='s'
exp=0 line=12 cur=None end=None text=None ch='s'
exp=0 line=12 cur=None end=None text=None ch='e'
exp=0 line=12 cur=None end=None text=None ch='s'
exp=0 line=13 cur=None end=None text=None ch='\n'
comment: ' Bang to invert addresses'
exp=0 line=13 cur=None end=None text=None ch='$'
----- Found address 1: struct_addr(addr_type=7, addr_number=0, addr_step=0, addr_regex=None)
exp=0 line=13 cur=None end=None text=None ch=' '
exp=0 line=13 cur=None end=None text=None ch='!'
----- Found negation: !
exp=0 line=13 cur=None end=None text=None ch=' '
exp=0 line=13 cur=None end=None text=None ch='p'
----- Found command: 'p'
exp=0 line=14 cur=None end=None text=None ch='\n'
exp=0 line=15 cur=None end=None text=None ch='\n'
----- Found command: '\n'
exp=0 line=15 cur=None end=None text=None ch='#'
----- Found command: '#'
exp=0 line=15 cur=None end=None text=None ch=' '
exp=0 line=15 cur=None end=None text=None ch='C'
exp=0 line=15 cur=None end=None text=None ch='o'
exp=0 line=15 cur=None end=None text=None ch='m'
exp=0 line=15 cur=None end=None text=None ch='m'
exp=0 line=15 cur=None end=None text=None ch='a'
exp=0 line=15 cur=None end=None text=None ch='n'
exp=0 line=15 cur=None end=None text=None ch='d'
exp=0 line=15 cur=None end=None text=None ch='s'
exp=0 line=15 cur=None end=None text=None ch=' '
exp=0 line=15 cur=None end=None text=None ch='w'
exp=0 line=15 cur=None end=None text=None ch='i'
exp=0 line=15 cur=None end=None text=None ch='t'
exp=0 line=15 cur=None end=None text=None ch='h'
exp=0 line=15 cur=None end=None text=None ch=' '
exp=0 line=15 cur=None end=None text=None ch='n'
exp=0 line=15 cur=None end=None text=None ch='o'
exp=0 line=15 cur=None end=None text=None ch=' '
exp=0 line=15 cur=None end=None text=None ch='a'
exp=0 line=15 cur=None end=None text=None ch='r'
exp=0 line=15 cur=None end=None text=None ch='g'
exp=0 line=15 cur=None end=None text=None ch='u'
exp=0 line=15 cur=None end=None text=None ch='m'
exp=0 line=15 cur=None end=None text=None ch='e'
exp=0 line=15 cur=None end=None text=None ch='n'
exp=0 line=15 cur=None end=None text=None ch='t'
exp=0 line=15 cur=None end=None text=None ch='s'
exp=0 line=16 cur=None end=None text=None ch='\n'
comment: ' Commands with no arguments'
exp=0 line=16 cur=None end=None text=None ch='='
----- Found command: '='
exp=0 line=17 cur=None end=None text=None ch='\n'
exp=0 line=17 cur=None end=None text=None ch='b'
----- Found command: 'b'
exp=0 line=18 cur=None end=None text=None ch='\n'
exp=0 line=18 cur=None end=None text=None ch='savchar(\n)'
exp=0 line=18 cur=None end=None text=None ch='\n'
label: ''
exp=0 line=18 cur=None end=None text=None ch='d'
----- Found command: 'd'
exp=0 line=19 cur=None end=None text=None ch='\n'
exp=0 line=19 cur=None end=None text=None ch='D'
----- Found command: 'D'
exp=0 line=20 cur=None end=None text=None ch='\n'
exp=0 line=20 cur=None end=None text=None ch='F'
----- Found command: 'F'
exp=0 line=21 cur=None end=None text=None ch='\n'
exp=0 line=21 cur=None end=None text=None ch='g'
----- Found command: 'g'
exp=0 line=22 cur=None end=None text=None ch='\n'
exp=0 line=22 cur=None end=None text=None ch='G'
----- Found command: 'G'
exp=0 line=23 cur=None end=None text=None ch='\n'
exp=0 line=23 cur=None end=None text=None ch='h'
----- Found command: 'h'
exp=0 line=24 cur=None end=None text=None ch='\n'
exp=0 line=24 cur=None end=None text=None ch='H'
----- Found command: 'H'
exp=0 line=25 cur=None end=None text=None ch='\n'
exp=0 line=25 cur=None end=None text=None ch='l'
----- Found command: 'l'
exp=0 line=26 cur=None end=None text=None ch='\n'
int_arg: -1
exp=0 line=26 cur=None end=None text=None ch='savchar(\n)'
exp=0 line=26 cur=None end=None text=None ch='\n'
exp=0 line=26 cur=None end=None text=None ch='L'
----- Found command: 'L'
exp=0 line=27 cur=None end=None text=None ch='\n'
int_arg: -1
exp=0 line=27 cur=None end=None text=None ch='savchar(\n)'
exp=0 line=27 cur=None end=None text=None ch='\n'
exp=0 line=27 cur=None end=None text=None ch='n'
----- Found command: 'n'
exp=0 line=28 cur=None end=None text=None ch='\n'
exp=0 line=28 cur=None end=None text=None ch='N'
----- Found command: 'N'
exp=0 line=29 cur=None end=None text=None ch='\n'
exp=0 line=29 cur=None end=None text=None ch='p'
----- Found command: 'p'
exp=0 line=30 cur=None end=None text=None ch='\n'
exp=0 line=30 cur=None end=None text=None ch='P'
----- Found command: 'P'
exp=0 line=31 cur=None end=None text=None ch='\n'
exp=0 line=31 cur=None end=None text=None ch='q'
----- Found command: 'q'
exp=0 line=32 cur=None end=None text=None ch='\n'
int_arg: -1
exp=0 line=32 cur=None end=None text=None ch='savchar(\n)'
exp=0 line=32 cur=None end=None text=None ch='\n'
exp=0 line=32 cur=None end=None text=None ch='Q'
----- Found command: 'Q'
exp=0 line=33 cur=None end=None text=None ch='\n'
int_arg: -1
exp=0 line=33 cur=None end=None text=None ch='savchar(\n)'
exp=0 line=33 cur=None end=None text=None ch='\n'
exp=0 line=33 cur=None end=None text=None ch='t'
----- Found command: 't'
exp=0 line=34 cur=None end=None text=None ch='\n'
exp=0 line=34 cur=None end=None text=None ch='savchar(\n)'
exp=0 line=34 cur=None end=None text=None ch='\n'
label: ''
exp=0 line=34 cur=None end=None text=None ch='T'
----- Found command: 'T'
exp=0 line=35 cur=None end=None text=None ch='\n'
exp=0 line=35 cur=None end=None text=None ch='savchar(\n)'
exp=0 line=35 cur=None end=None text=None ch='\n'
label: ''
exp=0 line=35 cur=None end=None text=None ch='x'
----- Found command: 'x'
exp=0 line=36 cur=None end=None text=None ch='\n'
exp=0 line=36 cur=None end=None text=None ch='z'
----- Found command: 'z'
exp=0 line=37 cur=None end=None text=None ch='\n'
exp=0 line=38 cur=None end=None text=None ch='\n'
----- Found command: '\n'
exp=0 line=38 cur=None end=None text=None ch='#'
----- Found command: '#'
exp=0 line=38 cur=None end=None text=None ch=' '
exp=0 line=38 cur=None end=None text=None ch='C'
exp=0 line=38 cur=None end=None text=None ch='o'
exp=0 line=38 cur=None end=None text=None ch='m'
exp=0 line=38 cur=None end=None text=None ch='m'
exp=0 line=38 cur=None end=None text=None ch='a'
exp=0 line=38 cur=None end=None text=None ch='n'
exp=0 line=38 cur=None end=None text=None ch='d'
exp=0 line=38 cur=None end=None text=None ch='s'
exp=0 line=38 cur=None end=None text=None ch=' '
exp=0 line=38 cur=None end=None text=None ch='w'
exp=0 line=38 cur=None end=None text=None ch='i'
exp=0 line=38 cur=None end=None text=None ch='t'
exp=0 line=38 cur=None end=None text=None ch='h'
exp=0 line=38 cur=None end=None text=None ch=' '
exp=0 line=38 cur=None end=None text=None ch='n'
exp=0 line=38 cur=None end=None text=None ch='u'
exp=0 line=38 cur=None end=None text=None ch='m'
exp=0 line=38 cur=None end=None text=None ch='e'
exp=0 line=38 cur=None end=None text=None ch='r'
exp=0 line=38 cur=None end=None text=None ch='i'
exp=0 line=38 cur=None end=None text=None ch='c'
exp=0 line=38 cur=None end=None text=None ch=' '
exp=0 line=38 cur=None end=None text=None ch='a'
exp=0 line=38 cur=None end=None text=None ch='r'
exp=0 line=38 cur=None end=None text=None ch='g'
exp=0 line=38 cur=None end=None text=None ch='u'
exp=0 line=38 cur=None end=None text=None ch='m'
exp=0 line=38 cur=None end=None text=None ch='e'
exp=0 line=38 cur=None end=None text=None ch='n'
exp=0 line=38 cur=None end=None text=None ch='t'
exp=0 line=39 cur=None end=None text=None ch='\n'
comment: ' Commands with numeric argument'
exp=0 line=39 cur=None end=None text=None ch='q'
----- Found command: 'q'
exp=0 line=39 cur=None end=None text=None ch=' '
exp=0 line=39 cur=None end=None text=None ch='1'
exp=0 line=40 cur=None end=None text=None ch='\n'
exp=0 line=40 cur=None end=None text=None ch='savchar(\n)'
int_arg: 1
exp=0 line=40 cur=None end=None text=None ch='\n'
exp=0 line=40 cur=None end=None text=None ch='Q'
----- Found command: 'Q'
exp=0 line=40 cur=None end=None text=None ch=' '
exp=0 line=40 cur=None end=None text=None ch='2'
exp=0 line=40 cur=None end=None text=None ch='2'
exp=0 line=41 cur=None end=None text=None ch='\n'
exp=0 line=41 cur=None end=None text=None ch='savchar(\n)'
int_arg: 22
exp=0 line=41 cur=None end=None text=None ch='\n'
exp=0 line=41 cur=None end=None text=None ch='l'
----- Found command: 'l'
exp=0 line=41 cur=None end=None text=None ch=' '
exp=0 line=41 cur=None end=None text=None ch='3'
exp=0 line=41 cur=None end=None text=None ch='3'
exp=0 line=41 cur=None end=None text=None ch='3'
exp=0 line=42 cur=None end=None text=None ch='\n'
exp=0 line=42 cur=None end=None text=None ch='savchar(\n)'
int_arg: 333
exp=0 line=42 cur=None end=None text=None ch='\n'
exp=0 line=42 cur=None end=None text=None ch='L'
----- Found command: 'L'
exp=0 line=42 cur=None end=None text=None ch=' '
exp=0 line=42 cur=None end=None text=None ch='4'
exp=0 line=42 cur=None end=None text=None ch='4'
exp=0 line=42 cur=None end=None text=None ch='4'
exp=0 line=42 cur=None end=None text=None ch='4'
exp=0 line=43 cur=None end=None text=None ch='\n'
exp=0 line=43 cur=None end=None text=None ch='savchar(\n)'
int_arg: 4444
exp=0 line=43 cur=None end=None text=None ch='\n'
exp=0 line=44 cur=None end=None text=None ch='\n'
----- Found command: '\n'
exp=0 line=44 cur=None end=None text=None ch='#'
----- Found command: '#'
exp=0 line=44 cur=None end=None text=None ch=' '
exp=0 line=44 cur=None end=None text=None ch='C'
exp=0 line=44 cur=None end=None text=None ch='o'
exp=0 line=44 cur=None end=None text=None ch='m'
exp=0 line=44 cur=None end=None text=None ch='m'
exp=0 line=44 cur=None end=None text=None ch='a'
exp=0 line=44 cur=None end=None text=None ch='n'
exp=0 line=44 cur=None end=None text=None ch='d'
exp=0 line=44 cur=None end=None text=None ch='s'
exp=0 line=44 cur=None end=None text=None ch=' '
exp=0 line=44 cur=None end=None text=None ch='w'
exp=0 line=44 cur=None end=None text=None ch='i'
exp=0 line=44 cur=None end=None text=None ch='t'
exp=0 line=44 cur=None end=None text=None ch='h'
exp=0 line=44 cur=None end=None text=None ch=' '
exp=0 line=44 cur=None end=None text=None ch='l'
exp=0 line=44 cur=None end=None text=None ch='a'
exp=0 line=44 cur=None end=None text=None ch='b'
exp=0 line=44 cur=None end=None text=None ch='e'
exp=0 line=44 cur=None end=None text=None ch='l'
exp=0 line=44 cur=None end=None text=None ch='s'
exp=0 line=45 cur=None end=None text=None ch='\n'
comment: ' Commands with labels'
exp=0 line=45 cur=None end=None text=None ch=':'
----- Found command: ':'
exp=0 line=45 cur=None end=None text=None ch=' '
exp=0 line=45 cur=None end=None text=None ch='l'
exp=0 line=45 cur=None end=None text=None ch='a'
exp=0 line=45 cur=None end=None text=None ch='b'
exp=0 line=45 cur=None end=None text=None ch='e'
exp=0 line=45 cur=None end=None text=None ch='l'
exp=0 line=46 cur=None end=None text=None ch='\n'
exp=0 line=46 cur=None end=None text=None ch='savchar(\n)'
exp=0 line=46 cur=None end=None text=None ch='\n'
label: 'label'
exp=0 line=46 cur=None end=None text=None ch='b'
----- Found command: 'b'
exp=0 line=46 cur=None end=None text=None ch=' '
exp=0 line=46 cur=None end=None text=None ch='l'
exp=0 line=46 cur=None end=None text=None ch='a'
exp=0 line=46 cur=None end=None text=None ch='b'
exp=0 line=46 cur=None end=None text=None ch='e'
exp=0 line=46 cur=None end=None text=None ch='l'
exp=0 line=46 cur=None end=None text=None ch='_'
exp=0 line=46 cur=None end=None text=None ch='b'
exp=0 line=47 cur=None end=None text=None ch='\n'
exp=0 line=47 cur=None end=None text=None ch='savchar(\n)'
exp=0 line=47 cur=None end=None text=None ch='\n'
label: 'label_b'
exp=0 line=47 cur=None end=None text=None ch='t'
----- Found command: 't'
exp=0 line=47 cur=None end=None text=None ch=' '
exp=0 line=47 cur=None end=None text=None ch='l'
exp=0 line=47 cur=None end=None text=None ch='a'
exp=0 line=47 cur=None end=None text=None ch='b'
exp=0 line=47 cur=None end=None text=None ch='e'
exp=0 line=47 cur=None end=None text=None ch='l'
exp=0 line=47 cur=None end=None text=None ch='_'
exp=0 line=47 cur=None end=None text=None ch='t'
exp=0 line=48 cur=None end=None text=None ch='\n'
exp=0 line=48 cur=None end=None text=None ch='savchar(\n)'
exp=0 line=48 cur=None end=None text=None ch='\n'
label: 'label_t'
exp=0 line=48 cur=None end=None text=None ch='T'
----- Found command: 'T'
exp=0 line=48 cur=None end=None text=None ch=' '
exp=0 line=48 cur=None end=None text=None ch='l'
exp=0 line=48 cur=None end=None text=None ch='a'
exp=0 line=48 cur=None end=None text=None ch='b'
exp=0 line=48 cur=None end=None text=None ch='e'
exp=0 line=48 cur=None end=None text=None ch='l'
exp=0 line=48 cur=None end=None text=None ch='_'
exp=0 line=48 cur=None end=None text=None ch='T'
exp=0 line=49 cur=None end=None text=None ch='\n'
exp=0 line=49 cur=None end=None text=None ch='savchar(\n)'
exp=0 line=49 cur=None end=None text=None ch='\n'
label: 'label_T'
exp=0 line=50 cur=None end=None text=None ch='\n'
----- Found command: '\n'
exp=0 line=50 cur=None end=None text=None ch='#'
----- Found command: '#'
exp=0 line=50 cur=None end=None text=None ch=' '
exp=0 line=50 cur=None end=None text=None ch='C'
exp=0 line=50 cur=None end=None text=None ch='o'
exp=0 line=50 cur=None end=None text=None ch='m'
exp=0 line=50 cur=None end=None text=None ch='m'
exp=0 line=50 cur=None end=None text=None ch='a'
exp=0 line=50 cur=None end=None text=None ch='n'
exp=0 line=50 cur=None end=None text=None ch='d'
exp=0 line=50 cur=None end=None text=None ch=' '
exp=0 line=50 cur=None end=None text=None ch='v'
exp=0 line=50 cur=None end=None text=None ch=' '
exp=0 line=50 cur=None end=None text=None ch='('
exp=0 line=50 cur=None end=None text=None ch='l'
exp=0 line=50 cur=None end=None text=None ch='a'
exp=0 line=50 cur=None end=None text=None ch='b'
exp=0 line=50 cur=None end=None text=None ch='e'
exp=0 line=50 cur=None end=None text=None ch='l'
exp=0 line=50 cur=None end=None text=None ch='-'
exp=0 line=50 cur=None end=None text=None ch='l'
exp=0 line=50 cur=None end=None text=None ch='i'
exp=0 line=50 cur=None end=None text=None ch='k'
exp=0 line=50 cur=None end=None text=None ch='e'
exp=0 line=50 cur=None end=None text=None ch=')'
exp=0 line=51 cur=None end=None text=None ch='\n'
comment: ' Command v (label-like)'
exp=0 line=51 cur=None end=None text=None ch='v'
----- Found command: 'v'
exp=0 line=51 cur=None end=None text=None ch=' '
exp=0 line=51 cur=None end=None text=None ch='4'
exp=0 line=51 cur=None end=None text=None ch='.'
exp=0 line=51 cur=None end=None text=None ch='2'
exp=0 line=52 cur=None end=None text=None ch='\n'
exp=0 line=52 cur=None end=None text=None ch='savchar(\n)'
exp=0 line=52 cur=None end=None text=None ch='\n'
argument: 4.2
exp=0 line=53 cur=None end=None text=None ch='\n'
----- Found command: '\n'
exp=0 line=53 cur=None end=None text=None ch='#'
----- Found command: '#'
exp=0 line=53 cur=None end=None text=None ch=' '
exp=0 line=53 cur=None end=None text=None ch='C'
exp=0 line=53 cur=None end=None text=None ch='o'
exp=0 line=53 cur=None end=None text=None ch='m'
exp=0 line=53 cur=None end=None text=None ch='m'
exp=0 line=53 cur=None end=None text=None ch='a'
exp=0 line=53 cur=None end=None text=None ch='n'
exp=0 line=53 cur=None end=None text=None ch='d'
exp=0 line=53 cur=None end=None text=None ch='s'
exp=0 line=53 cur=None end=None text=None ch=' '
exp=0 line=53 cur=None end=None text=None ch='w'
exp=0 line=53 cur=None end=None text=None ch='i'
exp=0 line=53 cur=None end=None text=None ch='t'
exp=0 line=53 cur=None end=None text=None ch='h'
exp=0 line=53 cur=None end=None text=None ch=' '
exp=0 line=53 cur=None end=None text=None ch='f'
exp=0 line=53 cur=None end=None text=None ch='i'
exp=0 line=53 cur=None end=None text=None ch='l'
exp=0 line=53 cur=None end=None text=None ch='e'
exp=0 line=53 cur=None end=None text=None ch='s'
exp=0 line=54 cur=None end=None text=None ch='\n'
comment: ' Commands with files'
exp=0 line=54 cur=None end=None text=None ch='r'
----- Found command: 'r'
exp=0 line=54 cur=None end=None text=None ch=' '
exp=0 line=54 cur=None end=None text=None ch='f'
exp=0 line=54 cur=None end=None text=None ch='i'
exp=0 line=54 cur=None end=None text=None ch='l'
exp=0 line=54 cur=None end=None text=None ch='e'
exp=0 line=54 cur=None end=None text=None ch='_'
exp=0 line=54 cur=None end=None text=None ch='r'
exp=0 line=55 cur=None end=None text=None ch='\n'
filename: 'file_r'
exp=0 line=55 cur=None end=None text=None ch='R'
----- Found command: 'R'
exp=0 line=55 cur=None end=None text=None ch=' '
exp=0 line=55 cur=None end=None text=None ch='f'
exp=0 line=55 cur=None end=None text=None ch='i'
exp=0 line=55 cur=None end=None text=None ch='l'
exp=0 line=55 cur=None end=None text=None ch='e'
exp=0 line=55 cur=None end=None text=None ch='_'
exp=0 line=55 cur=None end=None text=None ch='R'
exp=0 line=56 cur=None end=None text=None ch='\n'
filename: 'file_R'
exp=0 line=56 cur=None end=None text=None ch='w'
----- Found command: 'w'
exp=0 line=56 cur=None end=None text=None ch=' '
exp=0 line=56 cur=None end=None text=None ch='f'
exp=0 line=56 cur=None end=None text=None ch='i'
exp=0 line=56 cur=None end=None text=None ch='l'
exp=0 line=56 cur=None end=None text=None ch='e'
exp=0 line=56 cur=None end=None text=None ch='_'
exp=0 line=56 cur=None end=None text=None ch='w'
exp=0 line=57 cur=None end=None text=None ch='\n'
filename: 'file_w'
exp=0 line=57 cur=None end=None text=None ch='W'
----- Found command: 'W'
exp=0 line=57 cur=None end=None text=None ch=' '
exp=0 line=57 cur=None end=None text=None ch='f'
exp=0 line=57 cur=None end=None text=None ch='i'
exp=0 line=57 cur=None end=None text=None ch='l'
exp=0 line=57 cur=None end=None text=None ch='e'
exp=0 line=57 cur=None end=None text=None ch='_'
exp=0 line=57 cur=None end=None text=None ch='W'
exp=0 line=58 cur=None end=None text=None ch='\n'
filename: 'file_W'
exp=0 line=59 cur=None end=None text=None ch='\n'
----- Found command: '\n'
exp=0 line=59 cur=None end=None text=None ch='#'
----- Found command: '#'
exp=0 line=59 cur=None end=None text=None ch=' '
exp=0 line=59 cur=None end=None text=None ch='C'
exp=0 line=59 cur=None end=None text=None ch='o'
exp=0 line=59 cur=None end=None text=None ch='m'
exp=0 line=59 cur=None end=None text=None ch='m'
exp=0 line=59 cur=None end=None text=None ch='a'
exp=0 line=59 cur=None end=None text=None ch='n'
exp=0 line=59 cur=None end=None text=None ch='d'
exp=0 line=59 cur=None end=None text=None ch='s'
exp=0 line=59 cur=None end=None text=None ch=' '
exp=0 line=59 cur=None end=None text=None ch='w'
exp=0 line=59 cur=None end=None text=None ch='i'
exp=0 line=59 cur=None end=None text=None ch='t'
exp=0 line=59 cur=None end=None text=None ch='h'
exp=0 line=59 cur=None end=None text=None ch=' '
exp=0 line=59 cur=None end=None text=None ch='t'
exp=0 line=59 cur=None end=None text=None ch='e'
exp=0 line=59 cur=None end=None text=None ch='x'
exp=0 line=59 cur=None end=None text=None ch='t'
exp=0 line=60 cur=None end=None text=None ch='\n'
comment: ' Commands with text'
exp=0 line=60 cur=None end=None text=None ch='a'
----- Found command: 'a'
exp=0 line=60 cur=None end=None text=None ch=' '
exp=0 line=60 cur=None end=None text=None ch='t'
exp=0 line=60 cur=None end=None text=None ch='savchar(t)'
exp=0 line=60 cur=None end=None text=None ch='t'
exp=0 line=60 cur=None end=None text=None ch='e'
exp=0 line=60 cur=None end=None text=None ch='x'
exp=0 line=60 cur=None end=None text=None ch='t'
exp=0 line=60 cur=None end=None text=None ch='_'
exp=0 line=60 cur=None end=None text=None ch='a'
exp=0 line=61 cur=None end=None text=None ch='\n'
text: struct_text_buf(text=['t', 'e', 'x', 't', '_', 'a', '\n'])
exp=0 line=61 cur=None end=None text=None ch='i'
----- Found command: 'i'
exp=0 line=61 cur=None end=None text=None ch='\\'
exp=0 line=62 cur=None end=None text=None ch='\n'
exp=0 line=62 cur=None end=None text=None ch='t'
exp=0 line=62 cur=None end=None text=None ch='e'
exp=0 line=62 cur=None end=None text=None ch='x'
exp=0 line=62 cur=None end=None text=None ch='t'
exp=0 line=62 cur=None end=None text=None ch='_'
exp=0 line=62 cur=None end=None text=None ch='i'
exp=0 line=63 cur=None end=None text=None ch='\n'
text: struct_text_buf(text=['t', 'e', 'x', 't', '_', 'i', '\n'])
exp=0 line=63 cur=None end=None text=None ch='c'
----- Found command: 'c'
exp=0 line=63 cur=None end=None text=None ch='\\'
exp=0 line=64 cur=None end=None text=None ch='\n'
exp=0 line=64 cur=None end=None text=None ch='t'
exp=0 line=64 cur=None end=None text=None ch='e'
exp=0 line=64 cur=None end=None text=None ch='x'
exp=0 line=64 cur=None end=None text=None ch='t'
exp=0 line=64 cur=None end=None text=None ch='_'
exp=0 line=64 cur=None end=None text=None ch='c'
exp=0 line=64 cur=None end=None text=None ch='1'
exp=0 line=64 cur=None end=None text=None ch=' '
exp=0 line=64 cur=None end=None text=None ch='\\'
exp=0 line=65 cur=None end=None text=None ch='\n'
exp=0 line=65 cur=None end=None text=None ch='t'
exp=0 line=65 cur=None end=None text=None ch='e'
exp=0 line=65 cur=None end=None text=None ch='x'
exp=0 line=65 cur=None end=None text=None ch='t'
exp=0 line=65 cur=None end=None text=None ch='_'
exp=0 line=65 cur=None end=None text=None ch='c'
exp=0 line=65 cur=None end=None text=None ch='2'
exp=0 line=66 cur=None end=None text=None ch='\n'
text: struct_text_buf(text=['t', 'e', 'x', 't', '_', 'c', '1', ' ', '\\', '\n', 't', 'e', 'x', 't', '_', 'c', '2', '\n'])
exp=0 line=67 cur=None end=None text=None ch='\n'
----- Found command: '\n'
exp=0 line=67 cur=None end=None text=None ch='#'
----- Found command: '#'
exp=0 line=67 cur=None end=None text=None ch=' '
exp=0 line=67 cur=None end=None text=None ch='C'
exp=0 line=67 cur=None end=None text=None ch='o'
exp=0 line=67 cur=None end=None text=None ch='m'
exp=0 line=67 cur=None end=None text=None ch='m'
exp=0 line=67 cur=None end=None text=None ch='a'
exp=0 line=67 cur=None end=None text=None ch='n'
exp=0 line=67 cur=None end=None text=None ch='d'
exp=0 line=67 cur=None end=None text=None ch=' '
exp=0 line=67 cur=None end=None text=None ch='e'
exp=0 line=67 cur=None end=None text=None ch=' '
exp=0 line=67 cur=None end=None text=None ch='('
exp=0 line=67 cur=None end=None text=None ch='t'
exp=0 line=67 cur=None end=None text=None ch='e'
exp=0 line=67 cur=None end=None text=None ch='x'
exp=0 line=67 cur=None end=None text=None ch='t'
exp=0 line=67 cur=None end=None text=None ch='-'
exp=0 line=67 cur=None end=None text=None ch='l'
exp=0 line=67 cur=None end=None text=None ch='i'
exp=0 line=67 cur=None end=None text=None ch='k'
exp=0 line=67 cur=None end=None text=None ch='e'
exp=0 line=67 cur=None end=None text=None ch=')'
exp=0 line=68 cur=None end=None text=None ch='\n'
comment: ' Command e (text-like)'
exp=0 line=68 cur=None end=None text=None ch='e'
----- Found command: 'e'
exp=0 line=68 cur=None end=None text=None ch=' '
exp=0 line=68 cur=None end=None text=None ch='d'
exp=0 line=68 cur=None end=None text=None ch='savchar(d)'
exp=0 line=68 cur=None end=None text=None ch='d'
exp=0 line=68 cur=None end=None text=None ch='a'
exp=0 line=68 cur=None end=None text=None ch='t'
exp=0 line=68 cur=None end=None text=None ch='e'
exp=0 line=69 cur=None end=None text=None ch='\n'
text: struct_text_buf(text=['d', 'a', 't', 'e', '\n'])
exp=0 line=70 cur=None end=None text=None ch='\n'
----- Found command: '\n'
exp=0 line=70 cur=None end=None text=None ch='#'
----- Found command: '#'
exp=0 line=70 cur=None end=None text=None ch=' '
exp=0 line=70 cur=None end=None text=None ch='C'
exp=0 line=70 cur=None end=None text=None ch='o'
exp=0 line=70 cur=None end=None text=None ch='m'
exp=0 line=70 cur=None end=None text=None ch='m'
exp=0 line=70 cur=None end=None text=None ch='a'
exp=0 line=70 cur=None end=None text=None ch='n'
exp=0 line=70 cur=None end=None text=None ch='d'
exp=0 line=70 cur=None end=None text=None ch=' '
exp=0 line=70 cur=None end=None text=None ch='y'
exp=0 line=71 cur=None end=None text=None ch='\n'
comment: ' Command y'
exp=0 line=71 cur=None end=None text=None ch='y'
----- Found command: 'y'
exp=0 line=71 cur=None end=None text=None ch='/'
exp=0 line=71 cur=None end=None text=None ch='a'
exp=0 line=71 cur=None end=None text=None ch='b'
exp=0 line=71 cur=None end=None text=None ch='c'
exp=0 line=71 cur=None end=None text=None ch='/'
y pattern: 'abc'
exp=0 line=71 cur=None end=None text=None ch='1'
exp=0 line=71 cur=None end=None text=None ch='2'
exp=0 line=71 cur=None end=None text=None ch='3'
exp=0 line=71 cur=None end=None text=None ch='/'
y replacement: '123'
exp=0 line=72 cur=None end=None text=None ch='\n'
exp=0 line=72 cur=None end=None text=None ch='y'
----- Found command: 'y'
exp=0 line=72 cur=None end=None text=None ch='@'
exp=0 line=72 cur=None end=None text=None ch='a'
exp=0 line=72 cur=None end=None text=None ch='b'
exp=0 line=72 cur=None end=None text=None ch='c'
exp=0 line=72 cur=None end=None text=None ch='@'
y pattern: 'abc'
exp=0 line=72 cur=None end=None text=None ch='1'
exp=0 line=72 cur=None end=None text=None ch='2'
exp=0 line=72 cur=None end=None text=None ch='3'
exp=0 line=72 cur=None end=None text=None ch='@'
y replacement: '123'
exp=0 line=73 cur=None end=None text=None ch='\n'
exp=0 line=74 cur=None end=None text=None ch='\n'
----- Found command: '\n'
exp=0 line=74 cur=None end=None text=None ch='#'
----- Found command: '#'
exp=0 line=74 cur=None end=None text=None ch=' '
exp=0 line=74 cur=None end=None text=None ch='C'
exp=0 line=74 cur=None end=None text=None ch='o'
exp=0 line=74 cur=None end=None text=None ch='m'
exp=0 line=74 cur=None end=None text=None ch='m'
exp=0 line=74 cur=None end=None text=None ch='a'
exp=0 line=74 cur=None end=None text=None ch='n'
exp=0 line=74 cur=None end=None text=None ch='d'
exp=0 line=74 cur=None end=None text=None ch=' '
exp=0 line=74 cur=None end=None text=None ch='s'
exp=0 line=75 cur=None end=None text=None ch='\n'
comment: ' Command s'
exp=0 line=75 cur=None end=None text=None ch='s'
----- Found command: 's'
exp=0 line=75 cur=None end=None text=None ch='/'
exp=0 line=75 cur=None end=None text=None ch='/'
s pattern: ''
exp=0 line=75 cur=None end=None text=None ch='/'
s replacement: ''
exp=0 line=76 cur=None end=None text=None ch='\n'
s flag candidate: '\n'
s flags: ''
exp=0 line=76 cur=None end=None text=None ch='s'
----- Found command: 's'
exp=0 line=76 cur=None end=None text=None ch='|'
exp=0 line=76 cur=None end=None text=None ch='|'
s pattern: ''
exp=0 line=76 cur=None end=None text=None ch='|'
s replacement: ''
exp=0 line=76 cur=None end=None text=None ch='3'
s flag candidate: '3'
exp=0 line=77 cur=None end=None text=None ch='\n'
exp=0 line=77 cur=None end=None text=None ch='savchar(\n)'
exp=0 line=77 cur=None end=None text=None ch='\n'
s flag candidate: '\n'
s flags: '3'
exp=0 line=77 cur=None end=None text=None ch='s'
----- Found command: 's'
exp=0 line=77 cur=None end=None text=None ch='/'
exp=0 line=77 cur=None end=None text=None ch='p'
exp=0 line=77 cur=None end=None text=None ch='a'
exp=0 line=77 cur=None end=None text=None ch='t'
exp=0 line=77 cur=None end=None text=None ch='t'
exp=0 line=77 cur=None end=None text=None ch='/'
s pattern: 'patt'
exp=0 line=77 cur=None end=None text=None ch='r'
exp=0 line=77 cur=None end=None text=None ch='e'
exp=0 line=77 cur=None end=None text=None ch='p'
exp=0 line=77 cur=None end=None text=None ch='l'
exp=0 line=77 cur=None end=None text=None ch='/'
s replacement: 'repl'
exp=0 line=77 cur=None end=None text=None ch='g'
s flag candidate: 'g'
exp=0 line=77 cur=None end=None text=None ch='i'
s flag candidate: 'i'
exp=0 line=77 cur=None end=None text=None ch='p'
s flag candidate: 'p'
exp=0 line=77 cur=None end=None text=None ch='w'
s flag candidate: 'w'
exp=0 line=77 cur=None end=None text=None ch=' '
exp=0 line=77 cur=None end=None text=None ch='f'
exp=0 line=77 cur=None end=None text=None ch='i'
exp=0 line=77 cur=None end=None text=None ch='l'
exp=0 line=77 cur=None end=None text=None ch='e'
exp=0 line=77 cur=None end=None text=None ch='w'
exp=0 line=78 cur=None end=None text=None ch='\n'
s flag filename: 'filew'
s flags: 'gipw'
exp=0 line=79 cur=None end=None text=None ch='\n'
----- Found command: '\n'
exp=0 line=79 cur=None end=None text=None ch='#'
----- Found command: '#'
exp=0 line=79 cur=None end=None text=None ch=' '
exp=0 line=79 cur=None end=None text=None ch='B'
exp=0 line=79 cur=None end=None text=None ch='l'
exp=0 line=79 cur=None end=None text=None ch='o'
exp=0 line=79 cur=None end=None text=None ch='c'
exp=0 line=79 cur=None end=None text=None ch='k'
exp=0 line=79 cur=None end=None text=None ch='s'
exp=0 line=80 cur=None end=None text=None ch='\n'
comment: ' Blocks'
exp=0 line=80 cur=None end=None text=None ch='$'
----- Found address 1: struct_addr(addr_type=7, addr_number=0, addr_step=0, addr_regex=None)
exp=0 line=80 cur=None end=None text=None ch=' '
exp=0 line=80 cur=None end=None text=None ch='{'
----- Found command: '{'
exp=0 line=81 cur=None end=None text=None ch='\n'
exp=0 line=81 cur=None end=None text=None ch=' '
exp=0 line=81 cur=None end=None text=None ch=' '
exp=0 line=81 cur=None end=None text=None ch=' '
exp=0 line=81 cur=None end=None text=None ch=' '
exp=0 line=81 cur=None end=None text=None ch='p'
----- Found command: 'p'
exp=0 line=82 cur=None end=None text=None ch='\n'
exp=0 line=82 cur=None end=None text=None ch='}'
----- Found command: '}'
exp=0 line=83 cur=None end=None text=None ch='\n'
exp=0 line=83 cur=None end=None text=None ch=''
sedparse-0.1.2/tests/test_cmdline.md 0000664 0000000 0000000 00000004517 13566611474 0017502 0 ustar 00root root 0000000 0000000 # sedparse command line tests
Just run `clitest --prefix 4 tests/test_cmdline.md` to test this file.
Note that tests for combining `-e` and `-f` in the same command are made in `test_misc.py`.
## Help message
$ python sedparse.py -h | sed 1q
usage: sedparse.py [-h] [-e script] [-f script-file] [--full] [-v] [-V]
$
## Show version
Redirecting because in Python 2.7 the version number is sent to STDERR.
$ python sedparse.py --version 2>&1 | tr -s 0-9 9
sedparse.py 9.9.9
$
## No sed script informed
$ python sedparse.py
sedparse: No sed script to be parsed. Use -e and/or -f.
$ python sedparse.py --full --verbose
sedparse: No sed script to be parsed. Use -e and/or -f.
$
## Error message when using an expression
$ python sedparse.py -e k
sedparse: -e expression #1, char 1: unknown command: `k'
$
## Error message when using a file
$ echo k > k.sed
$ echo k | python sedparse.py -f k.sed
sedparse: file k.sed line 1: unknown command: `k'
$ rm k.sed
## Error message when using STDIN
$ echo k | python sedparse.py -f -
sedparse: file - line 1: unknown command: `k'
$
## Runtime errors are sent to STDERR and return 1
$ python sedparse.py >/dev/null; echo $?
sedparse: No sed script to be parsed. Use -e and/or -f.
1
$
Parse errors are already well tested in `test_errors.py`.
## Normal execution should print to STDOUT and return zero
$ python sedparse.py -e x 2>/dev/null; echo $?
[
{
"cmd": "x",
"line": 1
}
]
0
$
## Empty sed script
$ python sedparse.py -e ''
[]
$ touch empty.sed
$ python sedparse.py -f empty.sed
[]
$ cat empty.sed | python sedparse.py -f -
[]
$ rm empty.sed
$
## Both -e and --expression should work
$ python sedparse.py -e x
[
{
"cmd": "x",
"line": 1
}
]
$ python sedparse.py --expression x
[
{
"cmd": "x",
"line": 1
}
]
$
## Both -f and --file should work
$ echo x > x.sed
$ python sedparse.py -f x.sed
[
{
"cmd": "x",
"line": 1
}
]
$ python sedparse.py --file x.sed
[
{
"cmd": "x",
"line": 1
}
]
$ rm x.sed
$
sedparse-0.1.2/tests/test_errors.py 0000664 0000000 0000000 00000007550 13566611474 0017433 0 ustar 00root root 0000000 0000000 # Test all error messages.
# coding: utf-8
import unittest
from context import sedparse
TEST_DATA = [
# pylint: disable=bad-whitespace
# fmt: off
# Note: Not all possible error messages are tested, those that were left
# out are not available in the port.
# Format: (sed script, char nr, constant, error message)
# ANCIENT_VERSION expected newer version of sed
("!!p", 2, "BAD_BANG", "multiple `!'s"),
("1,p", 3, "BAD_COMMA", "unexpected `,'"),
("s★a★b★", 2, "BAD_DELIM",
"delimiter character is not a single-byte character"),
("+1p", 2, "BAD_STEP", "invalid usage of +N or ~N as first address"),
("~1p", 2, "BAD_STEP", "invalid usage of +N or ~N as first address"),
(":", 1, "COLON_LACKS_LABEL", '":" lacks a label'),
# DISALLOWED_CMD e/r/w commands disabled in sandbox mode
("}", 1, "EXCESS_CLOSE_BRACE", "unexpected `}'"),
("b}", 2, "EXCESS_CLOSE_BRACE", "unexpected `}'"),
("bx}", 3, "EXCESS_CLOSE_BRACE", "unexpected `}'"),
("s/a/b/gg", 8, "EXCESS_G_OPT", "multiple `g' options to `s' command"),
("dp", 2, "EXCESS_JUNK", "extra characters after command"),
("xx", 2, "EXCESS_JUNK", "extra characters after command"),
("s/a/b/2p2", 9, "EXCESS_N_OPT", "multiple number options to `s' command"),
("{", 0, "EXCESS_OPEN_BRACE", "unmatched `{'"),
# ^here it should be 1. It's a GNU sed bug that sedparse emulates.
("s/a/b/pp", 8, "EXCESS_P_OPT", "multiple `p' options to `s' command"),
("a", 1, "EXPECTED_SLASH", "expected \\ after `a', `c' or `i'"),
# INCOMPLETE_CMD incomplete command
("0p", 2, "INVALID_LINE_0", "invalid usage of line address 0"),
("0,5p", 4, "INVALID_LINE_0", "invalid usage of line address 0"),
("s/a/b/w", 7, "MISSING_FILENAME", "missing filename in r/R/w/W commands"),
("r", 1, "MISSING_FILENAME", "missing filename in r/R/w/W commands"),
("{p;$}", 5, "NO_CLOSE_BRACE_ADDR", "`}' doesn't want any addresses"),
# NO_COLON_ADDR : doesn't want any addresses
("1", 1, "NO_COMMAND", "missing command"),
("1\n", 2, "NO_COMMAND", "missing command"),
# NO_SHARP_ADDR comments don't accept any addresses
# ONE_ADDR command only uses one address
# RECURSIVE_ESCAPE_C recursive escaping after \\c not allowed
("u", 1, "UNKNOWN_CMD", "unknown command: `u'"),
("s/a/b/z", 7, "UNKNOWN_S_OPT", "unknown option to `s'"),
("s/a/b/\r", 7, "UNKNOWN_S_OPT", "unknown option to `s'"),
("/a", 2, "UNTERM_ADDR_RE", "unterminated address regex"),
("s/a/b", 5, "UNTERM_S_CMD", "unterminated `s' command"),
("y/a/", 4, "UNTERM_Y_CMD", "unterminated `y' command"),
# Y_CMD_LEN strings for `y' command are different lengths
("s/a/b/0", 7, "ZERO_N_OPT", "number option to `s' command may not be zero"),
]
class TestSedparseErrors(unittest.TestCase): # pylint: disable=unused-variable
def test_errors(self):
for script, char_nr, _, message in TEST_DATA:
expected = "sedparse: -e expression #%d, char %d: %s" % (
sedparse.cur_input.string_expr_count + 1,
char_nr,
message,
)
try:
parsed = []
sedparse.compile_string(parsed, script)
sedparse.check_final_program()
self.fail(msg=script) # it should never reach here
except sedparse.ParseError as err:
self.assertEqual(expected, err.message, msg=script)
self.assertEqual(sedparse.EXIT_BAD_USAGE, err.exitcode, msg=script)
if __name__ == "__main__":
unittest.main()
sedparse-0.1.2/tests/test_misc.py 0000664 0000000 0000000 00000012575 13566611474 0017055 0 ustar 00root root 0000000 0000000 # Misc tests.
# coding: utf-8
import json
import os
import tempfile
import unittest
from context import sedparse
from utils import parse_string
class TestSedparseMisc(unittest.TestCase): # pylint: disable=unused-variable
def test_string_expr_count(self):
"""Calling compile_string() should increase by one the expression count."""
before = sedparse.cur_input.string_expr_count
_ = parse_string("p")
_ = parse_string("p")
_ = parse_string("p")
after = sedparse.cur_input.string_expr_count
self.assertEqual(before + 3, after)
def test_global_data_cleanup(self):
"""
Global variables should be reset after an error and after the end of
normal execution, to avoid leaking and affecting the next run.
"""
# After compile_string(), prog.* should be NULL
script = ["p", "x", "s/foo/bar/g"]
sedparse.compile_string([], "\n".join(script))
self.assertIsNone(sedparse.prog.base)
self.assertIsNone(sedparse.prog.cur)
self.assertIsNone(sedparse.prog.end)
self.assertIsNone(sedparse.prog.text)
# After compile_file(), prog.file should be NULL
script = ["p", "x", "s/foo/bar/g"]
with tempfile.NamedTemporaryFile(mode="w", delete=False) as file:
file.write("\n".join(script))
filename = file.name
sedparse.compile_file([], filename)
self.assertIsNone(sedparse.prog.file)
os.remove(filename)
# After normal execution, blocks is back to zero and old_text_buf will
# still hold some contents.
script = ["{", "i\\", "foo", "}"]
_ = parse_string("\n".join(script))
self.assertEqual(0, sedparse.blocks)
self.assertIsNone(sedparse.pending_text)
# After an error, every global should be reset
script = ["{", "i\\", "foo", "XXX"]
try:
_ = parse_string("\n".join(script))
except sedparse.ParseError:
pass
self.assertEqual(0, sedparse.blocks)
self.assertIsNone(sedparse.old_text_buf)
self.assertIsNone(sedparse.pending_text)
self.assertIsNone(sedparse.prog.base)
self.assertIsNone(sedparse.prog.cur)
self.assertIsNone(sedparse.prog.end)
self.assertIsNone(sedparse.prog.text)
self.assertIsNone(sedparse.prog.file)
def test_expressions_and_files(self):
"""
In the commmand line, the sed script to be parsed can be informed using
a string `-e` and/or a file `-f`. Both options can be used multiple
times to compose a larger script in smaller chunks. The original option
order is respected. This mimics how GNU sed itself works.
Option `-e` is mapped to `compile_string()` and option `-f` is mapped to
`compile_file()`. Both are called here in different combinations to make
sure they work as expected.
"""
# Create a script file
with tempfile.NamedTemporaryFile(mode="w", delete=False) as file:
file.write("x\n")
filename = file.name
data = [
# @ means the file must be loaded (-f file)
(["@"], ["x"]),
(["p"], ["p"]),
(["p", "d", "q"], ["p", "d", "q"]),
(["@", "p"], ["x", "p"]),
(["p", "@"], ["p", "x"]),
(["p", "@", "d", "@", "q"], ["p", "x", "d", "x", "q"]),
]
for scripts, expected_commands in data:
args = []
for script in scripts:
if script == "@":
args.extend(["-f", filename])
else:
args.extend(["-e", script])
the_json = sedparse.main(args)
the_program = json.loads(the_json)
self.assertEqual(
expected_commands, [x["cmd"] for x in the_program], msg=scripts
)
os.remove(filename)
def test_savchar_with_unicode(self):
"""
savchar() should handle Unicode characters correctly. That means going
back N bytes when the input is a file, where N is the lenght in bytes of
the current Unicode character (i.e., ★ is composed of 3 bytes).
In this test, while reading the numeric argument for the "q" command in
`in_integer()`, it will detect the "9" and then a non-number "★". At
this point `savchar()` will be called to go back before the "★". Then
the parser will read "★" again and complain about "extra characters
after command". If Unicode backtracking is not supported, the parser
error would be different.
"""
script = "q9★\n"
# Create a script file
with tempfile.NamedTemporaryFile(mode="w", delete=False) as file:
file.write(script)
filename = file.name
# Test reading from a file (-f)
with self.assertRaises(sedparse.ParseError) as manager:
sedparse.compile_file([], filename)
self.assertTrue(
manager.exception.message.endswith("extra characters after command")
)
os.remove(filename)
# Test reading from a string (-e)
with self.assertRaises(sedparse.ParseError) as manager:
sedparse.compile_string([], script)
self.assertTrue(
manager.exception.message.endswith("extra characters after command")
)
if __name__ == "__main__":
unittest.main()
sedparse-0.1.2/tests/test_output.py 0000664 0000000 0000000 00000006127 13566611474 0017456 0 ustar 00root root 0000000 0000000 # Test output from struct.to_dict() and struct.to_json().
import json
import unittest
from utils import parse_string
class TestSedparseOutput(unittest.TestCase): # pylint: disable=unused-variable
def test_diet(self):
data = [
(
"0~2p",
{
"a1": {"addr_type": 4, "addr_number": 0, "addr_step": 2},
"cmd": "p",
"line": 1,
},
),
(
"1,~2p",
{
"a1": {"addr_type": 3, "addr_number": 1},
"a2": {"addr_type": 6, "addr_number": 0, "addr_step": 2},
"cmd": "p",
"line": 1,
},
),
(
"1,+2p",
{
"a1": {"addr_type": 3, "addr_number": 1},
"a2": {"addr_type": 5, "addr_number": 0, "addr_step": 2},
"cmd": "p",
"line": 1,
},
),
(
"/x/p",
{
"a1": {
"addr_type": 2,
"addr_regex": {"pattern": "x", "slash": "/"},
},
"cmd": "p",
"line": 1,
},
),
(
"s/x/y/",
{
"cmd": "s",
"x": {
"cmd_subst": {
"regx": {"pattern": "x", "slash": "/"},
"replacement": {"text": "y"},
}
},
"line": 1,
},
),
("$p", {"a1": {"addr_type": 7}, "cmd": "p", "line": 1}),
("q0", {"cmd": "q", "x": {"int_arg": 0}, "line": 1}),
("!p", {"addr_bang": True, "cmd": "p", "line": 1}),
("p", {"cmd": "p", "line": 1}),
]
for script, output in data:
parsed = parse_string(script)
self.assertEqual(output, parsed[0].to_dict(), msg=script)
self.assertEqual(output, json.loads(parsed[0].to_json()), msg=script)
def test_full(self):
script = "p"
output = {
"a1": None,
"a2": None,
"addr_bang": False,
"cmd": "p",
"x": {
"cmd_txt": {"text": []},
"int_arg": -1,
"fname": "",
"cmd_subst": {
"regx": {"pattern": "", "flags": "", "slash": ""},
"replacement": {"text": ""},
"outf": {"name": ""},
},
"label_name": "",
"comment": "",
},
"line": 1,
}
parsed = parse_string(script)
self.assertEqual(output, parsed[0].to_dict(remove_empty=False), msg=script)
self.assertEqual(
output, json.loads(parsed[0].to_json(remove_empty=False)), msg=script
)
if __name__ == "__main__":
unittest.main()
sedparse-0.1.2/tests/test_parser.py 0000664 0000000 0000000 00000076737 13566611474 0017430 0 ustar 00root root 0000000 0000000 # Test the parser, feeding it with tricky sed scripts.
# coding: utf-8
import unittest
from utils import parse_string
# The global holder for all the test data
TEST_DATA = {}
# Aligning test cases makes them way more readable
# pylint: disable=bad-whitespace
# -----------------------------------------------------------------------------
# Test data for ADDRESSES
TEST_DATA["address"] = [
# Test cases for addresses: numeric, $, /regex/
# Source: compile_address(), match_slash()
# fmt: off
# sed script ! addr1 addr2
# --------------------------------------------
# no address
("p", False, None, None),
("!p", True, None, None),
("{}", False, None, None),
("!{}", True, None, None),
# last line
("$p", False, "$", None),
("${}", False, "$", None),
("$!p", True, "$", None),
(" $ p", False, "$", None),
(" $ {}", False, "$", None),
(" $ ! p", True, "$", None),
# numeric
("5p", False, "5", None),
("5{}", False, "5", None),
("5!p", True, "5", None),
(" 5 p", False, "5", None),
(" 5 {}", False, "5", None),
(" 5 ! p", True, "5", None),
# numeric range
("1,5p", False, "1", "5"),
("1,5{}", False, "1", "5"),
("1,5!p", True, "1", "5"),
(" 1 , 5 p", False, "1", "5"),
(" 1 , 5 {}", False, "1", "5"),
(" 1 , 5 ! p", True, "1", "5"),
# inverted range
("5,1p", False, "5", "1"),
("$,1p", False, "$", "1"),
# zero is allowed if second address is a regex
("0,/x/p", False, "0", "/x/"),
# steps ~ and +
("1~2p", False, "1~2", None),
("0~2p", False, "0~2", None),
("5~0p", False, "5", None), # source change
("1,~2p", False, "1", "~2"),
("1,+2p", False, "1", "+2"),
("1,~0p", False, "1", "~0"),
("1,+0p", False, "1", "+0"),
# regex with /
("/x/p", False, "/x/", None),
("/x/{}", False, "/x/", None),
("/x/!p", True, "/x/", None),
(" /x/ p", False, "/x/", None),
(" /x/ {}", False, "/x/", None),
(" /x/ ! p", True, "/x/", None),
("/x/,/y/p", False, "/x/", "/y/"),
("/x/,/y/{}", False, "/x/", "/y/"),
("/x/,/y/!p", True, "/x/", "/y/"),
(" /x/ , /y/ p", False, "/x/", "/y/"),
(" /x/ , /y/ {}", False, "/x/", "/y/"),
(" /x/ , /y/ ! p", True, "/x/", "/y/"),
# flags (GNU extension)
("/x/Ip", False, "/x/I", None),
("/x/I{}", False, "/x/I", None),
("/x/I!p", True, "/x/I", None),
(" /x/ I p", False, "/x/I", None),
(" /x/ I {}", False, "/x/I", None),
(" /x/ I ! p", True, "/x/I", None),
# combining flags
("/x/IMp", False, "/x/IM", None),
("/x/MIp", False, "/x/MI", None),
("/x/ M I p", False, "/x/MI", None),
# repeated flags are not removed
("/x/MMIIMIp", False, "/x/MMIIMI", None),
# escaped / delimiter will loose the escape
(r"\/x/p", False, r"/x/", None), # source change
# regex with other delimiter (\n and non-ASCII not allowed)
(r"\;x;p", False, r"\;x;", None),
(r"\,x,p", False, r"\,x,", None),
(r"\(x(p", False, r"\(x(", None),
(r"\[x[p", False, r"\[x[", None),
(r"\ x p", False, r"\ x ", None),
( "\\\tx\tp", False, "\\\tx\t", None), # tab
(r"\\x\p", False, "\\\\x\\", None), # \
#(r"\★x★p", False, "\\★x★", None), # ★
# regex: command as delimiter
(r"\pxpp", False, r"\pxp", None),
(r"\=x==", False, r"\=x=", None),
(r"\{x{{}", False, r"\{x{", None),
# regex: bang as delimiter
(r"\!x!p", False, r"\!x!", None),
(r"\!x!!p", True, r"\!x!", None),
# regex: flag letter as delimiter
(r"\IxIp", False, r"\IxI", None),
(r"\IxIIp", False, r"\IxII", None),
# empty regex
(r"//p", False, r"//", None),
(r"\ppp", False, r"\pp", None),
(r"//,//p", False, r"//", r"//"),
(r"\,,,\ppp", False, r"\,,", r"\pp"),
(r"\III,\MMMp", False, r"\III", r"\MMM"),
# same address repeated
("5,5p", False, "5", "5"),
("$,$p", False, "$", "$"),
("/x/,/x/p", False, "/x/", "/x/"),
("//,//p", False, "//", "//"),
# Non-ASCII chars are allowed
("/★/,/★/p", False, "/★/", "/★/"),
# regex that looks numeric or last line
("/0/p", False, "/0/", None),
("/5/p", False, "/5/", None),
("/1,5/p", False, "/1,5/", None),
("/$/p", False, "/$/", None),
# mixed extra tabs and spaces
(" 1\t ,\t 5\t p", False, "1", "5"),
("\t /x/\t !\t p", True, "/x/", None),
("\t /x/\t I\t p", False, "/x/I", None),
# regex: escaped delimiter (start, middle, end)
(r"/\/\/\//p", False, r"/\/\/\//", None),
(r"\|\|\|\||p", False, r"\|\|\|\||", None),
# Delimiter inside a regex character class
("/[/]/p", False, "/[/]/", None),
]
# -----------------------------------------------------------------------------
# Test data for FILENAME commands
TEST_DATA["r"] = [
# Test cases for command: r, R, w, W
# Note that "s///w filename" is tested in the "s" tests.
# Note: all scripts end in EOF. At run time the \n ending is also tested.
# Source: read_filename()
# Format: (sed script, expected filename)
# fmt: off
("rname", "name"),
# Leading spaces are ignored
("r space", "space"),
("r\ttab", "tab"),
("r \t \t mixed", "mixed"),
# Every char is valid (it reads until \n), so ;}# are not special
("r;", ";"),
("r}", "}"),
("r#", "#"),
("r\\", "\\"),
("r foo}; \t#\\", "foo}; \t#\\"),
# Non-ASCII chars are allowed
("r★", "★"),
]
# Copy all "r" tests to: R, w, W
TEST_DATA["R"] = [("R" + script[1:], filename) for script, filename in TEST_DATA["r"]]
TEST_DATA["w"] = [("w" + script[1:], filename) for script, filename in TEST_DATA["r"]]
TEST_DATA["W"] = [("W" + script[1:], filename) for script, filename in TEST_DATA["r"]]
# Filename is the command name
TEST_DATA["r"].append(("rr", "r"))
TEST_DATA["R"].append(("RR", "R"))
TEST_DATA["w"].append(("ww", "w"))
TEST_DATA["W"].append(("WW", "W"))
# -----------------------------------------------------------------------------
# Test data for LABEL commands
TEST_DATA[":"] = [
# Test cases for commands: :, b, t, T, v
# Note: all scripts end in EOF. At run time the \n ending is also tested.
# Source: read_label()
# Format: (sed script, expected label name)
# fmt: off
(":name", "name"),
# Leading spaces are ignored
(": space", "space"),
(":\ttab", "tab"),
(": \t \t mixed", "mixed"),
# Those chars end a label: tab space ; #
# Note that } also ends a label, but it will be tested later
(":label\t", "label"),
(":label ", "label"),
(":label;", "label"),
(":label#", "label"),
# All other chars are valid as labels
(":!", "!"),
(":{", "{"),
(":\\", "\\"),
# Non-ASCII chars are allowed
(":★", "★"),
]
# Copy all ":" tests to: b, t, T, v
TEST_DATA["b"] = [("b" + script[1:], label) for script, label in TEST_DATA[":"]]
TEST_DATA["t"] = [("t" + script[1:], label) for script, label in TEST_DATA[":"]]
TEST_DATA["T"] = [("T" + script[1:], label) for script, label in TEST_DATA[":"]]
TEST_DATA["v"] = [("v" + script[1:], label) for script, label in TEST_DATA[":"]]
# Label name is the command name
TEST_DATA[":"].append(("::", ":"))
TEST_DATA["b"].append(("bb", "b"))
TEST_DATA["t"].append(("tt", "t"))
TEST_DATA["T"].append(("TT", "T"))
TEST_DATA["v"].append(("vv", "v"))
# Labels are ended by the } command
TEST_DATA[":"].append(("{:label}", "label"))
TEST_DATA["b"].append(("{blabel}", "label"))
TEST_DATA["t"].append(("{tlabel}", "label"))
TEST_DATA["T"].append(("{Tlabel}", "label"))
TEST_DATA["v"].append(("{vlabel}", "label"))
# Empty labels are allowed when jumping
TEST_DATA["b"].append(("b", ""))
TEST_DATA["t"].append(("t", ""))
TEST_DATA["T"].append(("T", ""))
# The v command can also be empty
TEST_DATA["v"].append(("v", ""))
# Those chars end an empty label: tab space ; } #
TEST_DATA["b"].append(("b\t", ""))
TEST_DATA["b"].append(("b ", ""))
TEST_DATA["b"].append(("b;", ""))
TEST_DATA["b"].append(("{b}", ""))
TEST_DATA["b"].append(("b#", ""))
# -----------------------------------------------------------------------------
# Test data for TEXT commands
TEST_DATA["a"] = [
# Test cases for commands: a, i, c, e
# Source: read_text()
# Format: (sed script, expected text)
# fmt: off
# Traditional sed requires a line break after \
("a\\\ntext", "text"),
# GNU sed allows no line break
("a\\text", "text"),
# GNU sed allows no \ either
("atext", "text"),
# Multiline texts with leading a\\n, a\, a should produce the same output
("a\\\n1\\\n2\\\n3", "1\\\n2\\\n3"),
( "a\\1\\\n2\\\n3", "1\\\n2\\\n3"),
( "a1\\\n2\\\n3", "1\\\n2\\\n3"),
# Empty text at EOF is allowed (when having \ and/or \n)
("a\\\n", ""),
("a\\", ""),
("a\n", ""),
#("a", ""), # Error: expected \ after `a', `c' or `i'
# Leading spaces before \ are ignored
("a \\space", "space"),
("a\t\\tab", "tab"),
("a \t \t \\mixed", "mixed"),
# Leading spaces after \ are preserved
("a\\ text", " text"),
("a\\\ttext", "\ttext"),
("a\\ \t \t text", " \t \t text"),
# Leading spaces are ignored when no \ is used
("a space", "space"),
("a\ttab", "tab"),
("a \t \t mixed", "mixed"),
# Trailing spaces are always preserved
("atext ", "text "),
("atext\t", "text\t"),
("atext \t \t ", "text \t \t "),
# From second line on, leading and trailing spaces are always preserved
("a\\\n1\\\n 2 \\\n\t3\t", "1\\\n 2 \\\n\t3\t"),
( "a\\1\\\n 2 \\\n\t3\t", "1\\\n 2 \\\n\t3\t"),
( "a1\\\n 2 \\\n\t3\t", "1\\\n 2 \\\n\t3\t"),
# Literal escape at beginning and middle of the line
("a\\\n\\text\\text", "\\text\\text"),
( "a\\\\text\\text", "\\text\\text"),
( "atext\\text", "text\\text"),
# Literal escape at EOL is allowed except in the last line
#XXX why only odd numbers work?
("a\\\n1" + "\\"*1 + "\n2", "1" + "\\"*1 + "\n2"),
# ("a\\\n1" + "\\"*2 + "\n2p", "1" + "\\"*2 + "\n2p"),
("a\\\n1" + "\\"*3 + "\n2", "1" + "\\"*3 + "\n2"),
# ("a\\\n1" + "\\"*4 + "\n2", "1" + "\\"*4 + "\n2"),
("a\\\n1" + "\\"*5 + "\n2", "1" + "\\"*5 + "\n2"),
# Every char is valid (it reads until \n), so ;}# are not special
("a;", ";"),
("a}", "}"),
("a#", "#"),
("a\\ foo}; \t#", " foo}; \t#"),
# Non-ASCII chars are allowed
("a★", "★"),
]
# Copy all "a" tests to: i, c, e
TEST_DATA["i"] = [("i" + script[1:], text) for script, text in TEST_DATA["a"]]
TEST_DATA["c"] = [("c" + script[1:], text) for script, text in TEST_DATA["a"]]
TEST_DATA["e"] = [("e" + script[1:], text) for script, text in TEST_DATA["a"]]
# Empty bare "e" is allowed (but forbidden for a, i, c)
TEST_DATA["e"].append(("e", ""))
# -----------------------------------------------------------------------------
# Test data for "y" and "s" commands
TEST_DATA["y"] = [
# Test cases for commands: y, s
# Source: match_slash()
# Format: (sed script, delimiter, source, dest)
# fmt: off
# Simple usage
("y/a/A/", "/", "a", "A"),
# Empty source and dest
("y///", "/", "", ""),
# Source and dest are equal
("y/a/a/", "/", "a", "a"),
# Space and tab in source and dest
("y/ /\t/", "/", " ", "\t"),
("y/\t/ /", "/", "\t", " "),
# Otherwise special chars as delimiter
("y;a;A;", ";", "a", "A"),
("y[a[A[", "[", "a", "A"),
("y{a{A{", "{", "a", "A"),
("y}a}A}", "}", "a", "A"),
("y#a#A#", "#", "a", "A"),
("y a A ", " ", "a", "A"),
("y\ta\tA\t", "\t", "a", "A"),
("y\\a\\A\\", "\\", "a", "A"),
# Literal / must be escaped as \/ in source and dest
("y/\\/a/\\/A/", "/", "\\/a", "\\/A"),
# Literal x must be escaped as \x in source and dest when delim=x
("y#\\#a#\\#A#", "#", "\\#a", "\\#A"),
# Literal \ must be escaped as \\ in source and dest
("y/\\\\/\\\\/", "/", "\\\\", "\\\\"),
# Literal \n must be escaped as \\n in source and dest
("y/\\\n/\\\n/", "/", "\\\n", "\\\n"),
# Literal \ is not allowed when \ is the delimiter
#("y\\\\\\a\\\\\\A\\", "\\", "\\\\a", "\\\\A"),
# Non-ASCII chars are NOT allowed as delimiter
#("y★a★A★", "★", "a", "A"),
# Non-ASCII chars are allowed as source and dest
("y/★/★/", "/", "★", "★"),
]
# Copy all "y" tests to: s
TEST_DATA["s"] = [
("s" + script[1:], delimiter, source, dest)
for script, delimiter, source, dest in TEST_DATA["y"]
]
# y: source and dest are allowed to have different lengths
# Note: This differs from the GNU sed parser. Since we do not perform the
# de-escaping of \/, \\ and \\n, the length check is turned off.
TEST_DATA["y"].append(("y/a/aa/", "/", "a", "aa"))
# Command name as delimiter
TEST_DATA["y"].append(("yyayAy", "y", "a", "A"))
TEST_DATA["s"].append(("ssasAs", "s", "a", "A"))
# Delimiter inside a regex character class
TEST_DATA["s"].append(("s/[/]//", "/", "[/]", ""))
# -----------------------------------------------------------------------------
# Test data for using flags in the "s" command
TEST_DATA["s-flags"] = [
# Source: match_slash(), mark_subst_opts()
# Format: (sed script, delimiter, pattern, replacement, flags, flag_arg)
# fmt: off
# Flags: traditional sed
("s/a/A/g", "/", "a", "A", "g", ""),
("s/a/A/p", "/", "a", "A", "p", ""),
("s/a/A/1", "/", "a", "A", "1", ""),
("s/a/A/99", "/", "a", "A", "99", ""),
("s/a/A/999", "/", "a", "A", "999", ""),
("s/a/A/wfile", "/", "a", "A", "w", "file"),
# Flags: GNU sed extensions
("s/a/A/e", "/", "a", "A", "e", ""),
("s/a/A/m", "/", "a", "A", "m", ""),
("s/a/A/i", "/", "a", "A", "i", ""),
("s/a/A/M", "/", "a", "A", "M", ""),
("s/a/A/I", "/", "a", "A", "I", ""),
# Flags: trailing \r\n is allowed
("s/a/A/g\r\n", "/", "a", "A", "g", ""),
# Flags mixed (note that the order is preserved)
("s/a/A/gpemiMIwfile", "/", "a", "A", "gpemiMIw", "file"),
# Flags: GNU sed extensions can be repeated
("s/a/A/eemmiiMMII", "/", "a", "A", "eemmiiMMII", ""),
("s/a/A/emiMIemiMI", "/", "a", "A", "emiMIemiMI", ""),
# Flag w: must be the last flag (everything is a filename after it)
("s/a/A/wfile gp", "/", "a", "A", "w", "file gp"),
# Flag w: leading spaces are ignored
("s/a/A/w space", "/", "a", "A", "w", "space"),
("s/a/A/w\ttab", "/", "a", "A", "w", "tab"),
("s/a/A/w \t \t mixed", "/", "a", "A", "w", "mixed"),
# Flag w: every char is valid (it reads until \n), so ;}# are not special
("s/a/A/w;", "/", "a", "A", "w", ";"),
("s/a/A/w}", "/", "a", "A", "w", "}"),
("s/a/A/w#", "/", "a", "A", "w", "#"),
("s/a/A/w\\", "/", "a", "A", "w", "\\"),
("s/a/A/w foo}; \t#\\", "/", "a", "A", "w", "foo}; \t#\\"),
# Flag w: non-ASCII chars are allowed
("s/a/A/w★", "/", "a", "A", "w", "★"),
]
# -----------------------------------------------------------------------------
TEST_DATA["#"] = [
# Test cases for comments
# Preserving comments is a sedparse extension. GNU sed discards them.
# Note: all scripts end in EOF. At run time the \n ending is also tested.
# Note: result_index identifies # command index in the parsing results list.
# Source: read_comment()
# Format: (result_index, sed script, comment)
# fmt: off
# Empty comment
(0, "#", ""),
(1, "p#", ""),
(1, "p;#", ""),
# No spaces around #
(0, "#foo", "foo"),
(1, "p#foo", "foo"),
(1, "p;#foo", "foo"),
# Leading spaces before # are ignored
(0, " \t#foo", "foo"),
(1, "p \t#foo", "foo"),
(1, "p; \t#foo", "foo"),
# Leading and trailing spaces in the comment contents are preserved
(0, "# foo ", " foo "),
(0, "#\t\tfoo\t\t", "\t\tfoo\t\t"),
# Extra leading # are treated as comment content
(0, "##foo", "#foo"),
(0, "####foo", "###foo"),
# An escape at line end is not special inside comments
(0, "#foo\\", "foo\\"),
# Command-ending characters are not special inside comments
(0, "#foo;", "foo;"),
(0, "#foo}", "foo}"),
# Comment right after a label command
(1, ":a#foo", "foo"),
(1, "ba#foo", "foo"),
(1, "b #foo", "foo"),
(1, "b#foo", "foo"),
# Comment right after y and s
(1, "y/a/A/#foo", "foo"),
(1, "s/a/A/g#foo", "foo"),
# Comment right after blocks
# Note: "{#foo" is the only allowed partial comment in BSD sed (no ; before)
(1, "{#foo\n}", "foo"),
(2, "{}#foo", "foo"),
# The special #n at first line is treated as a normal comment by the parser.
# After parsing, the calling code can make it special if desired.
(0, "#n", "n"),
]
# -----------------------------------------------------------------------------
TEST_DATA["\n"] = [
# Test cases for blank lines
# Preserving blank lines is a sedparse extension. GNU sed discards them.
# Source: ignore_trailing_fluff() and also search for "sedparse" comments.
# Format: (sed script, *expected_parsed_commands)
# fmt: off
# 100% blank lines script
("\n", "\n"),
("\n\n", "\n", "\n"),
("\n\n\n", "\n", "\n", "\n"),
# blank lines at the top and bottom should be preserved
("\n\np", "\n", "\n", "p"),
("p\n\n\n", "p", "\n", "\n"),
# blank lines between solo commands should be preserved
("p\nq", "p", "q"),
("p\n\nq", "p", "\n", "q"),
("p\n\n\nq", "p", "\n", "\n", "q"),
# blank lines between label commands should be preserved
("b\nq", "b", "q"),
("b\n\nq", "b", "\n", "q"),
("b\n\n\nq", "b", "\n", "\n", "q"),
# blank lines between filename commands should be preserved
("rfoo\nq", "r", "q"),
("rfoo\n\nq", "r", "\n", "q"),
("rfoo\n\n\nq", "r", "\n", "\n", "q"),
# blank lines between text commands should be preserved
("a\\\nfoo\nq", "a", "q"),
("a\\\nfoo\n\nq", "a", "\n", "q"),
("a\\\nfoo\n\n\nq", "a", "\n", "\n", "q"),
# blank lines between consecutive blocks should be preserved
("{\n}\n{}", "{", "}", "{", "}"),
("{\n\n}\n\n{}", "{", "\n", "}", "\n", "{", "}"),
("{\n\n\n}\n\n\n{}", "{", "\n", "\n", "}", "\n", "\n", "{", "}"),
# blank lines between nested blocks should be preserved
("{\n{}\n}", "{", "{", "}", "}"),
("{\n\n{}\n\n}", "{", "\n", "{", "}", "\n", "}"),
("{\n\n\n{}\n\n\n}", "{", "\n", "\n", "{", "}", "\n", "\n", "}"),
# blank lines between comments should be preserved
("#foo\n#bar", "#", "#"),
("#foo\n\n#bar", "#", "\n", "#"),
("#foo\n\n\n#bar", "#", "\n", "\n", "#"),
]
# -----------------------------------------------------------------------------
TEST_DATA["block"] = [
# Test cases for blocks
# Note: all scripts end in EOF. At run time the \n ending is also tested.
# Format: (sed script, *expected_parsed_commands)
# fmt: off
# Empty blocks are allowed
("{}", "{", "}"),
# Nested empty blocks are allowed
("{{}}", "{", "{", "}", "}"),
# Using ; is optional around { and }
("{p}", "{", "p", "}"),
("{p;}", "{", "p", "}"),
("{;p}", "{", "p", "}"),
("{;p;}", "{", "p", "}"),
("{p;};", "{", "p", "}"),
]
# -----------------------------------------------------------------------------
TEST_DATA["gotcha"] = [
# Test cases for some gotchas
# Note: all scripts end in EOF. At run time the \n ending is also tested.
# Format: (sed script, *expected_parsed_commands)
# fmt: off
# Test read_label() detection for the next command
("blabel\t", "b"),
("blabel ", "b"),
("blabel;", "b"),
("{blabel}", "{", "b", "}"),
("blabel#", "b", "#"),
("blabel;;; #", "b", "#"),
# Same tests repeated, now with an empty label
("b\t", "b"),
("b ", "b"),
("b;", "b"),
("{b}", "{", "b", "}"),
("b#", "b", "#"),
("b;;; #", "b", "#"),
]
# -----------------------------------------------------------------------------
TEST_DATA["trailing_fluff"] = [
# Test cases for ignore_trailing_fluff()
# Note: all scripts end in EOF. At run time the \n ending is also tested.
# Format: (sed script, *expected_parsed_commands)
# fmt: off
# Ignore trailing spaces and tabs
("p ", "p"),
("p\t\t\t", "p"),
("p\t \t ", "p"),
# Ignore trailing semicolons
("p;", "p"),
("p;;;;;", "p"),
("p;;;;;x", "p", "x"),
# Mixing spaces and semicolons
("p ;\t; ", "p"),
("p ;;\tx", "p", "x"),
]
class TestSedparseParser(unittest.TestCase): # pylint: disable=unused-variable
def _assert_defaults(self, data, skip=None, msg=""):
"""Assert that all command attributes are set to their default values.
Use `skip=["foo"]` to skip checking the `foo` attribute.
"""
# pylint: disable=too-many-branches
if skip is None:
skip = []
if "a1" not in skip:
self.assertEqual(None, data.a1, msg=msg)
if "a2" not in skip:
self.assertEqual(None, data.a2, msg=msg)
if "addr_bang" not in skip:
self.assertEqual(False, data.addr_bang, msg=msg)
if "int_arg" not in skip:
self.assertEqual(-1, data.x.int_arg, msg=msg)
if "fname" not in skip:
self.assertEqual("", data.x.fname, msg=msg)
if "label_name" not in skip:
self.assertEqual("", data.x.label_name, msg=msg)
if "cmd_txt" not in skip:
self.assertEqual("", str(data.x.cmd_txt), msg=msg)
if "comment" not in skip:
self.assertEqual("", data.x.comment, msg=msg)
if "slash" not in skip:
self.assertEqual("", data.x.cmd_subst.regx.slash, msg=msg)
if "pattern" not in skip:
self.assertEqual("", data.x.cmd_subst.regx.pattern, msg=msg)
if "replacement" not in skip:
self.assertEqual("", data.x.cmd_subst.replacement.text, msg=msg)
if "flags" not in skip:
self.assertEqual("", data.x.cmd_subst.regx.flags, msg=msg)
if "outf" not in skip:
self.assertEqual("", data.x.cmd_subst.outf.name, msg=msg)
def test_address(self):
for script, bang, addr1, addr2 in TEST_DATA["address"]:
expected = [bang, addr1, addr2]
# only the first command matters, i.e., { when {}
parsed = parse_string(script)[0]
self.assertListEqual(
expected,
[
parsed.addr_bang,
str(parsed.a1) if parsed.a1 else None,
str(parsed.a2) if parsed.a2 else None,
],
msg=script,
)
def test_commands_with_no_args(self):
commands = (
"=",
"d",
"D",
"F",
"g",
"G",
"h",
"H",
"l",
"L",
"n",
"N",
"p",
"P",
"q",
"Q",
"x",
"z",
)
for command in commands:
for template in ("%s", "%s;", "{%s}", "%s#foo", "{ \t%s \t}"):
script = template % command
parsed = parse_string(script)
parsed = parsed[1] if "{" in script else parsed[0]
self.assertEqual(command, parsed.cmd, msg=script)
self._assert_defaults(parsed, skip=None, msg=script)
def test_commands_with_numeric_arg(self):
# Note that those commands "solo", with no numeric arguments,
# are already tested in test_commands_with_no_args().
for command in ("l", "L", "q", "Q"):
for arg in (0, 5, 99):
for template in (
"%s%d",
"%s%d;",
"{%s%d}",
"%s%d#foo",
"{ \t%s \t%d \t}",
):
script = template % (command, arg)
parsed = parse_string(script)
parsed = parsed[1] if "{" in script else parsed[0]
self.assertEqual(command, parsed.cmd, msg=script)
self.assertEqual(arg, parsed.x.int_arg, msg=script)
self._assert_defaults(parsed, skip=["int_arg"], msg=script)
def test_commands_with_filename(self):
for command in ("r", "R", "w", "W"):
for script_end in ("", "\n"): # empty=EOF
for script, filename in TEST_DATA[command]:
script = script + script_end
parsed = parse_string(script)[0]
self.assertEqual(command, parsed.cmd, msg=script)
self.assertEqual(filename, parsed.x.fname, msg=script)
self._assert_defaults(parsed, skip=["fname"], msg=script)
def test_commands_with_label(self):
for command in (":", "b", "t", "T", "v"):
for script_end in ("", "\n"): # empty=EOF
for script, label in TEST_DATA[command]:
script = script + script_end
parsed = parse_string(script)
if parsed[0].cmd == "{":
parsed = parsed[1]
else:
parsed = parsed[0]
self.assertEqual(command, parsed.cmd, msg=script)
self.assertEqual(label, parsed.x.label_name, msg=script)
self._assert_defaults(parsed, skip=["label_name"], msg=script)
def test_commands_with_text(self):
for command in ("a", "i", "c", "e"):
for script, text in TEST_DATA[command]:
parsed = parse_string(script)[0]
self.assertEqual(command, parsed.cmd, msg=script)
self.assertEqual(text, str(parsed.x.cmd_txt), msg=script)
self._assert_defaults(parsed, skip=["cmd_txt"], msg=script)
def test_commands_y_and_s(self):
for command in ("y", "s"):
for script, delimiter, arg1, arg2 in TEST_DATA[command]:
parsed = parse_string(script)[0]
self.assertEqual(command, parsed.cmd, msg=script)
self.assertEqual(delimiter, parsed.x.cmd_subst.regx.slash, msg=script)
self.assertEqual(arg1, parsed.x.cmd_subst.regx.pattern, msg=script)
self.assertEqual(arg2, parsed.x.cmd_subst.replacement.text, msg=script)
self._assert_defaults(
parsed, skip=["slash", "pattern", "replacement"], msg=script
)
def test_command_s_flags(self):
command = "s"
for script, delimiter, pattern, replacement, flags, flag_arg in TEST_DATA[
"s-flags"
]:
parsed = parse_string(script)[0]
self.assertEqual(command, parsed.cmd, msg=script)
self.assertEqual(delimiter, parsed.x.cmd_subst.regx.slash, msg=script)
self.assertEqual(pattern, parsed.x.cmd_subst.regx.pattern, msg=script)
self.assertEqual(
replacement, parsed.x.cmd_subst.replacement.text, msg=script
)
self.assertEqual(flags, parsed.x.cmd_subst.regx.flags, msg=script)
self.assertEqual(flag_arg, parsed.x.cmd_subst.outf.name, msg=script)
self._assert_defaults(
parsed,
skip=["slash", "pattern", "replacement", "flags", "outf"],
msg=script,
)
def test_comments(self): # sedparse extension
command = "#"
for script_end in ("", "\n"): # empty=EOF
for index, script, comment in TEST_DATA[command]:
script = script + script_end
parsed = parse_string(script)[index]
self.assertEqual(command, parsed.cmd, msg=script)
self.assertEqual(comment, parsed.x.comment, msg=script)
self._assert_defaults(parsed, skip=["comment"], msg=script)
def test_blank_lines(self): # sedparse extension
for data in TEST_DATA["\n"]:
script = data[0]
expected_commands = list(data[1:])
self.assertEqual(
expected_commands, [x.cmd for x in parse_string(script)], msg=script
)
def test_blocks(self):
for script_end in ("", "\n"): # empty=EOF
for data in TEST_DATA["block"]:
script = data[0] + script_end
expected_commands = list(data[1:])
self.assertEqual(
expected_commands, [x.cmd for x in parse_string(script)], msg=script
)
def test_gotchas(self):
for script_end in ("", "\n"): # empty=EOF
for data in TEST_DATA["gotcha"]:
script = data[0] + script_end
expected_commands = list(data[1:])
self.assertEqual(
expected_commands, [x.cmd for x in parse_string(script)], msg=script
)
def test_ignore_trailing_fluff(self):
for script_end in ("", "\n"): # empty=EOF
for data in TEST_DATA["trailing_fluff"]:
script = data[0] + script_end
expected_commands = list(data[1:])
self.assertEqual(
expected_commands, [x.cmd for x in parse_string(script)], msg=script
)
def test_command_data_cleanup(self):
"""
All data from the previous command must be cleared when reading
the next one. Those tests check that the last bare "p" command
should be using the default values for all the data fields.
"""
# a1, a2, bang, slash, pattern, replacement, flags, outf
script = ["/a1/I, /a2/M ! s/foo/bar/igw file", "p"]
p_data = parse_string("\n".join(script))[-1]
self._assert_defaults(p_data, skip=None, msg=script)
# int_arg
script = ["q99", "p"]
p_data = parse_string("\n".join(script))[-1]
self._assert_defaults(p_data, skip=None, msg=script)
# fname
script = ["r file", "p"]
p_data = parse_string("\n".join(script))[-1]
self._assert_defaults(p_data, skip=None, msg=script)
# label_name
script = [":label", "p"]
p_data = parse_string("\n".join(script))[-1]
self._assert_defaults(p_data, skip=None, msg=script)
# cmd_txt
script = ["a", "text", "p"]
p_data = parse_string("\n".join(script))[-1]
self._assert_defaults(p_data, skip=None, msg=script)
if __name__ == "__main__":
unittest.main()
sedparse-0.1.2/tests/test_repr.py 0000664 0000000 0000000 00000006002 13566611474 0017056 0 ustar 00root root 0000000 0000000 # Test the repr() output from the structs.
# Note: test_str.py uses the same tests, keep both in sync.
import unittest
from context import sedparse
from utils import parse_string
class TestSedparseRepr(unittest.TestCase): # pylint: disable=unused-variable
def test_repr_struct_addr(self):
"""Check repr for all kinds of addresses"""
data = [
# pylint: disable=line-too-long
(
"$",
"struct_addr(addr_type=7, addr_number=0, addr_step=0, addr_regex=None)",
"None",
),
(
"91,92",
"struct_addr(addr_type=3, addr_number=91, addr_step=0, addr_regex=None)",
"struct_addr(addr_type=3, addr_number=92, addr_step=0, addr_regex=None)",
),
(
"91~992",
"struct_addr(addr_type=4, addr_number=91, addr_step=992, addr_regex=None)",
"None",
),
(
"91,~992",
"struct_addr(addr_type=3, addr_number=91, addr_step=0, addr_regex=None)",
"struct_addr(addr_type=6, addr_number=0, addr_step=992, addr_regex=None)",
),
(
"91,+992",
"struct_addr(addr_type=3, addr_number=91, addr_step=0, addr_regex=None)",
"struct_addr(addr_type=5, addr_number=0, addr_step=992, addr_regex=None)",
),
(
"/foo/IM",
"struct_addr(addr_type=2, addr_number=0, addr_step=0,"
" addr_regex=struct_regex(slash='/', pattern='foo', flags='IM'))",
"None",
),
]
for address, repr_a1, repr_a2 in data:
script = address + "p"
parsed = parse_string(script)
self.assertEqual(repr_a1, repr(parsed[0].a1), msg=script)
self.assertEqual(repr_a2, repr(parsed[0].a2), msg=script)
def test_repr_struct_text_buf(self):
script = "a L1\\\nL2"
expected = "struct_text_buf(text=['L', '1', '\\\\', '\\n', 'L', '2', '\\n'])"
self.assertEqual(expected, repr(parse_string(script)[0].x.cmd_txt))
def test_repr_struct_text_buf_raw(self):
"""Test using the struct only, not the parser"""
struct = sedparse.struct_text_buf()
struct.text = ["f", "o", "o"]
expected = "struct_text_buf(text=['f', 'o', 'o'])"
self.assertEqual(expected, repr(struct))
def test_repr_struct_misc(self):
"""Check repr for struct_{regex,replacement,output}"""
script = "s/foo/bar/igw file"
parsed = parse_string(script)
self.assertEqual(
"struct_regex(slash='/', pattern='foo', flags='igw')",
repr(parsed[0].x.cmd_subst.regx),
)
self.assertEqual(
"struct_replacement(text='bar')", repr(parsed[0].x.cmd_subst.replacement)
)
self.assertEqual("struct_output(name='file')", repr(parsed[0].x.cmd_subst.outf))
if __name__ == "__main__":
unittest.main()
sedparse-0.1.2/tests/test_str.py 0000664 0000000 0000000 00000004013 13566611474 0016716 0 ustar 00root root 0000000 0000000 # Test the str() output from the structs.
# Note: test_repr.py uses the same tests, keep both in sync.
import unittest
from context import sedparse
from utils import parse_string
class TestSedparsestr(unittest.TestCase): # pylint: disable=unused-variable
def test_str_struct_addr(self):
"""Check str for all kinds of addresses"""
data = [
("$", "$", "None"),
("91,92", "91", "92"),
("91~992", "91~992", "None"),
("91,~992", "91", "~992"),
("91,+992", "91", "+992"),
("/foo/IM", "/foo/IM", "None"),
]
for address, str_a1, str_a2 in data:
script = address + "p"
parsed = parse_string(script)
self.assertEqual(str_a1, str(parsed[0].a1), msg=script)
self.assertEqual(str_a2, str(parsed[0].a2), msg=script)
def test_str_struct_text_buf(self):
script = "a L1\\\nL2"
expected = "L1\\\nL2"
self.assertEqual(expected, str(parse_string(script)[0].x.cmd_txt))
def test_str_struct_text_buf_raw(self):
"""Test using the struct only, not the parser"""
struct = sedparse.struct_text_buf()
struct.text = ["f", "o", "o"]
expected = "fo" # last char (usually a \n) is chopped
self.assertEqual(expected, str(struct))
def test_str_struct_misc(self):
"""Check str for struct_{regex,replacement,output}"""
script = "s/foo/bar/igw file"
parsed = parse_string(script)
self.assertEqual("/foo/igw", str(parsed[0].x.cmd_subst.regx))
self.assertEqual("bar", str(parsed[0].x.cmd_subst.replacement))
self.assertEqual("file", str(parsed[0].x.cmd_subst.outf))
def test_str_int_arg(self):
"""Check str for commands with int_arg"""
data = [("q0", "q 0"), ("q1", "q 1"), ("q99", "q 99")]
for script, expected in data:
parsed = parse_string(script)
self.assertEqual(expected, str(parsed[0]), msg=script)
if __name__ == "__main__":
unittest.main()
sedparse-0.1.2/tests/utils.py 0000664 0000000 0000000 00000000346 13566611474 0016214 0 ustar 00root root 0000000 0000000 # Utilities for testing
from context import sedparse
def parse_string(script): # pylint: disable=unused-variable
parsed = []
sedparse.compile_string(parsed, script)
sedparse.check_final_program()
return parsed