diff --git a/Zephir.iml b/Zephir.iml
deleted file mode 100644
index 2698cf2..0000000
--- a/Zephir.iml
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml
index b008447..c835f33 100644
--- a/resources/META-INF/plugin.xml
+++ b/resources/META-INF/plugin.xml
@@ -1,7 +1,7 @@
com.zephir
Zephir
- 0.3.0
+ 0.3.1
Zephir Team
0.3.0: Fixed many bugs with syntax recognition, added few words to highlight, improved completion
+ 0.3.1: Fixed much bugs with syntax recognition, fixed extra space in completion for method params
+ 0.3.0: Fixed many bugs with syntax recognition, added few words to highlight, improved completion
0.2.5: Fixed "switch" keyword detection
0.2.4: Added brace matching
0.2.3: Fixed build
diff --git a/src/com/zephir/Zephir.bnf b/src/com/zephir/Zephir.bnf
index 17a2767..5e9ad3f 100644
--- a/src/com/zephir/Zephir.bnf
+++ b/src/com/zephir/Zephir.bnf
@@ -157,6 +157,9 @@ c_block ::= cblock
private top_statement ::= namespace_statement import_statement* c_block* (class_definition | interface_definition)
+php_reserved ::= '$resource' | '$namespace' | '$internal'
+
+
namespace_statement ::= 'namespace' complex_id ';' {pin=2}
import_statement ::= 'use' complex_id ('as' id)? ';' {pin=2}
@@ -182,7 +185,7 @@ abstract_method_definition ::= 'abstract' interface_method_definition
constant_definition ::= 'const' id default_value? ';' {pin=2}
-property_definition ::= 'static'? visibility id default_value? member_meta_access? ';' {pin=3}
+property_definition ::= 'static'? visibility 'static'? id default_value? member_meta_access? ';' {pin=4}
private member_meta_access ::= '{' member_meta_modifier (',' member_meta_modifier)* '}' {pin=1}
private member_meta_modifier ::= 'get' | 'set' | '__toString'
@@ -193,26 +196,27 @@ method_modifiers ::= 'static' | 'inline' | 'deprecated' | 'final'
private method_header ::= (visibility method_modifiers* | method_modifiers* visibility ) FUNCTION id
code_block ::= '{' code* '}' {pin=1}
-return_type ::= '->' type ('|' type)* {pin(".*")=1}
+return_type ::= '->' (type | 'null') ('|' (type | 'null'))* {pin(".*")=1}
arguments ::= argument (',' argument)* {pin(".*")=1}
-argument ::= type? '!'? id default_value? {pin=3}
+argument ::= type? '!'? (php_reserved | id) default_value? {pin=3}
default_value ::= '=' expr {pin=1}
visibility ::= 'public' | 'protected' | 'private'
id ::= identifier
-complex_id ::= '\'? id ('\' id)* {pin(".*")=2}
+complex_id ::= '$'? '\'? id ('\' id)* {pin(".*")=3}
complex_id_list ::= complex_id (',' complex_id)* {pin(".*")=1}
-type ::= void_type | scalar_type | class_type
+type ::= void_type | scalar_type | class_type | resource_type
scalar_type ::= 'var' | number_type | string_type | bool_type | 'array' | 'object' | 'callable' | 'resource'
private string_type ::= 'string' | 'char' | 'uchar'
private bool_type ::= 'bool' | 'boolean'
private number_type ::= int_type | double_type | 'uint' | 'long' | 'ulong'
private int_type ::= 'int' | 'integer'
-private double_type ::= 'dobule' | 'float'
+private double_type ::= 'double' | 'float'
private class_type ::= '<' complex_id array_append_expr? '>'
+private resource_type ::= '<' '$'complex_id array_append_expr? '>'
private void_type ::= 'void'
code ::= declaration_statement |
@@ -232,11 +236,13 @@ code ::= declaration_statement |
declaration_statement ::= type declaration_statement_element (',' declaration_statement_element)* ';' {pin(".*")=1}
-private declaration_statement_element ::= id default_value?
+private declaration_statement_element ::= (id | php_reserved) default_value?
let_statement ::= 'let' change_variable_expr (',' change_variable_expr)* ';' {pin(".*")=1}
+
change_variable_expr ::= assignment_expr | increment_expr
-assignment_expr ::= variable array_append_expr? assignment_operator typecast? expr { rightAssociative=true }
+assignment_expr ::= (typecast | type)? (variable | php_reserved) array_append_expr? assignment_operator (typecast | type)? (php_reserved | expr) { rightAssociative=true }
+
private array_append_expr ::= '[' ']'
assignment_operator ::= '=' | '+=' | '-=' | '*=' | '**=' | '/=' | '%=' | '.='
typecast ::= '(' scalar_type ')'
@@ -257,25 +263,27 @@ infinity_loop_statement ::= 'loop' code_block {pin=1}
while_loop_statement ::= 'while' expr code_block {pin=2}
foreach_loop_statement ::= 'for' id (',' id)? 'in' expr code_block {pin=2}
-unset_statement ::= 'unset' variable ';'
+unset_statement ::= 'unset' (variable | '(' variable ')') ';'
+
+switch_statement ::= 'switch' expr '{' case_expr* '}' {pin=1}
+static_call_expr ::= ((('{' id '}') | 'static') '::') call_expr {pin=1}
-switch_statement ::= 'switch' expr '{' switch_body '}' {pin=1}
-switch_body ::= ('case' expr | 'default') ':' code* {pin=1}
+case_expr ::= ('case' expr | 'default') ':' code* {pin=1}
if_statement ::= 'if' ('likely' | 'unlikely')? expr code_block elseif_statements* else_statement? {pin=1}
elseif_statements ::= 'elseif' expr code_block {pin=1}
else_statement ::= 'else' code_block {pin=1}
try_statement ::= 'try' code_block catch_block* {pin=1}
-catch_block ::= 'catch' class_type? id code_block {pin=3}
+catch_block ::= 'catch' class_type? complex_id (',' complex_id)* code_block {pin=3}
-return_statement ::= 'return' expr? ';'
+return_statement ::= 'return' (require_statement | (typecast? expr? ';'))
echo_statement ::= 'echo' expr (',' expr)* ';' {pin(".*")=1}
throw_statement ::= 'throw' expr ';' {pin=1}
-require_statement ::= 'require' expr ';' {pin=1}
-
+require_statement ::= require_expr ';' {pin=1}
+private require_expr ::= 'require' expr
expr ::= unary_expr |
bit_expr |
@@ -285,7 +293,7 @@ expr ::= unary_expr |
special_group_expr
private bool_group_expr ::= bool_expr | ternary_expr | empty_expr | isset_expr | fetch_expr | instanceof_expr
-private primary_group_expr ::= literal_expr | paren_expr | callback_expr | call_expr
+private primary_group_expr ::= static_call_expr | literal_expr | paren_expr | precast_expr | callback_expr | call_expr | clone_expr
private special_group_expr ::= new_expr | typeof_expr
bit_expr ::= expr bit_operator expr
@@ -301,19 +309,27 @@ bool_operator ::= '&&' | '||' | '>' | '<' | '==' | '>=' | '<=' | '===' | '!=' |
ternary_expr ::= expr '?' expr ':' expr {pin=1}
literal_expr ::= variable | scalar
paren_expr ::= '(' expr ')' {pin=1}
+precast_expr ::= '{' expr '}' {pin=1}
+
+
empty_expr ::= 'empty' expr {pin=1}
isset_expr ::= 'isset' expr {pin=1}
fetch_expr ::= 'fetch' id ',' expr {pin=2}
instanceof_expr ::= variable 'instanceof' expr {pin=2}
-call_expr ::= expr '(' call_arguments? ')' {pin=2}
+
+call_expr ::= expr '(' call_arguments? ')' ('->' id '(' call_arguments? ')')* array_access? {pin=3}
+magic_call_expr ::= '$'('clone' | 'fetch') '(' arguments* ')'
callback_expr ::= 'function' '(' arguments* ')' code_block {pin=1}
+clone_expr ::= 'clone' variable
-new_expr ::= 'new' complex_id ('(' call_arguments? ')')? {pin=2}
+new_expr ::= new_expr_classic | new_expr_dynamic
+private new_expr_classic ::= 'new' complex_id ('(' call_arguments? ')')? {pin=2}
+private new_expr_dynamic ::= 'new' '{' expr '}' ('(' call_arguments? ')')? {pin=2}
typeof_expr ::= 'typeof' expr {pin=1}
call_arguments ::= call_argument (',' call_argument)* {pin(".*")=1}
-private call_argument ::= expr
+private call_argument ::= typecast? expr
private scalar_short ::= string | schar | double | integer | scalar_value
scalar ::= scalar_short | array_value
@@ -326,5 +342,5 @@ array_key_value ::= (scalar_short | expr) ':' expr
variable ::= complex_id (property_access | array_append_expr | array_access)*
-private property_access ::= ('::' | '->') (variable | '{' (string | id) '}') {pin=2}
-private array_access ::= '[' expr ']' {pin=1}
+private property_access ::= ('::' | '->') (variable | '{' (string | id) '}' | magic_call_expr) {pin=2}
+private array_access ::= '[' (expr | php_reserved) ']' {pin=1}
diff --git a/src/com/zephir/completion/Priority.java b/src/com/zephir/completion/Priority.java
new file mode 100644
index 0000000..41b2c66
--- /dev/null
+++ b/src/com/zephir/completion/Priority.java
@@ -0,0 +1,10 @@
+package com.zephir.completion;
+
+/**
+ * Completion priority
+ */
+public class Priority {
+
+ public static double METHOD_SCOPE_PRIORITY = 2.0;
+
+}
diff --git a/src/com/zephir/completion/ZephirKeywordCompletionContributor.java b/src/com/zephir/completion/ZephirKeywordCompletionContributor.java
index 4a95792..552c3ff 100644
--- a/src/com/zephir/completion/ZephirKeywordCompletionContributor.java
+++ b/src/com/zephir/completion/ZephirKeywordCompletionContributor.java
@@ -15,23 +15,34 @@
public class ZephirKeywordCompletionContributor extends CompletionContributor {
public ZephirKeywordCompletionContributor() {
-
- extend(CompletionType.BASIC,
- PlatformPatterns.psiElement().withLanguage(ZephirLanguage.INSTANCE),
- new FileScopeKeywordsProvider()
- );
-
- extend(
- CompletionType.BASIC,
- PlatformPatterns.psiElement().withLanguage(ZephirLanguage.INSTANCE),
- new MethodScopeCompletionProvider()
- );
-
- extend(
- CompletionType.BASIC,
- PlatformPatterns.psiElement().withLanguage(ZephirLanguage.INSTANCE),
- new ClassScopeKeywordsProvider()
- );
+ try {
+ extend(CompletionType.BASIC,
+ PlatformPatterns.psiElement().withLanguage(ZephirLanguage.INSTANCE),
+ new FileScopeKeywordsProvider()
+ );
+ } catch (Exception e) {
+ // @todo show message to developer and request him about report bug
+ }
+
+ try{
+ extend(
+ CompletionType.BASIC,
+ PlatformPatterns.psiElement().withLanguage(ZephirLanguage.INSTANCE),
+ new MethodScopeCompletionProvider()
+ );
+ } catch (Exception e) {
+ // @todo show message to developer and request him about report bug
+ }
+
+ try {
+ extend(
+ CompletionType.BASIC,
+ PlatformPatterns.psiElement().withLanguage(ZephirLanguage.INSTANCE),
+ new ClassScopeKeywordsProvider()
+ );
+ } catch (Exception e) {
+ // @todo show message to developer and request him about report bug
+ }
}
diff --git a/src/com/zephir/completion/providers/MethodScopeCompletionProvider.java b/src/com/zephir/completion/providers/MethodScopeCompletionProvider.java
index b602243..25bf9f4 100644
--- a/src/com/zephir/completion/providers/MethodScopeCompletionProvider.java
+++ b/src/com/zephir/completion/providers/MethodScopeCompletionProvider.java
@@ -4,8 +4,12 @@
import com.intellij.codeInsight.completion.CompletionProvider;
import com.intellij.codeInsight.completion.CompletionResultSet;
import com.intellij.codeInsight.lookup.LookupElementBuilder;
+import com.intellij.codeInsight.completion.PrioritizedLookupElement;
+
+
import com.intellij.psi.PsiElement;
import com.intellij.util.ProcessingContext;
+import com.zephir.completion.Priority;
import com.zephir.psi.ZephirArgument;
import com.zephir.psi.ZephirArguments;
import com.zephir.psi.ZephirFile;
@@ -18,6 +22,7 @@
public class MethodScopeCompletionProvider extends CompletionProvider {
+
private static int MAX_SYNTAX_TREE_DEEP = 256;
private String[] keywords = new String[] {
@@ -56,8 +61,8 @@ protected void addCompletions(@NotNull CompletionParameters parameters,
for (ZephirArgument arg : methodArgs) {
LookupElementBuilder completionElement = LookupElementBuilder
//empty space to pull up arguments of method
- .create(arg.getId().getText(), " " + arg.getId().getText())
- .withTypeText(arg.getType().getText(), true)
+ .create(arg.getId().getText(), arg.getId().getText())
+ .withTypeText(arg.getType() != null ? arg.getType().getText() : "", true)
.withBoldness(true)
.withLookupString(arg.getId().getText())
.withTailText(
@@ -65,7 +70,7 @@ protected void addCompletions(@NotNull CompletionParameters parameters,
true
);
- result.addElement(completionElement);
+ result.addElement(PrioritizedLookupElement.withPriority(completionElement, Priority.METHOD_SCOPE_PRIORITY));
}
for (String keyword : this.keywords) {
@@ -80,14 +85,14 @@ protected void addCompletions(@NotNull CompletionParameters parameters,
private ZephirMethodDefinition getMethodByCurrentPos(PsiElement psiElement) {
PsiElement parent = psiElement.getParent();
- if((parent instanceof ZephirFile)) {
+ if (parent == null || parent instanceof ZephirFile) {
return null;
}
int findLimitCounter = 0;
- do{
+ do {
parent = parent.getParent();
- if((parent instanceof ZephirFile)) {
+ if (parent == null || parent instanceof ZephirFile) {
return null;
} else if (parent instanceof ZephirMethodDefinition) {
return (ZephirMethodDefinition)parent;
@@ -97,5 +102,4 @@ private ZephirMethodDefinition getMethodByCurrentPos(PsiElement psiElement) {
return null;
}
-
}