Skip to content

Commit

Permalink
Merge pull request #16 from xp-framework/refactor/omit-start-token
Browse files Browse the repository at this point in the history
Omit start token from stream
  • Loading branch information
thekid authored Oct 9, 2020
2 parents 54e601b + 7f8cf8a commit 5ec36df
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 22 deletions.
13 changes: 0 additions & 13 deletions src/main/php/lang/ast/nodes/Start.class.php

This file was deleted.

7 changes: 5 additions & 2 deletions src/main/php/lang/ast/syntax/PHP.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
ReturnStatement,
ScopeExpression,
Signature,
Start,
StaticLocals,
SwitchStatement,
TernaryExpression,
Expand Down Expand Up @@ -520,8 +519,12 @@ public function __construct() {

$this->stmt('<?', function($parse, $token) {
$syntax= $parse->token->value;
if ('php' !== $syntax) {
$parse->raise('Unexpected syntax '.$syntax.', expecting php', $token->value);
}

$parse->forward();
return new Start($syntax, $token->line);
return $this->statement($parse);
});

$this->stmt('{', function($parse, $token) {
Expand Down
12 changes: 5 additions & 7 deletions src/test/php/lang/ast/unittest/parse/StartTokensTest.class.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
<?php namespace lang\ast\unittest\parse;

use lang\ast\nodes\{NamespaceDeclaration, Start};
use lang\ast\Errors;
use lang\ast\nodes\NamespaceDeclaration;
use unittest\{Assert, Test};

class StartTokensTest extends ParseTest {

#[Test]
public function php() {
$this->assertParsed(
[new Start('php', self::LINE), new NamespaceDeclaration('test', self::LINE)],
[new NamespaceDeclaration('test', self::LINE)],
'<?php namespace test;'
);
}

#[Test]
#[Test, Expect(class: Errors::class, withMessage: 'Unexpected syntax hh, expecting php in <?')]
public function hack() {
$this->assertParsed(
[new Start('hh', self::LINE), new NamespaceDeclaration('test', self::LINE)],
'<?hh namespace test;'
);
$this->parse('<?hh namespace test;')->tree();
}
}

0 comments on commit 5ec36df

Please sign in to comment.