From f8ea57479ccd724e138a31e328560d3ae123f113 Mon Sep 17 00:00:00 2001 From: Alex Baranezky Date: Mon, 29 May 2017 23:32:10 +0300 Subject: [PATCH 1/4] Reduced phalcon syntax errors from 30 to 16 Fixed completion bug when invoking AC in method definition block --- README.md | 10 ++-------- src/com/zephir/Zephir.bnf | 17 ++++++++++------- .../MethodScopeCompletionProvider.java | 11 +++++++++-- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 13fe068..d465c8e 100644 --- a/README.md +++ b/README.md @@ -2,21 +2,15 @@ Plugin page: http://plugins.jetbrains.com/plugin/7558 -## Getting started +## Getting started develop plugin 1. Install next plugins for Intellij * https://plugins.jetbrains.com/plugin/6606-grammar-kit - * https://plugins.jetbrains.com/plugin/227-psiviewer + 2. Go to `Zephir.bnf` file and run "Generate parser code" through context menu 3. Go to `src/com/zephir/Zephir.flex` and run "Run JFlex generator" through context menu 4. Run the plugin by Menu -> Run -> Run -To automatically detect "Zephir plugin" in the debugged IDE, uncomment next lines in the `resources/META-INF/plugin.xml` - -```xml - -``` - ## Links + [**`phalcon/zephir`**](https://github.com/phalcon/zephir) - Zephir is a compiled high level language aimed to the creation of C-extensions for PHP diff --git a/src/com/zephir/Zephir.bnf b/src/com/zephir/Zephir.bnf index 5e9ad3f..451e7e0 100644 --- a/src/com/zephir/Zephir.bnf +++ b/src/com/zephir/Zephir.bnf @@ -22,6 +22,7 @@ double='regexp:([\-]?[0-9]+[\.][0-9]+)' schar="regexp:(['] ([\\][']|[\\].|[\001-\377]\[\\'])* ['])" string='regexp:(["] ([\\]["]|[\\].|[\001-\377]\[\\"])* ["])' + // string='regexp:"([\\][\"]|[\\].|[\001-\377])*"' cblock='regexp:%{([^}]+|[}]+[^%{])*}%' // OOP keywords @@ -190,8 +191,9 @@ property_definition ::= 'static'? visibility 'static'? id default_value? member private member_meta_access ::= '{' member_meta_modifier (',' member_meta_modifier)* '}' {pin=1} private member_meta_modifier ::= 'get' | 'set' | '__toString' -method_definition ::= method_header '(' arguments* ')' return_type? code_block {pin=2} +method_definition ::= method_header '(' arguments* ')' return_type? method_body {pin=2} method_modifiers ::= 'static' | 'inline' | 'deprecated' | 'final' +method_body ::= code_block private method_header ::= (visibility method_modifiers* | method_modifiers* visibility ) FUNCTION id code_block ::= '{' code* '}' {pin=1} @@ -204,7 +206,8 @@ argument ::= type? '!'? (php_reserved | id) default_value? {pin=3} default_value ::= '=' expr {pin=1} visibility ::= 'public' | 'protected' | 'private' -id ::= identifier +id ::= '$'?identifier + complex_id ::= '$'? '\'? id ('\' id)* {pin(".*")=3} complex_id_list ::= complex_id (',' complex_id)* {pin(".*")=1} @@ -245,7 +248,7 @@ assignment_expr ::= (typecast | type)? (variable | php_reserved) array_append_ex private array_append_expr ::= '[' ']' assignment_operator ::= '=' | '+=' | '-=' | '*=' | '**=' | '/=' | '%=' | '.=' -typecast ::= '(' scalar_type ')' +typecast ::= '(' scalar_type ')' | '<' complex_id '>' increment_expr ::= variable increment_operator {rightAssociative=true} increment_operator ::= '++' | '--' @@ -262,7 +265,7 @@ 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} +foreach_loop_statement ::= 'for' id (',' id)? 'in' 'reverse'? (php_reserved | expr) code_block {pin=2} unset_statement ::= 'unset' (variable | '(' variable ')') ';' switch_statement ::= 'switch' expr '{' case_expr* '}' {pin=1} @@ -307,7 +310,7 @@ bool_expr ::= expr bool_operator expr bool_operator ::= '&&' | '||' | '>' | '<' | '==' | '>=' | '<=' | '===' | '!=' | '!==' ternary_expr ::= expr '?' expr ':' expr {pin=1} -literal_expr ::= variable | scalar +literal_expr ::= typecast? (variable | scalar) paren_expr ::= '(' expr ')' {pin=1} precast_expr ::= '{' expr '}' {pin=1} @@ -329,9 +332,9 @@ typeof_expr ::= 'typeof' expr {pin=1} call_arguments ::= call_argument (',' call_argument)* {pin(".*")=1} -private call_argument ::= typecast? expr +private call_argument ::= 'require'? typecast? (php_reserved | expr) -private scalar_short ::= string | schar | double | integer | scalar_value +private scalar_short ::= string | schar | double | integer | scalar_value scalar ::= scalar_short | array_value scalar_value ::= 'null' | 'true' | 'false' diff --git a/src/com/zephir/completion/providers/MethodScopeCompletionProvider.java b/src/com/zephir/completion/providers/MethodScopeCompletionProvider.java index 172e80b..f786828 100644 --- a/src/com/zephir/completion/providers/MethodScopeCompletionProvider.java +++ b/src/com/zephir/completion/providers/MethodScopeCompletionProvider.java @@ -59,12 +59,17 @@ protected void addCompletions(@NotNull CompletionParameters parameters, return; } - processMethodArguments(methodDefinition, result); - ZephirClassBody classBody = (ZephirClassBody)getPsiByCurrentPos(psiElement, "class"); if (classBody == null) { return; } + + ZephirMethodBody methodBody = (ZephirMethodBody)getPsiByCurrentPos(psiElement, "method_body"); + if (methodBody == null) { + return; + } + + processMethodArguments(methodDefinition, result); processClassMembers(classBody, result); processClassConstants(classBody, result); processClassMethods(classBody, result); @@ -182,6 +187,8 @@ private PsiElement getPsiByCurrentPos(PsiElement psiElement, String objectType) return parent; } else if (objectType.equals("class") && parent instanceof ZephirClassBody) { return parent; + } else if (objectType.equals("method_body") && parent instanceof ZephirMethodBody) { + return parent; } ++findLimitCounter; } while (findLimitCounter < MAX_SYNTAX_TREE_DEEP); // to avoid possible infinite cycles From 7d6f26ac8cf6bf152fe997e3c6740e8d645166b2 Mon Sep 17 00:00:00 2001 From: Alex Baranezky Date: Tue, 30 May 2017 00:02:36 +0300 Subject: [PATCH 2/4] Created full version --- resources/META-INF/plugin.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index 5c66e05..5c1614c 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -12,7 +12,7 @@ ]]> 0.3.2-beta1: Introduced class members in completion list +
  • 0.3.2: Introduced class members in completion list, improved syntax support
  • 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
  • From 1f059aa92e35dd21c7f006ec284f846dc55cd281 Mon Sep 17 00:00:00 2001 From: Alex Baranezky Date: Tue, 30 May 2017 00:03:46 +0300 Subject: [PATCH 3/4] Changed version --- resources/META-INF/plugin.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index 5c1614c..6c09eff 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -12,7 +12,7 @@ ]]> 0.3.2: Introduced class members in completion list, improved syntax support +
  • 0.3.2-alpha: Introduced class members in completion list, improved syntax support
  • 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
  • From d9c9ef377fbb178a28135c5f97078458b5a3b357 Mon Sep 17 00:00:00 2001 From: Alex Baranezky Date: Tue, 30 May 2017 00:15:18 +0300 Subject: [PATCH 4/4] Changed version --- resources/META-INF/plugin.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index 6c09eff..d2890b9 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -12,7 +12,7 @@ ]]> 0.3.2-alpha: Introduced class members in completion list, improved syntax support +
  • 0.3.2-beta2: Introduced class members in completion list, improved syntax support
  • 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