-
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.
idea: implement psi parser and the start of symbol declarations
- Loading branch information
Showing
21 changed files
with
340 additions
and
80 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
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,3 @@ | ||
package gay.pizza.pork.parser | ||
|
||
class ParseError(val error: String) : RuntimeException(error) |
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
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
support/pork-idea/src/main/kotlin/gay/pizza/pork/idea/PorkCommenter.kt
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 gay.pizza.pork.idea | ||
|
||
import com.intellij.lang.Commenter | ||
|
||
class PorkCommenter : Commenter { | ||
override fun getLineCommentPrefix(): String { | ||
return "//" | ||
} | ||
|
||
override fun getBlockCommentPrefix(): String { | ||
return "/*" | ||
} | ||
|
||
override fun getBlockCommentSuffix(): String { | ||
return "*/" | ||
} | ||
|
||
override fun getCommentedBlockCommentPrefix(): String? { | ||
return null | ||
} | ||
|
||
override fun getCommentedBlockCommentSuffix(): String? { | ||
return null | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
support/pork-idea/src/main/kotlin/gay/pizza/pork/idea/PorkElementTypes.kt
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,49 @@ | ||
package gay.pizza.pork.idea | ||
|
||
import com.intellij.psi.tree.IElementType | ||
import com.intellij.psi.tree.TokenSet | ||
import gay.pizza.pork.ast.NodeType | ||
import gay.pizza.pork.parser.TokenType | ||
|
||
object PorkElementTypes { | ||
private val tokenTypeToElementType = mutableMapOf<TokenType, IElementType>() | ||
private val elementTypeToTokenType = mutableMapOf<IElementType, TokenType>() | ||
|
||
private val nodeTypeToElementType = mutableMapOf<NodeType, IElementType>() | ||
private val elementTypeToNodeType = mutableMapOf<IElementType, NodeType>() | ||
|
||
init { | ||
for (tokenType in TokenType.entries) { | ||
val elementType = IElementType(tokenType.name, PorkLanguage) | ||
tokenTypeToElementType[tokenType] = elementType | ||
elementTypeToTokenType[elementType] = tokenType | ||
} | ||
|
||
for (nodeType in NodeType.entries) { | ||
val elementType = IElementType(nodeType.name, PorkLanguage) | ||
nodeTypeToElementType[nodeType] = elementType | ||
elementTypeToNodeType[elementType] = nodeType | ||
} | ||
} | ||
|
||
val CommentSet = TokenSet.create( | ||
elementTypeFor(TokenType.BlockComment), | ||
elementTypeFor(TokenType.LineComment) | ||
) | ||
|
||
val StringSet = TokenSet.create( | ||
elementTypeFor(TokenType.StringLiteral) | ||
) | ||
|
||
fun tokenTypeFor(elementType: IElementType): TokenType? = | ||
elementTypeToTokenType[elementType] | ||
|
||
fun elementTypeFor(tokenType: TokenType): IElementType = | ||
tokenTypeToElementType[tokenType]!! | ||
|
||
fun nodeTypeFor(elementType: IElementType): NodeType? = | ||
elementTypeToNodeType[elementType] | ||
|
||
fun elementTypeFor(nodeType: NodeType): IElementType = | ||
nodeTypeToElementType[nodeType]!! | ||
} |
13 changes: 13 additions & 0 deletions
13
support/pork-idea/src/main/kotlin/gay/pizza/pork/idea/PorkFile.kt
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,13 @@ | ||
package gay.pizza.pork.idea | ||
|
||
import com.intellij.extapi.psi.PsiFileBase | ||
import com.intellij.openapi.fileTypes.FileType | ||
import com.intellij.psi.FileViewProvider | ||
|
||
class PorkFile(viewProvider: FileViewProvider) : PsiFileBase(viewProvider, PorkLanguage) { | ||
override fun getFileType(): FileType { | ||
return PorkFileType | ||
} | ||
|
||
override fun toString(): String = "Pork File" | ||
} |
11 changes: 11 additions & 0 deletions
11
support/pork-idea/src/main/kotlin/gay/pizza/pork/idea/PorkFunctionSymbol.kt
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,11 @@ | ||
package gay.pizza.pork.idea | ||
|
||
import com.intellij.model.Pointer | ||
import com.intellij.model.Symbol | ||
|
||
@Suppress("UnstableApiUsage") | ||
data class PorkFunctionSymbol(val id: String) : Symbol { | ||
override fun createPointer(): Pointer<out Symbol> { | ||
return Pointer { this } | ||
} | ||
} |
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
6 changes: 6 additions & 0 deletions
6
support/pork-idea/src/main/kotlin/gay/pizza/pork/idea/PorkNodeKey.kt
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,6 @@ | ||
package gay.pizza.pork.idea | ||
|
||
import com.intellij.openapi.util.Key | ||
import gay.pizza.pork.ast.Node | ||
|
||
object PorkNodeKey : Key<Node>("PorkAstNode") |
21 changes: 21 additions & 0 deletions
21
support/pork-idea/src/main/kotlin/gay/pizza/pork/idea/PorkParser.kt
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,21 @@ | ||
package gay.pizza.pork.idea | ||
|
||
import com.intellij.lang.ASTNode | ||
import com.intellij.lang.PsiBuilder | ||
import com.intellij.lang.PsiParser | ||
import com.intellij.psi.tree.IElementType | ||
import gay.pizza.pork.parser.Parser | ||
|
||
class PorkParser : PsiParser { | ||
override fun parse(root: IElementType, builder: PsiBuilder): ASTNode { | ||
val psiBuilderMarkAttribution = PsiBuilderMarkAttribution(builder) | ||
val source = PsiBuilderTokenSource(builder) | ||
val parser = Parser(source, psiBuilderMarkAttribution) | ||
try { | ||
parser.within { parser.readCompilationUnit() } | ||
} catch (_: ExitParser) {} | ||
return builder.treeBuilt | ||
} | ||
|
||
class ExitParser(val error: String) : RuntimeException("Exit Parser: $error") | ||
} |
45 changes: 45 additions & 0 deletions
45
support/pork-idea/src/main/kotlin/gay/pizza/pork/idea/PorkParserDefinition.kt
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,45 @@ | ||
package gay.pizza.pork.idea | ||
|
||
import com.intellij.extapi.psi.ASTWrapperPsiElement | ||
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 | ||
|
||
class PorkParserDefinition : ParserDefinition { | ||
val fileElementType = IFileElementType(PorkLanguage) | ||
|
||
override fun createLexer(project: Project?): Lexer { | ||
return PorkLexer() | ||
} | ||
|
||
override fun createParser(project: Project?): PsiParser { | ||
return PorkParser() | ||
} | ||
|
||
override fun getFileNodeType(): IFileElementType { | ||
return fileElementType | ||
} | ||
|
||
override fun getCommentTokens(): TokenSet { | ||
return PorkElementTypes.CommentSet | ||
} | ||
|
||
override fun getStringLiteralElements(): TokenSet { | ||
return PorkElementTypes.StringSet | ||
} | ||
|
||
override fun createElement(node: ASTNode): PsiElement { | ||
return ASTWrapperPsiElement(node) | ||
} | ||
|
||
override fun createFile(viewProvider: FileViewProvider): PsiFile { | ||
return PorkFile(viewProvider) | ||
} | ||
} |
Oops, something went wrong.