Skip to main content

A hygienic syntax extension system for Python

Project description

Moshmosh

example.png

The TRUE implementation of pattern matching for Python.

For more than pattern matching, check syntax_rule.py.

@syntax_rule(pattern_matching)
def f(x, r=1):
    with match(x):
        if case[0]: return 1
        if case[x]: return f(x-1, r * x)

return f(10)

Features

  • Tree pattern matching: if C1(C2(1), ""): ...

  • Unlike projects using inspect.getsource, syntax extensions are achieved without evil IO operations or requiring source files.

  • Literal patterns:

    • string, number and other constant patterns
    • tuple, list patterns
  • Provided with the capabilities to customize semantics of python syntaxes.

Benchmarks

Check benchmark.py.

Although Pampy is much weaker than moshmosh, it's also much slower than moshmosh :) . Note tha moshmosh is currently a simple prototype implemented in few hours.

Thus we can safely conclude, A true one is always better than the fakers.

Acknowledgements

See older implementations and search "pattern matching" in Python-ideas.

Salute all the people used to work for Python pattern matching.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

moshmosh_syntax-0.1.1-py3-none-any.whl (8.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page