Skip to content

Commit a967865

Browse files
authored
feat: highlight skip and awaiting slot keywords (#89)
Add the JSX-slot control keywords introduced in jaclang to the syntax highlighter: - skip (KW_SKIP) — slot early-exit, jaseci#6083 - awaiting (KW_AWAITING) — try-clause, jaseci#6063 Both join the keyword.control.flow.jac block. Adds examples/slot_keywords.jac fixture and token-scope tests covering skip;, the trailing for, try, and awaiting.
1 parent 9b966cc commit a967865

3 files changed

Lines changed: 69 additions & 1 deletion

File tree

examples/slot_keywords.jac

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""JSX-slot keywords: `skip;` (KW_SKIP) and `try {} awaiting {}` (KW_AWAITING)."""
2+
3+
obj UserCard {
4+
has name: str;
5+
}
6+
7+
def:pub Skeleton -> JsxElement {
8+
return <p>Loading…</p>;
9+
}
10+
11+
def:pub CardView(user: UserCard) -> JsxElement {
12+
return <h2>{user.name}</h2>;
13+
}
14+
15+
cl {
16+
def:pub TasksPanel(tasks: list, loading: bool) -> JsxElement {
17+
return
18+
<div>
19+
{if loading {
20+
<p>Loading...</p>
21+
skip;
22+
}if len(tasks) == 0 {
23+
<p>Empty</p>
24+
skip;
25+
}for t in tasks {
26+
<TaskItem task={t}/>
27+
}}
28+
</div>;
29+
}
30+
31+
def:pub UserPanel(user: UserCard) -> JsxElement {
32+
return
33+
<section>
34+
{try {
35+
<CardView user={user}/>
36+
} awaiting {
37+
<Skeleton/>
38+
}}
39+
</section>;
40+
}
41+
}

src/__tests__/inspectTokenScopes.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const accessModContent = fs.readFileSync(path.join(EXAMPLES_DIR, 'access_modi
4141
const lambdaFstringContent = fs.readFileSync(path.join(EXAMPLES_DIR, 'lambda_fstring.jac'), 'utf-8');
4242
const overrideFnContent = fs.readFileSync(path.join(EXAMPLES_DIR, 'override_fn.jac'), 'utf-8');
4343
const propAccessorsContent = fs.readFileSync(path.join(EXAMPLES_DIR, 'property_accessors.jac'), 'utf-8');
44+
const slotKeywordsContent = fs.readFileSync(path.join(EXAMPLES_DIR, 'slot_keywords.jac'), 'utf-8');
4445

4546
/**
4647
* Helper to assert a token has expected text and contains expected scopes
@@ -1116,3 +1117,29 @@ describe('property_accessors.jac', () => {
11161117
expectToken(result, 29, 9, 16, 'deleter', ['source.jac', 'meta.function.accessor.jac', 'storage.type.function.jac']);
11171118
});
11181119
});
1120+
1121+
// ---------------------------------------------------------------------------
1122+
// slot_keywords.jac — `skip;` (KW_SKIP) and `try {} awaiting {}` (KW_AWAITING)
1123+
// ---------------------------------------------------------------------------
1124+
describe('slot_keywords.jac', () => {
1125+
let result: TokenizeResult;
1126+
const flow = ['source.jac', 'keyword.control.flow.jac'];
1127+
1128+
beforeAll(async () => {
1129+
result = await tokenizeContent(slotKeywordsContent, GRAMMAR_PATH, WASM_PATH);
1130+
});
1131+
1132+
test('skip keyword is control flow (lines 21, 24)', () => {
1133+
expectToken(result, 21, 21, 25, 'skip', flow);
1134+
expectToken(result, 24, 21, 25, 'skip', flow);
1135+
});
1136+
1137+
test('for keyword in slot after skip (line 25)', () => {
1138+
expectToken(result, 25, 18, 21, 'for', flow);
1139+
});
1140+
1141+
test('try / awaiting clause (lines 34, 36)', () => {
1142+
expectToken(result, 34, 18, 21, 'try', flow);
1143+
expectToken(result, 36, 19, 27, 'awaiting', flow);
1144+
});
1145+
});

syntaxes/jac.tmLanguage.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,7 @@
995995
},
996996
{
997997
"name": "keyword.control.flow.jac",
998-
"match": "(?x)\n \\b(?<!\\.)(\n async | await | continue | entry | exit | del | assert | break | finally | for\n | from | elif | else | if | except | pass | raise\n | return | report | try | while | with | to | by | spawn | ignore | visit | disengage | lambda\n )\\b\n"
998+
"match": "(?x)\n \\b(?<!\\.)(\n async | await | awaiting | continue | entry | exit | del | assert | break | finally | for\n | from | elif | else | if | except | pass | raise\n | return | report | try | while | with | to | by | spawn | ignore | visit | disengage | skip | lambda\n )\\b\n"
999999
},
10001000
{
10011001
"name": "storage.modifier.declaration.jac",

0 commit comments

Comments
 (0)