Skip to content

Commit

Permalink
Added annotation tokens, remove non-null assertions (#14)
Browse files Browse the repository at this point in the history
* added the annotation token

* added annotation tokens

* added files to gitignore

* gitignore fix

* fixed gitignore

* added antlr files to gitignore

* whitespace fix
  • Loading branch information
Yash-bhagwat authored Sep 26, 2023
1 parent 619ba79 commit c85f30a
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
.idea
.qodana
build
.vscode
bin
src/main/antlr/.antlr
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ You can add these colours to your IDE colour scheme by going to `Preferences →
<option name="FOREGROUND" value="ff7abd" />
</value>
</option>
<option name="TYPEQL_ANNOTATION">
<value>
<option name="FOREGROUND" value="ffa187" />
</value>
</option>
<option name="TYPEQL_LINE_COMMENT">
<value>
<option name="FOREGROUND" value="4dc97c" />
Expand Down Expand Up @@ -133,6 +138,11 @@ You can add these colours to your IDE colour scheme by going to `Preferences →
<option name="FOREGROUND" value="fb3196" />
</value>
</option>
<option name="TYPEQL_ANNOTATION">
<value>
<option name="FOREGROUND" value="ff6b00" />
</value>
</option>
<option name="TYPEQL_LINE_COMMENT">
<value>
<option name="FOREGROUND" value="309c59" />
Expand Down
2 changes: 1 addition & 1 deletion src/main/antlr/TypeQL.g4
Original file line number Diff line number Diff line change
Expand Up @@ -363,4 +363,4 @@ fragment ESCAPE_SEQ_ : '\\' . ;

COMMENT : '#' .*? '\r'? ('\n' | EOF) -> channel(HIDDEN) ;
WS : [ \t\r\n]+ -> channel(HIDDEN) ;
UNRECOGNISED : . ;
UNRECOGNISED : . ;
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ sort asc;
AttributesDescriptor("Boolean", TypeQLSyntaxHighlighter.Companion.BOOLEAN),
AttributesDescriptor("Aggregate", TypeQLSyntaxHighlighter.Companion.AGGREGATE),
AttributesDescriptor("Type", TypeQLSyntaxHighlighter.Companion.TYPE),
AttributesDescriptor("Annotation", TypeQLSyntaxHighlighter.Companion.ANNOTATION),
//AttributesDescriptor("Bad Value", TypeQLSyntaxHighlighter.Companion.BAD_CHARACTER)
)

Expand All @@ -88,6 +89,7 @@ sort asc;
ColorDescriptor("Boolean", ColorKey.createColorKey("Orange", Color(255, 161, 135)), ColorDescriptor.Kind.FOREGROUND),
ColorDescriptor("Aggregate", ColorKey.createColorKey("Pink", Color(255, 122, 189)), ColorDescriptor.Kind.FOREGROUND),
ColorDescriptor("Type", ColorKey.createColorKey("Blue", Color(130, 182, 255)), ColorDescriptor.Kind.FOREGROUND),
ColorDescriptor("Annotation", ColorKey.createColorKey("Orange", Color(255, 161, 135)), ColorDescriptor.Kind.FOREGROUND),
//ColorDescriptor("Bad Value", ColorKey.createColorKey("Line Comment", Color(10, 10, 10)), ColorDescriptor.Kind.FOREGROUND),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class TypeQLSyntaxHighlighter : SyntaxHighlighterBase() {
TypeQLLexer.LABEL_SCOPED_, TypeQLLexer.ORDER_
-> KEYWORD

TypeQLLexer.ANNOTATION_KEY, TypeQLLexer.ANNOTATION_UNIQUE -> ANNOTATION

TypeQLLexer.COUNT, TypeQLLexer.MAX, TypeQLLexer.MIN, TypeQLLexer.MEAN, TypeQLLexer.MEDIAN, TypeQLLexer.STD,
TypeQLLexer.SUM, TypeQLLexer.GROUP
-> AGGREGATE
Expand Down Expand Up @@ -75,6 +77,7 @@ class TypeQLSyntaxHighlighter : SyntaxHighlighterBase() {
val LINE_COMMENT =
TextAttributesKey.createTextAttributesKey("TYPEQL_LINE_COMMENT", DefaultLanguageHighlighterColors.LINE_COMMENT)
val KEYWORD = TextAttributesKey.createTextAttributesKey("TYPEQL_KEYWORD", DefaultLanguageHighlighterColors.KEYWORD)
val ANNOTATION = TextAttributesKey.createTextAttributesKey("TYPEQL_ANNOTATION")
val STRING = TextAttributesKey.createTextAttributesKey("TYPEQL_STRING", DefaultLanguageHighlighterColors.STRING)
val NUMBER = TextAttributesKey.createTextAttributesKey("TYPEQL_NUMBER", DefaultLanguageHighlighterColors.NUMBER)
val ID = TextAttributesKey.createTextAttributesKey("TYPEQL_IDENTIFIER", DefaultLanguageHighlighterColors.CONSTANT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,19 +252,19 @@ object TypeQLPsiUtils {
fun setName(element: PsiTypeQLElement, newName: String): PsiElement {
if (element is PsiTypeConstraint) {
val typeProperty = TypeQLPsiElementFactory.createTypeProperty(element.getProject(), newName)
element.getParent().node.replaceChild(element.getNode(), typeProperty!!.node)
element.getParent().node.replaceChild(element.getNode(), typeProperty.node)
} else if (element is PsiSubTypeConstraint) {
val subTypeProperty = TypeQLPsiElementFactory.createSubTypeProperty(element.getProject(), newName)
element.getParent().node.replaceChild(element.getNode(), subTypeProperty!!.node)
element.getParent().node.replaceChild(element.getNode(), subTypeProperty.node)
} else if (element is PsiRelatesTypeConstraint) {
val typeProperty = TypeQLPsiElementFactory.createRelatesTypeProperty(element.getProject(), newName)
element.getNode().replaceChild(
element.getFirstChild().nextSibling.nextSibling.node,
typeProperty!!.firstChild.nextSibling.nextSibling.node
typeProperty.firstChild.nextSibling.nextSibling.node
)
} else if (element is PsiPlaysTypeConstraint) {
val playsTypeProperty = TypeQLPsiElementFactory.createPlaysTypeProperty(element.getProject(), newName)
element.getParent().node.replaceChild(element.getNode(), playsTypeProperty!!.node)
element.getParent().node.replaceChild(element.getNode(), playsTypeProperty.node)
} else {
throw UnsupportedOperationException()
}
Expand Down

0 comments on commit c85f30a

Please sign in to comment.