Skip to content

Commit

Permalink
Merge pull request #66 from anboralabs/fix-issue
Browse files Browse the repository at this point in the history
Fixed minor issues with formatting and boolean expressions.
  • Loading branch information
dalgarins authored May 2, 2021
2 parents 0ae7197 + a030a51 commit 14faea3
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 19 deletions.
9 changes: 3 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ plugins {
id 'java'
id 'org.jetbrains.intellij' version '0.6.5'
id 'org.jetbrains.kotlin.jvm' version '1.4.10'
id "org.jetbrains.grammarkit" version "2020.3.2"
id "org.jetbrains.grammarkit" version "2021.1.2"
}

grammarKit {
jflexRelease = '1.7.0-1'
grammarKitRelease = 'f75d0d8'
}
apply plugin: 'org.jetbrains.grammarkit'

group 'co.anbora.labs'
version '2.5.5-SNAPSHOT'
version '2.5.6-SNAPSHOT'

repositories {
mavenCentral()
Expand Down
19 changes: 11 additions & 8 deletions src/main/grammar/FirebaseRules.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ private PermissionStatementItem ::= !(':'|';') PermissionKeyWord (',' | &(':'|';
private Permission_recover ::= !(':' |';' | GET_KEYWORD | READ_KEYWORD | WRITE_KEYWORD | LIST_KEYWORD
| CREATE_KEYWORD | UPDATE_KEYWORD | DELETE_KEYWORD)

ConditionalStatement ::= IF_KEYWORD ConditionalExpression {
ConditionalStatement ::= IF_KEYWORD ConditionalBlock {
pin=1
}

ConditionalExpression ::= Expression (BooleanOperator Expression)*
ConditionalBlock ::= Expression
//Allow Statement End

FullBuiltInParameterStatement ::= (SLASH PathBuiltInParameterStatement)+
Expand All @@ -140,6 +140,8 @@ PathBuiltInParameterStatement ::= (DOT? IDENTIFIER|PATH_BUILT_IN)

BuiltInFunctionStatement ::= (GET_KEYWORD|EXITS_KEYWORD)

BuiltInTypes ::= LIST_KEYWORD

//Function Definition Begin
FunctionDef ::= FUNCTION_KEYWORD IDENTIFIER FunctionParameterList FunctionBlock
{
Expand Down Expand Up @@ -179,7 +181,7 @@ ParameterStatement ::= Expression(COMMA Expression)*
ReturnStatement ::= RETURN_KEYWORD ReturnBlock {
pin=1
}
ReturnBlock ::= ConditionalExpression DOT_COMMA
ReturnBlock ::= Expression DOT_COMMA

Expression ::=
OrExpr
Expand All @@ -205,6 +207,7 @@ LiteralExpr ::= LiteralStatement
| BooleanStatement
| NullStatement
| BuiltInFunctionStatement
| BuiltInTypes
| IdentifierExpr
| FullBuiltInParameterStatement

Expand All @@ -219,6 +222,10 @@ private AtomExpr ::=
private MulExprItem ::= DivExpr | MulExpr | ModExpr
private AddExprItem ::= PlusExpr | MinusExpr
private LogicalEqExprItem ::= EqualsExpr | NotEqualsExpr | LessEqualsExpr | LessExpr | GreaterEqualsExpr | GreaterExpr
| InExpr | IsExpr

InExpr ::= Expression IN_KEYWORD Expression
IsExpr ::= Expression IS_KEYWORD Expression

EqualsExpr ::= Expression EQEQ Expression
NotEqualsExpr ::= Expression NE Expression
Expand All @@ -244,12 +251,8 @@ private ArrayExpr ::= LB (ParameterStatement) RB

LiteralStatement ::= (number|string)

VariableStatement ::= LET_KEYWORD IDENTIFIER EQ ConditionalExpression (DOT_COMMA?)
VariableStatement ::= LET_KEYWORD IDENTIFIER EQ Expression (DOT_COMMA?)

NullStatement ::= NULL_KEYWORD

BooleanOperator ::= (PathOperator|OROR|ANDAND|LT|LE|GT|GE|IN_KEYWORD|IS_KEYWORD)

PathOperator ::= (EQEQ|NE)

BooleanStatement ::= (TRUE_KEYWORD|FALSE_KEYWORD)
14 changes: 11 additions & 3 deletions src/main/html/change-notes.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
Versions:
<ul>
<li>All Intellij products support: 2.5.5</li>
<li>Android Studio support: 2.5.4</li>
<li>All Intellij products support: 2.5.6</li>
<li>Android Studio support: 2.5.7</li>
</ul>

<br>
Plugin updates:
<ul>
<li><b>2.5.7</b> <em>(2021-05-02)</em> - Fixed minor issues - Android version</li>
<ul>
<li>Fixed formatting code issues </li>
</ul>
<li><b>2.5.6</b> <em>(2021-05-02)</em> - Fixed minor issues</li>
<ul>
<li>Fixed formatting code issues </li>
</ul>
<li><b>2.5.5</b> <em>(2021-04-22)</em> - Fixed minor issues</li>
<ul>
<li>Fixed formatting code issues </li>
Expand Down
3 changes: 2 additions & 1 deletion src/main/html/description.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Provides support for the <a href="https://firebase.google.com/docs/rules/rules-language">Firebase rules</a> language.<br>

<a href="https://www.buymeacoffee.com/dalgarins" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" alt="Buy Me A Coffee" style="height: 41px !important;width: 174px !important;box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;" ></a>
<br>
Features:<br>
<ul>
<li>Syntax highlighting</li>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package co.anbora.labs.firebase.ide.formatter

import co.anbora.labs.firebase.lang.FirebaseRulesLanguage
import co.anbora.labs.firebase.lang.core.psi.FirebaseRulesParameterStatement
import co.anbora.labs.firebase.lang.core.psi.FirebaseRulesTypes.*
import com.intellij.formatting.*
import com.intellij.lang.ASTNode
Expand All @@ -10,11 +11,14 @@ import com.intellij.psi.tree.IElementType

fun FirebaseFormatterBlock.computeIndent(): Indent? {
val parent = node.treeParent
val psi = node.psi
return when {
parent?.treeParent == null -> Indent.getNoneIndent()
node.areBraces() -> Indent.getNoneIndent()
node.isBooleanOperator() -> Indent.getNormalIndent()
parent.isComposeBlock() -> Indent.getNormalIndent()
parent.isBooleanExpr() -> Indent.getNormalIndent()
parent.isCallExpr() && psi is FirebaseRulesParameterStatement -> Indent.getNormalIndent()
else -> Indent.getNoneIndent()
}
}
Expand Down Expand Up @@ -52,7 +56,14 @@ fun createSpacingBuilder(commonSettings: CodeStyleSettings): SpacingBuilder {
.after(COLON).spacing(1, 1, 0, false, 0)
.after(IF_KEYWORD).spacing(1, 1, 0, false, 0)
.after(EXPRESSION).spacing(1, 1, 0, false, 0)
.after(BOOLEAN_OPERATOR).spacing(1, 1, 0, false, 0)
.after(OROR).spacing(1, 1, 0, false, 0)
.after(ANDAND).spacing(1, 1, 0, false, 0)
.after(LT).spacing(1, 1, 0, false, 0)
.after(GT).spacing(1, 1, 0, false, 0)
.after(LE).spacing(1, 1, 0, false, 0)
.after(GE).spacing(1, 1, 0, false, 0)
.after(EQEQ).spacing(1, 1, 0, false, 0)
.after(NE).spacing(1, 1, 0, false, 0)
.before(DOT_COMMA).spacing(0,0,0,false,0)
}

Expand All @@ -66,6 +77,19 @@ fun ASTNode.isBooleanOperator(): Boolean {
elementType == ANDAND
}

fun ASTNode.isCallExpr(): Boolean {
return this.elementType == CALL_EXPR
}

fun ASTNode.isBooleanExpr(): Boolean {
return this.elementType == OR_EXPR
|| this.elementType == AND_EXPR
}

fun ASTNode.isParenthesisBlock(): Boolean {
return this.elementType == PARENS_EXPR
}

fun ASTNode.isComposeBlock(): Boolean {
val elementType: IElementType = this.elementType
return elementType == SERVICE_BLOCK ||
Expand Down

0 comments on commit 14faea3

Please sign in to comment.