Skip to content

Commit 3751b10

Browse files
authored
Merge pull request #92 from anboralabs/structure
Added support for structures
2 parents a9754b0 + dcc0f0b commit 3751b10

File tree

9 files changed

+132
-24
lines changed

9 files changed

+132
-24
lines changed

FAQ.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
## I am a student or an OSS developer, can I get a license for free?
2+
3+
Sure! Please follow
4+
[https://jetbrains.com/student/](https://jetbrains.com/student/) (students) or
5+
[https://jetbrains.com/buy/opensource/](https://jetbrains.com/buy/opensource/)
6+
(OSS developer) instructions. If you are facing issues, please contact JetBrains
7+
support directly. Unfortunately, I can do nothing, this is on the JetBrains
8+
side.
9+
10+
Also, if you contributed to Firebase Rules Syntax Highlighter, please email me,
11+
or send a private message on Twitter (dalgarins): I have some coupons for free
12+
licenses for you.
13+
14+
## I received a coupon for a free license, how does it work?
15+
16+
Please note a coupon is not an activation code, it's a bit weird. You need to
17+
hit the "Buy" button (monthly or yearly subscription, it doesn't matter), then
18+
enter the coupon code. The form will now say you will get a 9-months license at
19+
no cost. You can activate your coupons when you want, they have no expiration
20+
date.
21+
22+
## Extra Notes
23+
24+
Firebase Rules Syntax Highlighter is still:
25+
26+
- free (MIT license). You can do what you want with it.
27+
- partially gratis: you can get the sources, remove the code that asks for a
28+
JetBrains license, repackage the plugin, then install it in your IDE at no
29+
cost. This is legal, and this is why I will stick to the MIT license. You only
30+
have to pay if you want to install the plugin from the JetBrains marketplace.
31+
- opensource: you can learn from the project's source code, you can contribute
32+
(I will send free licenses to contributors, because I think
33+
`contributing == supporting`) and - this is only my opinion - this is the
34+
meaning of OSS: sharing **and** contribution.

README.md

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
1-
<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>
2-
3-
# intellij-firebase-highlighter
1+
:rocket: With release 2022.1.1, Firebase Rules Syntax Highlighter is now a paid
2+
plugin: 5$/year (or 0.5$/month). Price decreases over time, and it's free for
3+
students, teachers and OSS developers. If you don't want to (or can't) support
4+
my work, feel free to use previous releases. You can also package your own
5+
version of the plugin and install it for free, it's still free (MIT license) and
6+
OpenSource. You only have to pay if you want to download and use my version of
7+
the plugin that is hosted on the JetBrains marketplace. I think it's a way to
8+
support my work. If you have questions about this, please read the
9+
[FAQ](./FAQ.md).
10+
11+
<h1 align="center">
12+
<a href="https://plugins.jetbrains.com/plugin/15189-firebase-rules-syntax-highlighter">
13+
<img src="./src/main/resources/META-INF/pluginIcon.svg" width="84" height="84" alt="logo"/>
14+
</a><br/>
15+
Firebase Rules Syntax Highlighter
16+
</h1>
17+
18+
<p align="center">
19+
<a href="https://plugins.jetbrains.com/plugin/15189-firebase-rules-syntax-highlighter"><img src="https://img.shields.io/jetbrains/plugin/v/15189-firebase-rules-syntax-highlighter.svg"/></a>
20+
<a href="https://plugins.jetbrains.com/plugin/15189-firebase-rules-syntax-highlighter"><img src="https://img.shields.io/jetbrains/plugin/d/15189-firebase-rules-syntax-highlighter.svg"/></a>
21+
<a href="https://github.com/anboralabs/intellij-firebase-highlighter/blob/master/LICENSE.txt"><img src="https://img.shields.io/github/license/anboralabs/intellij-firebase-highlighter"/></a>
22+
<a href="https://github.com/anboralabs/intellij-firebase-highlighter/stargazers"><img src="https://img.shields.io/github/stars/anboralabs/intellij-firebase-highlighter"/></a><br>
23+
</p>
424

525
![Plugin](/images/highlighted.png)
626

@@ -57,6 +77,8 @@ The main ideas used here were borrowed from:
5777
- https://github.com/ferronrsmith/intellij-fbp-highlighter
5878
- https://github.com/lark-parser/intellij-syntax-highlighting
5979
- https://github.com/klazuka/intellij-elm
80+
- https://github.com/pontem-network/intellij-move
81+
- https://github.com/jonathanlermitage/intellij-extra-icons-plugin
6082

6183
## License
6284

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
plugins {
22
id 'java'
3-
id 'org.jetbrains.intellij' version '1.4.0'
3+
id 'org.jetbrains.intellij' version '1.5.2'
44
id 'org.jetbrains.kotlin.jvm' version '1.6.10'
5-
id "org.jetbrains.grammarkit" version "2021.2.1"
5+
id "org.jetbrains.grammarkit" version "2021.2.2"
66
}
77

88
apply plugin: 'org.jetbrains.grammarkit'
99

1010
group 'co.anbora.labs'
11-
version '2.7.1'
11+
version '2022.1.2'
1212

1313
repositories {
1414
mavenCentral()

src/main/grammar/FirebaseRules.bnf

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,13 @@ ConditionalStatement ::= IF_KEYWORD ConditionalBlock {
157157
ConditionalBlock ::= Expression
158158
//Allow Statement End
159159

160-
FullBuiltInParameterStatement ::= (SLASH PathBuiltInParameterStatement)+
160+
FullBuiltInParameterStatement ::= PathBuiltInItem+
161161

162-
PathBuiltInParameterStatement ::= (DOT? IDENTIFIER|PATH_BUILT_IN)
162+
private PathBuiltInItem ::= SLASH PathBuiltInParameterStatement {
163+
pin="SLASH"
164+
}
163165

164-
private existsFunction ::= <<existsFunction>>
165-
private getFunction ::= <<getFunction>>
166+
PathBuiltInParameterStatement ::= (DOT? IDENTIFIER|PATH_BUILT_IN)
166167

167168
//Function Definition Begin
168169
FunctionDef ::= FUNCTION_KEYWORD IdentifierExpr FunctionParameterList FunctionBlock
@@ -193,9 +194,10 @@ FunctionBlock ::= LEFT_BRACE FunctionBlockItems RIGHT_BRACE
193194
}
194195
private FunctionBlockItems ::= !('}' | <<eof>>) VariableStatement* ReturnStatement
195196
{
196-
pin = 1
197-
recoverWhile = Item_recover
197+
pin=1
198+
recoverWhile = FunctionBlock_recover
198199
}
200+
private FunctionBlock_recover ::= !('}' | <<eof>>)
199201
//Function Definition Ends
200202

201203
ParameterStatement ::= Expression(COMMA Expression)*
@@ -231,6 +233,23 @@ CallExpr ::= Expression CallArguments
231233
CallArguments ::= '(' ParameterStatement? ')'
232234
//CallArguments ::= '(' (Expression &(','|')'))? ')' { pin = 1 }
233235

236+
StructLiteralExpr ::= '{' StructLiteralField_with_recover* '}' { pin = 1 }
237+
238+
private StructLiteralField_with_recover ::= !'}' StructLiteralField (',' | &'}')
239+
{
240+
pin = 1
241+
recoverWhile = StructLiteralField_recover
242+
}
243+
private StructLiteralField_recover ::= !('}' | IDENTIFIER)
244+
245+
StructLiteralField ::= LiteralExpr StructLiteralFieldAssignment?
246+
{
247+
pin = 1
248+
}
249+
250+
//private StructLiteralExprField_recover ::= !(',' | '}')
251+
StructLiteralFieldAssignment ::= ':' Expression { pin = 1 }
252+
234253
LiteralExpr ::= LiteralStatement
235254
| BooleanStatement
236255
| NullStatement
@@ -241,6 +260,7 @@ private AtomExpr ::=
241260
ArrayLiteralExpr
242261
| CallExpr
243262
| ParensExpr
263+
| StructLiteralExpr
244264
| IndexExpr
245265
| DotExpr
246266
| LiteralExpr
@@ -277,7 +297,7 @@ private ArrayExpr ::= LB (ParameterStatement) RB
277297

278298
LiteralStatement ::= (number|string)
279299

280-
VariableStatement ::= LET_KEYWORD IdentifierExpr EQ Expression (DOT_COMMA?)
300+
VariableStatement ::= LET_KEYWORD IdentifierExpr EQ Expression (DOT_COMMA?) { pin = 1 }
281301

282302
NullStatement ::= NULL_KEYWORD
283303

src/main/html/description.html

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
1+
<h1 align="center">
2+
<a href="https://plugins.jetbrains.com/plugin/15189-firebase-rules-syntax-highlighter">
3+
<img src="https://raw.githubusercontent.com/anboralabs/intellij-firebase-highlighter/master/src/main/resources/META-INF/pluginIcon.svg" width="84" height="84" alt="logo"/>
4+
</a><br/>
5+
Firebase Rules Syntax Highlighter
6+
</h1>
7+
8+
<p align="center">
9+
<a href="https://plugins.jetbrains.com/plugin/15189-firebase-rules-syntax-highlighter"><img src="https://img.shields.io/jetbrains/plugin/v/15189-firebase-rules-syntax-highlighter.svg"/></a>
10+
<a href="https://plugins.jetbrains.com/plugin/15189-firebase-rules-syntax-highlighter"><img src="https://img.shields.io/jetbrains/plugin/d/15189-firebase-rules-syntax-highlighter.svg"/></a>
11+
<a href="https://github.com/anboralabs/intellij-firebase-highlighter/blob/master/LICENSE.txt"><img src="https://img.shields.io/github/license/anboralabs/intellij-firebase-highlighter"/></a>
12+
<a href="https://github.com/anboralabs/intellij-firebase-highlighter/stargazers"><img src="https://img.shields.io/github/stars/anboralabs/intellij-firebase-highlighter"/></a><br>
13+
</p>
14+
115
Provides support for the <a href="https://firebase.google.com/docs/rules/rules-language">Firebase rules</a> language.<br>
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>
16+
317
<br>
418
Features:<br>
519
<ul>

src/main/kotlin/co/anbora/labs/firebase/ide/annotator/HighlightingAnnotator.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
package co.anbora.labs.firebase.ide.annotator
22

33
import co.anbora.labs.firebase.ide.color.FirebaseColors
4-
import co.anbora.labs.firebase.lang.core.psi.FirebaseElement
54
import co.anbora.labs.firebase.lang.core.psi.FirebaseRulesCallExpr
65
import co.anbora.labs.firebase.lang.core.psi.FirebaseRulesIdentifierExpr
7-
import co.anbora.labs.firebase.lang.core.psi.FirebaseRulesLiteralExpr
8-
import co.anbora.labs.firebase.lang.core.psi.FirebaseRulesTypes.IDENTIFIER
96
import co.anbora.labs.firebase.lang.core.psi.ext.elementType
107
import com.intellij.lang.annotation.AnnotationHolder
118
import com.intellij.lang.annotation.Annotator

src/main/kotlin/co/anbora/labs/firebase/ide/color/FirebaseColors.kt

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,32 @@ import com.intellij.lang.annotation.HighlightSeverity
44
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors
55
import com.intellij.openapi.editor.HighlighterColors
66
import com.intellij.openapi.editor.colors.TextAttributesKey
7+
import com.intellij.openapi.editor.markup.TextAttributes
78
import com.intellij.openapi.options.colors.AttributesDescriptor
9+
import java.awt.Color
10+
import java.awt.Font
811

912
enum class FirebaseColors(humanName: String, default: TextAttributesKey) {
1013

1114
KEY_WORD("Keywords", DefaultLanguageHighlighterColors.KEYWORD),
1215
BAD_CHAR("Bad Character", HighlighterColors.BAD_CHARACTER),
1316
PERMISSIONS("Permissions", DefaultLanguageHighlighterColors.CONSTANT),
14-
PATH_AND_STRING("Path and Strings", DefaultLanguageHighlighterColors.STRING),
17+
STRINGS("Literals//Strings", DefaultLanguageHighlighterColors.STRING),
18+
PATH_VARIABLE("Literals//Path Variable", TextAttributesKey.createTextAttributesKey("DEFAULT_PATH_VARIABLE", DefaultLanguageHighlighterColors.STRING)),
19+
PATH_BUILT_IN("Literals//Path", TextAttributesKey.createTextAttributesKey("DEFAULT_PATH_BUILT_IN", DefaultLanguageHighlighterColors.STRING)),
20+
NUMBERS("Literals//Numbers", DefaultLanguageHighlighterColors.NUMBER),
1521
COMMENTS("Comments", DefaultLanguageHighlighterColors.LINE_COMMENT),
16-
CALL_FUNCTION("Functions", DefaultLanguageHighlighterColors.FUNCTION_CALL),
17-
NUMBERS("Numbers", DefaultLanguageHighlighterColors.NUMBER),
18-
SERVICE_NAME("Service name", DefaultLanguageHighlighterColors.NUMBER);
22+
CALL_FUNCTION(
23+
"Functions",
24+
TextAttributesKey.createTempTextAttributesKey(
25+
"FIREBASE_CALL_FUNCTION",
26+
TextAttributes(Color.decode("#E8C32A"), null, null, null, Font.PLAIN)
27+
)
28+
),
29+
SEMICOLON("Operators//Semicolon", DefaultLanguageHighlighterColors.SEMICOLON),
30+
DOT("Operators//Dot", DefaultLanguageHighlighterColors.DOT),
31+
COMMA("Operators//Comma", DefaultLanguageHighlighterColors.COMMA),
32+
SERVICE_NAME("Service name", TextAttributesKey.createTextAttributesKey("DEFAULT_SERVICE_NAME", DefaultLanguageHighlighterColors.NUMBER));
1933

2034
val textAttributesKey = TextAttributesKey.createTextAttributesKey("co.anbora.labs.firebase.$name", default)
2135
val attributesDescriptor = AttributesDescriptor(humanName, textAttributesKey)

src/main/kotlin/co/anbora/labs/firebase/ide/highlight/FirebaseSyntaxHighlighter.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,20 @@ class FirebaseSyntaxHighlighter: SyntaxHighlighterBase() {
1818
companion object {
1919
fun map(tokenType: IElementType?): FirebaseColors? =
2020
when (tokenType) {
21-
RULES_VERSION, DOT_COMMA, SERVICE_KEYWORD, MATCH_KEYWORD, ALLOW_KEYWORD,
21+
RULES_VERSION, SERVICE_KEYWORD, MATCH_KEYWORD, ALLOW_KEYWORD,
2222
TRUE_KEYWORD, FALSE_KEYWORD, NULL_KEYWORD,
2323
IF_KEYWORD, FUNCTION_KEYWORD, RETURN_KEYWORD,
2424
IN_KEYWORD, LET_KEYWORD, IS_KEYWORD -> FirebaseColors.KEY_WORD
25-
PATH_VARIABLE, PATH_BUILT_IN, STRING, VERSIONS -> FirebaseColors.PATH_AND_STRING
25+
DOT_COMMA -> FirebaseColors.SEMICOLON
26+
DOT -> FirebaseColors.DOT
27+
COMMA -> FirebaseColors.COMMA
28+
PATH_VARIABLE -> FirebaseColors.PATH_VARIABLE
29+
PATH_BUILT_IN -> FirebaseColors.PATH_BUILT_IN
30+
VERSIONS, STRING -> FirebaseColors.STRINGS
2631
LINE_COMMENT, BLOCK_COMMENT -> FirebaseColors.COMMENTS
2732
CALL_EXPR -> FirebaseColors.CALL_FUNCTION
2833
NUMBER -> FirebaseColors.NUMBERS
29-
SERVICE_NAME -> FirebaseColors.NUMBERS
34+
SERVICE_NAME -> FirebaseColors.SERVICE_NAME
3035
TokenType.BAD_CHARACTER -> FirebaseColors.BAD_CHAR
3136
else -> null
3237
}

src/main/resources/META-INF/plugin.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<id>co.anbora.labs.firebase-syntax-highlighting</id>
33
<name>Firebase Rules Syntax Highlighter</name>
44
<vendor email="anboralabs@gmail.com" url="https://labs.anbora.co">Anbora-labs</vendor>
5+
<!-- TODO reminder: update the release-date and pluginVersion on new release, but change the release-version on new year only -->
6+
<product-descriptor code="PFIREHIGHLIGHT" release-date="20220325" release-version="20221"/>
57

68
<!-- please see https://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/plugin_compatibility.html
79
on how to target different products -->

0 commit comments

Comments
 (0)