Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jcgoble3 committed Dec 27, 2015
0 parents commit 21ad845
Show file tree
Hide file tree
Showing 14 changed files with 1,465 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text eol=lf
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Python bytecode
__pycache__/

# py.test junk
.cache/
.coverage
htmlcov/

# setuptools artifacts
build/
dist/
*.egg-info/
35 changes: 35 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
branches:
only:
- develop
- master

language: python

python:
- "3.5"
- "3.5-dev" # 3.5 development branch
- "nightly" # currently points to 3.6-dev

matrix:
allow_failures:
- python: "3.5-dev"
- python: "nightly"

install:
- pip install flake8

script:
- if [[ $TRAVIS_PYTHON_VERSION = 3.5 ]]; then flake8 luapatt; fi
- if [[ $TRAVIS_PYTHON_VERSION = nightly ]]; then python -m pytest; fi
- if [[ $TRAVIS_PYTHON_VERSION = 3.5* ]]; then python3.5 -m pytest; fi
- if [[ $TRAVIS_PYTHON_VERSION = 3.5 ]]; then python3.4 -m pytest; fi
- if [[ $TRAVIS_PYTHON_VERSION = 3.5 ]]; then python3.3 -m pytest; fi

deploy:
provider: pypi
user: jcgoble3
on:
branch: master
tags: true
python: "3.5"
distributions: sdist bdist_wheel
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2015 Jonathan Goble

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# luapatt

A Python 3.3+ implementation of the
[Lua language's](http://www.lua.org/home.html) pattern matching functions.
Lua's pattern matching is simpler than regular expressions and lacks several
features that regexes have, such as `|` for alternation, but also contains some
features difficult or impossible to duplicate in most regex flavors, such as
the ability to easily match a balanced pair of parentheses (or any two other
characters).

## Installation

`pip install -i https://testpypi.python.org/pypi luapatt`

Upload to the regular PyPI will come "soon".

## Documentation

For documentation on how pattern matching works, please read the
[Lua reference manual](http://www.lua.org/manual/5.3/manual.html#6.4.1).
This library contains the following differences from stock Lua:

* `%c`, `%g`, `%p`, and their negated counterparts are not available;
attempting to use them will raise the built-in `NotImplementedError`.
* Other character classes that rely on the meaning of a character call Python's
`str.is*` family of methods, and so use the Unicode definition of that meaning.
* String positions are zero-based instead of one-based, reflecting the fact
that Python is generally zero-based (as opposed to Lua, which has one-based
indexes). This affects position captures and the indexes returned as the first
two results from `find()`.
* Function return values are combined into a tuple, as is standard with Python.
However, singleton tuples are not returned; the single value is returned
directly instead.
* `gsub()` does *not* return the number of substitutions by default, instead
returning only the new string. To get the count, pass the named argument
`count=True` to the call (which will result in a 2-tuple of the new string and
the count).
* An extra function, `set_escape_char()`, is provided to change the escape
character. It takes one argument: the new escape character, which must be a
`str` object of length 1. The escape character cannot be set to any of the
other special characters. While it is possible to set it to a letter or number,
this is not recommended as it may interfere with other aspects of pattern
matching, and doing so may be disallowed in the future.
* **NOTE:** Because `set_escape_char` modifies global state, it is **not**
thread-safe.
* Unlike Lua, which has no notion of a Unicode string and assumes all
characters are one byte in length, this library operates on full Unicode
strings (i.e. `str` objects). If you pass bytes objects to this library, the
behavior is undefined.

## Licensing

As with Lua itself, this library is released under the MIT License. See the
[`LICENSE` file](./LICENSE) for more details.
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[metadata]
description-file = README.md
39 changes: 39 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from setuptools import setup, find_packages

from codecs import open
from os import path

here = path.abspath(path.dirname(__file__))

with open(path.join(here, 'README.md'), encoding='utf-8') as f:
long_description = f.read()

setup(
name='luapatt',
version='0.9.0b1',
description='Python implementation of Lua-style pattern matching',
long_description=long_description,
url='https://github.com/jcgoble3/luapatt',
author='Jonathan Goble',
author_email='[email protected]',
license='MIT',
classifiers=[
'Development Status :: 4 - Beta',
# 'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Topic :: Software Development :: Libraries :: Python Modules',
'Topic :: Text Processing :: General'
],
keywords='Lua pattern matching regex regular expressions',
package_dir={'': 'src'},
py_modules=["luapatt"],
install_requires=[], # no dependencies
extras_require={'test': ['pytest']}
)
Loading

0 comments on commit 21ad845

Please sign in to comment.