This repository has been archived by the owner on May 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dc2818e
commit 98e9ac6
Showing
14 changed files
with
266 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/com/github/le_yams/openfga4intellij/OpenFGAFile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.github.le_yams.openfga4intellij; | ||
|
||
import com.intellij.extapi.psi.PsiFileBase; | ||
import com.intellij.openapi.fileTypes.FileType; | ||
import com.intellij.psi.FileViewProvider; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class OpenFGAFile extends PsiFileBase { | ||
|
||
public OpenFGAFile(@NotNull FileViewProvider viewProvider) { | ||
super(viewProvider, OpenFGALanguage.INSTANCE); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public FileType getFileType() { | ||
return OpenFGAFileType.INSTANCE; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getFileType().getName(); | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...ple/openfga4intellij/OpenFGAFileType.java → ...ams/openfga4intellij/OpenFGAFileType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...xample/openfga4intellij/OpenFGAIcons.java → ...e_yams/openfga4intellij/OpenFGAIcons.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ple/openfga4intellij/OpenFGALanguage.java → ...ams/openfga4intellij/OpenFGALanguage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/main/java/com/github/le_yams/openfga4intellij/OpenFGALexerAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.github.le_yams.openfga4intellij; | ||
|
||
import com.github.le_yams.openfga4intellij.parsing.OpenFGALexer; | ||
import com.intellij.lexer.FlexAdapter; | ||
|
||
public class OpenFGALexerAdapter extends FlexAdapter { | ||
|
||
public OpenFGALexerAdapter() { | ||
super(new OpenFGALexer(null)); | ||
} | ||
|
||
} |
4 changes: 2 additions & 2 deletions
4
...nfga4intellij/psi/OpenFGAElementType.java → ...4intellij/parsing/OpenFGAElementType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/main/java/com/github/le_yams/openfga4intellij/parsing/OpenFGALexer.flex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.github.le_yams.openfga4intellij.parsing; | ||
|
||
import com.intellij.lexer.FlexLexer; | ||
import com.intellij.psi.tree.IElementType; | ||
|
||
import static com.intellij.psi.TokenType.BAD_CHARACTER; | ||
import static com.intellij.psi.TokenType.WHITE_SPACE; | ||
import static com.github.le_yams.openfga4intellij.psi.OpenFGATypes.*; | ||
|
||
%% | ||
|
||
%{ | ||
public OpenFGALexer() { | ||
this((java.io.Reader)null); | ||
} | ||
%} | ||
|
||
%public | ||
%class OpenFGALexer | ||
%implements FlexLexer | ||
%function advance | ||
%type IElementType | ||
%unicode | ||
|
||
ALPHA_NUMERIC=[a-zA-Z0-9_-]+ | ||
END_OF_LINE=(\r\n)|\n | ||
WHITESPACE=[\ \t] | ||
IDENT1=((\ {2})|\t) | ||
IDENT2=((\ {4})|(\t{2})) | ||
SINGLE_LINE_COMMENT=[ \t]*#.* | ||
|
||
%% | ||
<YYINITIAL> { | ||
" " { return WHITE_SPACE; } | ||
|
||
"model" { return MODEL; } | ||
"schema" { return SCHEMA; } | ||
"1.1" { return SCHEMA_VERSION_V1_1; } | ||
"type" { return TYPE; } | ||
"relations" { return RELATIONS; } | ||
"define" { return DEFINE; } | ||
"#" { return HASH; } | ||
":" { return COLON; } | ||
"*" { return WILDCARD; } | ||
"[" { return L_SQUARE; } | ||
"]" { return R_SQUARE; } | ||
"," { return COMMA; } | ||
"and" { return AND; } | ||
"or" { return OR; } | ||
"but not" { return BUT_NOT; } | ||
"from" { return FROM; } | ||
"EOF" { return EOF; } | ||
|
||
{ALPHA_NUMERIC} { return ALPHA_NUMERIC; } | ||
{END_OF_LINE} { return END_OF_LINE; } | ||
{WHITESPACE} { return WHITESPACE; } | ||
{IDENT1} { return IDENT1; } | ||
{IDENT2} { return IDENT2; } | ||
{SINGLE_LINE_COMMENT} { return SINGLE_LINE_COMMENT; } | ||
|
||
} | ||
|
||
[^] { return BAD_CHARACTER; } |
71 changes: 71 additions & 0 deletions
71
src/main/java/com/github/le_yams/openfga4intellij/parsing/OpenFGAParserDefinition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.github.le_yams.openfga4intellij.parsing; | ||
|
||
import com.github.le_yams.openfga4intellij.OpenFGAFile; | ||
import com.github.le_yams.openfga4intellij.OpenFGALanguage; | ||
import com.github.le_yams.openfga4intellij.OpenFGALexerAdapter; | ||
import com.github.le_yams.openfga4intellij.psi.OpenFGATypes; | ||
import com.intellij.lang.ASTNode; | ||
import com.intellij.lang.ParserDefinition; | ||
import com.intellij.lang.PsiParser; | ||
import com.intellij.lexer.Lexer; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.psi.FileViewProvider; | ||
import com.intellij.psi.PsiElement; | ||
import com.intellij.psi.PsiFile; | ||
import com.intellij.psi.tree.IFileElementType; | ||
import com.intellij.psi.tree.TokenSet; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class OpenFGAParserDefinition implements ParserDefinition { | ||
|
||
public static final IFileElementType FILE = new IFileElementType(OpenFGALanguage.INSTANCE); | ||
|
||
@NotNull | ||
@Override | ||
public Lexer createLexer(Project project) { | ||
return new OpenFGALexerAdapter(); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public TokenSet getCommentTokens() { | ||
return OpenFGATokenSets.SINGLE_LINE_COMMENT; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public TokenSet getStringLiteralElements() { | ||
return TokenSet.EMPTY; | ||
} | ||
|
||
// @NotNull | ||
// @Override | ||
// public TokenSet getWhitespaceTokens() { | ||
// return OpenFGATokenSets.WHITE_SPACE; | ||
// } | ||
|
||
@NotNull | ||
@Override | ||
public PsiParser createParser(final Project project) { | ||
return new OpenFGAParser(); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public IFileElementType getFileNodeType() { | ||
return FILE; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public PsiFile createFile(@NotNull FileViewProvider viewProvider) { | ||
return new OpenFGAFile(viewProvider); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public PsiElement createElement(ASTNode node) { | ||
return OpenFGATypes.Factory.createElement(node); | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/github/le_yams/openfga4intellij/parsing/OpenFGATokenSets.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.github.le_yams.openfga4intellij.parsing; | ||
|
||
import com.github.le_yams.openfga4intellij.psi.OpenFGATypes; | ||
import com.intellij.psi.tree.TokenSet; | ||
|
||
public interface OpenFGATokenSets { | ||
|
||
TokenSet KEYWORDS = TokenSet.create( | ||
OpenFGATypes.MODEL, | ||
OpenFGATypes.SCHEMA, | ||
OpenFGATypes.TYPE, | ||
OpenFGATypes.RELATIONS, | ||
OpenFGATypes.DEFINE, | ||
OpenFGATypes.OR, | ||
OpenFGATypes.FROM | ||
); | ||
|
||
TokenSet RELATION_NAME = TokenSet.create(OpenFGATypes.RELATION_NAME); | ||
TokenSet TYPE_IDENTIFIER = TokenSet.create(OpenFGATypes.TYPE_IDENTIFIER); | ||
TokenSet SINGLE_LINE_COMMENT = TokenSet.create(OpenFGATypes.COMMENT); | ||
// TokenSet DUMMY_WHITE_SPACE = TokenSet.create(OpenFGATypes.DUMMY_WHITE_SPACE); | ||
} |
4 changes: 2 additions & 2 deletions
4
...penfga4intellij/psi/OpenFGATokenType.java → ...ga4intellij/parsing/OpenFGATokenType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.