Skip to content

Context Sensitive Lexer #1054

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions Zend/tests/grammar/regression_001.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
--TEST--
Test to check static method calls syntax regression
--FILE--
<?php

class Foo {
public static function function(){ echo __METHOD__, PHP_EOL; }
}

Foo::function();

Foo::
function();

Foo::
function();


Foo::
function(

);

echo "\nDone\n";

--EXPECTF--

Foo::function
Foo::function
Foo::function
Foo::function

Done
22 changes: 22 additions & 0 deletions Zend/tests/grammar/regression_002.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
Test to ensure ::class still works
--FILE--
<?php

class Foo {}

var_dump(Foo::class);

var_dump(Foo:: class);

var_dump(Foo:: CLASS);

var_dump(Foo::

CLASS);

--EXPECTF--
string(3) "Foo"
string(3) "Foo"
string(3) "Foo"
string(3) "Foo"
12 changes: 12 additions & 0 deletions Zend/tests/grammar/regression_003.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
Test to ensure ::class is reserved in obj scope
--FILE--
<?php

class Obj
{
const CLASS = 'class';
}

--EXPECTF--
Fatal error: Cannot redefine class constant Obj::CLASS as it is reserved in %s on line 5
15 changes: 15 additions & 0 deletions Zend/tests/grammar/regression_004.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
Test possible function naming regression on procedural scope
--FILE--
<?php

class Obj
{
function echo(){} // valid
function return(){} // valid
}

function echo(){} // not valid

--EXPECTF--
Parse error: syntax error, unexpected 'echo' (T_ECHO), expecting identifier (T_STRING) or '(' in %s on line 9
14 changes: 14 additions & 0 deletions Zend/tests/grammar/regression_005.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
Test possible constant naming regression on procedural scope
--FILE--
<?php

class Obj
{
const return = 'yep';
}

const return = 'nope';

--EXPECTF--
Parse error: syntax error, unexpected 'return' (T_RETURN), expecting identifier (T_STRING) in %s on line 8
30 changes: 30 additions & 0 deletions Zend/tests/grammar/regression_006.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--TEST--
Test to ensure const list syntax declaration works
--FILE--
<?php

class Obj
{
const DECLARE = 'declare',
RETURN = 'return',
FUNCTION = 'function',
USE = 'use';
}

echo Obj::DECLARE, PHP_EOL;
echo Obj::RETURN, PHP_EOL;
echo Obj::FUNCTION, PHP_EOL;
echo Obj::USE, PHP_EOL;
echo Obj::

USE, PHP_EOL;
echo "\nDone\n";

--EXPECTF--
declare
return
function
use
use

Done
44 changes: 44 additions & 0 deletions Zend/tests/grammar/regression_007.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
--TEST--
Test to ensure semi reserved words allow deference
--FILE--
<?php

class Foo {
const use = 'yay';

public static function new() {
echo __METHOD__, PHP_EOL;
return new static();
}

public function self() {
echo __METHOD__, PHP_EOL;
return $this;
}
}

Foo::new()::new()::new();

var_dump(
(new Foo)->self()::new()->self()->self()::use
);

Foo::{'new'}();

var_dump(Foo::use);

echo "\nDone\n";

--EXPECTF--
Foo::new
Foo::new
Foo::new
Foo::self
Foo::new
Foo::self
Foo::self
string(3) "yay"
Foo::new
string(3) "yay"

Done
21 changes: 21 additions & 0 deletions Zend/tests/grammar/regression_008.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
Test to check regressions on string interpolation with class members access
--FILE--
<?php

class Friday {
public $require = "fun";
}

$friday = new Friday;

echo "$friday->require ($friday->require) {$friday->require}", PHP_EOL;

echo "\nDone\n";


--EXPECTF--

fun (fun) fun

Done
18 changes: 18 additions & 0 deletions Zend/tests/grammar/regression_009.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
Test to check regressions on use statements and lexer state
--FILE--
<?php

use A\B\C\D;

class Foo
{
private static $foo;

}

echo PHP_EOL, "Done", PHP_EOL;

--EXPECTF--

Done
14 changes: 14 additions & 0 deletions Zend/tests/grammar/regression_010.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
Test to check regressions on T_IMPLEMENTS followed by a T_NS_SEPARATOR
--FILE--
<?php

interface A{}

class B implements\A {}

echo "Done", PHP_EOL;

--EXPECTF--

Done
18 changes: 18 additions & 0 deletions Zend/tests/grammar/regression_011.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
Testing instantiation using namespace:: prefix
--FILE--
<?php

namespace foo;

class bar {
}

class_alias('foo\bar', 'foo\baz');

var_dump(new namespace\baz);

?>
--EXPECTF--
object(foo\bar)#%d (0) {
}
13 changes: 13 additions & 0 deletions Zend/tests/grammar/regression_012.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
Testing for regression on const list syntax and arrays
--FILE--
<?php

class A {
const A = [1, FOREACH];
}

?>
--EXPECTF--

Parse error: syntax error, unexpected 'FOREACH' (T_FOREACH), expecting ']' in %s on line %d
13 changes: 13 additions & 0 deletions Zend/tests/grammar/regression_013.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
Testing for regression with encapsed variables in class declaration context
--FILE--
<?php

class A { function foo() { "{${$a}}"; } function list() {} }

echo "Done", PHP_EOL;

?>
--EXPECTF--

Done
Loading