Skip to main content

Python Domain Specific Language Tools

Project description


pydsl is a language library written in python. It provides high level functions for Grammars/Alphabets,
hiding the complexity of parsers and similar tools:
* guess(input, [gd]): returns a list of _grammar_ and _alphabets_ that are compatible with the input
* check(d, input): test the input string against the spec
* extract(gd, input): extract all the slices of the input that are accepted by the definition


supported formats:
* regular expressions
* pydsl BNF format
* mongo database query dictionaries
* python ply module (only check support)

* enum(gd): yields a list of accepted words
* first(gd): yields a list of the first accepted subword/char
* minsize(gd): length of the smaller accepted word
* maxsize(gd): length of the biggest accepted word
* alphabet(gd): returns the alphabet used by this gd

* validate(gd, input): test the input string against the spec. In case of failure, it returns a list of errors


Alphabets are a set of grammar definitions that are recognized using a regular grammar.

* grammar_list(ad): return the list of allowed grammars for this alphabet

* lexer(ad, input): Generates a tokenlist from a string (it is a special case of translate)


pydsl also offers functions to store grammars and alphabets into directories and files. Here are the related functions:
* manager s query: search for an element within a memory
* manager i identifier: returns information about the element

* disttools:
* python3 install
* pip:
* pip install pydsl

To use pydsl as a library for your code, you can:

Loading content from files
from pydsl.Memory.File.BNF import load_bnf_file
grammardefinition = loand_bnf_file('myfile.bnf')
from pydsl.Memory.Loader import *
mychecker = load_checker(grammardefinition)
mychecker('mystring') # returns True or False

Loading content from a directory
First store your grammar definitions in a directory,

from pydsl.Memory.Storage.Directory import DirStorage
from pydsl.Guess import Guesser
a = DirStorage("directory/")
guess = Guesser([a])

Using contrib
from pydsl.Memory.Loader import *
mychecker = load_checker(integer)

pydsl also provides a command line interface for the main functions:

* : Searchs and displays information about grammar/alphabets
* Checks if input data belongs to a grammar
* guess:py: Returns a list of the types that match the input element
* Perform a validation routine for user data according to a grammar
* Generates a token list from an input according to an alphaber
* extract all the slices of the input that are accepted by a definition

* python >= 2.7
* optional: ply library ( )


GPLv3, see LICENSE file

pydsl is a language library written in python
Copyright (C) 2008-2013 Nestor Arocha (

Project details

Download files

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

Files for pydsl, version 0.2.0
Filename, size File type Python version Upload date Hashes
Filename, size pydsl-0.2.0.tar.gz (59.0 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page