-
Notifications
You must be signed in to change notification settings - Fork 3
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
Allow for custom Token definiton entry #2
Comments
Any suggestion how to define such regex in array config like below?
|
None really. I made CustomTokenDefn class that extends TokenDefn: class CustomTokenDefn extends TokenDefn
{
/**
* CustomTokenDefn constructor.
*
* @param string $name
* @param string $regex
*/
public function __construct(string $name, string $regex)
{
parent::__construct($name, $regex);
$this->name = $name;
$this->regex = $regex;
}
} and I can add that to the config with /**
* @param TokenDefn[] $tokenDefinitions
*/
public function __construct(array $tokenDefinitions)
{
foreach ($tokenDefinitions as $k => $v) {
if ($v instanceof TokenDefn) {
$this->addTokenDefinition($v);
} elseif (is_string($k) && is_string($v)) {
$this->addTokenDefinition(new TokenDefn($v, $k));
}
}
} says that the constructor accepts only an array of TokenDefn object, while it also accepts normal assoc array (even in your example). That makes PHPstan throw an error. Correct phpdoc would be: /**
* @param TokenDefn[]|array $tokenDefinitions
*/ |
Currently, this module only allows adding definitions by adding TokenDefn objects. TokenDefn constructor has this line:
$this->regex = sprintf('%s^%s%s%s', $delimiter, $regex, $delimiter, $modifiers);
Sometimes, you don't want to add
^
into your expression. There should be a way to insert regex token only by giving it regex(string) and token name.The text was updated successfully, but these errors were encountered: