Skip to content

Commit

Permalink
Optimize pins to build the AST in more cases #191
Browse files Browse the repository at this point in the history
  • Loading branch information
xonixx committed May 11, 2023
1 parent ccfeded commit 1fb3d81
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
16 changes: 9 additions & 7 deletions src/main/java/intellij_awk/Awk.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,17 @@ statement_for_conditions ::= simple_statement_opt SEMICOLON newlines_opt expr_op

private terminator ::= (NEWLINE|SEMICOLON) newlines_opt

gawk_statement_switch ::= switch_start RBRACE newlines_opt
gawk_statement_switch ::= SWITCH LPAREN expr RPAREN newlines_opt switch_action
{ pin=1 }

private switch_start ::= SWITCH LPAREN expr RPAREN newlines_opt LBRACE newlines_opt case_statement*
{
pin=6
recoverWhile=recover_switch
}
private switch_action ::= switch_action_start RBRACE newlines_opt
private switch_action_start ::= LBRACE newlines_opt case_statement*
{
pin=1
recoverWhile=recover_on_rbrace
}

private recover_switch ::= !RBRACE
private recover_on_rbrace ::= !RBRACE

case_statement ::= (CASE case_value | DEFAULT) COLON newlines_opt (statement terminator*)*

Expand Down
7 changes: 5 additions & 2 deletions src/test/java/intellij_awk/AwkEnsurePinsTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,22 @@ public void test1() {
public void test2() {
checkByText("function f(b,c,){}");
}

public void test3() {
checkByText("BEGIN { if }");
}

public void test4() {
checkByText("BEGIN { for }");
}

public void test5() {
checkByText("BEGIN { while }");
}

/*public void test6() {
public void test6() {
checkByText("BEGIN { switch }");
}*/
}

// XXX for some reason fixing below makes it terribly slow or hanging on profile5.awk
/*
Expand Down

0 comments on commit 1fb3d81

Please sign in to comment.