Skip to content

Commit ca35bca

Browse files
committed
feat(devin-lang): update code_content support #101
1 parent d5fa471 commit ca35bca

File tree

3 files changed

+31
-16
lines changed

3 files changed

+31
-16
lines changed

exts/devin-lang/src/grammar/DevInLexer.flex

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,16 @@ import com.intellij.psi.TokenType;
2626
%s VARIABLE_BLOCK
2727
%s COMMAND_BLOCK
2828
%s CODE_BLOCK
29+
%s LANG_ID
2930

3031
IDENTIFIER=[a-zA-Z0-9][_\-a-zA-Z0-9]*
32+
3133
VARIABLE_ID=[a-zA-Z0-9][_\-a-zA-Z0-9]*
3234
AGENT_ID=[a-zA-Z0-9][_\-a-zA-Z0-9]*
3335
COMMAND_ID=[a-zA-Z0-9][_\-a-zA-Z0-9]*
34-
REF_BLOCK=([$/@] {IDENTIFIER} )
36+
LANGUAGE_ID=[a-zA-Z0-9][_\-a-zA-Z0-9]*
37+
3538
TEXT_SEGMENT=[^$/@\n]+
36-
//CODE_CONTENT="```" {IDENTIFIER} ([^$/@\n]+ | \n)* "```"
3739
CODE_CONTENT=([^$/@\n]+ )
3840
NEWLINE= \n | \r | \r\n
3941

@@ -66,7 +68,7 @@ NEWLINE= \n | \r | \r\n
6668
"@" { yybegin(AGENT_BLOCK); return AGENT_START; }
6769
"/" { yybegin(COMMAND_BLOCK); return COMMAND_START; }
6870
"$" { yybegin(VARIABLE_BLOCK); return VARIABLE_START; }
69-
"```" {IDENTIFIER} { yybegin(CODE_BLOCK); isCodeStart = true; return CODE_BLOCK_START; }
71+
"```" {IDENTIFIER} { yybegin(LANG_ID); isCodeStart = true; yypushback(yylength()); }
7072

7173
{TEXT_SEGMENT} { if(isCodeStart) { return codeContent(); } else { return TEXT_SEGMENT; } }
7274
{NEWLINE} { return NEWLINE; }
@@ -90,6 +92,13 @@ NEWLINE= \n | \r | \r\n
9092

9193
<CODE_BLOCK> {
9294
{CODE_CONTENT} { return codeContent(); }
95+
{NEWLINE} { return NEWLINE; }
9396
<<EOF>> { isCodeStart = false; return codeContent(); }
9497
[^] { }
9598
}
99+
100+
<LANG_ID> {
101+
"```" { return CODE_BLOCK_START; }
102+
{IDENTIFIER} { yybegin(YYINITIAL); return LANGUAGE_ID; }
103+
[^] { yypushback(1); yybegin(CODE_BLOCK); }
104+
}

exts/devin-lang/src/grammar/DevInParser.bnf

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
CODE_BLOCK = "CODE_BLOCK"
2424
CODE_CONTENT = "CODE_CONTENT"
2525
IDENTIFIER = "IDENTIFIER"
26+
LANGUAGE_ID = "LANGUAGE_ID"
2627
]
2728
}
2829

@@ -35,5 +36,7 @@ used ::= (
3536
)
3637

3738
code ::= (
38-
CODE_BLOCK_START (NEWLINE | CODE_CONTENT)* CODE_BLOCK_END
39-
)
39+
CODE_BLOCK_START LANGUAGE_ID code_contents CODE_BLOCK_END
40+
)
41+
42+
code_contents ::= (NEWLINE | CODE_CONTENT)*

exts/devin-lang/src/test/testData/parser/JavaHelloWorld.txt

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@ DevInFile
33
PsiElement(DevInTokenType.NEWLINE)('\n')
44
PsiElement(DevInTokenType.NEWLINE)('\n')
55
DevInCodeImpl(CODE)
6-
PsiElement(DevInTokenType.CODE_BLOCK_START)('```java')
7-
PsiElement(DevInTokenType.CODE_CONTENT)('\npublic class Main {')
8-
PsiElement(DevInTokenType.NEWLINE)('\n')
9-
PsiElement(DevInTokenType.CODE_CONTENT)(' public static void main(String[] args) {')
10-
PsiElement(DevInTokenType.NEWLINE)('\n')
11-
PsiElement(DevInTokenType.CODE_CONTENT)(' System.out.println("Hello, world!");')
12-
PsiElement(DevInTokenType.NEWLINE)('\n')
13-
PsiElement(DevInTokenType.CODE_CONTENT)(' }')
14-
PsiElement(DevInTokenType.NEWLINE)('\n')
15-
PsiElement(DevInTokenType.CODE_CONTENT)('}')
16-
PsiElement(DevInTokenType.NEWLINE)('\n')
6+
PsiElement(DevInTokenType.CODE_BLOCK_START)('```')
7+
PsiElement(DevInTokenType.LANGUAGE_ID)('java')
8+
DevInCodeContentsImpl(CODE_CONTENTS)
9+
PsiElement(DevInTokenType.NEWLINE)('\n')
10+
PsiElement(DevInTokenType.CODE_CONTENT)('public class Main {')
11+
PsiElement(DevInTokenType.NEWLINE)('\n')
12+
PsiElement(DevInTokenType.CODE_CONTENT)(' public static void main(String[] args) {')
13+
PsiElement(DevInTokenType.NEWLINE)('\n')
14+
PsiElement(DevInTokenType.CODE_CONTENT)(' System.out.println("Hello, world!");')
15+
PsiElement(DevInTokenType.NEWLINE)('\n')
16+
PsiElement(DevInTokenType.CODE_CONTENT)(' }')
17+
PsiElement(DevInTokenType.NEWLINE)('\n')
18+
PsiElement(DevInTokenType.CODE_CONTENT)('}')
19+
PsiElement(DevInTokenType.NEWLINE)('\n')
1720
PsiElement(DevInTokenType.CODE_BLOCK_END)('```')
1821
PsiElement(DevInTokenType.NEWLINE)('\n')
1922
PsiElement(DevInTokenType.NEWLINE)('\n')

0 commit comments

Comments
 (0)