Skip to content

Commit 896b71d

Browse files
committed
Add lexer processing
1 parent a307897 commit 896b71d

File tree

4 files changed

+32
-24
lines changed

4 files changed

+32
-24
lines changed

.gitignore

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
1-
otspot.xml
2-
hs_err_pid*
3-
*.class
4-
*.log
5-
*.ctxt
61
*.jar
7-
*.war
8-
*.ear
9-
*.zip
10-
*.tar.gz
11-
*.rar
12-
cmake-build-debug/
13-
cmake-build-release/
14-
out/
152
.gradle
163
build
17-
.build-cache
18-
config.properties
194
.idea
20-
!lib/dev-kt-v1.3-SNAPSHOT.jar
215
!gradle/wrapper/gradle-wrapper.jar

build.gradle.kts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import java.io.*
22

3-
val kotlinVersion = "1.2.31"
3+
val kotlinVersion = "1.2.40"
44

55
group = "com.intellij.devkt.json"
6-
version = "v1.0-SNAPSHOT"
6+
version = "v1.0"
77

88
plugins { java }
99

@@ -22,10 +22,13 @@ java.sourceSets {
2222
repositories {
2323
mavenCentral()
2424
jcenter()
25+
maven("https://jitpack.io")
2526
}
2627

2728
dependencies {
2829
compileOnly(kotlin("compiler-embeddable", kotlinVersion))
29-
compileOnly(files(*File("lib").listFiles()))
30+
val version = "5a71725385"
31+
compileOnly(group = "com.github.ice1000.dev-kt", name = "common", version = version)
32+
runtime(group = "com.github.ice1000.dev-kt", name = "swing", version = version)
3033
}
3134

lib/dev-kt-v1.3-SNAPSHOT.jar

-55.5 KB
Binary file not shown.

src/com/intellij/devkt/json/Json.java

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
import org.ice1000.devkt.openapi.ExtendedDevKtLanguage;
55
import org.jetbrains.annotations.NotNull;
66
import org.jetbrains.annotations.Nullable;
7+
import org.jetbrains.kotlin.com.intellij.lexer.LayeredLexer;
8+
import org.jetbrains.kotlin.com.intellij.lexer.Lexer;
9+
import org.jetbrains.kotlin.com.intellij.lexer.StringLiteralLexer;
10+
import org.jetbrains.kotlin.com.intellij.openapi.project.Project;
711
import org.jetbrains.kotlin.com.intellij.psi.StringEscapesTokenTypes;
812
import org.jetbrains.kotlin.com.intellij.psi.tree.IElementType;
913

@@ -17,8 +21,7 @@ public String getLineCommentStart() {
1721
}
1822

1923
@Override
20-
public @NotNull
21-
Icon getIcon() {
24+
public @NotNull Icon getIcon() {
2225
return JsonFileType.INSTANCE.getIcon();
2326
}
2427

@@ -27,19 +30,37 @@ public Json() {
2730
}
2831

2932
@Override
30-
public boolean satisfies(String fileName) {
33+
public boolean satisfies(@NotNull String fileName) {
3134
return fileName.endsWith(".json") || fileName.equals(".pinpoint");
3235
}
3336

37+
public @NotNull Lexer createLexer(@NotNull Project project) {
38+
LayeredLexer layeredLexer = new LayeredLexer(new JsonLexer());
39+
layeredLexer.registerSelfStoppingLayer(new StringLiteralLexer('\"',
40+
JsonElementTypes.DOUBLE_QUOTED_STRING,
41+
false,
42+
"/",
43+
false,
44+
false), new IElementType[]{JsonElementTypes.DOUBLE_QUOTED_STRING}, IElementType.EMPTY_ARRAY);
45+
layeredLexer.registerSelfStoppingLayer(new StringLiteralLexer('\'',
46+
JsonElementTypes.SINGLE_QUOTED_STRING,
47+
false,
48+
"/",
49+
false,
50+
false), new IElementType[]{JsonElementTypes.SINGLE_QUOTED_STRING}, IElementType.EMPTY_ARRAY);
51+
return layeredLexer;
52+
}
53+
3454
@Override
35-
public @Nullable
36-
T attributesOf(IElementType iElementType, ColorScheme<? extends T> colorScheme) {
55+
public @Nullable T attributesOf(@NotNull IElementType iElementType, @NotNull ColorScheme<? extends T> colorScheme) {
3756
if (iElementType == JsonElementTypes.LINE_COMMENT) return colorScheme.getLineComments();
3857
else if (iElementType == JsonElementTypes.BLOCK_COMMENT) return colorScheme.getBlockComments();
3958
else if (iElementType == JsonElementTypes.NUMBER) return colorScheme.getNumbers();
4059
else if (iElementType == JsonElementTypes.SINGLE_QUOTED_STRING) return colorScheme.getString();
4160
else if (iElementType == JsonElementTypes.DOUBLE_QUOTED_STRING) return colorScheme.getProperty();
4261
else if (iElementType == StringEscapesTokenTypes.VALID_STRING_ESCAPE_TOKEN) return colorScheme.getStringEscape();
62+
else if (iElementType == StringEscapesTokenTypes.INVALID_UNICODE_ESCAPE_TOKEN) return colorScheme.getUnknown();
63+
else if (iElementType == StringEscapesTokenTypes.INVALID_CHARACTER_ESCAPE_TOKEN) return colorScheme.getUnknown();
4364
else if (iElementType == JsonElementTypes.IDENTIFIER) return colorScheme.getIdentifiers();
4465
else if (iElementType == JsonElementTypes.COLON) return colorScheme.getColon();
4566
else if (iElementType == JsonElementTypes.COMMA) return colorScheme.getComma();

0 commit comments

Comments
 (0)