@@ -34,6 +34,11 @@ class Conveyor {
3434 */
3535 protected $ next = null ;
3636
37+ /**
38+ * @var int Next string length
39+ */
40+ protected $ length = 0 ;
41+
3742 /**
3843 * @var int Current cursor line
3944 */
@@ -49,6 +54,16 @@ class Conveyor {
4954 */
5055 public function __construct (string $ source ) {
5156 $ this ->next = $ source ;
57+ $ this ->length = strlen ($ source );
58+ }
59+
60+ /**
61+ * Returns next string length
62+ *
63+ * @return int
64+ */
65+ public function length (): int {
66+ return $ this ->length ;
5267 }
5368
5469 /**
@@ -72,6 +87,7 @@ public function move(int $offset) {
7287 }
7388
7489 $ this ->next = substr ($ this ->next , $ offset );
90+ $ this ->length -= $ offset ;
7591 }
7692
7793 /**
@@ -90,6 +106,7 @@ public function readOperator(string $operator, bool $required = false): bool {
90106 }
91107
92108 if ($ required ) {
109+ // TODO Parsing exception class
93110 throw new \Exception ("$ operator not found at {$ this ->line } line {$ this ->row } row " );
94111 }
95112
@@ -100,7 +117,20 @@ public function readOperator(string $operator, bool $required = false): bool {
100117 * Moves conveyor to next not-space symbol
101118 */
102119 public function skipSpaces () {
103- if (preg_match ('/^\s*/ ' , $ this ->next , $ matches ) === 1 ) {
120+ if (preg_match ('/^ \\s*/ ' , $ this ->next , $ matches ) === 1 ) {
121+ $ this ->move (strlen ($ matches [0 ]));
122+ }
123+ }
124+
125+ /**
126+ * Skips comment if exists
127+ */
128+ public function skipComment () {
129+ if (preg_match ('/^ \\/ \\*[ \\s \\S]* \\* \\// ' , $ this ->next , $ matches ) === 1 ) {
130+ $ this ->move (strlen ($ matches [0 ]));
131+ }
132+
133+ if (preg_match ('/^ \\/ \\/.*/ ' , $ this ->next , $ matches ) === 1 ) {
104134 $ this ->move (strlen ($ matches [0 ]));
105135 }
106136 }
@@ -112,7 +142,7 @@ public function skipSpaces() {
112142 * @return string Namespace
113143 */
114144 public function readNamespace (): string {
115- if (preg_match ('/^[a-z_][\w \\]* \w/i ' , $ this ->next , $ matches ) === 1 ) {
145+ if (preg_match ('/^[a-z_][ \\ w \\\\ ]* \ \w/i ' , $ this ->next , $ matches ) === 1 ) {
116146 $ this ->move (strlen ($ matches [0 ]));
117147
118148 return $ matches [0 ];
@@ -128,7 +158,7 @@ public function readNamespace(): string {
128158 * @return string Class name
129159 */
130160 public function readClassname (): string {
131- if (preg_match ('/^[a-z_]\w*/i ' , $ this ->next , $ matches ) === 1 ) {
161+ if (preg_match ('/^[a-z_] \\ w*/i ' , $ this ->next , $ matches ) === 1 ) {
132162 $ this ->move (strlen ($ matches [0 ]));
133163
134164 return $ matches [0 ];
@@ -144,13 +174,13 @@ public function readClassname(): string {
144174 * @return string Extended class name
145175 */
146176 public function readExtendedClassname (): string {
147- if (preg_match ('/^( \\[a-z_]\w*)+/i ' , $ this ->next , $ matches ) === 1 ) {
177+ if (preg_match ('/^( \\\\ [a-z_] \ \w*)+/i ' , $ this ->next , $ matches ) === 1 ) {
148178 $ this ->move (strlen ($ matches [0 ]));
149179
150180 return $ matches [0 ];
151181 }
152182
153- return static :: readClassname ($ next );
183+ return $ this -> readClassname ();
154184 }
155185
156186 /**
0 commit comments