Add arithmetic expressions

This commit is contained in:
2026-06-17 23:00:14 +09:00
parent dc28cddbff
commit 3f7dd7c692
18 changed files with 6336 additions and 2757 deletions
+1
View File
@@ -50,6 +50,7 @@ export const nav = [
{ title: 'Import', slug: 'language/expression/import' },
{ title: 'Composition', slug: 'language/expression/composition' },
{ title: 'Default', slug: 'language/expression/default' },
{ title: 'Arithmetic', slug: 'language/expression/arithmetic' },
{ title: 'String Interpolation', slug: 'language/expression/string-interpolation' },
],
},
+10 -3
View File
@@ -28,12 +28,13 @@ export function highlightCode(code, language = '') {
export function highlightDecodal(source) {
let html = '';
let index = 0;
let canEndExpression = false;
while (index < source.length) {
const char = source[index];
const next = source[index + 1];
if (char === '/' && next === '/') {
if (char === '#') {
const end = readUntilLineEnd(source, index);
html += token('comment', source.slice(index, end));
index = end;
@@ -44,13 +45,15 @@ export function highlightDecodal(source) {
const end = readString(source, index);
html += token('string', source.slice(index, end));
index = end;
canEndExpression = true;
continue;
}
if (char === '/' && next && next !== '/') {
if (char === '/' && next && next !== '/' && !canEndExpression) {
const end = readRegex(source, index);
html += token('regex', source.slice(index, end));
index = end;
canEndExpression = true;
continue;
}
@@ -58,6 +61,7 @@ export function highlightDecodal(source) {
const end = readNumber(source, index);
html += token('number', source.slice(index, end));
index = end;
canEndExpression = true;
continue;
}
@@ -68,6 +72,7 @@ export function highlightDecodal(source) {
else if (DECODAL_TYPES.has(ident)) html += token('type', ident);
else if (DECODAL_LITERALS.has(ident)) html += token('literal', ident);
else html += escapeHtml(ident);
canEndExpression = true;
index = end;
continue;
}
@@ -75,6 +80,7 @@ export function highlightDecodal(source) {
if (isOperatorStart(char)) {
const end = readOperator(source, index);
html += token('operator', source.slice(index, end));
canEndExpression = /[})\]]/.test(char);
index = end;
continue;
}
@@ -184,11 +190,12 @@ function readIdentifier(source, start) {
}
function isOperatorStart(char) {
return /[&=<>!|:;,.{}()[\]]/.test(char ?? '');
return '&=<>!|:;,.{}()[]+-*/'.includes(char ?? '');
}
function readOperator(source, start) {
let index = start + 1;
if (source[start] === '/' && source[index] === '/') return index + 1;
if ((source[start] === '<' || source[start] === '>' || source[start] === '=' || source[start] === '!') && source[index] === '=') {
index += 1;
}
+1 -1
View File
@@ -9,7 +9,7 @@ const starterFiles = {
in
schema.Service & {
name = "api";
port = 9443;
port = 9000 + 443;
}
`,
'schemas/service.dcdl': `Service = {
Binary file not shown.