Debian Codegraph @

vendor/mck89/peast/lib/Peast/Syntax/Node/RegExpLiteral.php

raw
1 <?php
2 /**
3 * This file is part of the Peast package
4 *
5 * (c) Marco Marchiò <[email protected]>
6 *
7 * For the full copyright and license information refer to the LICENSE file
8 * distributed with this source code
9 */
10 namespace Peast\Syntax\Node;
11
12 /**
13 * A node that represents a regular expression literal.
14 *
15 * @author Marco Marchiò <[email protected]>
16 */
17 class RegExpLiteral extends Literal
18 {
19 /**
20 * Map of node properties
21 *
22 * @var array
23 */
24 protected $propertiesMap = array(
25 "flags" => false,
26 "pattern" => false
27 );
28
29 /**
30 * Regex flags
31 *
32 * @var string
33 */
34 protected $flags = "";
35
36 /**
37 * Regex pattern
38 *
39 * @var string
40 */
41 protected $pattern = "";
42
43 /**
44 * Returns node's type
45 *
46 * @return string
47 */
48 public function getType()
49 {
50 return "RegExpLiteral";
51 }
52
53 /**
54 * Returns regex pattern
55 *
56 * @return string
57 */
58 public function getPattern()
59 {
60 return $this->pattern;
61 }
62
63 /**
64 * Sets regex pattern
65 *
66 * @param string $pattern Regex pattern
67 *
68 * @return $this
69 */
70 public function setPattern($pattern)
71 {
72 $this->pattern = $pattern;
73 return $this;
74 }
75
76 /**
77 * Returns regex flags
78 *
79 * @return string
80 */
81 public function getFlags()
82 {
83 return $this->flags;
84 }
85
86 /**
87 * Sets regex flags
88 *
89 * @param string $flags Regex flags
90 *
91 * @return $this
92 */
93 public function setFlags($flags)
94 {
95 $this->flags = $flags;
96 return $this;
97 }
98
99 /**
100 * Returns node's raw value
101 *
102 * @return string
103 */
104 public function getRaw()
105 {
106 return "/" . $this->getPattern() . "/" . $this->getFlags();
107 }
108
109 /**
110 * Sets node's raw value that must include delimiters
111 *
112 * @param string $raw Raw value
113 *
114 * @return $this
115 */
116 public function setRaw($raw)
117 {
118
119 $parts = explode("/", substr($raw, 1));
120 $flags = array_pop($parts);
121 $this->setPattern(implode("/", $parts));
122 $this->setFlags($flags);
123 return $this;
124 }
125
126 /**
127 * Returns node's value
128 *
129 * @return string
130 */
131 public function getValue()
132 {
133 return $this->getRaw();
134 }
135
136 /**
137 * Sets node's value
138 *
139 * @param mixed $value Value
140 *
141 * @return $this
142 */
143 public function setValue($value)
144 {
145 return $this->setRaw($value);
146 }
147 }