Skip to content

Commit

Permalink
Merge pull request #9 from AsterAI/fix_regex_errors
Browse files Browse the repository at this point in the history
Beta2 release
  • Loading branch information
sergeyklay authored May 30, 2017
2 parents 994a03b + d9c9ef3 commit 169a18a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<!--<lang.parserDefinition language="Zephir" implementationClass="com.zephir.ZephirParserDefinition"/>-->
```

## Links

+ [**`phalcon/zephir`**](https://github.com/phalcon/zephir) - Zephir is a compiled high level language aimed to the creation of C-extensions for PHP
Expand Down
2 changes: 1 addition & 1 deletion resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
]]></description>

<change-notes><![CDATA[
<li><b>0.3.2-beta1</b>: Introduced class members in completion list</li>
<li><b>0.3.2-beta2</b>: Introduced class members in completion list, improved syntax support</li>
<li><b>0.3.1</b>: Fixed much bugs with syntax recognition, fixed extra space in completion for method params</li>
<li><b>0.3.0</b>: Fixed many bugs with syntax recognition, added few words to highlight, improved completion</li>
<li><b>0.2.5</b>: Fixed "switch" keyword detection</li>
Expand Down
17 changes: 10 additions & 7 deletions src/com/zephir/Zephir.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand All @@ -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}

Expand Down Expand Up @@ -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 ::= '++' | '--'
Expand All @@ -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}
Expand Down Expand Up @@ -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}

Expand All @@ -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'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 169a18a

Please sign in to comment.