Skip to content

Commit c60086e

Browse files
committed
refactor: remove system block and adjust related tests
BREAKING CHANGE: remove `#` system API syntax support This commit removes the `#` system API syntax support from the DevIn language, introducing a breaking change. The following changes have been made: 1. **Grammar Changes**: - Removed the `SYSTEM_START` rule from `DevInParser.bnf`. - Commented out the `SYSTEM_BLOCK` state and related rules in `DevInLexer.flex`. - Updated the `TEXT_SEGMENT` regex to exclude `#` from valid characters. 2. **Compiler Changes**: - Removed the `SYSTEM_START` and `NUMBER` token handling from `DevInSyntaxHighlighter.kt`. - Updated the expected output in `DevInCompilerTest.kt` to reflect the removal of the system API syntax. 3. **Documentation Updates**: - Updated `devins-language.md` to reflect the removal of the `#` system API syntax, marking it as deprecated and removed in version 2.0.0. **Impact**: - Any existing code that relies on the `#` system API syntax will no longer work and will need to be refactored. - Developers should update their code to use alternative mechanisms for interacting with third-party systems. **Migration Guide**: - Replace any usage of `#` system API syntax with alternative approaches, such as custom commands or agents. - Update any tests or documentation that reference the `#` system API syntax. This change is part of the effort to simplify the language and remove less commonly used features to improve maintainability and clarity.
1 parent d175671 commit c60086e

File tree

8 files changed

+43
-55
lines changed

8 files changed

+43
-55
lines changed

docs/devins/devins-language.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Based on: [JetBrains' Markdown Util](https://github.com/JetBrains/intellij-commu
2222
- `/` Builtin Command, natural language command with IDE/editor, like read file, write file, etc.
2323
- `@` Agent, natural language custom function / system function name, the handler or command,
2424
- `$` Variable, natural language variable name, like file name, file content, etc.
25-
- `#` Third-party system API for traditional, like `#kanban:afd`, `#issue:233`, `#github:111`, etc.
25+
- ~~`#` Third-party system API for traditional, like `#kanban:afd`, `#issue:233`, `#github:111`, etc.~~ (Removed in 2.0.0)
2626

2727
## Language spec
2828

@@ -33,7 +33,6 @@ used ::= (
3333
AGENT_START AGENT_ID
3434
| COMMAND_START COMMAND_ID (COLON COMMAND_PROP?)?
3535
| VARIABLE_START VARIABLE_ID
36-
| SYSTEM_START SYSTEM_ID
3736
)
3837
3938
code ::= CODE_BLOCK_START LANGUAGE_ID? NEWLINE? code_contents? CODE_BLOCK_END?

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

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import java.util.regex.Pattern;
3131
%s COMMAND_BLOCK
3232
%s COMMAND_VALUE_BLOCK
3333

34-
%s SYSTEM_BLOCK
34+
//%s SYSTEM_BLOCK
3535

3636
%s CODE_BLOCK
3737
%s COMMENT_BLOCK
@@ -47,7 +47,7 @@ COMMAND_ID=[a-zA-Z0-9][_\-a-zA-Z0-9]*
4747
LANGUAGE_ID=[a-zA-Z][_\-a-zA-Z0-9 .]*
4848
SYSTEM_ID=[a-zA-Z][_\-a-zA-Z0-9]*
4949
NUMBER=[0-9]+
50-
TEXT_SEGMENT=[^$/@#\n]+
50+
TEXT_SEGMENT=[^$/@\n]+
5151

5252
// READ LINE FORMAT: L2C2-L0C100 or L1-L1
5353
LINE_INFO=L[0-9]+(C[0-9]+)?(-L[0-9]+(C[0-9]+)?)?
@@ -125,32 +125,32 @@ SHARP=#
125125
}
126126
}
127127

128-
private IElementType command_value() {
129-
String text = yytext().toString().trim();
130-
String [] split = text.split("#");
131-
132-
if (split.length == 1) {
133-
return COMMAND_PROP;
134-
}
135-
136-
// split by # if it is a line info
137-
String last = split[split.length - 1];
138-
Pattern compile = Pattern.compile("L\\d+(C\\d+)?(-L\\d+(C\\d+)?)?");
139-
Matcher matcher = compile.matcher(last);
140-
if (matcher.matches()) {
141-
// before # is command prop, after # is line info
142-
int number = last.length() + "#".length();
143-
if (number > 0) {
144-
yypushback(number);
145-
yybegin(LINE_BLOCK);
146-
return COMMAND_PROP;
147-
} else {
148-
return COMMAND_PROP;
149-
}
150-
}
151-
152-
return COMMAND_PROP;
153-
}
128+
// private IElementType command_value() {
129+
// String text = yytext().toString().trim();
130+
// String [] split = text.split("#");
131+
//
132+
// if (split.length == 1) {
133+
// return TEXT_SEGMENT;
134+
// }
135+
//
136+
// // split by # if it is a line info
137+
// String last = split[split.length - 1];
138+
// Pattern compile = Pattern.compile("L\\d+(C\\d+)?(-L\\d+(C\\d+)?)?");
139+
// Matcher matcher = compile.matcher(last);
140+
// if (matcher.matches()) {
141+
// // before # is command prop, after # is line info
142+
// int number = last.length() + "#".length();
143+
// if (number > 0) {
144+
// yypushback(number);
145+
// yybegin(LINE_BLOCK);
146+
// return COMMAND_PROP;
147+
// } else {
148+
// return COMMAND_PROP;
149+
// }
150+
// }
151+
//
152+
// return TEXT_SEGMENT;
153+
// }
154154
%}
155155

156156
%%
@@ -170,7 +170,7 @@ SHARP=#
170170
"@" { yybegin(AGENT_BLOCK); return AGENT_START; }
171171
"/" { yybegin(COMMAND_BLOCK); return COMMAND_START; }
172172
"$" { yybegin(VARIABLE_BLOCK); return VARIABLE_START; }
173-
"#" { yybegin(SYSTEM_BLOCK); return SYSTEM_START; }
173+
// "#" { yybegin(SYSTEM_BLOCK); return SYSTEM_START; }
174174

175175
"```" {IDENTIFIER}? { yybegin(LANG_ID); if (isCodeStart == true) { isCodeStart = false; return CODE_BLOCK_END; } else { isCodeStart = true; }; yypushback(yylength()); }
176176

@@ -187,7 +187,7 @@ SHARP=#
187187
}
188188

189189
<COMMAND_VALUE_BLOCK> {
190-
{COMMAND_PROP} { return command_value(); }
190+
{COMMAND_PROP} { return COMMAND_PROP; }
191191
" " { yypushback(1); yybegin(YYINITIAL); }
192192
[^] { yypushback(1); yybegin(YYINITIAL); }
193193
}
@@ -208,12 +208,13 @@ SHARP=#
208208
[^] { return TokenType.BAD_CHARACTER; }
209209
}
210210

211-
<SYSTEM_BLOCK> {
212-
{SYSTEM_ID} { return SYSTEM_ID; }
213-
{COLON} { return COLON; }
214-
{NUMBER} { return NUMBER; }
215-
[^] { yybegin(YYINITIAL); yypushback(yylength()); }
216-
}
211+
//<SYSTEM_BLOCK> {
212+
// " " { yypushback(2); return TEXT_SEGMENT; }
213+
// {SYSTEM_ID} { return SYSTEM_ID; }
214+
// {COLON} { return COLON; }
215+
// {NUMBER} { return NUMBER; }
216+
// [^] { yybegin(YYINITIAL); yypushback(yylength()); }
217+
//}
217218

218219
<CODE_BLOCK> {
219220
{CODE_CONTENT} { if(isCodeStart) { return codeContent(); } else { yybegin(YYINITIAL); yypushback(yylength()); } }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ used ::= (
4242
AGENT_START AGENT_ID
4343
| COMMAND_START COMMAND_ID (COLON COMMAND_PROP (SHARP LINE_INFO)?)?
4444
| VARIABLE_START VARIABLE_ID
45-
| SYSTEM_START SYSTEM_ID COLON NUMBER
45+
// | SYSTEM_START SYSTEM_ID COLON NUMBER
4646
)
4747

4848
code ::= CODE_BLOCK_START LANGUAGE_ID? NEWLINE? code_contents? CODE_BLOCK_END?

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/highlight/DevInSyntaxHighlighter.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ class DevInSyntaxHighlighter : SyntaxHighlighter {
4141

4242
ATTRIBUTES[DevInTypes.SYSTEM_START] = DefaultLanguageHighlighterColors.KEYWORD
4343
ATTRIBUTES[DevInTypes.SYSTEM_ID] = DefaultLanguageHighlighterColors.CONSTANT
44-
ATTRIBUTES[DevInTypes.NUMBER] = DefaultLanguageHighlighterColors.NUMBER
4544
}
4645
}
4746

exts/devins-lang/src/test/kotlin/cc/unitmesh/devti/language/compiler/DevInCompilerTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class DevInCompilerTest : LightJavaCodeInsightFixtureTestCase() {
1212
val file = myFixture.configureByText("test.devin", code)
1313

1414
val compile = DevInsCompiler(project, file as DevInFile, myFixture.editor).compile()
15-
assertEquals("Normal String /", compile.output)
15+
assertEquals("Normal String", compile.output)
1616
}
1717

1818
fun testForWriting() {

exts/devins-lang/src/test/testData/parser/AutoCommand.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,4 @@ DevInFile
33
PsiElement(DevInTokenType.COMMAND_START)('/')
44
PsiElement(DevInTokenType.COMMAND_ID)('write')
55
PsiElement(DevInTokenType.COLON)(':')
6-
PsiElement(DevInTokenType.COMMAND_PROP)('Sample.file')
7-
PsiElement(DevInTokenType.SHARP)('#')
8-
PsiElement(DevInTokenType.LINE_INFO)('L1-L12')
6+
PsiElement(DevInTokenType.COMMAND_PROP)('Sample.file#L1-L12')

exts/devins-lang/src/test/testData/parser/AutoRefactor.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,4 @@ DevInFile
3232
PsiElement(DevInTokenType.COMMAND_ID)('refactor')
3333
PsiElement(DevInTokenType.COLON)(':')
3434
PsiElement(DevInTokenType.COMMAND_PROP)('extractMethod')
35-
PsiElement(DevInTokenType.TEXT_SEGMENT)(' cc.unitmesh.devti.language.run.DevInsProgramRunnerImpl.run')
36-
PsiElement(DevInTokenType.SYSTEM_START)('#')
37-
PsiElement(DevInTokenType.SYSTEM_ID)('L20-L30')
38-
PsiErrorElement:DevInTokenType.COLON expected
39-
<empty list>
35+
PsiElement(DevInTokenType.TEXT_SEGMENT)(' cc.unitmesh.devti.language.run.DevInsProgramRunnerImpl.run#L20-L30')

exts/devins-lang/src/test/testData/parser/BasicTest.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,4 @@ DevInFile
3131
PsiElement(DevInTokenType.COMMAND_PROP)('632372da')
3232
PsiElement(DevInTokenType.TEXT_SEGMENT)(' 从版本库中读取内容')
3333
PsiElement(DevInTokenType.NEWLINE)('\n')
34-
DevInUsedImpl(USED)
35-
PsiElement(DevInTokenType.SYSTEM_START)('#')
36-
PsiElement(DevInTokenType.SYSTEM_ID)('system_id')
37-
PsiElement(DevInTokenType.COLON)(':')
38-
PsiElement(DevInTokenType.NUMBER)('51')
39-
PsiElement(DevInTokenType.TEXT_SEGMENT)(' 传递参数到 story_id')
34+
PsiElement(DevInTokenType.TEXT_SEGMENT)('#system_id:51 传递参数到 story_id')

0 commit comments

Comments
 (0)