-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ narc (#7) ] Finish lexer, initial parsing
- Loading branch information
Showing
16 changed files
with
172 additions
and
33 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
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,61 @@ | ||
package org.ice1000.tt.psi.narc; | ||
|
||
import com.intellij.lexer.FlexLexer; | ||
import com.intellij.psi.tree.IElementType; | ||
import static org.ice1000.tt.psi.narc.NarcTokenType.*; | ||
import static org.ice1000.tt.psi.narc.NarcTypes.*; | ||
|
||
import static com.intellij.psi.TokenType.BAD_CHARACTER; | ||
import static com.intellij.psi.TokenType.WHITE_SPACE; | ||
|
||
%% | ||
|
||
%{ | ||
public NarcLexer() { this((java.io.Reader)null); } | ||
|
||
private int commentStart = 0; | ||
private int commentDepth = 0; | ||
%} | ||
|
||
%public | ||
%class NarcLexer | ||
%implements FlexLexer | ||
%function advance | ||
%type IElementType | ||
%unicode | ||
%eof{ return; | ||
%eof} | ||
|
||
WHITE_SPACE=[\ \t\f\r\n]+ | ||
UNIVERSE = Type | ||
IDENTIFIER=[a-zA-Z][a-zA-Z0-9\-'\\/]* | ||
COMMENTS = \/\/[^\n\r]* | ||
|
||
%% | ||
|
||
"->" { return ARROW; } | ||
= { return EQ; } | ||
_ { return META; } | ||
; { return SEMI; } | ||
: { return COLON; } | ||
\. { return DOT; } | ||
\( { return LPAREN; } | ||
\) { return RPAREN; } | ||
\{ { return LBRACE; } | ||
\} { return RBRACE; } | ||
\$ { return DOLLAR; } | ||
\|_ { return LINACCESS; } | ||
_\| { return RINACCESS; } | ||
|
||
data { return KW_DATA; } | ||
clause { return KW_CLAUSE; } | ||
codata { return KW_CODATA; } | ||
definition { return KW_DEFINITION; } | ||
projection { return KW_PROJECTION; } | ||
constructor { return KW_CONSTRUCTOR; } | ||
{UNIVERSE} { return KW_TYPE; } | ||
{COMMENTS} { return LINE_COMMENT; } | ||
{IDENTIFIER} { return IDENTIFIER; } | ||
{WHITE_SPACE} { return WHITE_SPACE; } | ||
|
||
[^] { return BAD_CHARACTER; } |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
0.7.3<br/> | ||
0.8.0<br/> | ||
<ul> | ||
<li>Parse and syntax highlight Narc files</li> | ||
</ul> | ||
0.7.2<br/> | ||
<ul> | ||
|
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
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,16 @@ | ||
package org.ice1000.tt.editing.narc | ||
|
||
import com.intellij.lang.BracePair | ||
import org.ice1000.tt.editing.TTBraceMatcher | ||
import org.ice1000.tt.psi.narc.NarcTypes | ||
|
||
class NarcBraceMatcher : TTBraceMatcher() { | ||
private companion object Pairs { | ||
private val PAIRS = arrayOf( | ||
BracePair(NarcTypes.LBRACE, NarcTypes.RBRACE, false), | ||
BracePair(NarcTypes.LINACCESS, NarcTypes.RINACCESS, false), | ||
BracePair(NarcTypes.LPAREN, NarcTypes.RPAREN, false)) | ||
} | ||
|
||
override fun getPairs() = PAIRS | ||
} |
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,37 @@ | ||
package org.ice1000.tt.editing.narc | ||
|
||
import com.intellij.openapi.editor.colors.TextAttributesKey | ||
import com.intellij.psi.tree.IElementType | ||
import org.ice1000.tt.psi.narc.NarcTokenType | ||
import org.ice1000.tt.psi.narc.NarcTypes | ||
|
||
object NarcHighlighter : NarcGeneratedSyntaxHighlighter() { | ||
@JvmField | ||
val KEYWORDS = listOf( | ||
NarcTypes.KW_CLAUSE, | ||
NarcTypes.KW_DEFINITION, | ||
NarcTypes.KW_CODATA, | ||
NarcTypes.KW_DATA, | ||
NarcTypes.KW_CONSTRUCTOR, | ||
NarcTypes.KW_PROJECTION, | ||
NarcTypes.KW_TYPE | ||
) | ||
@JvmField | ||
val OPERATORS = listOf( | ||
NarcTypes.DOLLAR, | ||
NarcTypes.ARROW, | ||
NarcTypes.DOT | ||
) | ||
|
||
override fun getTokenHighlights(type: IElementType?): Array<TextAttributesKey> = when (type) { | ||
NarcTypes.SEMI -> SEMICOLON_KEY | ||
NarcTypes.IDENTIFIER -> IDENTIFIER_KEY | ||
NarcTokenType.LINE_COMMENT -> LINE_COMMENT_KEY | ||
NarcTypes.LPAREN, NarcTypes.RPAREN -> PAREN_KEY | ||
NarcTypes.LBRACE, NarcTypes.RBRACE -> BRACE_KEY | ||
NarcTypes.LINACCESS, NarcTypes.RINACCESS -> INACCESS_KEY | ||
in OPERATORS -> OPERATOR_KEY | ||
in KEYWORDS -> KEYWORD_KEY | ||
else -> emptyArray() | ||
} | ||
} |
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,19 @@ | ||
package org.ice1000.tt.psi.narc | ||
|
||
import com.intellij.openapi.project.Project | ||
import com.intellij.psi.PsiFileFactory | ||
import com.intellij.psi.tree.IElementType | ||
import com.intellij.psi.tree.TokenSet | ||
import org.ice1000.tt.NarcLanguage | ||
|
||
class NarcTokenType(debugName: String) : IElementType(debugName, NarcLanguage.INSTANCE) { | ||
companion object Builtin { | ||
@JvmField val LINE_COMMENT = NarcTokenType("line comment") | ||
@JvmField val COMMENTS = TokenSet.create(LINE_COMMENT) | ||
@JvmField val IDENTIFIERS = TokenSet.create(NarcTypes.IDENTIFIER) | ||
|
||
fun fromText(text: String, project: Project) = PsiFileFactory.getInstance(project).createFileFromText(NarcLanguage.INSTANCE, text).firstChild | ||
fun createDef(text: String, project: Project) = fromText(text, project) as? NarcDefinition | ||
} | ||
} | ||
|
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