function it_should_create_a_character_class_from_a_node() { $characterClassNode = new CharacterClassNode('a-z'); $characterClassCode = <<<EOS if (preg_match('/^[a-z]\$/', substr(\$this->string, \$this->position, 1))) { \$_success = true; \$this->value = substr(\$this->string, \$this->position, 1); \$this->position += 1; } else { \$_success = false; } EOS; $characterClassNode->accept($this->getWrappedObject()); $this->getResult()->shouldBe($characterClassCode); }
public function visitCharacterClass(CharacterClassNode $node) { $pattern = var_export("/^[{$node->getString()}]\$/", true); $this->results[] = <<<EOS if (preg_match({$pattern}, substr(\$this->string, \$this->position, 1))) { \$_success = true; \$this->value = substr(\$this->string, \$this->position, 1); \$this->position += 1; } else { \$_success = false; } EOS; }