Skip to content

Commit 5972478

Browse files
committed
Minor fixes to prevent duplicate tokens and missing RAV's
1 parent 6e734bb commit 5972478

File tree

3 files changed

+80
-5
lines changed

3 files changed

+80
-5
lines changed

src/Lexer/AbstractLexer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@ public function getNextToken(): ?TokenInterface
8787
// Match a Recursive Annotation Variation:
8888
if (preg_match('/^\s*[\(|\)]/s', $this->buffer, $matches)) {
8989
$this->buffer = substr($this->buffer, strlen($matches[0]));
90-
return new RecursiveAnnotationVariation($matches[0] === '(');
90+
return new RecursiveAnnotationVariation(trim($matches[0]) === '(');
9191
}
9292

9393
// Match a Numeric Annotation Glyph
9494
if (preg_match('/^\s*\$([0-9]+)\s*/', $this->buffer, $matches)) {
9595
$this->buffer = substr($this->buffer, strlen($matches[0]));
96-
return new NumericAnnotationGlyph((int)$matches[1]);
96+
return new NumericAnnotationGlyph((int)trim($matches[1]));
9797
}
9898

9999
// Match a null move

src/Reader/AbstractReader.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ public function __construct(LexerInterface $lexer)
3939
*/
4040
public function read(): ?TokenIterator
4141
{
42-
$token = $this->lexer->peekNextToken();
43-
44-
if ($token === null) {
42+
if ($this->lexer->peekNextToken() === null) {
4543
return null;
4644
}
4745

46+
$token = $this->lexer->getNextToken();
47+
4848
$tokens = [];
4949

5050
while ($token instanceof TagPair) {

tests/Lexer/AbstractLexerTest.php

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,36 @@ public function testMatchRecursiveAnnotationVariationOpening()
183183
static::assertTrue($result->isOpening());
184184
}
185185

186+
public function testMatchRecursiveAnnotationVariationOpeningWithSpaceAtBegin()
187+
{
188+
// Arrange
189+
$buffer = ' (';
190+
191+
$lexer = new StringLexer($buffer);
192+
193+
// Act
194+
$result = $lexer->getNextToken();
195+
196+
// Assert
197+
static::assertInstanceOf(RecursiveAnnotationVariation::class, $result);
198+
static::assertTrue($result->isOpening());
199+
}
200+
201+
public function testMatchRecursiveAnnotationVariationOpeningWithSpaceAtEnd()
202+
{
203+
// Arrange
204+
$buffer = '( ';
205+
206+
$lexer = new StringLexer($buffer);
207+
208+
// Act
209+
$result = $lexer->getNextToken();
210+
211+
// Assert
212+
static::assertInstanceOf(RecursiveAnnotationVariation::class, $result);
213+
static::assertTrue($result->isOpening());
214+
}
215+
186216
public function testMatchRecursiveAnnotationVariationClosing()
187217
{
188218
// Arrange
@@ -198,6 +228,36 @@ public function testMatchRecursiveAnnotationVariationClosing()
198228
static::assertFalse($result->isOpening());
199229
}
200230

231+
public function testMatchRecursiveAnnotationVariationClosingWithSpaceAtEnd()
232+
{
233+
// Arrange
234+
$buffer = ') ';
235+
236+
$lexer = new StringLexer($buffer);
237+
238+
// Act
239+
$result = $lexer->getNextToken();
240+
241+
// Assert
242+
static::assertInstanceOf(RecursiveAnnotationVariation::class, $result);
243+
static::assertFalse($result->isOpening());
244+
}
245+
246+
public function testMatchRecursiveAnnotationVariationClosingWithSpaceAtBegin()
247+
{
248+
// Arrange
249+
$buffer = ' )';
250+
251+
$lexer = new StringLexer($buffer);
252+
253+
// Act
254+
$result = $lexer->getNextToken();
255+
256+
// Assert
257+
static::assertInstanceOf(RecursiveAnnotationVariation::class, $result);
258+
static::assertFalse($result->isOpening());
259+
}
260+
201261
public function testMatchNumericAnnotationGlyph()
202262
{
203263
// Arrange
@@ -213,6 +273,21 @@ public function testMatchNumericAnnotationGlyph()
213273
static::assertEquals(123, $result->getValue());
214274
}
215275

276+
public function testMatchNumericAnnotationGlyphWithSpace()
277+
{
278+
// Arrange
279+
$buffer = ' $123';
280+
281+
$lexer = new StringLexer($buffer);
282+
283+
// Act
284+
$result = $lexer->getNextToken();
285+
286+
// Assert
287+
static::assertInstanceOf(NumericAnnotationGlyph::class, $result);
288+
static::assertEquals(123, $result->getValue());
289+
}
290+
216291
public function testMatchSANCastling()
217292
{
218293
// Arrange

0 commit comments

Comments
 (0)