Skip to content

Commit 276c9bd

Browse files
committed
Add group of String, Operator and Separator
Fixed String indent
1 parent 4aafa0e commit 276c9bd

5 files changed

Lines changed: 53 additions & 40 deletions

File tree

dev/print-lezer-tree.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ enum Color {
150150
}
151151

152152
function colorize(value: any, color: number): string {
153-
// return "\u001b[" + color + "m" + String(value) + "\u001b[39m"
153+
// return "\u001b[" + color + 'm' + String(value) + "\u001b[39m"
154154
return String(value)
155155
}
156156

@@ -193,13 +193,13 @@ export function printTree(
193193
const hasRange = node.from !== node.to
194194
state.output +=
195195
(node.type.isError || !validator.state.valid ? colorize(node.type.name, Color.Red) : node.type.name) +
196-
" " +
196+
' ' +
197197
(hasRange
198-
? "[" +
198+
? '[' +
199199
colorize(locAt(text, start + node.from), Color.Yellow) +
200200
".." +
201201
colorize(locAt(text, start + node.to), Color.Yellow) +
202-
"]"
202+
']'
203203
: colorize(locAt(text, start + node.from), Color.Yellow))
204204
if (hasRange && node.isLeaf) {
205205
state.output += ": " + colorize(JSON.stringify(inp.read(node.from, node.to)), Color.Green)
@@ -215,7 +215,7 @@ export function printTree(
215215

216216
function locAt(text: Text, pos: number): string {
217217
const line = text.lineAt(pos)
218-
return line.number + ":" + (pos - line.from)
218+
return line.number + ':' + (pos - line.from)
219219
}
220220

221221
export function logTree(

src/csharp.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,33 +46,32 @@ export const csharpLanguage = LRLanguage.define({
4646
parser: parser.configure({
4747
props: [
4848
indentNodeProp.add({
49-
BracesDelim: continuedIndent({ except: /^\s*[\}]/ }),
50-
BracketsDelim: continuedIndent({ except: /^\s*[\]]/ }),
51-
ParensDelim: continuedIndent({ except: /^\s*[\)]/ }),
52-
ChevronsDelim: continuedIndent({ except: /^\s*[\>]/ }),
49+
BracesDelim: continuedIndent({ except: /^\s*}/ }),
50+
BracketsDelim: continuedIndent({ except: /^\s*]/ }),
51+
ParensDelim: continuedIndent({ except: /^\s*\)/ }),
52+
ChevronsDelim: continuedIndent({ except: /^\s*>/ }),
5353
IfStmt: continuedIndent({ except: /^\s*({|else\b)/ }),
5454
TryStmt: continuedIndent({ except: /^\s*({|catch\b|finally\b)/ }),
55-
LabeledStmt: flatIndent,
55+
"String LabeledStmt": flatIndent,
5656
"Expression Declaration Statement": continuedIndent({ except: /^\s*{/ })
5757
}),
5858
foldNodeProp.add({
5959
Delim: foldInside,
60-
BlockComment(tree) { return { from: tree.from + 2, to: tree.to - 2 } },
60+
BlockComment(node) { return { from: node.from + 2, to: node.to - 2 } },
6161
}),
6262
styleTags({
6363
"Keyword ContextualKeyword SimpleType": tags.keyword,
6464
BooleanLiteral: tags.bool,
6565
NullLiteral: tags.null,
6666
IntegerLiteral: tags.integer,
6767
RealLiteral: tags.float,
68-
'StringLiteral UTF8StringLiteral RawStringLiteral CharacterLiteral InterpolatedRegularString InterpolatedVerbatimString InterpolatedRawString $" @$" $@"':
69-
tags.string,
68+
String: tags.string,
7069
LineComment: tags.lineComment,
7170
BlockComment: tags.blockComment,
7271
DocComment: tags.docComment,
7372

74-
". .. : Astrisk Slash % + - ++ -- Not ~ << & | ^ && || < > <= >= == NotEq = += -= *= SlashEq %= &= |= ^= ? ?? ??= =>":
75-
tags.operator,
73+
Operator: tags.operator,
74+
Separator: tags.separator,
7675

7776
PP_Directive: tags.keyword,
7877

@@ -96,7 +95,7 @@ export const csharpLanguage = LRLanguage.define({
9695
return null;
9796
}
9897
const content = input.read(node.from, node.to);
99-
if (content.indexOf("<") === -1) {
98+
if (content.indexOf('<') === -1) {
10099
return null;
101100
}
102101
const overlay = docCommentXmlOverlay(node.from, content);
@@ -113,8 +112,8 @@ export const csharpLanguage = LRLanguage.define({
113112
}),
114113
languageData: {
115114
commentTokens: { line: "//", block: { open: "/*", close: "*/" } },
116-
closeBrackets: { brackets: ["(", "[", "{", '"', "'", '"""'] },
117-
indentOnInput: /^\s*([\)\]\}]$|(else|else\s+if|catch|finally)\b)/
115+
closeBrackets: { brackets: ['(', '[', '{', '"', '\'', '"""'] },
116+
indentOnInput: /^\s*([)\]}]$|(else|else\s+if|catch|finally)\b)/
118117
}
119118
});
120119

src/keymap.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ export const continueDocComment = keymap.of([{
2424

2525
const nodeInner = syntaxTree(state).resolveInner(pos);
2626
let inTagNode = nodeInner.name === "Element"
27-
&& doc.sliceString(pos - 1, pos) === ">"
28-
&& doc.sliceString(pos, pos + 1) === "<";
27+
&& doc.sliceString(pos - 1, pos) === '>'
28+
&& doc.sliceString(pos, pos + 1) === '<';
2929
if (inTagNode) {
3030
insert += prefix;
3131
}

src/syntax.grammar

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@
175175

176176
// String literals
177177

178-
StringLiteral {
178+
StringLiteral[group=String] {
179179
regularString
180180
| verbatimString
181181
}
@@ -205,13 +205,18 @@
205205

206206
// Operators and punctuators
207207

208-
'{' '}' '[' ']' '(' ')' '.' ',' ':' ';'
209-
'+' '-' '*'[@name=Astrisk] '/'[@name=Slash] '%' '&' '|' '^' '!'[@name=Not] '~'
210-
'=' '<' '>' '?' '??' '::' '++' '--' '&&' '||'
211-
'->' '==' '!='[@name=NotEq] '<=' '>=' '+=' '-=' '*=' '/='[@name=SlashEq] '%='
212-
'&=' '|=' '^=' '<<' '<<=' '=>' '??='
213-
'$"' '@$"' '$@"' '$"""'
214-
'..'
208+
'{' '}' '[' ']' '(' ')' ',' ';'
209+
'.'[group=Separator] '::'[group=Separator]
210+
'..'[group=Operator] ':'[group=Operator]
211+
'++'[group=Operator] '--'[group=Operator] '+'[group=Operator] '-'[group=Operator]
212+
'*'[@name=Astrisk, group=Operator] '/'[@name=Slash, group=Operator] '%'[group=Operator]
213+
'!'[@name=Not, group=Operator] '~'[group=Operator]
214+
'<<='[group=Operator] '<<'[group=Operator] '<='[group=Operator] '>='[group=Operator] '<'[group=Operator] '>'[group=Operator]
215+
'=='[group=Operator] '!='[@name=NotEq, group=Operator] '&&'[group=Operator] '||'[group=Operator] '&'[group=Operator] '|'[group=Operator] '^'[group=Operator]
216+
'??='[group=Operator] '??'[group=Operator] '?'[group=Operator]
217+
'='[group=Operator] '+='[group=Operator] '-='[group=Operator] '*='[group=Operator] '/='[@name=SlashEq, group=Operator] '%='[group=Operator] '&='[group=Operator] '|='[group=Operator] '^='[group=Operator]
218+
'->'[group=Operator] '=>'[group=Operator]
219+
'$"'[group=String] '@$"'[group=String] '$@"'[group=String]
215220

216221

217222
// General
@@ -397,17 +402,17 @@ typeArgumentList { !typeArgs chevrons<csep1<type>> }
397402

398403
// General (Literals)
399404

400-
UTF8StringLiteral {
405+
UTF8StringLiteral[group=String] {
401406
StringLiteral utf8StringLiteralEnd
402407
}
403408

404-
RawStringLiteral {
409+
RawStringLiteral[group=String] {
405410
regularRawString
406411
}
407412

408413
regularRawString { rawStringStart regularRawStringContent* rawStringEnd }
409414

410-
UTF8RawStringLiteral {
415+
UTF8RawStringLiteral[group=String] {
411416
RawStringLiteral utf8StringLiteralEnd
412417
}
413418

@@ -495,21 +500,21 @@ InterpolatedStringExpr[group=Expression] {
495500
| InterpolatedRawString
496501
}
497502

498-
InterpolatedRegularString { '$"' interpStringParts* interpStringEnd }
503+
InterpolatedRegularString[group=String] { '$"' interpStringParts* interpStringEnd }
499504

500505
interpStringParts {
501506
interpStringContent
502507
| interpStringBrace expr (',' literal)? (':' identifier+)? '}'
503508
}
504509

505-
InterpolatedVerbatimString { ('$@"' | '@$"') interpVStringParts* interpVStringEnd }
510+
InterpolatedVerbatimString[group=String] { ('$@"' | '@$"') interpVStringParts* interpVStringEnd }
506511

507512
interpVStringParts {
508513
interpVStringContent
509514
| interpVStringBrace expr (',' literal)? (':' identifier+)? '}'
510515
}
511516

512-
InterpolatedRawString { interpRawStringStart interpRawStringParts* interpRawStringEnd }
517+
InterpolatedRawString[group=String] { interpRawStringStart interpRawStringParts* interpRawStringEnd }
513518

514519
interpRawStringParts {
515520
interpRawStringContent
@@ -727,7 +732,16 @@ namedEntityTarget {
727732

728733
// Pointer member access
729734

730-
pointerMemberAccess { PrimaryExpr !memberAccess '->' simpleName }
735+
pointerMemberAccess {
736+
PrimaryExpr !memberAccess '->' VarName
737+
| PrimaryExpr !memberAccess pointerMemberCall
738+
| SimpleType !memberAccess '->' VarName
739+
| SimpleType !memberAccess pointerMemberCall
740+
| QualifiedAliasMember !memberAccess '->' VarName
741+
| QualifiedAliasMember !memberAccess pointerMemberCall
742+
}
743+
744+
pointerMemberCall { '->' MethodName typeArgumentList? !memberCall arguments }
731745

732746

733747
// Await expression

src/xml.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ import { xml } from "@codemirror/lang-xml";
22
import { atoms, keywords, types } from "./keywords";
33

44
const elements = [
5-
{ name: "a", attributes: ["href"] },
6-
{ name: "b" },
5+
{ name: 'a', attributes: ["href"] },
6+
{ name: 'b' },
77
{ name: "br" },
8-
{ name: "c" },
8+
{ name: 'c' },
99
{ name: "code" },
1010
{ name: "completionlist", top: true, attributes: ["cref"] },
1111
{ name: "description" },
1212
{ name: "example", top: true, children: ["code"] },
1313
{ name: "exception", top: true, attributes: ["cref"] },
14-
{ name: "i" },
14+
{ name: 'i' },
1515
{ name: "include", top: true, attributes: ["file", "path"] },
1616
{ name: "inheritdoc", top: true, attributes: ["cref", "path"] },
1717
{ name: "item", children: ["term", "description"] },
@@ -30,7 +30,7 @@ const elements = [
3030
{ name: "tt" },
3131
{ name: "typeparam", top: true, attributes: ["name"] },
3232
{ name: "typeparamref", attributes: ["name"] },
33-
{ name: "u" },
33+
{ name: 'u' },
3434
{ name: "value", top: true }
3535
] as const;
3636

0 commit comments

Comments
 (0)