Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python binding #42

Closed
wants to merge 56 commits into from
Closed

Python binding #42

wants to merge 56 commits into from

Conversation

moskupols
Copy link
Contributor

@moskupols moskupols commented Aug 17, 2016

This is a cython-based python binding of PIRE. Mako template engine is used heavily to address repetitiveness of similar interfaces.

What is not wrapped:

  • It is impossible yet to subclass Features and Scanners in python and pass the extension back to C++;
  • Most low-level operations with Fsm;
  • mmap- and Action-related methods and functions;
  • Run for pair of scanners;
  • Feature and Encoding classes.

Interface of the binding is similar to the original one. Differences:

  • All C++-space global template functions are wrapped as python instance methods.
  • Fsm::operator * () is wrapped as Fsm.Iterated().
  • All scanners' states are represented as classes similar to Pire::RunHelper.
  • Encoding, Feature and Option abstractions are replaced with single Options abstraction, which is used to tweak Lexer behavior. Options can be either parsed from string such as "aiyu" or composed of predefined constants such as I and UTF8.
  • Instead of lexer::AddFeature(Capture(42)) you use lexer.AddCapturing(42).
  • An OverflowError is raised on unsuccessful glue operation instead of returning empty scanner.

Just in case cython treats POD-types differently (apparently it does).
This is intended for both support of `Pire::Regexp` class from
pire/easy.h and simpler enum-based interface to features and encodings.

`Pire::Option<...>` and all the `Pire::Options::Proxy` magic classes proved to
be too hard to wrap in Cython, so `Pire::Option` is replaced with integer
enum `OptionFlag`, and `Pire::Options` is represented literally as set of
`OptionFlag`'s, which is converted to `Pire::Options` where needed.

Mako provides a way to manage the set of available
options/`Feature`s/`Encoding`s: once a new option is needed, it should
suffice to add a corresponding `OptionSpec` to render.py and probably an
`#include` to options.h.mako.
@moskupols
Copy link
Contributor Author

#47

@moskupols moskupols closed this Sep 28, 2016
@moskupols moskupols deleted the python-binding branch February 8, 2017 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant