Skip to content

Commit addb7dd

Browse files
committed
[IDEA] added missing @CLOBBERBUILTINS annotation + corrected regex for numbers
1 parent 444747b commit addb7dd

9 files changed

Lines changed: 73 additions & 16 deletions

File tree

IDEA/build.gradle.kts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,10 @@ intellijPlatform {
7676
}
7777

7878
project(":") {
79-
val generateLexer = // targetClass.set("KerboScriptLexer")
79+
val generateLexer =
8080
tasks.register<GenerateLexerTask>("generateMyLexer", fun GenerateLexerTask.() {
8181
sourceFile.set(file("src/main/grammar/KerboScript.flex"))
8282
targetOutputDir.set(file("src/gen/ksp/kos/ideaplugin/parser"))
83-
// targetClass.set("KerboScriptLexer")
8483
purgeOldFiles.set(true)
8584
})
8685

IDEA/src/main/grammar/KerboScript.bnf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
tokenTypeClass="ksp.kos.ideaplugin.psi.KerboScriptTokenType"
2626

2727
extends(".*_stmt|directive|instruction_block")=instruction
28-
extends("lazyglobal_directive")=directive
28+
extends("lazyglobal_directive|clobberbuiltins_directive")=directive
2929
extends("function_trailer|array_trailer")=suffixterm_trailer
3030
extends("[a-z]*_expr|factor|suffix|suffixterm|atom|.*number")=expr
3131

@@ -109,13 +109,14 @@
109109
ALL = 'regexp:(?i)all'
110110
IDENTIFIER = 'regexp:[a-zA-Z_][a-zA-Z0-9_]*'
111111
FILEIDENT = 'regexp:[a-zA-Z_][a-zA-Z0-9_]*(\.[a-zA-Z0-9_][a-zA-Z0-9_]*)*'
112-
INTEGER = 'regexp:[0-9]+'
113-
DOUBLE = 'regexp:[0-9]*\.[0-9]+'
112+
INTEGER = 'regexp:[0-9][0-9_]*'
113+
DOUBLE = 'regexp:([0-9]+(_[0-9]*)*)?\.[0-9]+(_[0-9]*)*'
114114
STRING = 'regexp:@?"(""|[^"])*"'
115115
EOI = '.'
116116
//Compiler Directives
117117
ATSIGN = '@'
118118
LAZYGLOBAL = 'regexp:(?i)lazyglobal'
119+
CLOBBERBUILTINS = 'regexp:(?i)clobberbuiltins'
119120
//Special
120121
//EOF = '$'
121122
//[Skip]
@@ -127,7 +128,7 @@
127128

128129
// Rules
129130
// ===================================================
130-
Start ::= (instruction)*
131+
Start ::= (directive|instruction)*
131132
instruction_block ::= CURLYOPEN instruction* CURLYCLOSE
132133
instruction ::= !(CURLYCLOSE | <<eof>>) instruction_inner {
133134
pin = 1
@@ -174,7 +175,6 @@ private instruction_inner ::= empty_stmt |
174175
unset_stmt |
175176
instruction_block |
176177
identifier_led_stmt | // any statement that starts with an identifier.
177-
directive // allow directives anywhere for now, let the compiler decide if it's in the wrong place, not the parser.
178178

179179
// ------------ directives --------------------
180180
lazyglobal_directive ::= LAZYGLOBAL onoff_trailer EOI

IDEA/src/main/grammar/KerboScript.flex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ ARRAYINDEX = #
9898
ALL = all
9999
IDENTIFIER = [a-zA-Z_][a-zA-Z0-9_]*
100100
FILEIDENT = [a-zA-Z_][a-zA-Z0-9_]*(\.[a-zA-Z0-9_][a-zA-Z0-9_]*)*
101-
INTEGER = [0-9]+
102-
DOUBLE = [0-9]*\.[0-9]+
101+
INTEGER = [0-9][0-9_]*
102+
DOUBLE = ([0-9]+(_[0-9]*)*)?\.[0-9]+(_[0-9]*)*
103103
STRING = @?\"(\"\"|[^\"])*\"
104104
EOI = \.
105105
//Compiler Directives

IDEA/src/main/java/ksp/kos/ideaplugin/Magic.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ object Magic {
5858
KerboScriptTypes.UNSET,
5959
KerboScriptTypes.CHOOSE,
6060
KerboScriptTypes.ATSIGN,
61-
KerboScriptTypes.LAZYGLOBAL
61+
KerboScriptTypes.LAZYGLOBAL,
62+
KerboScriptTypes.CLOBBERBUILTINS
6263
)
6364
}

IDEA/src/main/java/ksp/kos/ideaplugin/dataflow/ContextBuilder.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ public void visit(ExpressionVisitor visitor) {
3131
}
3232

3333
public String getText() {
34-
String text = "";
34+
StringBuilder text = new StringBuilder();
3535
for (Flow<?> flow : getList()) {
36-
if (!text.isEmpty()) text += "\n";
37-
text += flow.getText();
36+
if (!text.isEmpty()) {
37+
text.append("\n");
38+
}
39+
text.append(flow.getText());
3840
}
39-
return text;
41+
return text.toString();
4042
}
4143

4244
public void differentiate(LocalContext context, ContextBuilder contextBuilder) {

IDEA/src/main/java/ksp/kos/ideaplugin/highlighting/KerboScriptSyntaxHighlighter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ public class KerboScriptSyntaxHighlighter extends SyntaxHighlighterBase {
8181
KerboScriptTypes.UNSET,
8282
KerboScriptTypes.CHOOSE,
8383
KerboScriptTypes.ATSIGN,
84-
KerboScriptTypes.LAZYGLOBAL
84+
KerboScriptTypes.LAZYGLOBAL,
85+
KerboScriptTypes.CLOBBERBUILTINS
8586
)
8687
);
8788

@@ -93,7 +94,7 @@ public Lexer getHighlightingLexer() {
9394

9495
@NotNull
9596
@Override
96-
public TextAttributesKey[] getTokenHighlights(IElementType tokenType) {
97+
public TextAttributesKey @NotNull [] getTokenHighlights(IElementType tokenType) {
9798
// TODO - Ideally syntax highlight based off of parser, not lexer, to handle keywords used as variables.
9899
if (tokenType.equals(KerboScriptTypes.IDENTIFIER)) {
99100
return createKeys(IDENTIFIER);

IDEA/src/test/kotlin/ksp/kos/ideaplugin/parsing/KerboScriptParsingTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ class KerboScriptParsingTest : ParsingTestCase("", "ks", KerboScriptParserDefini
1010

1111
fun testBasic() = doTest(true)
1212
fun testErrorRecovery() = doTest(true)
13+
fun testAnnotations() = doTest(true)
1314
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@LAZYGLOBAL OFF.
2+
@CLOBBERBUILTINS ON.
3+
4+
local decimalsWith_ is 10_000.00.
5+
local integerWith_ is 10_000.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
FILE(0,102)
2+
KerboScriptDirectiveImpl(DIRECTIVE)(0,16)
3+
PsiElement(@)('@')(0,1)
4+
KerboScriptLazyglobalDirectiveImpl(LAZYGLOBAL_DIRECTIVE)(1,16)
5+
PsiElement(LAZYGLOBAL)('LAZYGLOBAL')(1,11)
6+
PsiWhiteSpace(' ')(11,12)
7+
KerboScriptOnoffTrailerImpl(ONOFF_TRAILER)(12,15)
8+
PsiElement(OFF)('OFF')(12,15)
9+
PsiElement(.)('.')(15,16)
10+
PsiWhiteSpace('\n')(16,17)
11+
KerboScriptDirectiveImpl(DIRECTIVE)(17,37)
12+
PsiElement(@)('@')(17,18)
13+
KerboScriptClobberbuiltinsDirectiveImpl(CLOBBERBUILTINS_DIRECTIVE)(18,37)
14+
PsiElement(CLOBBERBUILTINS)('CLOBBERBUILTINS')(18,33)
15+
PsiWhiteSpace(' ')(33,34)
16+
KerboScriptOnoffTrailerImpl(ONOFF_TRAILER)(34,36)
17+
PsiElement(ON)('ON')(34,36)
18+
PsiElement(.)('.')(36,37)
19+
PsiWhiteSpace('\n\n')(37,39)
20+
KerboScriptDeclareStmtImpl(DECLARE_STMT)(39,72)
21+
PsiElement(LOCAL)('local')(39,44)
22+
PsiWhiteSpace(' ')(44,45)
23+
KerboScriptDeclareIdentifierClauseImpl(DECLARE_IDENTIFIER_CLAUSE)(45,72)
24+
KerboScriptIdentImpl(IDENT)(45,58)
25+
PsiElement(IDENTIFIER)('decimalsWith_')(45,58)
26+
PsiWhiteSpace(' ')(58,59)
27+
PsiElement(IS)('is')(59,61)
28+
PsiWhiteSpace(' ')(61,62)
29+
KerboScriptSuffixtermImpl(SUFFIXTERM)(62,71)
30+
KerboScriptAtomImpl(ATOM)(62,71)
31+
KerboScriptNumberImpl(NUMBER)(62,71)
32+
PsiElement(DOUBLE)('10_000.00')(62,71)
33+
PsiElement(.)('.')(71,72)
34+
PsiWhiteSpace('\n')(72,73)
35+
KerboScriptDeclareStmtImpl(DECLARE_STMT)(73,102)
36+
PsiElement(LOCAL)('local')(73,78)
37+
PsiWhiteSpace(' ')(78,79)
38+
KerboScriptDeclareIdentifierClauseImpl(DECLARE_IDENTIFIER_CLAUSE)(79,102)
39+
KerboScriptIdentImpl(IDENT)(79,91)
40+
PsiElement(IDENTIFIER)('integerWith_')(79,91)
41+
PsiWhiteSpace(' ')(91,92)
42+
PsiElement(IS)('is')(92,94)
43+
PsiWhiteSpace(' ')(94,95)
44+
KerboScriptSuffixtermImpl(SUFFIXTERM)(95,101)
45+
KerboScriptAtomImpl(ATOM)(95,101)
46+
KerboScriptNumberImpl(NUMBER)(95,101)
47+
PsiElement(INTEGER)('10_000')(95,101)
48+
PsiElement(.)('.')(101,102)

0 commit comments

Comments
 (0)