Skip to content

Commit

Permalink
Parsley name was taken by another library.
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Apr 23, 2014
1 parent 3b57973 commit bff4edb
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 61 deletions.
20 changes: 10 additions & 10 deletions README.md
@@ -1,22 +1,22 @@
# Parsley
# Paggern

[![Build Status](https://travis-ci.org/gajus/parsley.png?branch=master)](https://travis-ci.org/gajus/parsley)
[![Coverage Status](https://coveralls.io/repos/gajus/parsley/badge.png?branch=master&cache=123)](https://coveralls.io/r/gajus/parsley?branch=master)
[![Latest Stable Version](https://poser.pugx.org/gajus/parsley/version.png)](https://packagist.org/packages/gajus/parsley)
[![License](https://poser.pugx.org/gajus/parsley/license.png)](https://packagist.org/packages/gajus/parsley)
[![Build Status](https://travis-ci.org/gajus/paggern.png?branch=master)](https://travis-ci.org/gajus/paggern)
[![Coverage Status](https://coveralls.io/repos/gajus/paggern/badge.png?branch=master&cache=123)](https://coveralls.io/r/gajus/paggern?branch=master)
[![Latest Stable Version](https://poser.pugx.org/gajus/paggern/version.png)](https://packagist.org/packages/gajus/paggern)
[![License](https://poser.pugx.org/gajus/paggern/license.png)](https://packagist.org/packages/gajus/paggern)

Pattern interpreter for generating random strings.

## Generator

```php
$generator = new \Gajus\Parsley\Generator();
$generator = new \Gajus\Paggern\Generator();

/**
* Generate a set of random codes based on Parsley pattern.
* Generate a set of random codes based on Paggern pattern.
* Codes are guaranteed to be unique within the set.
*
* @param string $pattern Parsley pattern.
* @param string $pattern Paggern pattern.
* @param int $amount Number of codes to generate.
* @param int $safeguard Number of additional codes generated in case there are duplicates that need to be replaced.
* @return array
Expand All @@ -26,14 +26,14 @@ $codes = $generator->generateFromPattern('FOO[A-Z]{10}[0-9]{2}', 100);

The above example will generate an array containing 100 codes, each prefixed with "FOO", followed by 10 characters from "ABCDEFGHKMNOPRSTUVWXYZ23456789" haystack and 2 numbers from "0123456789" haystack.

Parsley utilises [RandomLib](https://github.com/ircmaxell/RandomLib) to generate the pattern matching random character pool.
Paggern utilises [RandomLib](https://github.com/ircmaxell/RandomLib) to generate the pattern matching random character pool.

## Lexer

Lexer exposes a method to tokenise the string. `Lexer` is independant of the `Generator`. You can choose to interpret `Lexer` tokens using your own implementation of the `Generator`.

```php
$lexer = new \Gajus\Parsley\Lexer();
$lexer = new \Gajus\Paggern\Lexer();

/**
* Tokeniser explodes input into components describing the properties expressed in the pattern.
Expand Down
6 changes: 3 additions & 3 deletions composer.json
@@ -1,9 +1,9 @@
{
"name": "gajus/parsley",
"name": "gajus/paggern",
"version": "0.1.1",
"description": "Pattern interpreter for generating random strings.",
"keywords": ["parser", "generator", "voucher", "code"],
"homepage": "https://github.com/gajus/parsley",
"homepage": "https://github.com/gajus/paggern",
"type": "library",
"license": "BSD-3-Clause",
"authors": [
Expand All @@ -21,7 +21,7 @@
},
"autoload": {
"psr-4": {
"Gajus\\Parsley\\": "src/"
"Gajus\\Paggern\\": "src/"
}
}
}
8 changes: 4 additions & 4 deletions src/Exception/LogicException.php
@@ -1,10 +1,10 @@
<?php
namespace Gajus\Parsley\Exception;
namespace Gajus\Paggern\Exception;

/**
* @link https://github.com/gajus/parsley for the canonical source repository
* @license https://github.com/gajus/parsley/blob/master/LICENSE BSD 3-Clause
* @link https://github.com/gajus/paggern for the canonical source repository
* @license https://github.com/gajus/paggern/blob/master/LICENSE BSD 3-Clause
*/
class LogicException extends ParsleyException {
class LogicException extends PaggernException {

}
8 changes: 8 additions & 0 deletions src/Exception/PaggernException.php
@@ -0,0 +1,8 @@
<?php
namespace Gajus\Paggern\Exception;

/**
* @link https://github.com/gajus/paggern for the canonical source repository
* @license https://github.com/gajus/paggern/blob/master/LICENSE BSD 3-Clause
*/
class PaggernException extends \Exception {}
8 changes: 0 additions & 8 deletions src/Exception/ParsleyException.php

This file was deleted.

8 changes: 4 additions & 4 deletions src/Exception/RuntimeException.php
@@ -1,10 +1,10 @@
<?php
namespace Gajus\Parsley\Exception;
namespace Gajus\Paggern\Exception;

/**
* @link https://github.com/gajus/parsley for the canonical source repository
* @license https://github.com/gajus/parsley/blob/master/LICENSE BSD 3-Clause
* @link https://github.com/gajus/paggern for the canonical source repository
* @license https://github.com/gajus/paggern/blob/master/LICENSE BSD 3-Clause
*/
class RuntimeException extends ParsleyException {
class RuntimeException extends PaggernException {

}
8 changes: 4 additions & 4 deletions src/Exception/UnexpectedValueException.php
@@ -1,10 +1,10 @@
<?php
namespace Gajus\Parsley\Exception;
namespace Gajus\Paggern\Exception;

/**
* @link https://github.com/gajus/parsley for the canonical source repository
* @license https://github.com/gajus/parsley/blob/master/LICENSE BSD 3-Clause
* @link https://github.com/gajus/paggern for the canonical source repository
* @license https://github.com/gajus/paggern/blob/master/LICENSE BSD 3-Clause
*/
class UnexpectedValueException extends ParsleyException {
class UnexpectedValueException extends PaggernException {

}
12 changes: 6 additions & 6 deletions src/Generator.php
@@ -1,9 +1,9 @@
<?php
namespace Gajus\Parsley;
namespace Gajus\Paggern;

/**
* @link https://github.com/gajus/parsley for the canonical source repository
* @license https://github.com/gajus/parsley/blob/master/LICENSE BSD 3-Clause
* @link https://github.com/gajus/paggern for the canonical source repository
* @license https://github.com/gajus/paggern/blob/master/LICENSE BSD 3-Clause
*/
class Generator {
private
Expand All @@ -20,16 +20,16 @@ public function __construct (\RandomLib\Generator $generator = null) {
}

/**
* Generate a set of random codes based on Parsley pattern.
* Generate a set of random codes based on Paggern pattern.
* Codes are guaranteed to be unique within the set.
*
* @param string $pattern Parsley pattern.
* @param string $pattern Paggern pattern.
* @param int $amount Number of codes to generate.
* @param int $safeguard Number of additional codes generated in case there are duplicates that need to be replaced.
* @return array
*/
public function generateFromPattern ($pattern, $amount = 1, $safeguard = 100) {
$lexer = new \Gajus\Parsley\Lexer();
$lexer = new \Gajus\Paggern\Lexer();
$tokens = $lexer->tokenise($pattern, true);

$codes = array_fill(0, $amount + $safeguard, '');
Expand Down
6 changes: 3 additions & 3 deletions src/Lexer.php
@@ -1,9 +1,9 @@
<?php
namespace Gajus\Parsley;
namespace Gajus\Paggern;

/**
* @link https://github.com/gajus/parsley for the canonical source repository
* @license https://github.com/gajus/parsley/blob/master/LICENSE BSD 3-Clause
* @link https://github.com/gajus/paggern for the canonical source repository
* @license https://github.com/gajus/paggern/blob/master/LICENSE BSD 3-Clause
*/
class Lexer {
const
Expand Down
10 changes: 5 additions & 5 deletions tests/GeneratorTest.php
@@ -1,23 +1,23 @@
<?php
class GeneratorTest extends PHPUnit_Framework_TestCase {
public function testLiteral () {
$generator = new \Gajus\Parsley\Generator();
$generator = new \Gajus\Paggern\Generator();
$codes = $generator->generateFromPattern('abc');

$this->assertCount(1, $codes);
$this->assertSame(['abc'], $codes);
}

public function testRange () {
$generator = new \Gajus\Parsley\Generator();
$generator = new \Gajus\Paggern\Generator();
$codes = $generator->generateFromPattern('[a-c]');

$this->assertCount(1, $codes);
$this->assertContains($codes[0], ['a', 'b', 'c']);
}

public function testClass () {
$generator = new \Gajus\Parsley\Generator();
$generator = new \Gajus\Paggern\Generator();
$codes = $generator->generateFromPattern('\U{10}', 100);

$this->assertCount(100, $codes);
Expand All @@ -29,11 +29,11 @@ public function testClass () {
}

/**
* @expectedException Gajus\Parsley\Exception\RuntimeException
* @expectedException Gajus\Paggern\Exception\RuntimeException
* @expectedExceptionMessage Unique combination pool exhausted.
*/
public function testUniquePoolExhaustion () {
$generator = new \Gajus\Parsley\Generator();
$generator = new \Gajus\Paggern\Generator();
$codes = $generator->generateFromPattern('abc', 2);
}
}
8 changes: 4 additions & 4 deletions tests/RangeTest.php
Expand Up @@ -4,7 +4,7 @@ class RangeTest extends PHPUnit_Framework_TestCase {
* @dataProvider alphabeticalProvider
*/
public function testAlphabetical ($range_defition, $haystack) {
$this->assertSame($haystack, \Gajus\Parsley\Lexer::expandRange($range_defition));
$this->assertSame($haystack, \Gajus\Paggern\Lexer::expandRange($range_defition));
}

public function alphabeticalProvider () {
Expand All @@ -18,11 +18,11 @@ public function alphabeticalProvider () {

/**
* @dataProvider invalidProvider
* @expectedException Gajus\Parsley\Exception\LogicException
* @expectedException Gajus\Paggern\Exception\LogicException
* @expectedExceptionMessage Invalid range definition. Start greater than end.
*/
public function testInvalid ($range_defition) {
\Gajus\Parsley\Lexer::expandRange($range_defition);
\Gajus\Paggern\Lexer::expandRange($range_defition);
}

public function invalidProvider () {
Expand All @@ -36,7 +36,7 @@ public function invalidProvider () {
* @dataProvider composedProvider
*/
public function testComposed ($range_defition, $haystack) {
$this->assertSame($haystack, \Gajus\Parsley\Lexer::expandRange($range_defition));
$this->assertSame($haystack, \Gajus\Paggern\Lexer::expandRange($range_defition));
}

public function composedProvider () {
Expand Down
20 changes: 10 additions & 10 deletions tests/TokenisationTest.php
@@ -1,54 +1,54 @@
<?php
class TokenisationTest extends PHPUnit_Framework_TestCase {
public function testLiteralString () {
$lexer = new \Gajus\Parsley\Lexer();
$lexer = new \Gajus\Paggern\Lexer();
$tokens = $lexer->tokenise('abc');

$this->assertCount(1, $tokens);
$this->assertSame(['type' => 'literal', 'string' => 'abc'], $tokens[0]);
}

public function testRangeImplicit () {
$lexer = new \Gajus\Parsley\Lexer();
$lexer = new \Gajus\Paggern\Lexer();
$tokens = $lexer->tokenise('[0-9]');

$this->assertCount(1, $tokens);
$this->assertSame(['type' => 'range', 'token' => '0-9', 'repetition' => 1], $tokens[0]);
}

public function testRangeExplicit () {
$lexer = new \Gajus\Parsley\Lexer();
$lexer = new \Gajus\Paggern\Lexer();
$tokens = $lexer->tokenise('[a-z]{2}');

$this->assertCount(1, $tokens);
$this->assertSame(['type' => 'range', 'token' => 'a-z', 'repetition' => 2], $tokens[0]);
}

public function testClassImplicit () {
$lexer = new \Gajus\Parsley\Lexer();
$lexer = new \Gajus\Paggern\Lexer();
$tokens = $lexer->tokenise('\U');

$this->assertCount(1, $tokens);
$this->assertSame(['type' => 'class', 'class' => \Gajus\Parsley\Lexer::CLASS_UPPERCASE_UNAMBIGUOUS, 'repetition' => 1], $tokens[0]);
$this->assertSame(['type' => 'class', 'class' => \Gajus\Paggern\Lexer::CLASS_UPPERCASE_UNAMBIGUOUS, 'repetition' => 1], $tokens[0]);
}

public function testClassExplicit () {
$lexer = new \Gajus\Parsley\Lexer();
$lexer = new \Gajus\Paggern\Lexer();
$tokens = $lexer->tokenise('\U{10}');

$this->assertCount(1, $tokens);
$this->assertSame(['type' => 'class', 'class' => \Gajus\Parsley\Lexer::CLASS_UPPERCASE_UNAMBIGUOUS, 'repetition' => 10], $tokens[0]);
$this->assertSame(['type' => 'class', 'class' => \Gajus\Paggern\Lexer::CLASS_UPPERCASE_UNAMBIGUOUS, 'repetition' => 10], $tokens[0]);
}

public function testCombined () {
$lexer = new \Gajus\Parsley\Lexer();
$lexer = new \Gajus\Paggern\Lexer();
$tokens = $lexer->tokenise('abc[a-z]{2}[0-9]\U\U{3}');
$this->assertCount(5, $tokens);

$this->assertSame(['type' => 'literal', 'string' => 'abc'], $tokens[0]);
$this->assertSame(['type' => 'range', 'token' => 'a-z', 'repetition' => 2], $tokens[1]);
$this->assertSame(['type' => 'range', 'token' => '0-9', 'repetition' => 1], $tokens[2]);
$this->assertSame(['type' => 'class', 'class' => \Gajus\Parsley\Lexer::CLASS_UPPERCASE_UNAMBIGUOUS, 'repetition' => 1], $tokens[3]);
$this->assertSame(['type' => 'class', 'class' => \Gajus\Parsley\Lexer::CLASS_UPPERCASE_UNAMBIGUOUS, 'repetition' => 3], $tokens[4]);
$this->assertSame(['type' => 'class', 'class' => \Gajus\Paggern\Lexer::CLASS_UPPERCASE_UNAMBIGUOUS, 'repetition' => 1], $tokens[3]);
$this->assertSame(['type' => 'class', 'class' => \Gajus\Paggern\Lexer::CLASS_UPPERCASE_UNAMBIGUOUS, 'repetition' => 3], $tokens[4]);
}
}

0 comments on commit bff4edb

Please sign in to comment.