Skip to content

Commit 099ed69

Browse files
author
Enrico Granata
committed
Keep hacking at the aria.js grammar until it works
1 parent d0e2581 commit 099ed69

File tree

3 files changed

+34
-17
lines changed

3 files changed

+34
-17
lines changed

_includes/head-custom.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66

77
hljs.registerLanguage("aria", aria);
88

9-
// optional: built-in languages you use elsewhere
10-
// import javascript from "https://esm.sh/highlight.js@11/es/languages/javascript";
11-
// hljs.registerLanguage("javascript", javascript);
9+
import bash from "https://esm.sh/highlight.js@11/es/languages/bash";
10+
hljs.registerLanguage("bash", bash);
1211

1312
document.addEventListener("DOMContentLoaded", () => {
1413
document.querySelectorAll("pre code").forEach(el => hljs.highlightElement(el));

assets/js/aria.js

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default function (hljs) {
3939
'and', 'case', 'isa', 'instance', 'reverse', 'try', 'catch', 'break', 'continue', 'for'
4040
].join(' '),
4141
literal: 'true false',
42-
built_in: 'println assert',
42+
built_in: 'alloc arity exit getenv hasattr listattrs print println readattr readln setenv sleep system writeattr',
4343
type: 'Int Float String Bool Result Maybe Any'
4444
};
4545

@@ -69,16 +69,17 @@ export default function (hljs) {
6969
const OP_SYM = /\+\-|u\-|\+|\-|\*|\/|%|<<|>>|==|<=|>=|<|>|\&|\||\^|\(\)|\[\]=|\[\]/;
7070
const OP_DEF = {
7171
className: 'function',
72+
keywords: KEYWORDS,
7273
begin: new RegExp(`\\b(?:reverse\\s+)?operator\\s+(${OP_SYM.source})\\s*\\(`),
7374
beginScope: { 1: 'title.function' },
7475
end: /\)/,
7576
excludeEnd: true,
76-
keywords: KEYWORDS,
7777
contains: [LINE_COMMENT]
7878
};
7979

8080
const TYPE_LIKE_DEF = {
8181
className: 'class',
82+
keywords: KEYWORDS,
8283
variants: [
8384
{ begin: new RegExp(`\\bstruct\\s+(${IDENT.source})\\b`) },
8485
{ begin: new RegExp(`\\benum\\s+(${IDENT.source})\\b`) },
@@ -88,14 +89,15 @@ export default function (hljs) {
8889
};
8990

9091
const EXTENSION_DEF = {
91-
begin: new RegExp(`\\bextension\\s+(${IDENT.source})\\b`),
92-
beginScope: { 1: 'type' }
92+
match: new RegExp(`\\b(extension)\\s+(${IDENT.source})\\b`),
93+
scope: { 1: 'keyword', 2: 'type' },
94+
relevance: 0
9395
};
9496

9597
const ENUM_CASE_DECL = {
96-
className: 'constant',
97-
begin: new RegExp(`\\bcase\\s+(${IDENT.source})\\b`),
98-
beginScope: { 1: 'constant' }
98+
match: new RegExp(`\\b(case)\\s+(${IDENT.source})\\b`),
99+
scope: { 1: 'keyword', 2: 'constant' },
100+
relevance: 0
99101
};
100102

101103
const ENUM_CASE_USE = {
@@ -138,21 +140,37 @@ export default function (hljs) {
138140
// Continuation lines: ::: ...
139141
const REPL_CONT = { className: 'meta', begin: /^:::\s?/m, relevance: 0 };
140142

143+
const BLOCK = {
144+
begin: /\{/,
145+
end: /\}/,
146+
keywords: KEYWORDS,
147+
contains: [
148+
'self',
149+
LINE_COMMENT,
150+
DQ_STRING, SQ_STRING,
151+
DEC_FLOAT, HEX_INT, OCT_INT, BIN_INT, DEC_INT,
152+
LAMBDA_HEAD, TRY_PROTOCOL, ASSIGN_OP, INDEXING,
153+
FUNC_DEF, METHOD_DEF, OP_DEF,
154+
TYPE_LIKE_DEF, EXTENSION_DEF,
155+
ENUM_CASE_DECL, ENUM_CASE_USE,
156+
IMPORTS
157+
],
158+
relevance: 0
159+
};
160+
141161
return {
142162
name: 'Aria',
143163
aliases: ['aria'],
144164
keywords: KEYWORDS,
145165
contains: [
146-
SHEBANG,
147-
REPL_PROMPT, REPL_CONT,
148-
LINE_COMMENT,
149-
DQ_STRING, SQ_STRING,
166+
SHEBANG, REPL_PROMPT, REPL_CONT,
167+
LINE_COMMENT, DQ_STRING, SQ_STRING,
150168
DEC_FLOAT, HEX_INT, OCT_INT, BIN_INT, DEC_INT,
151169
FUNC_DEF, METHOD_DEF, OP_DEF,
152170
TYPE_LIKE_DEF, EXTENSION_DEF,
153171
ENUM_CASE_DECL, ENUM_CASE_USE,
154-
LAMBDA_HEAD, TRY_PROTOCOL, ASSIGN_OP,
155-
INDEXING,
172+
LAMBDA_HEAD, TRY_PROTOCOL, ASSIGN_OP, INDEXING,
173+
BLOCK,
156174
IMPORTS
157175
]
158176
};

manual.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,7 @@ Square bracket access is defined by means of `operator [](index)` and `operator
10061006

10071007
Defining `operator ()` allows objects to be called as if they are functions, e.g.
10081008

1009-
```assert
1009+
```aria
10101010
struct CallMe {
10111011
type func new() { return alloc(This); }
10121012
operator ()(x,y,z) {

0 commit comments

Comments
 (0)