Repository navigation
Expand file tree
/
Copy pathlanguage.ts
More file actions
90 lines (86 loc) · 3.33 KB
/
Copy pathlanguage.ts
File metadata and controls
90 lines (86 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import {
continuedIndent,
flatIndent,
foldInside,
foldNodeProp,
indentNodeProp,
LanguageSupport,
LRLanguage
} from "@codemirror/language"
import {styleTags, Tag, tags as t} from "@codemirror/highlight"
// Make sure that the code is generated (npm run build-grammar)
import {parser} from "./parser"
export const customTags = {
call: Tag.define(),
annotationAttribute: Tag.define()
}
export const javaLanguage = LRLanguage.define({
parser: parser.configure({
props: [
indentNodeProp.add({
IfStatement: continuedIndent({except: /^\s*({|else\b)/}),
TryStatement: continuedIndent({except: /^\s*({|catch|finally)\b/}),
LabeledStatement: flatIndent,
SwitchBlock: context => {
let after = context.textAfter, closed = /^\s*\}/.test(after),
isCase = /^\s*(case|default)\b/.test(after)
return context.baseIndent + (closed ? 0 : isCase ? 1 : 2) * context.unit
},
BlockComment: () => -1,
Statement: continuedIndent({except: /^{/})
}),
foldNodeProp.add({
["Block SwitchBlock ClassBody ElementValueArrayInitializer ModuleBody EnumBody " +
"ConstructorBody InterfaceBody ArrayInitializer"]: foldInside,
BlockComment(tree) {
return {from: tree.from + 2, to: tree.to - 2}
}
}),
styleTags({
instanceof: t.operatorKeyword,
"new var assert": t.keyword,
"class record interface extends implements module package import enum": t.definitionKeyword,
"switch const goto yield while for if else case default do break continue return try catch finally throw": t.controlKeyword,
["requires exports opens uses provides public private protected static transitive abstract final " +
"strictfp synchronized native transient volatile throws"]: t.modifier,
"this super null BooleanLiteral": t.constant(t.variableName),
IntegerLiteral: t.integer,
FloatLiteral: t.float,
'StringLiteral StringBlockLiteral': t.string,
CharacterLiteral: t.character,
LineComment: t.lineComment,
BlockComment: t.blockComment,
BooleanLiteral: t.bool,
'ElementValuePair/Identifier': customTags.annotationAttribute,
'void PrimitiveType': t.standard(t.typeName),
'TypeName': t.typeName,
Identifier: t.variableName,
'Annotation Annotation/Identifier MarkerAnnotation MarkerAnnotation/Identifier': t.annotation,
"FormalParameter/Definition": t.function(t.definition(t.variableName)),
"MethodName/Identifier": t.function(t.variableName),
'MethodInvocation/MethodName/Identifier': t.function(customTags.call),
Definition: t.definition(t.variableName),
ArithOp: t.arithmeticOperator,
LogicOp: t.logicOperator,
BitOp: t.bitwiseOperator,
CompareOp: t.compareOperator,
AssignOp: t.definitionOperator,
UpdateOp: t.updateOperator,
Asterisk: t.punctuation,
Label: t.labelName,
"( )": t.paren,
"[ ]": t.squareBracket,
"{ }": t.brace,
".": t.derefOperator,
", ;": t.separator
})
]
}),
languageData: {
commentTokens: {line: "//", block: {open: "/*", close: "*/"}},
indentOnInput: /^\s*(?:case |default:|\{|\})$/
}
})
export function java() {
return new LanguageSupport(javaLanguage)
}