Skip to content

Commit 14faea3

Browse files
authored
Merge pull request #66 from anboralabs/fix-issue
Fixed minor issues with formatting and boolean expressions.
2 parents 0ae7197 + a030a51 commit 14faea3

File tree

5 files changed

+52
-19
lines changed

5 files changed

+52
-19
lines changed

build.gradle

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@ plugins {
44
id 'java'
55
id 'org.jetbrains.intellij' version '0.6.5'
66
id 'org.jetbrains.kotlin.jvm' version '1.4.10'
7-
id "org.jetbrains.grammarkit" version "2020.3.2"
7+
id "org.jetbrains.grammarkit" version "2021.1.2"
88
}
99

10-
grammarKit {
11-
jflexRelease = '1.7.0-1'
12-
grammarKitRelease = 'f75d0d8'
13-
}
10+
apply plugin: 'org.jetbrains.grammarkit'
1411

1512
group 'co.anbora.labs'
16-
version '2.5.5-SNAPSHOT'
13+
version '2.5.6-SNAPSHOT'
1714

1815
repositories {
1916
mavenCentral()

src/main/grammar/FirebaseRules.bnf

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,11 @@ private PermissionStatementItem ::= !(':'|';') PermissionKeyWord (',' | &(':'|';
127127
private Permission_recover ::= !(':' |';' | GET_KEYWORD | READ_KEYWORD | WRITE_KEYWORD | LIST_KEYWORD
128128
| CREATE_KEYWORD | UPDATE_KEYWORD | DELETE_KEYWORD)
129129

130-
ConditionalStatement ::= IF_KEYWORD ConditionalExpression {
130+
ConditionalStatement ::= IF_KEYWORD ConditionalBlock {
131131
pin=1
132132
}
133133

134-
ConditionalExpression ::= Expression (BooleanOperator Expression)*
134+
ConditionalBlock ::= Expression
135135
//Allow Statement End
136136

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

141141
BuiltInFunctionStatement ::= (GET_KEYWORD|EXITS_KEYWORD)
142142

143+
BuiltInTypes ::= LIST_KEYWORD
144+
143145
//Function Definition Begin
144146
FunctionDef ::= FUNCTION_KEYWORD IDENTIFIER FunctionParameterList FunctionBlock
145147
{
@@ -179,7 +181,7 @@ ParameterStatement ::= Expression(COMMA Expression)*
179181
ReturnStatement ::= RETURN_KEYWORD ReturnBlock {
180182
pin=1
181183
}
182-
ReturnBlock ::= ConditionalExpression DOT_COMMA
184+
ReturnBlock ::= Expression DOT_COMMA
183185

184186
Expression ::=
185187
OrExpr
@@ -205,6 +207,7 @@ LiteralExpr ::= LiteralStatement
205207
| BooleanStatement
206208
| NullStatement
207209
| BuiltInFunctionStatement
210+
| BuiltInTypes
208211
| IdentifierExpr
209212
| FullBuiltInParameterStatement
210213

@@ -219,6 +222,10 @@ private AtomExpr ::=
219222
private MulExprItem ::= DivExpr | MulExpr | ModExpr
220223
private AddExprItem ::= PlusExpr | MinusExpr
221224
private LogicalEqExprItem ::= EqualsExpr | NotEqualsExpr | LessEqualsExpr | LessExpr | GreaterEqualsExpr | GreaterExpr
225+
| InExpr | IsExpr
226+
227+
InExpr ::= Expression IN_KEYWORD Expression
228+
IsExpr ::= Expression IS_KEYWORD Expression
222229

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

245252
LiteralStatement ::= (number|string)
246253

247-
VariableStatement ::= LET_KEYWORD IDENTIFIER EQ ConditionalExpression (DOT_COMMA?)
254+
VariableStatement ::= LET_KEYWORD IDENTIFIER EQ Expression (DOT_COMMA?)
248255

249256
NullStatement ::= NULL_KEYWORD
250257

251-
BooleanOperator ::= (PathOperator|OROR|ANDAND|LT|LE|GT|GE|IN_KEYWORD|IS_KEYWORD)
252-
253-
PathOperator ::= (EQEQ|NE)
254-
255258
BooleanStatement ::= (TRUE_KEYWORD|FALSE_KEYWORD)

src/main/html/change-notes.html

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
Versions:
22
<ul>
3-
<li>All Intellij products support: 2.5.5</li>
4-
<li>Android Studio support: 2.5.4</li>
3+
<li>All Intellij products support: 2.5.6</li>
4+
<li>Android Studio support: 2.5.7</li>
55
</ul>
6-
6+
<br>
77
Plugin updates:
88
<ul>
9+
<li><b>2.5.7</b> <em>(2021-05-02)</em> - Fixed minor issues - Android version</li>
10+
<ul>
11+
<li>Fixed formatting code issues </li>
12+
</ul>
13+
<li><b>2.5.6</b> <em>(2021-05-02)</em> - Fixed minor issues</li>
14+
<ul>
15+
<li>Fixed formatting code issues </li>
16+
</ul>
917
<li><b>2.5.5</b> <em>(2021-04-22)</em> - Fixed minor issues</li>
1018
<ul>
1119
<li>Fixed formatting code issues </li>

src/main/html/description.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Provides support for the <a href="https://firebase.google.com/docs/rules/rules-language">Firebase rules</a> language.<br>
2-
2+
<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>
3+
<br>
34
Features:<br>
45
<ul>
56
<li>Syntax highlighting</li>

src/main/kotlin/co/anbora/labs/firebase/ide/formatter/processor.kt

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package co.anbora.labs.firebase.ide.formatter
22

33
import co.anbora.labs.firebase.lang.FirebaseRulesLanguage
4+
import co.anbora.labs.firebase.lang.core.psi.FirebaseRulesParameterStatement
45
import co.anbora.labs.firebase.lang.core.psi.FirebaseRulesTypes.*
56
import com.intellij.formatting.*
67
import com.intellij.lang.ASTNode
@@ -10,11 +11,14 @@ import com.intellij.psi.tree.IElementType
1011

1112
fun FirebaseFormatterBlock.computeIndent(): Indent? {
1213
val parent = node.treeParent
14+
val psi = node.psi
1315
return when {
1416
parent?.treeParent == null -> Indent.getNoneIndent()
1517
node.areBraces() -> Indent.getNoneIndent()
1618
node.isBooleanOperator() -> Indent.getNormalIndent()
1719
parent.isComposeBlock() -> Indent.getNormalIndent()
20+
parent.isBooleanExpr() -> Indent.getNormalIndent()
21+
parent.isCallExpr() && psi is FirebaseRulesParameterStatement -> Indent.getNormalIndent()
1822
else -> Indent.getNoneIndent()
1923
}
2024
}
@@ -52,7 +56,14 @@ fun createSpacingBuilder(commonSettings: CodeStyleSettings): SpacingBuilder {
5256
.after(COLON).spacing(1, 1, 0, false, 0)
5357
.after(IF_KEYWORD).spacing(1, 1, 0, false, 0)
5458
.after(EXPRESSION).spacing(1, 1, 0, false, 0)
55-
.after(BOOLEAN_OPERATOR).spacing(1, 1, 0, false, 0)
59+
.after(OROR).spacing(1, 1, 0, false, 0)
60+
.after(ANDAND).spacing(1, 1, 0, false, 0)
61+
.after(LT).spacing(1, 1, 0, false, 0)
62+
.after(GT).spacing(1, 1, 0, false, 0)
63+
.after(LE).spacing(1, 1, 0, false, 0)
64+
.after(GE).spacing(1, 1, 0, false, 0)
65+
.after(EQEQ).spacing(1, 1, 0, false, 0)
66+
.after(NE).spacing(1, 1, 0, false, 0)
5667
.before(DOT_COMMA).spacing(0,0,0,false,0)
5768
}
5869

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

80+
fun ASTNode.isCallExpr(): Boolean {
81+
return this.elementType == CALL_EXPR
82+
}
83+
84+
fun ASTNode.isBooleanExpr(): Boolean {
85+
return this.elementType == OR_EXPR
86+
|| this.elementType == AND_EXPR
87+
}
88+
89+
fun ASTNode.isParenthesisBlock(): Boolean {
90+
return this.elementType == PARENS_EXPR
91+
}
92+
6993
fun ASTNode.isComposeBlock(): Boolean {
7094
val elementType: IElementType = this.elementType
7195
return elementType == SERVICE_BLOCK ||

0 commit comments

Comments
 (0)