Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enh(zephir) almost complete rework of the zephir grammar (#2387)
* (chore) zephir grammar cleanups and more The original grammar was lifted from PHP and is inaccurate in many ways.
- Loading branch information
1 parent
7bc073f
commit df36efb
Showing
4 changed files
with
146 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">testBefore</span><span class="hljs-params">(<Test> a, <span class="hljs-keyword">var</span> b = <span class="hljs-number">5</span>, <span class="hljs-keyword">int</span> c = <span class="hljs-number">10</span>)</span> | ||
</span>{ | ||
a->method1(); | ||
|
||
<span class="hljs-keyword">return</span> b + c; | ||
} | ||
|
||
<span class="hljs-keyword">namespace</span> <span class="hljs-title">Test</span>; | ||
|
||
<span class="hljs-keyword">use</span> <span class="hljs-title">RuntimeException</span> <span class="hljs-title">as</span> <span class="hljs-title">RE</span>; | ||
|
||
<span class="hljs-comment">/** | ||
* Example comment | ||
*/</span> | ||
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Test</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">CustomClass</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">TestInterface</span> | ||
</span>{ | ||
<span class="hljs-keyword">const</span> C1 = <span class="hljs-keyword">null</span>; | ||
|
||
<span class="hljs-comment">// Magic constant: http://php.net/manual/ru/language.constants.predefined.php</span> | ||
<span class="hljs-keyword">const</span> className = <span class="hljs-keyword">__CLASS__</span>; | ||
|
||
<span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">method1</span><span class="hljs-params">()</span> | ||
</span>{ | ||
<span class="hljs-keyword">int</span> a = <span class="hljs-number">1</span>, b = <span class="hljs-number">2</span>; | ||
<span class="hljs-keyword">return</span> a + b; | ||
} | ||
|
||
<span class="hljs-comment">// See fn is allowed like shortcut</span> | ||
<span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">fn</span> <span class="hljs-title">method2</span><span class="hljs-params">()</span> -> <<span class="hljs-title">Test</span>> | ||
</span>{ | ||
call_user_func(<span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> </span>{ <span class="hljs-keyword">echo</span> <span class="hljs-string">"hello"</span>; }); | ||
|
||
|
||
[<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>]->walk( | ||
<span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(<span class="hljs-keyword">int</span>! x)</span> </span>{ | ||
<span class="hljs-keyword">return</span> x * x; | ||
} | ||
); | ||
|
||
[<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>]->walk( | ||
<span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(_, <span class="hljs-keyword">int</span> key)</span> </span>{ <span class="hljs-keyword">echo</span> key; } | ||
); | ||
|
||
<span class="hljs-keyword">array</span> input = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>]; | ||
|
||
input->walk( | ||
<span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(_, <span class="hljs-keyword">int</span> key)</span> </span>{ <span class="hljs-keyword">echo</span> key; } | ||
); | ||
|
||
|
||
input->map(x => x * x); | ||
|
||
<span class="hljs-keyword">return</span> this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
function testBefore(<Test> a, var b = 5, int c = 10) | ||
{ | ||
a->method1(); | ||
|
||
return b + c; | ||
} | ||
|
||
namespace Test; | ||
|
||
use RuntimeException as RE; | ||
|
||
/** | ||
* Example comment | ||
*/ | ||
class Test extends CustomClass implements TestInterface | ||
{ | ||
const C1 = null; | ||
|
||
// Magic constant: http://php.net/manual/ru/language.constants.predefined.php | ||
const className = __CLASS__; | ||
|
||
public function method1() | ||
{ | ||
int a = 1, b = 2; | ||
return a + b; | ||
} | ||
|
||
// See fn is allowed like shortcut | ||
public fn method2() -> <Test> | ||
{ | ||
call_user_func(function() { echo "hello"; }); | ||
|
||
|
||
[1, 2, 3, 4, 5]->walk( | ||
function(int! x) { | ||
return x * x; | ||
} | ||
); | ||
|
||
[1, 2, 3, 4, 5]->walk( | ||
function(_, int key) { echo key; } | ||
); | ||
|
||
array input = [1, 2, 3, 4, 5]; | ||
|
||
input->walk( | ||
function(_, int key) { echo key; } | ||
); | ||
|
||
|
||
input->map(x => x * x); | ||
|
||
return this; | ||
} | ||
} |