Skip to content

Commit 882030f

Browse files
authored
Merge pull request #37 from niden-code/feature/static-variadic
Feature/static variadic
2 parents 846db55 + 1c2fa8b commit 882030f

8 files changed

Lines changed: 360 additions & 2 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com)
55
and this project adheres to [Semantic Versioning](http://semver.org).
66

7+
## [Unreleased]
8+
### Added
9+
- Grammar: variadic parameters — `...` (`ELLIPSIS`) is now recognized before an argument name (e.g. `function foo(int ...values)`)
10+
- Grammar: `static` return type — `<static>` is now accepted as a class type, allowing `self`/`static` returns (e.g. `-> <static>`)
11+
- Grammar: closure `use` clause — `function () use (x, y) { }`, including `const` and by-reference (`&`) captured variables
12+
- Registered the `Zephir File` internal file template in `plugin.xml`
13+
714
## [0.6.0][0.6.0] - 2026-03-21
815
### Added
916
- Enhanced autocompletion for Zephir code:

‎src/main/grammar/Zephir.bnf‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146
ARROW = '->'
147147
DOUBLECOLON = '::'
148148
DOT = '.'
149+
ELLIPSIS = '...'
149150
ADD = '+'
150151
SUB = '-'
151152
MUL = '*'
@@ -250,7 +251,7 @@ CodeBlock ::= '{' Code* '}' {pin=1}
250251
ReturnType ::= '->' (Type | 'null') ('|' (Type | 'null'))* {pin(".*")=1}
251252

252253
Arguments ::= Argument (',' Argument)* {pin(".*")=1}
253-
Argument ::= Type? '!'? (PhpReserved | Id) DefaultValue? {pin=3}
254+
Argument ::= Type? '!'? '...'? (PhpReserved | Id) DefaultValue? {pin=4}
254255

255256
DefaultValue ::= '=' Expr {pin=1}
256257
Visibility ::= 'public' | 'protected' | 'private'
@@ -271,7 +272,7 @@ private BoolType ::= 'bool' | 'boolean'
271272
private NumberType ::= IntType | DoubleType | 'uint' | 'long' | 'ulong'
272273
private IntType ::= 'int' | 'integer'
273274
private DoubleType ::= 'double' | 'float'
274-
private ClassType ::= '<' ComplexId ArrayAppendExpr? '>'
275+
private ClassType ::= '<' (ComplexId | 'static') ArrayAppendExpr? '>'
275276
private ResourceType ::= '<' '$'ComplexId ArrayAppendExpr? '>'
276277
private VoidType ::= 'void'
277278

‎src/main/grammar/Zephir.flex‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ CBLOCK = ("%{"([^}]+|[}]+[^%{])*"}%")
176176
">" { yybegin(YYINITIAL); return GREATER; }
177177
"->" { yybegin(YYINITIAL); return ARROW; }
178178
"::" { yybegin(YYINITIAL); return DOUBLECOLON; }
179+
"..." { yybegin(YYINITIAL); return ELLIPSIS; }
179180
"." { yybegin(YYINITIAL); return DOT; }
180181
"+" { yybegin(YYINITIAL); return ADD; }
181182
"-" { yybegin(YYINITIAL); return SUB; }

‎src/test/kotlin/ZephirParserTest.kt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,9 @@ class ZephirParserTest : ParsingTestCase("parser", "zep", ZephirParserDefinition
1818

1919
fun testMixedType() = doTest(true)
2020

21+
fun testStaticSelfReturn() = doTest(true)
22+
23+
fun testVariadic() = doTest(true)
24+
2125
override fun getTestDataPath() = "src/test/testData"
2226
}
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
Zephir File
2+
ZephirNamespaceStatementImpl(NAMESPACE_STATEMENT)
3+
PsiElement(namespace)('namespace')
4+
PsiWhiteSpace(' ')
5+
ZephirComplexIdImpl(COMPLEX_ID)
6+
ZephirIdImpl(ID)
7+
PsiElement(IDENTIFIER)('Test')
8+
PsiElement(;)(';')
9+
PsiWhiteSpace('\n\n')
10+
ZephirClassDefinitionImpl(CLASS_DEFINITION)
11+
PsiElement(class)('class')
12+
PsiWhiteSpace(' ')
13+
ZephirIdImpl(ID)
14+
PsiElement(IDENTIFIER)('StaticSelfReturn')
15+
PsiWhiteSpace('\n')
16+
ZephirClassBodyImpl(CLASS_BODY)
17+
PsiElement({)('{')
18+
PsiWhiteSpace('\n ')
19+
ZephirMethodDefinitionImpl(METHOD_DEFINITION)
20+
ZephirVisibilityImpl(VISIBILITY)
21+
PsiElement(public)('public')
22+
PsiWhiteSpace(' ')
23+
PsiElement(function)('function')
24+
PsiWhiteSpace(' ')
25+
ZephirIdImpl(ID)
26+
PsiElement(IDENTIFIER)('makeStatic')
27+
PsiElement(()('(')
28+
PsiElement())(')')
29+
PsiWhiteSpace(' ')
30+
ZephirReturnTypeImpl(RETURN_TYPE)
31+
PsiElement(->)('->')
32+
PsiWhiteSpace(' ')
33+
ZephirTypeImpl(TYPE)
34+
PsiElement(<)('<')
35+
PsiElement(static)('static')
36+
PsiElement(>)('>')
37+
PsiWhiteSpace('\n ')
38+
ZephirMethodBodyImpl(METHOD_BODY)
39+
ZephirCodeBlockImpl(CODE_BLOCK)
40+
PsiElement({)('{')
41+
PsiWhiteSpace('\n ')
42+
ZephirCodeImpl(CODE)
43+
ZephirReturnStatementImpl(RETURN_STATEMENT)
44+
PsiElement(return)('return')
45+
PsiWhiteSpace(' ')
46+
ZephirLiteralExprImpl(LITERAL_EXPR)
47+
ZephirScalarImpl(SCALAR)
48+
ZephirScalarValueImpl(SCALAR_VALUE)
49+
PsiElement(null)('null')
50+
PsiElement(;)(';')
51+
PsiWhiteSpace('\n ')
52+
PsiElement(})('}')
53+
PsiWhiteSpace('\n\n ')
54+
ZephirMethodDefinitionImpl(METHOD_DEFINITION)
55+
ZephirVisibilityImpl(VISIBILITY)
56+
PsiElement(public)('public')
57+
PsiWhiteSpace(' ')
58+
PsiElement(function)('function')
59+
PsiWhiteSpace(' ')
60+
ZephirIdImpl(ID)
61+
PsiElement(IDENTIFIER)('makeSelf')
62+
PsiElement(()('(')
63+
PsiElement())(')')
64+
PsiWhiteSpace(' ')
65+
ZephirReturnTypeImpl(RETURN_TYPE)
66+
PsiElement(->)('->')
67+
PsiWhiteSpace(' ')
68+
ZephirTypeImpl(TYPE)
69+
PsiElement(<)('<')
70+
ZephirComplexIdImpl(COMPLEX_ID)
71+
ZephirIdImpl(ID)
72+
PsiElement(IDENTIFIER)('self')
73+
PsiElement(>)('>')
74+
PsiWhiteSpace('\n ')
75+
ZephirMethodBodyImpl(METHOD_BODY)
76+
ZephirCodeBlockImpl(CODE_BLOCK)
77+
PsiElement({)('{')
78+
PsiWhiteSpace('\n ')
79+
ZephirCodeImpl(CODE)
80+
ZephirReturnStatementImpl(RETURN_STATEMENT)
81+
PsiElement(return)('return')
82+
PsiWhiteSpace(' ')
83+
ZephirLiteralExprImpl(LITERAL_EXPR)
84+
ZephirScalarImpl(SCALAR)
85+
ZephirScalarValueImpl(SCALAR_VALUE)
86+
PsiElement(null)('null')
87+
PsiElement(;)(';')
88+
PsiWhiteSpace('\n ')
89+
PsiElement(})('}')
90+
PsiWhiteSpace('\n\n ')
91+
ZephirMethodDefinitionImpl(METHOD_DEFINITION)
92+
ZephirVisibilityImpl(VISIBILITY)
93+
PsiElement(public)('public')
94+
PsiWhiteSpace(' ')
95+
PsiElement(function)('function')
96+
PsiWhiteSpace(' ')
97+
ZephirIdImpl(ID)
98+
PsiElement(IDENTIFIER)('makeUnion')
99+
PsiElement(()('(')
100+
PsiElement())(')')
101+
PsiWhiteSpace(' ')
102+
ZephirReturnTypeImpl(RETURN_TYPE)
103+
PsiElement(->)('->')
104+
PsiWhiteSpace(' ')
105+
ZephirTypeImpl(TYPE)
106+
PsiElement(<)('<')
107+
ZephirComplexIdImpl(COMPLEX_ID)
108+
ZephirIdImpl(ID)
109+
PsiElement(IDENTIFIER)('Foo')
110+
PsiElement(>)('>')
111+
PsiWhiteSpace(' ')
112+
PsiElement(|)('|')
113+
PsiWhiteSpace(' ')
114+
ZephirTypeImpl(TYPE)
115+
PsiElement(<)('<')
116+
PsiElement(static)('static')
117+
PsiElement(>)('>')
118+
PsiWhiteSpace('\n ')
119+
ZephirMethodBodyImpl(METHOD_BODY)
120+
ZephirCodeBlockImpl(CODE_BLOCK)
121+
PsiElement({)('{')
122+
PsiWhiteSpace('\n ')
123+
ZephirCodeImpl(CODE)
124+
ZephirReturnStatementImpl(RETURN_STATEMENT)
125+
PsiElement(return)('return')
126+
PsiWhiteSpace(' ')
127+
ZephirLiteralExprImpl(LITERAL_EXPR)
128+
ZephirScalarImpl(SCALAR)
129+
ZephirScalarValueImpl(SCALAR_VALUE)
130+
PsiElement(null)('null')
131+
PsiElement(;)(';')
132+
PsiWhiteSpace('\n ')
133+
PsiElement(})('}')
134+
PsiWhiteSpace('\n')
135+
PsiElement(})('}')
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace Test;
2+
3+
class StaticSelfReturn
4+
{
5+
public function makeStatic() -> <static>
6+
{
7+
return null;
8+
}
9+
10+
public function makeSelf() -> <self>
11+
{
12+
return null;
13+
}
14+
15+
public function makeUnion() -> <Foo> | <static>
16+
{
17+
return null;
18+
}
19+
}
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
Zephir File
2+
ZephirNamespaceStatementImpl(NAMESPACE_STATEMENT)
3+
PsiElement(namespace)('namespace')
4+
PsiWhiteSpace(' ')
5+
ZephirComplexIdImpl(COMPLEX_ID)
6+
ZephirIdImpl(ID)
7+
PsiElement(IDENTIFIER)('Test')
8+
PsiElement(;)(';')
9+
PsiWhiteSpace('\n\n')
10+
ZephirClassDefinitionImpl(CLASS_DEFINITION)
11+
PsiElement(class)('class')
12+
PsiWhiteSpace(' ')
13+
ZephirIdImpl(ID)
14+
PsiElement(IDENTIFIER)('Variadic')
15+
PsiWhiteSpace('\n')
16+
ZephirClassBodyImpl(CLASS_BODY)
17+
PsiElement({)('{')
18+
PsiWhiteSpace('\n ')
19+
ZephirMethodDefinitionImpl(METHOD_DEFINITION)
20+
ZephirVisibilityImpl(VISIBILITY)
21+
PsiElement(public)('public')
22+
PsiWhiteSpace(' ')
23+
PsiElement(function)('function')
24+
PsiWhiteSpace(' ')
25+
ZephirIdImpl(ID)
26+
PsiElement(IDENTIFIER)('untyped')
27+
PsiElement(()('(')
28+
ZephirArgumentsImpl(ARGUMENTS)
29+
ZephirArgumentImpl(ARGUMENT)
30+
PsiElement(...)('...')
31+
ZephirIdImpl(ID)
32+
PsiElement(IDENTIFIER)('args')
33+
PsiElement())(')')
34+
PsiWhiteSpace('\n ')
35+
ZephirMethodBodyImpl(METHOD_BODY)
36+
ZephirCodeBlockImpl(CODE_BLOCK)
37+
PsiElement({)('{')
38+
PsiWhiteSpace('\n ')
39+
ZephirCodeImpl(CODE)
40+
ZephirReturnStatementImpl(RETURN_STATEMENT)
41+
PsiElement(return)('return')
42+
PsiWhiteSpace(' ')
43+
ZephirLiteralExprImpl(LITERAL_EXPR)
44+
ZephirVariableImpl(VARIABLE)
45+
ZephirComplexIdImpl(COMPLEX_ID)
46+
ZephirIdImpl(ID)
47+
PsiElement(IDENTIFIER)('args')
48+
PsiElement(;)(';')
49+
PsiWhiteSpace('\n ')
50+
PsiElement(})('}')
51+
PsiWhiteSpace('\n\n ')
52+
ZephirMethodDefinitionImpl(METHOD_DEFINITION)
53+
ZephirVisibilityImpl(VISIBILITY)
54+
PsiElement(public)('public')
55+
PsiWhiteSpace(' ')
56+
PsiElement(function)('function')
57+
PsiWhiteSpace(' ')
58+
ZephirIdImpl(ID)
59+
PsiElement(IDENTIFIER)('typed')
60+
PsiElement(()('(')
61+
ZephirArgumentsImpl(ARGUMENTS)
62+
ZephirArgumentImpl(ARGUMENT)
63+
ZephirTypeImpl(TYPE)
64+
ZephirScalarTypeImpl(SCALAR_TYPE)
65+
PsiElement(string)('string')
66+
PsiWhiteSpace(' ')
67+
PsiElement(...)('...')
68+
ZephirIdImpl(ID)
69+
PsiElement(IDENTIFIER)('names')
70+
PsiElement())(')')
71+
PsiWhiteSpace('\n ')
72+
ZephirMethodBodyImpl(METHOD_BODY)
73+
ZephirCodeBlockImpl(CODE_BLOCK)
74+
PsiElement({)('{')
75+
PsiWhiteSpace('\n ')
76+
ZephirCodeImpl(CODE)
77+
ZephirReturnStatementImpl(RETURN_STATEMENT)
78+
PsiElement(return)('return')
79+
PsiWhiteSpace(' ')
80+
ZephirLiteralExprImpl(LITERAL_EXPR)
81+
ZephirVariableImpl(VARIABLE)
82+
ZephirComplexIdImpl(COMPLEX_ID)
83+
ZephirIdImpl(ID)
84+
PsiElement(IDENTIFIER)('names')
85+
PsiElement(;)(';')
86+
PsiWhiteSpace('\n ')
87+
PsiElement(})('}')
88+
PsiWhiteSpace('\n\n ')
89+
ZephirMethodDefinitionImpl(METHOD_DEFINITION)
90+
ZephirVisibilityImpl(VISIBILITY)
91+
PsiElement(public)('public')
92+
PsiWhiteSpace(' ')
93+
PsiElement(function)('function')
94+
PsiWhiteSpace(' ')
95+
ZephirIdImpl(ID)
96+
PsiElement(IDENTIFIER)('classType')
97+
PsiElement(()('(')
98+
ZephirArgumentsImpl(ARGUMENTS)
99+
ZephirArgumentImpl(ARGUMENT)
100+
ZephirTypeImpl(TYPE)
101+
PsiElement(<)('<')
102+
ZephirComplexIdImpl(COMPLEX_ID)
103+
ZephirIdImpl(ID)
104+
PsiElement(IDENTIFIER)('Foo')
105+
PsiElement(>)('>')
106+
PsiWhiteSpace(' ')
107+
PsiElement(...)('...')
108+
ZephirIdImpl(ID)
109+
PsiElement(IDENTIFIER)('items')
110+
PsiElement())(')')
111+
PsiWhiteSpace('\n ')
112+
ZephirMethodBodyImpl(METHOD_BODY)
113+
ZephirCodeBlockImpl(CODE_BLOCK)
114+
PsiElement({)('{')
115+
PsiWhiteSpace('\n ')
116+
ZephirCodeImpl(CODE)
117+
ZephirReturnStatementImpl(RETURN_STATEMENT)
118+
PsiElement(return)('return')
119+
PsiWhiteSpace(' ')
120+
ZephirLiteralExprImpl(LITERAL_EXPR)
121+
ZephirVariableImpl(VARIABLE)
122+
ZephirComplexIdImpl(COMPLEX_ID)
123+
ZephirIdImpl(ID)
124+
PsiElement(IDENTIFIER)('items')
125+
PsiElement(;)(';')
126+
PsiWhiteSpace('\n ')
127+
PsiElement(})('}')
128+
PsiWhiteSpace('\n\n ')
129+
ZephirMethodDefinitionImpl(METHOD_DEFINITION)
130+
ZephirVisibilityImpl(VISIBILITY)
131+
PsiElement(public)('public')
132+
PsiWhiteSpace(' ')
133+
PsiElement(function)('function')
134+
PsiWhiteSpace(' ')
135+
ZephirIdImpl(ID)
136+
PsiElement(IDENTIFIER)('combined')
137+
PsiElement(()('(')
138+
ZephirArgumentsImpl(ARGUMENTS)
139+
ZephirArgumentImpl(ARGUMENT)
140+
ZephirIdImpl(ID)
141+
PsiElement(IDENTIFIER)('a')
142+
PsiElement(,)(',')
143+
PsiWhiteSpace(' ')
144+
ZephirArgumentImpl(ARGUMENT)
145+
PsiElement(...)('...')
146+
ZephirIdImpl(ID)
147+
PsiElement(IDENTIFIER)('rest')
148+
PsiElement())(')')
149+
PsiWhiteSpace('\n ')
150+
ZephirMethodBodyImpl(METHOD_BODY)
151+
ZephirCodeBlockImpl(CODE_BLOCK)
152+
PsiElement({)('{')
153+
PsiWhiteSpace('\n ')
154+
ZephirCodeImpl(CODE)
155+
ZephirReturnStatementImpl(RETURN_STATEMENT)
156+
PsiElement(return)('return')
157+
PsiWhiteSpace(' ')
158+
ZephirLiteralExprImpl(LITERAL_EXPR)
159+
ZephirVariableImpl(VARIABLE)
160+
ZephirComplexIdImpl(COMPLEX_ID)
161+
ZephirIdImpl(ID)
162+
PsiElement(IDENTIFIER)('rest')
163+
PsiElement(;)(';')
164+
PsiWhiteSpace('\n ')
165+
PsiElement(})('}')
166+
PsiWhiteSpace('\n')
167+
PsiElement(})('}')

0 commit comments

Comments
 (0)