Skip to content

Commit 8fc17ec

Browse files
committed
fix(devin-lang): add support for variable and command identifiers in grammar and lexer #101
The commit introduces new token types for variable ($VAR) and command (COMMAND) identifiers, as well as an agent identifier (AGENT). This change also includes a new state in the lexer to handle content parsing more efficiently.
1 parent 5031a54 commit 8fc17ec

File tree

4 files changed

+48
-10
lines changed

4 files changed

+48
-10
lines changed

docs/scenes/legacy-migration.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Building upon the experience accumulated in our "[System Refactoring and Migrati
2020

2121
Support language: Java.
2222

23+
Screenshot EXAMPLE:
24+
2325
![AutoDev Living Documentation](https://unitmesh.cc/auto-dev/gen-test-data.png)
2426

2527
Simply right-click on the Java Controller code, select "Generate Test Data (APIs)," and API test data will be generated.
@@ -51,6 +53,8 @@ Select the corresponding code, right-click, and choose `Generate Documentation`
5153

5254
## Use [Custom Living Documentation](/custom/living-documentation) for generating dynamic documentation.
5355

56+
Screenshot EXAMPLE:
57+
5458
![AutoDev Living Documentation](https://unitmesh.cc/auto-dev/autodev-living-doc.png)
5559

5660
Configuration: `Settings` -> `Tools` -> `AutoDev` -> `Customize Engine prompt`, add custom formats for living documentation. Example:
@@ -87,6 +91,6 @@ AutoDev has been supporting basic PL/SQL migration since version 1.5.5.
8791
- Generate Test Cases
8892
- Generate Java Code
8993

90-
Screenshot:
94+
Screenshot EXAMPLE:
9195

9296
![SQL Migration](https://unitmesh.cc/auto-dev/autodev-sql-migration.png)

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

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ import com.intellij.psi.TokenType;
2222
%eof{ return;
2323
%eof}
2424

25+
%s YYUSED
2526
%s AGENT_BLOCK
2627
%s VARIABLE_BLOCK
2728
%s COMMAND_BLOCK
29+
2830
%s CODE_BLOCK
2931
%s LANG_ID
3032

@@ -65,21 +67,51 @@ NEWLINE= \n | \r | \r\n
6567

6668
return CODE_CONTENT;
6769
}
70+
71+
private IElementType content() {
72+
String text = yytext().toString().trim();
73+
if (isCodeStart == true && text.equals("```")) {
74+
return codeContent();
75+
}
76+
77+
if (isCodeStart == false && text.startsWith("```")) {
78+
isCodeStart = true;
79+
yypushback(yylength() - 3);
80+
yybegin(LANG_ID);
81+
82+
return CODE_BLOCK_START;
83+
}
84+
85+
if (isCodeStart) {
86+
return CODE_CONTENT;
87+
} else {
88+
yypushback(yylength());
89+
yybegin(YYUSED);
90+
91+
return TEXT_SEGMENT;
92+
}
93+
}
6894
%}
6995

7096
%%
7197
<YYINITIAL> {
72-
"@" { if(!isCodeStart) { yybegin(AGENT_BLOCK); return AGENT_START; } else { yypushback(1); yybegin(CODE_BLOCK); }}
73-
"/" { if(!isCodeStart) { yybegin(COMMAND_BLOCK); return COMMAND_START; } else { yypushback(1); yybegin(CODE_BLOCK); }}
74-
"$" { if(!isCodeStart) { yybegin(VARIABLE_BLOCK); return VARIABLE_START; } else { yypushback(1); yybegin(CODE_BLOCK); }}
75-
76-
"```" {IDENTIFIER}? { yybegin(LANG_ID); if (isCodeStart == true) { isCodeStart = false; return CODE_BLOCK_END; } else { isCodeStart = true; }; yypushback(yylength()); }
77-
78-
{TEXT_SEGMENT} { if(isCodeStart) { return codeContent(); } else { return TEXT_SEGMENT; } }
98+
{CODE_CONTENT} { return content(); }
7999
{NEWLINE} { return NEWLINE; }
80100
[^] { return TokenType.BAD_CHARACTER; }
81101
}
82102

103+
<YYUSED> {
104+
"@" { yybegin(AGENT_BLOCK); return AGENT_START; }
105+
"/" { yybegin(COMMAND_BLOCK); return COMMAND_START; }
106+
"$" { yybegin(VARIABLE_BLOCK); return VARIABLE_START; }
107+
108+
"```" {IDENTIFIER}? { yybegin(LANG_ID); if (isCodeStart == true) { isCodeStart = false; return CODE_BLOCK_END; } else { isCodeStart = true; }; yypushback(yylength()); }
109+
110+
{NEWLINE} { return NEWLINE; }
111+
{TEXT_SEGMENT} { return TEXT_SEGMENT; }
112+
[^] { }
113+
}
114+
83115
<AGENT_BLOCK> {
84116
{IDENTIFIER} { yybegin(YYINITIAL); return AGENT_ID; }
85117
[^] { return TokenType.BAD_CHARACTER; }

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
CODE_CONTENT = "CODE_CONTENT"
2525
IDENTIFIER = "IDENTIFIER"
2626
LANGUAGE_ID = "LANGUAGE_ID"
27+
VARIABLE_ID = "VARIABLE_ID"
28+
COMMAND_ID = "COMMAND_ID"
29+
AGENT_ID = "AGENT_ID"
2730
]
2831
}
2932

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ DevInFile
88
PsiElement(DevInTokenType.NEWLINE)('\n')
99
PsiElement(DevInTokenType.CODE_CONTENT)('@Retention(RetentionPolicy.RUNTIME)')
1010
PsiElement(DevInTokenType.NEWLINE)('\n')
11-
PsiElement(DevInTokenType.CODE_CONTENT)('public ')
12-
PsiElement(DevInTokenType.CODE_CONTENT)('@interface ExampleAnnotation {')
11+
PsiElement(DevInTokenType.CODE_CONTENT)('public @interface ExampleAnnotation {')
1312
PsiElement(DevInTokenType.NEWLINE)('\n')
1413
PsiElement(DevInTokenType.CODE_CONTENT)(' String value() default "";')
1514
PsiElement(DevInTokenType.NEWLINE)('\n')

0 commit comments

Comments
 (0)