Skip to content

Pattern expander mechanism #27

New issue

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

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

Already on GitHub? # to your account

Merged
merged 1 commit into from
Oct 1, 2014
Merged

Conversation

norberttech
Copy link
Member

This implementation allows us to create multiple expanders for type patterns.
Each expander can be created with unlimited amount of arguments.
Supported argument types

  • string
  • number (float/integer)
  • boolean
  • null
  • array

There is only one available expander atm.

  • StartsWith($stringBeginning, $ignoreCase = false)
  • EndsWith($stringEnding, $ignoreCase = false)
  • NotEmpty()
  • LowerThan($boundry)
  • GreaterThan($boundry)
  • InArray($value)

Example expander usage:

$factory = new SimpleFactory();
$matcher = $factory->createMatcher();
$matcher->match("lorem ipsum", "@string@.startsWith('lorem')"); 

Syntax error in pattern expander will throw exception, example:

$factory = new SimpleFactory();
$matcher = $factory->createMatcher();
$matcher->match("lorem ipsum", "@type@.expander('string',not_argument"); 
// Exception message: [Syntax Error] line 0, col 25: Error: Expected "string or number argument", got "not_argument"

Pattern syntax:

@type@.expander(args).expander(args).expander()

You can use as many expanders as you need. You can also create expanders without arguments.

@norberttech
Copy link
Member Author

Added new expanders and possibility to register custom expanders definition at parser object.
Expanders are now available at following patterns:

  • String
  • Integer
  • Double

Not sure if NotBlank is good name for expander, I think we could rename it to NotEmpty and create another Empty expander.
@defrag what do you think, any suggestions?

@norberttech norberttech changed the title Initial draft of expander mechanism with StartsWith expander example Pattern expander mechanism Oct 1, 2014
Replaced [] with array() in AST\Expander class for php 5.3 support

Refactoring

Added Boolean and Null argument types support

Added negative numbers support

Added  argument to StartsWith expander

Set Lexer as a dependency of Parser and Parser as a dependency of StringMatcher

Added possibility to add new expander definitions

Added notBlank expander

Changed expanderName definition

Added lowerThan expander

Implement expanders in IntegerMatcher

Added expanders to DoubleMatcher

Added GreaterThan expander

Added EndsWith expander

Renamed NotBlank into NotEmpty

Added array argument type support

Added InArray expander

Added Contains expander
norberttech added a commit that referenced this pull request Oct 1, 2014
@norberttech norberttech merged commit d21c4d4 into coduo:master Oct 1, 2014
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant