8000 Add highlighting information · geddski/python@5882b6b · GitHub
[go: up one dir, main page]

Skip to content

Commit 5882b6b

Browse files
committed
Add highlighting information
FEATURE: The parser now includes syntax highlighting information in its node types.
1 parent 7c0e21f commit 5882b6b

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"@rollup/plugin-node-resolve": "^9.0.0"
2020
},
2121
"dependencies": {
22-
"@lezer/lr": "^0.15.0"
22+
"@lezer/lr": "^0.15.0",
23+
"@lezer/highlight": "^0.15.0"
2324
},
2425
"repository": {
2526
"type" : "git",

src/highlight.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import {styleTags, tags as t} from "@lezer/highlight"
2+
3+
export const pythonHighlighting = styleTags({
4+
"async \"*\" \"**\" FormatConversion FormatSpec": t.modifier,
5+
"for while if elif else try except finally return raise break continue with pass assert await yield": t.controlKeyword,
6+
"in not and or is del": t.operatorKeyword,
7+
"from def class global nonlocal lambda": t.definitionKeyword,
8+
import: t.moduleKeyword,
9+
"with as print": t.keyword,
10+
Boolean: t.bool,
11+
None: t.null,
12+
VariableName: t.variableName,
13+
"CallExpression/VariableName": t.function(t.variableName),
14+
"FunctionDefinition/VariableName": t.function(t.definition(t.variableName)),
15+
"ClassDefinition/VariableName": t.definition(t.className),
16+
PropertyName: t.propertyName,
17+
"CallExpression/MemberExpression/PropertyName": t.function(t.propertyName),
18+
Comment: t.lineComment,
19+
Number: t.number,
20+
String: t.string,
21+
FormatString: t.special(t.string),
22+
UpdateOp: t.updateOperator,
23+
ArithOp: t.arithmeticOperator,
24+
BitOp: t.bitwiseOperator,
25+
CompareOp: t.compareOperator,
26+
AssignOp: t.definitionOperator,
27+
Ellipsis: t.punctuation,
28+
At: t.meta,
29+
"( )": t.paren,
30+
"[ ]": t.squareBracket,
31+
"{ }": t.brace,
32+
".": t.derefOperator,
33+
", ;": t.separator
34+
})

src/python.grammar

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,3 +309,7 @@ FormatReplacement { "{" (YieldExpression | commaSep<"*"? test>) FormatConversion
309309
}
310310

311311
@external tokens newlines from "./tokens" { newline, newlineBracketed, newlineEmpty, eof }
312+
313+
@external propSource pythonHighlighting from "./highlight"
314+
315+
@detectDelim

0 commit comments

Comments
 (0)
0