Skip to content

Commit

Permalink
fix(devin-lang): update parser and lexer tokens and rules for improve…
Browse files Browse the repository at this point in the history
…d grammar and tokenization. #101
  • Loading branch information
phodal committed Mar 11, 2024
1 parent b7e6106 commit eda58cd
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 16 deletions.
2 changes: 1 addition & 1 deletion exts/devin-lang/src/grammar/DevInLexer.flex
Expand Up @@ -27,7 +27,7 @@ import com.intellij.psi.TokenType;

IDENTIFIER=[a-zA-Z0-9]([_\-a-zA-Z0-9]*)
REF_BLOCK=("@" {IDENTIFIER} )
TEXT_SEGMENT=.*
TEXT_SEGMENT=[^$/@]+
NEWLINE=\n|\r\n

%{
Expand Down
7 changes: 6 additions & 1 deletion exts/devin-lang/src/grammar/DevInParser.bnf
Expand Up @@ -13,6 +13,11 @@
elementTypeHolderClass="cc.unitmesh.language.psi.DevInTypes"
elementTypeClass="cc.unitmesh.language.psi.DevInElementType"
tokenTypeClass="cc.unitmesh.language.lexer.DevInTokenType"

tokens=[
]
}

DevInFile ::= (REF_BLOCK | TEXT_SEGMENT | NEWLINE)*
DevInFile ::= (REF_BLOCK | TEXT_SEGMENT | CODE_FENCE | NEWLINE)*

//used ::= (AGENT | COMMAND | VARIABLE) IDENTIFIER
4 changes: 3 additions & 1 deletion exts/devin-lang/src/test/testData/parser/BasicTest.txt
@@ -1,2 +1,4 @@
FILE
PsiElement(DevInTokenType.TEXT_SEGMENT)('你好 @hello-world sm')
PsiElement(DevInTokenType.TEXT_SEGMENT)('你好 ')
PsiElement(DevInTokenType.REF_BLOCK)('@hello-world')
PsiElement(DevInTokenType.TEXT_SEGMENT)(' sm')
14 changes: 1 addition & 13 deletions exts/devin-lang/src/test/testData/parser/JavaHelloWorld.txt
@@ -1,14 +1,2 @@
FILE
PsiElement(DevInTokenType.TEXT_SEGMENT)('```java')
PsiElement(DevInTokenType.NEWLINE)('\n')
PsiElement(DevInTokenType.TEXT_SEGMENT)('public class Main {')
PsiElement(DevInTokenType.NEWLINE)('\n')
PsiElement(DevInTokenType.TEXT_SEGMENT)(' public static void main(String[] args) {')
PsiElement(DevInTokenType.NEWLINE)('\n')
PsiElement(DevInTokenType.TEXT_SEGMENT)(' System.out.println("Hello, world!");')
PsiElement(DevInTokenType.NEWLINE)('\n')
PsiElement(DevInTokenType.TEXT_SEGMENT)(' }')
PsiElement(DevInTokenType.NEWLINE)('\n')
PsiElement(DevInTokenType.TEXT_SEGMENT)('}')
PsiElement(DevInTokenType.NEWLINE)('\n')
PsiElement(DevInTokenType.TEXT_SEGMENT)('```')
PsiElement(DevInTokenType.TEXT_SEGMENT)('```java\npublic class Main {\n public static void main(String[] args) {\n System.out.println("Hello, world!");\n }\n}\n```')

0 comments on commit eda58cd

Please sign in to comment.