Skip to content

Commit d738101

Browse files
authored
Merge pull request #27 from anboralabs/migration-kotlin
Migration kotlin
2 parents 3eb90f3 + ba30395 commit d738101

30 files changed

+349
-408
lines changed

build.gradle

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import org.jetbrains.grammarkit.tasks.*
22

33
plugins {
44
id 'java'
5-
id 'org.jetbrains.intellij' version '0.4.26'
5+
id 'org.jetbrains.intellij' version '0.6.5'
6+
id 'org.jetbrains.kotlin.jvm' version '1.4.10'
67
id "org.jetbrains.grammarkit" version "2020.2.1"
78
}
89

@@ -12,21 +13,22 @@ grammarKit {
1213
}
1314

1415
group 'co.anbora.labs'
15-
version '1.1.5-SNAPSHOT'
16+
version '2.0.0-SNAPSHOT'
1617

1718
repositories {
1819
mavenCentral()
1920
}
2021

2122
dependencies {
23+
implementation "org.jetbrains.kotlin:kotlin-stdlib"
2224
testCompile group: 'junit', name: 'junit', version: '4.12'
2325
}
2426

2527
task generateFirebaseRulesLexer(type: GenerateLexer) {
2628
// source flex file
2729
source = "src/main/grammar/FirebaseRules.flex"
2830
// target directory for lexer
29-
targetDir = "src/main/gen/co/anbora/labs/firebase/syntax/"
31+
targetDir = "src/main/gen/co/anbora/labs/firebase/lang/core/lexer/"
3032
// target classname, target file will be targetDir/targetClass.java
3133
targetClass = "FirebaseRulesLexer"
3234
// if set, plugin will remove a lexer output file before generating new one. Default: false
@@ -39,19 +41,29 @@ task generateFirebaseRulesParser(type: GenerateParser) {
3941
// optional, task-specific root for the generated files. Default: none
4042
targetRoot = 'src/main/gen'
4143
// path to a parser file, relative to the targetRoot
42-
pathToParser = '/co/anbora/labs/firebase/syntax/parser/FirebaseRulesParser.java'
44+
pathToParser = '/co/anbora/labs/firebase/lang/core/parser/FirebaseRulesParser.java'
4345
// path to a directory with generated psi files, relative to the targetRoot
44-
pathToPsiRoot = '/co/anbora/labs/firebase/syntax/psi'
46+
pathToPsiRoot = '/co/anbora/labs/firebase/lang/core/psi'
4547
// if set, plugin will remove a parser output file and psi output directory before generating new ones. Default: false
4648
purgeOldFiles = true
4749
}
4850

4951
// Include the generated files in the source set
50-
sourceSets.main.java.srcDirs 'src/main/gen'
52+
def genRoot = file('src/main/gen')
53+
54+
sourceSets {
55+
main {
56+
kotlin.srcDir 'src/main/kotlin'
57+
java.srcDir genRoot
58+
resources.srcDir 'src/main/resources'
59+
}
60+
}
5161

5262
// See https://github.com/JetBrains/gradle-intellij-plugin/
5363
intellij { }
5464

65+
tasks.withType(JavaCompile) { options.encoding = 'UTF-8' }
66+
5567
buildPlugin {
5668
dependsOn(generateFirebaseRulesLexer, generateFirebaseRulesParser)
5769
}
@@ -63,6 +75,13 @@ publishPlugin {
6375
patchPluginXml {
6476
changeNotes """
6577
<ul>
78+
<li><b>2.0.0</b> <em>(2020-12-12)</em> - Added support block comments</li>
79+
<ul>
80+
<li>Added support for block comments </li>
81+
<li>Added support for keyboard combination: CMD + / </li>
82+
<li>Fixed issue with parenthesis and negation on expressions </li>
83+
</ul>
84+
</li>
6685
<li><b>1.1.5</b> <em>(2020-12-02)</em> - Added support for new IDE versions</li>
6786
<ul>
6887
<li>Added support for IDE version from build 192 </li>

src/main/grammar/FirebaseRules.bnf

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
// Copyright 2000-2020 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
22
{
3-
parserClass="co.anbora.labs.firebase.syntax.parser.FirebaseRulesParser"
4-
parserUtilClass="co.anbora.labs.firebase.syntax.parser.FirebaseRulesParserUtil"
3+
parserClass="co.anbora.labs.firebase.lang.core.parser.FirebaseRulesParser"
4+
parserUtilClass="co.anbora.labs.firebase.lang.core.parser.FirebaseParserUtil"
55
extends="com.intellij.extapi.psi.ASTWrapperPsiElement"
66

77
psiClassPrefix="FirebaseRules"
88
psiImplClassSuffix="Impl"
9-
psiPackage="co.anbora.labs.firebase.syntax.psi"
10-
psiImplPackage="co.anbora.labs.firebase.syntax.psi.impl"
9+
psiPackage="co.anbora.labs.firebase.lang.core.psi"
10+
psiImplPackage="co.anbora.labs.firebase.lang.core.psi.impl"
1111

12-
elementTypeHolderClass="co.anbora.labs.firebase.syntax.psi.FirebaseRulesTypes"
13-
elementTypeClass="co.anbora.labs.firebase.syntax.psi.FirebaseRulesElementType"
14-
tokenTypeClass="co.anbora.labs.firebase.syntax.psi.FirebaseRulesTokenType"
12+
elementTypeHolderClass="co.anbora.labs.firebase.lang.core.psi.FirebaseRulesTypes"
13+
elementTypeClass="co.anbora.labs.firebase.lang.core.psi.FirebaseElementType"
14+
tokenTypeClass="co.anbora.labs.firebase.lang.core.psi.FirebaseTokenType"
1515

1616
tokens = [
1717
WHITE_SPACE='regexp:\s+'
1818
LP = '('
1919
RP = ')'
2020
LB = '['
2121
RB = ']'
22-
LINE_COMMENT='LINE_COMMENT'
2322
number='regexp:\d+(\.\d*)?'
2423
string="regexp:('([^'\\]|\\.)*'|\"([^\"\\]|\\.)*\")"
2524
op = '->'
@@ -28,6 +27,8 @@
2827
EQ = '='
2928
DOT = '.'
3029
char = 'regexp:[\n\r\u2028\u2029]'
30+
LINE_COMMENT='LINE_COMMENT'
31+
BLOCK_COMMENT='BLOCK_COMMENT'
3132
]
3233

3334
}
@@ -36,15 +37,13 @@ root ::= root_item
3637

3738
private root_item ::= !<<eof>> property
3839

39-
property ::= RuleVersionStatement? (LINE_COMMENT|FunctionStatement)* ServiceStatement
40-
41-
private comment ::= LINE_COMMENT*
40+
property ::= RuleVersionStatement? (FunctionStatement)* ServiceStatement
4241

4342
RuleVersionStatement ::= RULES_VERSION EQ VERSIONS DOT_COMMA
4443

45-
ServiceStatement ::= SERVICE_KEYWORD SERVICE_NAME LEFT_BRACE (comment MatchStatement)+ RIGHT_BRACE
44+
ServiceStatement ::= SERVICE_KEYWORD SERVICE_NAME LEFT_BRACE (MatchStatement)+ RIGHT_BRACE
4645

47-
MatchStatement ::= MATCH_KEYWORD FullPathStatement LEFT_BRACE (comment AllowStatement|comment MatchStatement|comment FunctionStatement)+ RIGHT_BRACE
46+
MatchStatement ::= MATCH_KEYWORD FullPathStatement LEFT_BRACE (AllowStatement|MatchStatement|FunctionStatement)+ RIGHT_BRACE
4847

4948
FullPathStatement ::= (SLASH PathStatement)+
5049

@@ -79,7 +78,7 @@ ExistBuiltInFunctionStatement ::= EXITS_KEYWORD LP FullBuiltInParameterStatement
7978

8079
BuiltInFunctionStatement ::= (GetBuiltInFunctionStatement|ExistBuiltInFunctionStatement)
8180

82-
FunctionStatement ::= FUNCTION_KEYWORD CallFunctionStatement LEFT_BRACE comment ReturnStatement RIGHT_BRACE
81+
FunctionStatement ::= FUNCTION_KEYWORD CallFunctionStatement LEFT_BRACE ReturnStatement RIGHT_BRACE
8382

8483
ReturnStatement ::= RETURN_KEYWORD ConditionalExpression DOT_COMMA
8584

@@ -90,6 +89,14 @@ Expression ::= BooleanStatement
9089
| LiteralStatement
9190
| NullStatement
9291
| ArrayLiteralStatement
92+
| ParenthesizedExpression
93+
| NegatedExpression
94+
95+
ParenthesizedExpression ::=
96+
LP ConditionalExpression RP
97+
98+
NegatedExpression ::=
99+
NEGATE Expression
93100

94101
ArrayLiteralStatement ::= LB (ParameterStatement|ArrayLiteralStatement) RB
95102

src/main/grammar/FirebaseRules.flex

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
// Copyright 2000-2020 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
2-
package co.anbora.labs.firebase.syntax;
2+
package co.anbora.labs.firebase.lang.core.lexer;
33

44
import com.intellij.lexer.FlexLexer;
55
import com.intellij.psi.tree.IElementType;
6-
import static co.anbora.labs.firebase.syntax.psi.FirebaseRulesTypes.*;
6+
import static co.anbora.labs.firebase.lang.core.psi.FirebaseRulesTypes.*;
77
import com.intellij.psi.TokenType;
88

99
%%
1010

1111
%{
1212
public FirebaseRulesLexer() {
13-
this((java.io.Reader)null);
13+
this(null);
1414
}
1515
%}
1616

@@ -21,6 +21,19 @@ import com.intellij.psi.TokenType;
2121
%type IElementType
2222
%unicode
2323

24+
%{
25+
private int commentLevel = 0;
26+
private int charLength = 0;
27+
private boolean docComment = false;
28+
29+
private void startComment() {
30+
commentLevel = 1;
31+
yybegin(COMMENT);
32+
}
33+
%}
34+
35+
%xstate COMMENT
36+
2437
EOL="\r"|"\n"|"\r\n"
2538
LINE_WS=[\ \t\f]
2639
WHITE_SPACE=({LINE_WS}|{EOL})+
@@ -38,9 +51,29 @@ PATH_VARIABLE=[{][a-zA-Z_\-0-9]+(=\*\*)?[}]
3851
PATH_BUILT_IN=[$][(][a-zA-Z_\-0-9]+[a-zA-Z_\.\-0-9]*[)]
3952

4053
%%
54+
55+
<COMMENT> {
56+
"/*" {
57+
commentLevel++;
58+
}
59+
"*/" {
60+
if (--commentLevel == 0) {
61+
yybegin(YYINITIAL);
62+
return BLOCK_COMMENT;
63+
}
64+
}
65+
66+
<<EOF>> { commentLevel = 0; yybegin(YYINITIAL); return BLOCK_COMMENT; }
67+
68+
[^] { }
69+
}
70+
4171
<YYINITIAL> {
4272
{WHITE_SPACE} { return com.intellij.psi.TokenType.WHITE_SPACE; }
4373
{LINE_COMMENT} { return LINE_COMMENT; }
74+
"/*" {
75+
startComment();
76+
}
4477

4578
{PATH_BUILT_IN} { return PATH_BUILT_IN; }
4679
{PATH_VARIABLE} { return PATH_VARIABLE; }
@@ -76,6 +109,7 @@ PATH_BUILT_IN=[$][(][a-zA-Z_\-0-9]+[a-zA-Z_\.\-0-9]*[)]
76109
"<=" { return LE; }
77110
">" { return GT; }
78111
">=" { return GE; }
112+
"!" { return NEGATE; }
79113

80114
"+" { return PLUS_OP; }
81115
"-" { return MINUS_OP; }

src/main/java/co/anbora/labs/firebase/syntax/FirebaseRulesAdapter.java

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/main/java/co/anbora/labs/firebase/syntax/highlight/ColorSettings.java

Lines changed: 0 additions & 89 deletions
This file was deleted.

0 commit comments

Comments
 (0)