diff --git a/Parser/Shortcut/ClassParser.php b/Parser/Shortcut/ClassParser.php index 142bd16..83f8d13 100644 --- a/Parser/Shortcut/ClassParser.php +++ b/Parser/Shortcut/ClassParser.php @@ -33,15 +33,14 @@ public function parse($source) { // Matches an optional namespace, optional element, and required class // $source = 'test|input.ab6bd_field'; - // $matches = array (size=5) - // 0 => string 'test:input.ab6bd_field' (length=22) - // 1 => string 'test:' (length=5) - // 2 => string 'test' (length=4) - // 3 => string 'input' (length=5) - // 4 => string 'ab6bd_field' (length=11) - if (preg_match('/^(([a-z]+)\|)?([\w-]+|\*)?\.([\w-]+)$/i', trim($source), $matches)) { + // $matches = array (size=4) + // 0 => string 'test|input.ab6bd_field' (length=22) + // 1 => string 'test' (length=4) + // 2 => string 'input' (length=5) + // 3 => string 'ab6bd_field' (length=11) + if (preg_match('/^(?:([a-z]++)\|)?+([\w-]++|\*)?+\.([\w-]++)$/i', trim($source), $matches)) { return array( - new SelectorNode(new ClassNode(new ElementNode($matches[2] ?: null, $matches[3] ?: null), $matches[4])), + new SelectorNode(new ClassNode(new ElementNode($matches[1] ?: null, $matches[2] ?: null), $matches[3])), ); } diff --git a/Parser/Shortcut/ElementParser.php b/Parser/Shortcut/ElementParser.php index f62d259..00e4435 100644 --- a/Parser/Shortcut/ElementParser.php +++ b/Parser/Shortcut/ElementParser.php @@ -32,13 +32,12 @@ public function parse($source) { // Matches an optional namespace, required element or `*` // $source = 'testns|testel'; - // $matches = array (size=4) - // 0 => string 'testns:testel' (length=13) - // 1 => string 'testns:' (length=7) - // 2 => string 'testns' (length=6) - // 3 => string 'testel' (length=6) - if (preg_match('/^(([a-z]+)\|)?([\w-]+|\*)$/i', trim($source), $matches)) { - return array(new SelectorNode(new ElementNode($matches[2] ?: null, $matches[3]))); + // $matches = array (size=3) + // 0 => string 'testns|testel' (length=13) + // 1 => string 'testns' (length=6) + // 2 => string 'testel' (length=6) + if (preg_match('/^(?:([a-z]++)\|)?([\w-]++|\*)$/i', trim($source), $matches)) { + return array(new SelectorNode(new ElementNode($matches[1] ?: null, $matches[2]))); } return array(); diff --git a/Parser/Shortcut/HashParser.php b/Parser/Shortcut/HashParser.php index fde6141..3dbad79 100644 --- a/Parser/Shortcut/HashParser.php +++ b/Parser/Shortcut/HashParser.php @@ -33,15 +33,14 @@ public function parse($source) { // Matches an optional namespace, optional element, and required id // $source = 'test|input#ab6bd_field'; - // $matches = array (size=5) - // 0 => string 'test:input#ab6bd_field' (length=22) - // 1 => string 'test:' (length=5) - // 2 => string 'test' (length=4) - // 3 => string 'input' (length=5) - // 4 => string 'ab6bd_field' (length=11) - if (preg_match('/^(([a-z]+)\|)?([\w-]+|\*)?#([\w-]+)$/i', trim($source), $matches)) { + // $matches = array (size=4) + // 0 => string 'test|input#ab6bd_field' (length=22) + // 1 => string 'test' (length=4) + // 2 => string 'input' (length=5) + // 3 => string 'ab6bd_field' (length=11) + if (preg_match('/^(?:([a-z]++)\|)?+([\w-]++|\*)?+#([\w-]++)$/i', trim($source), $matches)) { return array( - new SelectorNode(new HashNode(new ElementNode($matches[2] ?: null, $matches[3] ?: null), $matches[4])), + new SelectorNode(new HashNode(new ElementNode($matches[1] ?: null, $matches[2] ?: null), $matches[3])), ); }