Skip to content

Generate random elements of a language defined by a context free grammar.

License

Notifications You must be signed in to change notification settings

dfremont/hypothesis-cfg

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Early version of implementation of Hypothesis strategy for Context Free Grammars.

from hypothesis import given
from hypothesis_cfg import ContextFreeGrammarStrategy

# Production rules
GRAMMAR = {
    'P': (('P', 'P'), ('A', 'R')),
    'A': (('L', 'P'), ('(',)),
    'L': (('(',),),
    'R': ((')',),),
}

@given(ContextFreeGrammarStrategy(GRAMMAR, max_length=20, start='P'))
def test_foo(foo):
    assert len(foo) <= 20

Currently no guarantees on the distribution. TODO: cite relevant works.

About

Generate random elements of a language defined by a context free grammar.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%