This commit is contained in:
2026-08-18 14:07:33 +03:00
parent 0fa388abeb
commit f4d089e5e5
21 changed files with 913 additions and 521 deletions
+2 -1
View File
@@ -62,7 +62,8 @@ let result = vm.execute()?; // Returns last expression's value
The dexpr language supports: The dexpr language supports:
- If/else conditionals with `if ... then ... else ... end` - If/else conditionals with `if ... then ... else ... end`
- String methods (e.g., `.upper()`, `.lower()`, `.trim()`, `.trimStart()`, `.trimEnd()`, `.split()`, `.replace()`, `.contains()`, `.startsWith()`, `.endsWith()`, `.length`, `.charAt()`, `.substring()`) - String methods (e.g., `.upper()`, `.lower()`, `.trim()`, `.trimStart()`, `.trimEnd()`, `.split()`, `.replace()`, `.contains()`, `.startsWith()`, `.endsWith()`, `.length`, `.charAt()`, `.substring()`)
- Arithmetic (`+`, `-`, `*`, `/`, `%`, `**`), comparison, and logical operators - Arithmetic (`+`, `-`, `*`, `/`, `%`, `**`), comparison, and logical operators. `==`/`!=` work on all types (structural, different types → `false`); `<`/`<=`/`>`/`>=` work on Number and String (lexicographic)
- `null` literal (`x == null`)
- `in` operator for membership testing (`"finans" in categories`, `5 in numbers`, `"hello" in "hello world"`, `"key" in obj`) - `in` operator for membership testing (`"finans" in categories`, `5 in numbers`, `"hello" in "hello world"`, `"key" in obj`)
- Compound assignments (`+=`, `-=`, `*=`, `/=`, `%=`) - Compound assignments (`+=`, `-=`, `*=`, `/=`, `%=`)
- Built-in `log()` function for output and `rand(min, max)` for random integers - Built-in `log()` function for output and `rand(min, max)` for random integers
Generated
+1 -1
View File
@@ -304,7 +304,7 @@ checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7"
[[package]] [[package]]
name = "dexpr" name = "dexpr"
version = "0.3.0" version = "0.4.0"
dependencies = [ dependencies = [
"bumpalo", "bumpalo",
"criterion", "criterion",
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "dexpr" name = "dexpr"
version = "0.3.0" version = "0.4.0"
edition = "2021" edition = "2021"
description = "Embeddable expression evaluator and bytecode VM" description = "Embeddable expression evaluator and bytecode VM"
license = "MIT" license = "MIT"
+2 -1
View File
@@ -74,7 +74,7 @@ Dil küçük olduğundan (7 keyword, ~20 operatör) iki gramer dosyasını sync
### Keyword Yönetimi ### Keyword Yönetimi
Keyword'ler `@extend` ile tanımlanır — `identifier` token'ından türetilir ama **her zaman** keyword olarak parse edilir. dexpr'de keyword'ler reserved'dır (`if`, `then`, `else`, `end`, `in`, `true`, `false`). Keyword'ler `@extend` ile tanımlanır — `identifier` token'ından türetilir ama **her zaman** keyword olarak parse edilir. dexpr'de keyword'ler reserved'dır (`if`, `then`, `else`, `end`, `in`, `true`, `false`, `null`).
### Error Recovery ### Error Recovery
@@ -95,6 +95,7 @@ Lezer GLR parser kullanır. Bozuk/yarım kod yazılırken:
|-------|-----------|-----------------| |-------|-----------|-----------------|
| `if`, `then`, `else`, `end`, `in`, `elseIf` | `keyword` | `#7c3aed` (mor) | | `if`, `then`, `else`, `end`, `in`, `elseIf` | `keyword` | `#7c3aed` (mor) |
| `true`, `false` | `bool` | `#d97706` (turuncu) | | `true`, `false` | `bool` | `#d97706` (turuncu) |
| `null` | `null` | `#d97706` (turuncu) |
| `"string"`, `'string'` | `string` | `#059669` (yeşil) | | `"string"`, `'string'` | `string` | `#059669` (yeşil) |
| `42`, `3.14` | `number` | `#2563eb` (mavi) | | `42`, `3.14` | `number` | `#2563eb` (mavi) |
| `// comment`, `/* comment */` | `lineComment` / `blockComment` | `#9ca3af` (gri, italic) | | `// comment`, `/* comment */` | `lineComment` / `blockComment` | `#9ca3af` (gri, italic) |
+2 -1
View File
@@ -72,6 +72,7 @@ En düşükten en yükseğe:
| Sayı | `42`, `3.14` | `Expr::Value(Number)` | | Sayı | `42`, `3.14` | `Expr::Value(Number)` |
| String | `"hello"`, `'world'` | `Expr::Value(String)` | | String | `"hello"`, `'world'` | `Expr::Value(String)` |
| Boolean | `true`, `false` | `Expr::Value(Boolean)` | | Boolean | `true`, `false` | `Expr::Value(Boolean)` |
| Null | `null` | `Expr::Value(Null)` |
| Parantezli ifade | `(a + b)` | İç ifade | | Parantezli ifade | `(a + b)` | İç ifade |
| Tekli negatif | `-x` | `Expr::UnaryOp(Neg, x)` | | Tekli negatif | `-x` | `Expr::UnaryOp(Neg, x)` |
| Tekli NOT | `!flag` | `Expr::UnaryOp(Not, flag)` | | Tekli NOT | `!flag` | `Expr::UnaryOp(Not, flag)` |
@@ -84,7 +85,7 @@ En düşükten en yükseğe:
### Ayrılmış Kelimeler ### Ayrılmış Kelimeler
`if`, `then`, `else`, `end`, `true`, `false`, `in` `if`, `then`, `else`, `end`, `true`, `false`, `null`, `in`
### Boşluk ve Yorumlar ### Boşluk ve Yorumlar
+2 -1
View File
@@ -126,7 +126,8 @@ struct VM<'a> {
- **`handle_neg()`** — Sadece Number tipinde tekli negatif - **`handle_neg()`** — Sadece Number tipinde tekli negatif
### Karşılaştırma ### Karşılaştırma
- **`compare_op(f, name)`** — Decimal değerler üzerinde karşılaştırma, Boolean döndürür - **`equality_op(negate)`** — `==` / `!=`. Her tip için çalışır, `Value`'nun `PartialEq`'i ile yapısal eşitlik (list, object dahil derin karşılaştırma). Farklı tipler hata vermez, `false` döner (`"1" == 1``false`, `x == null``x` Null ise `true`)
- **`compare_op(f, name)`** — `<`, `<=`, `>`, `>=`. Number/Number ve String/String (lexicographic byte sırası) destekler; diğer kombinasyonlar `InvalidOperation` hatası
### Boolean ### Boolean
- **`handle_and()`**, **`handle_or()`**, **`handle_not()`** — Boolean register'lar üzerinde mantık operasyonları - **`handle_and()`**, **`handle_or()`**, **`handle_not()`** — Boolean register'lar üzerinde mantık operasyonları
+35 -18
View File
@@ -41,7 +41,7 @@ var import_lr2 = require("@lezer/lr");
var import_lr = require("@lezer/lr"); var import_lr = require("@lezer/lr");
// src/parser.terms.js // src/parser.terms.js
var elseIf = 44; var elseIf = 46;
// src/tokens.ts // src/tokens.ts
var CH_e = 101; var CH_e = 101;
@@ -81,32 +81,33 @@ var elseIfTokenizer = new import_lr.ExternalTokenizer((input) => {
}); });
// src/parser.js // src/parser.js
var spec_identifier = { __proto__: null, if: 11, true: 21, false: 21, in: 43, then: 69, else: 71, end: 73 }; var spec_identifier = { __proto__: null, if: 11, true: 21, false: 21, null: 25, in: 47, then: 73, else: 75, end: 77 };
var parser = import_lr2.LRParser.deserialize({ var parser = import_lr2.LRParser.deserialize({
version: 14, version: 14,
states: "+^Q]QQOOOOQP'#Cb'#CbOOQP'#Ce'#CeOwQQO'#CiO`QQO'#CjO#TQRO'#DTO%bQRO'#D_OOQP'#D_'#D_O%iQRO'#D_OOQP'#D]'#D]OOQP'#DU'#DUQ]QQOOOwQQO'#C`O&eQQO,59TO&lQRO'#D_O(zQRO,59UO`QQO,59XO`QQO,59XO`QQO,59XO`QQO,59XO`QQO,59XO)wQQO,59hO)|QQO'#CzOOQP,59i,59iO`QQO,59mOOQP-E7S-E7SO*TQQO,58zOOQP1G.o1G.oO+oQRO1G.sO+vQRO1G.sO-bQRO1G.sO-iQRO1G.sO.[QRO1G.sOOQP'#Cy'#CyOOQP1G/S1G/SO/[QQO'#D`OOQP,59f,59fO/fQQO,59fO/kQRO1G/XO0bQRO1G.fO0oQQO1G/SOOQP7+$i7+$iOwQQO'#DVO1pQQO,59zOOQP1G/Q1G/QO1xQRO7+$QO2TQRO7+$QOwQQO'#DWOOQP7+$Q7+$QO2bQQO7+$QO2iQQO,59qOOQO-E7T-E7TOOQP-E7U-E7UOOQP<<Gl<<GlO2sQQO<<GlO2zQRO<<GlO3VQQO,59rO2sQQO<<GlO3^QQOAN=WOOQPAN=WAN=WO3^QQOAN=WO3eQRO1G/^OOQPG22rG22rO3rQQOG22rO3yQRO7+$xOOQPLD(^LD(^O)wQQO,59hO5RQQO1G.sO5YQQO1G.sO6[QQO1G.sO6cQQO1G.sO6jQQO1G.sO7QQQO,59UOwQQO,59XOwQQO,59XOwQQO,59XOwQQO,59XOwQQO,59XOwQQO'#Cj", states: "+dQ]QQOOOOQP'#Cb'#CbOO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#WPPP#W#WPP#WPPPPPPPPP#WP#x$OP$V#WPPP!UP!U$y%e%kPPPP%uP&T'kiXOZw!O!R!W!Z![!^!_!a!bhUOZw!O!R!W!Z![!^!_!a!bu^RS[`abcdfhz!P!k!l!m!n!o!p!_VORSZ[`abcdfhwz!O!P!R!W!Z![!^!_!a!b!k!l!m!n!o!pQreRx!dSgU^RyxtVRS[`abcdfhz!P!k!l!m!n!o!piWOZw!O!R!W!Z![!^!_!a!bQZO[iZ!O!Z![!a!bQ!OwQ!Z!RQ![!WQ!a!^R!b!_Q{sR!T{Q}wS!U}!XR!X!OiYOZw!O!R!W!Z![!^!_!a!bhTOZw!O!R!W!Z![!^!_!a!bQ]RQ_SQj[Ql`QmaQnbQocQpdQsfQvhQ!SzQ!Y!PQ!e!kQ!f!lQ!g!mQ!h!nQ!i!oR!j!pRuf", goto: "'p!VPPPP!WP!fPP#YP#YPPP#Y#YPP#YPPPPPPPPP#YP#z$QP$X#YPPP!WP!W${%g%mPPPP%wP&V'miYO[x!P!S!X![!]!_!`!b!chVO[x!P!S!X![!]!_!`!b!cu_ST]abcdegi{!Q!l!m!n!o!p!q!_WOST[]abcdegix{!P!Q!S!X![!]!_!`!b!c!l!m!n!o!p!qQsfRy!eShV_RzytWST]abcdegi{!Q!l!m!n!o!p!qiXO[x!P!S!X![!]!_!`!b!cQ[O[j[!P![!]!b!cQ!PxQ![!SQ!]!XQ!b!_R!c!`Q|tR!U|Q!OxS!V!O!YR!Y!PiZO[x!P!S!X![!]!_!`!b!chUO[x!P!S!X![!]!_!`!b!cQ^SQ`TQk]QmaQnbQocQpdQqeQtgQwiQ!T{Q!Z!QQ!f!lQ!g!mQ!h!nQ!i!oQ!j!pR!k!qRvg",
nodeNames: "\u26A0 LineComment BlockComment Program IfStatement if VariableName Number String BooleanLiteral BooleanLiteral ) ( ParenExpression UnaryExpression - ! BinaryExpression || && CompareOp in + * / % Power MethodCall . PropertyName ArgList , PropertyAccess FunctionCall then else end Assignment AssignOp ExprStatement", nodeNames: "\u26A0 LineComment BlockComment Program IfStatement if VariableName Number String BooleanLiteral BooleanLiteral NullLiteral NullLiteral ) ( ParenExpression UnaryExpression - ! BinaryExpression || && CompareOp in + * / % Power MethodCall . PropertyName ArgList , PropertyAccess FunctionCall then else end Assignment AssignOp ExprStatement",
maxTerm: 50, maxTerm: 52,
nodeProps: [ nodeProps: [
["group", -3, 4, 37, 39, "Statement", -10, 6, 7, 8, 9, 13, 14, 17, 27, 32, 33, "Expression"], ["group", -3, 4, 39, 41, "Statement", -11, 6, 7, 8, 9, 11, 15, 16, 19, 29, 34, 35, "Expression"],
["openedBy", 11, "("], ["openedBy", 13, "("],
["closedBy", 12, ")"] ["closedBy", 14, ")"]
], ],
skippedNodes: [0, 1, 2], skippedNodes: [0, 1, 2],
repeatNodeCount: 3, repeatNodeCount: 3,
tokenData: "+p~RiXY!pYZ!p]^!ppq!pqr#Rrs#`uv%Svw%awx%lxy'Zyz'`z{'e{|'u|}'}}!O(S!O!P([!P!Q(a!Q![*X!^!_*r!_!`*z!`!a*r!c!}+S#R#S+S#T#o+S#p#q+e~!uS!O~XY!pYZ!p]^!ppq!p~#WP`~!_!`#Z~#`Od~~#cWOY#`Zr#`rs#{s#O#`#O#P$Q#P;'S#`;'S;=`$|<%lO#`~$QOW~~$TRO;'S#`;'S;=`$^;=`O#`~$aXOY#`Zr#`rs#{s#O#`#O#P$Q#P;'S#`;'S;=`$|;=`<%l#`<%lO#`~%PP;=`<%l#`~%XPi~!_!`%[~%aOv~~%dPvw%g~%lOc~~%oWOY%lZw%lwx#{x#O%l#O#P&X#P;'S%l;'S;=`'T<%lO%l~&[RO;'S%l;'S;=`&e;=`O%l~&hXOY%lZw%lwx#{x#O%l#O#P&X#P;'S%l;'S;=`'T;=`<%l%l<%lO%l~'WP;=`<%l%l~'`O[~~'eOZ~~'jQg~z{'p!_!`%[~'uOj~~'zPf~!_!`%[~(SOo~~(XP_~!_!`%[~(aOl~~(fRh~z{(o!P!Q)p!_!`%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Z~+PPx~!_!`#Z~+XS!S~!Q![+S!c!}+S#R#S+S#T#o+S~+hP#p#q+k~+pOd~",
tokenizers: [elseIfTokenizer, 0], tokenizers: [elseIfTokenizer, 0],
topRules: { "Program": [0, 3] }, topRules: { "Program": [0, 3] },
specialized: [{ term: 48, get: (value) => spec_identifier[value] || -1 }], specialized: [{ term: 50, get: (value) => spec_identifier[value] || -1 }],
tokenPrec: 1033 tokenPrec: 1063
}); });
// src/language.ts // src/language.ts
var dexprHighlighting = (0, import_highlight.styleTags)({ var dexprHighlighting = (0, import_highlight.styleTags)({
"if then else end in elseIf": import_highlight.tags.keyword, "if then else end in elseIf": import_highlight.tags.keyword,
BooleanLiteral: import_highlight.tags.bool, BooleanLiteral: import_highlight.tags.bool,
NullLiteral: import_highlight.tags.null,
String: import_highlight.tags.string, String: import_highlight.tags.string,
Number: import_highlight.tags.number, Number: import_highlight.tags.number,
LineComment: import_highlight.tags.lineComment, LineComment: import_highlight.tags.lineComment,
@@ -165,6 +166,7 @@ var KEYWORDS = [
{ label: "end", type: "keyword" }, { label: "end", type: "keyword" },
{ label: "true", type: "keyword", detail: "Boolean" }, { label: "true", type: "keyword", detail: "Boolean" },
{ label: "false", type: "keyword", detail: "Boolean" }, { label: "false", type: "keyword", detail: "Boolean" },
{ label: "null", type: "keyword", detail: "Null" },
{ label: "in", type: "keyword", detail: "membership test" } { label: "in", type: "keyword", detail: "membership test" }
]; ];
function inferVariableTypes(context, knownVars) { function inferVariableTypes(context, knownVars) {
@@ -225,6 +227,10 @@ function inferExprType(node, doc, knownTypes) {
if (rootType === "Object") { if (rootType === "Object") {
return knownTypes.get(`${varName}.${fieldName}`) ?? null; return knownTypes.get(`${varName}.${fieldName}`) ?? null;
} }
if (rootType === "List") {
const fieldType = knownTypes.get(`${varName}.${fieldName}`) ?? null;
return projectedListType(fieldType);
}
} }
return null; return null;
} }
@@ -298,6 +304,11 @@ function inferMethodReturnType(method) {
return null; return null;
} }
} }
function projectedListType(fieldType) {
if (fieldType === "Number") return "NumberList";
if (fieldType === "String") return "StringList";
return "List";
}
function dedup(items) { function dedup(items) {
const seen = /* @__PURE__ */ new Set(); const seen = /* @__PURE__ */ new Set();
return items.filter((item) => { return items.filter((item) => {
@@ -367,12 +378,16 @@ function dexprCompletion(info) {
if (path.length === 1) return { type: rootType, path }; if (path.length === 1) return { type: rootType, path };
let currentType = rootType; let currentType = rootType;
for (let i = 1; i < path.length; i++) { for (let i = 1; i < path.length; i++) {
if (currentType !== "Object") { if (currentType === "Object") {
const key = `${path[i - 1]}.${path[i]}`;
currentType = varTypes.get(key) ?? null;
} else if (currentType === "List") {
const key = `${path[0]}.${path[i]}`;
const fieldType = varTypes.get(key) ?? null;
currentType = projectedListType(fieldType);
} else {
return { type: currentType, path }; return { type: currentType, path };
} }
const key = `${path[i - 1]}.${path[i]}`;
const fieldType = varTypes.get(key) ?? null;
currentType = fieldType;
} }
return { type: currentType, path }; return { type: currentType, path };
} }
@@ -403,8 +418,9 @@ function dexprCompletion(info) {
options = [...fieldItems, ...objMethods]; options = [...fieldItems, ...objMethods];
} else if (finalType === "List") { } else if (finalType === "List") {
const rootVarName = path[0]; const rootVarName = path[0];
const fieldItems = objectFieldCompletions.get(rootVarName) ?? [];
const listMethods = methodsByType["List"] ?? []; const listMethods = methodsByType["List"] ?? [];
options = [...listMethods]; options = [...fieldItems, ...listMethods];
} else if (finalType) { } else if (finalType) {
options = methodsByType[finalType] ?? allMethods; options = methodsByType[finalType] ?? allMethods;
} else { } else {
@@ -436,6 +452,7 @@ var import_highlight2 = require("@lezer/highlight");
var dexprHighlightStyle = import_language3.HighlightStyle.define([ var dexprHighlightStyle = import_language3.HighlightStyle.define([
{ tag: import_highlight2.tags.keyword, color: "#7c3aed" }, { tag: import_highlight2.tags.keyword, color: "#7c3aed" },
{ tag: import_highlight2.tags.bool, color: "#d97706" }, { tag: import_highlight2.tags.bool, color: "#d97706" },
{ tag: import_highlight2.tags.null, color: "#d97706" },
{ tag: import_highlight2.tags.string, color: "#059669" }, { tag: import_highlight2.tags.string, color: "#059669" },
{ tag: import_highlight2.tags.number, color: "#2563eb" }, { tag: import_highlight2.tags.number, color: "#2563eb" },
{ tag: import_highlight2.tags.lineComment, color: "#9ca3af", fontStyle: "italic" }, { tag: import_highlight2.tags.lineComment, color: "#9ca3af", fontStyle: "italic" },
+35 -18
View File
@@ -12,7 +12,7 @@ import { LRParser } from "@lezer/lr";
import { ExternalTokenizer } from "@lezer/lr"; import { ExternalTokenizer } from "@lezer/lr";
// src/parser.terms.js // src/parser.terms.js
var elseIf = 44; var elseIf = 46;
// src/tokens.ts // src/tokens.ts
var CH_e = 101; var CH_e = 101;
@@ -52,32 +52,33 @@ var elseIfTokenizer = new ExternalTokenizer((input) => {
}); });
// src/parser.js // src/parser.js
var spec_identifier = { __proto__: null, if: 11, true: 21, false: 21, in: 43, then: 69, else: 71, end: 73 }; var spec_identifier = { __proto__: null, if: 11, true: 21, false: 21, null: 25, in: 47, then: 73, else: 75, end: 77 };
var parser = LRParser.deserialize({ var parser = LRParser.deserialize({
version: 14, version: 14,
states: "+^Q]QQOOOOQP'#Cb'#CbOOQP'#Ce'#CeOwQQO'#CiO`QQO'#CjO#TQRO'#DTO%bQRO'#D_OOQP'#D_'#D_O%iQRO'#D_OOQP'#D]'#D]OOQP'#DU'#DUQ]QQOOOwQQO'#C`O&eQQO,59TO&lQRO'#D_O(zQRO,59UO`QQO,59XO`QQO,59XO`QQO,59XO`QQO,59XO`QQO,59XO)wQQO,59hO)|QQO'#CzOOQP,59i,59iO`QQO,59mOOQP-E7S-E7SO*TQQO,58zOOQP1G.o1G.oO+oQRO1G.sO+vQRO1G.sO-bQRO1G.sO-iQRO1G.sO.[QRO1G.sOOQP'#Cy'#CyOOQP1G/S1G/SO/[QQO'#D`OOQP,59f,59fO/fQQO,59fO/kQRO1G/XO0bQRO1G.fO0oQQO1G/SOOQP7+$i7+$iOwQQO'#DVO1pQQO,59zOOQP1G/Q1G/QO1xQRO7+$QO2TQRO7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t!`O~P]Oszitzi|zi~P]Ot!cO~P]Oszqtzq|zq~P]O_!nOd!mOe!mOf!nOg!oOh!oOi!oOj!oOl!dOZaibairaioai~Oc!lO~P4WOcai~P4WO_!nOg!oOh!oOi!oOj!oOl!dOZaibaicaidaieairaioai~Of!nO~P5aOfai~P5aO_!nOj!oOl!dOZairaioai~P-pO_!nOl!dOZ^ar^ao^a~P(]OvdjgQPQh~", stateData: "8^~O!QOSPOSQOS~OT]OVWOWWOYQO[RO^SOaTObTO!SPO~OVWOWWOYQO[RO^SOa!qOb!qO!SPO~OadOdaOebOfcOgcOhdOieOjeOkeOleOnfO~OTyXVyXWyXYyX[yX^yXbyX}yX!SyXuyXvyX!OyX~P!fOxiOT!TXV!TXW!TXY!TX[!TXa!TXb!TXd!TXe!TXf!TXg!TXh!TXi!TXj!TXk!TXl!TXn!TX}!TX!S!TXu!TXv!TX!O!TX~O^gO~P$TO^!TX~P$TOa!oOd!lOe!mOf!nOg!nOh!oOi!pOj!pOk!pOl!pOn!eO~O]lO~P%|O^gO]!TXa!TXd!TXe!TXf!TXg!TXh!TXi!TXj!TXk!TXl!TXn!TXT!TXV!TXW!TXY!TX[!TXb!TX}!TX!S!TXt!TXq!TXu!TXv!TX!O!TX~Od`ae`af`ag`ah`ai`aj`ak`al`a~OadOnfOT`aV`aW`aY`a[`a^`ab`a}`a!S`au`av`a!O`a~P(lO!SrO~O]uO~PzOtxO~P%|OadOfcOgcOhdOieOjeOkeOleOnfOTciVciWciYci[ci^cibcidci}ci!Sciucivci!Oci~OebO~P*nOeci~P*nOadOieOjeOkeOleOnfOTciVciWciYci[ci^cibcidciecifcigci}ci!Sciucivci!Oci~OhdO~P,dOhci~P,dOdciecifcigcihciicijcikci~OadOleOnfOTciVciWciYci[ci^cibci}ci!Sciucivci!Oci~P.YOq{O]!UX~P%|O]}O~OTwiVwiWwiYwi[wi^wibwi}wi!Swiuwivwi!Owi~P!fOu!SOv!RO!O!QO~P]O^gO]riaridrierifrigrihriirijrik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!S!X![!]!_!`!b!cQ[O[j[!P![!]!b!cQ!PxQ![!SQ!]!XQ!b!_R!c!`Q|tR!U|Q!OxS!V!O!YR!Y!PiZO[x!P!S!X![!]!_!`!b!chUO[x!P!S!X![!]!_!`!b!cQ^SQ`TQk]QmaQnbQocQpdQqeQtgQwiQ!T{Q!Z!QQ!f!lQ!g!mQ!h!nQ!i!oQ!j!pR!k!qRvg",
nodeNames: "\u26A0 LineComment BlockComment Program IfStatement if VariableName Number String BooleanLiteral BooleanLiteral ) ( ParenExpression UnaryExpression - ! BinaryExpression || && CompareOp in + * / % Power MethodCall . PropertyName ArgList , PropertyAccess FunctionCall then else end Assignment AssignOp ExprStatement", nodeNames: "\u26A0 LineComment BlockComment Program IfStatement if VariableName Number String BooleanLiteral BooleanLiteral NullLiteral NullLiteral ) ( ParenExpression UnaryExpression - ! BinaryExpression || && CompareOp in + * / % Power MethodCall . PropertyName ArgList , PropertyAccess FunctionCall then else end Assignment AssignOp ExprStatement",
maxTerm: 50, maxTerm: 52,
nodeProps: [ nodeProps: [
["group", -3, 4, 37, 39, "Statement", -10, 6, 7, 8, 9, 13, 14, 17, 27, 32, 33, "Expression"], ["group", -3, 4, 39, 41, "Statement", -11, 6, 7, 8, 9, 11, 15, 16, 19, 29, 34, 35, "Expression"],
["openedBy", 11, "("], ["openedBy", 13, "("],
["closedBy", 12, ")"] ["closedBy", 14, ")"]
], ],
skippedNodes: [0, 1, 2], skippedNodes: [0, 1, 2],
repeatNodeCount: 3, repeatNodeCount: 3,
tokenData: "+p~RiXY!pYZ!p]^!ppq!pqr#Rrs#`uv%Svw%awx%lxy'Zyz'`z{'e{|'u|}'}}!O(S!O!P([!P!Q(a!Q![*X!^!_*r!_!`*z!`!a*r!c!}+S#R#S+S#T#o+S#p#q+e~!uS!O~XY!pYZ!p]^!ppq!p~#WP`~!_!`#Z~#`Od~~#cWOY#`Zr#`rs#{s#O#`#O#P$Q#P;'S#`;'S;=`$|<%lO#`~$QOW~~$TRO;'S#`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=`O%l~&hXOY%lZw%lwx#{x#O%l#O#P&X#P;'S%l;'S;=`'T;=`<%l%l<%lO%l~'WP;=`<%l%l~'`O^~~'eO]~~'jQi~z{'p!_!`%[~'uOl~~'zPh~!_!`%[~(SOq~~(XPa~!_!`%[~(aOn~~(fRj~z{(o!P!Q)p!_!`%[~(rTOz(oz{)R{;'S(o;'S;=`)j<%lO(o~)UTO!P(o!P!Q)e!Q;'S(o;'S;=`)j<%lO(o~)jOQ~~)mP;=`<%l(o~)uSP~OY)pZ;'S)p;'S;=`*R<%lO)p~*UP;=`<%l)p~*^QV~!O!P*d!Q![*X~*gP!Q![*j~*oPV~!Q![*j~*wPf~!_!`#Z~+PPx~!_!`#Z~+XS!S~!Q![+S!c!}+S#R#S+S#T#o+S~+hP#p#q+k~+pOd~",
tokenizers: [elseIfTokenizer, 0], tokenizers: [elseIfTokenizer, 0],
topRules: { "Program": [0, 3] }, topRules: { "Program": [0, 3] },
specialized: [{ term: 48, get: (value) => spec_identifier[value] || -1 }], specialized: [{ term: 50, get: (value) => spec_identifier[value] || -1 }],
tokenPrec: 1033 tokenPrec: 1063
}); });
// src/language.ts // src/language.ts
var dexprHighlighting = styleTags({ var dexprHighlighting = styleTags({
"if then else end in elseIf": tags.keyword, "if then else end in elseIf": tags.keyword,
BooleanLiteral: tags.bool, BooleanLiteral: tags.bool,
NullLiteral: tags.null,
String: tags.string, String: tags.string,
Number: tags.number, Number: tags.number,
LineComment: tags.lineComment, LineComment: tags.lineComment,
@@ -138,6 +139,7 @@ var KEYWORDS = [
{ label: "end", type: "keyword" }, { label: "end", type: "keyword" },
{ label: "true", type: "keyword", detail: "Boolean" }, { label: "true", type: "keyword", detail: "Boolean" },
{ label: "false", type: "keyword", detail: "Boolean" }, { label: "false", type: "keyword", detail: "Boolean" },
{ label: "null", type: "keyword", detail: "Null" },
{ label: "in", type: "keyword", detail: "membership test" } { label: "in", type: "keyword", detail: "membership test" }
]; ];
function inferVariableTypes(context, knownVars) { function inferVariableTypes(context, knownVars) {
@@ -198,6 +200,10 @@ function inferExprType(node, doc, knownTypes) {
if (rootType === "Object") { if (rootType === "Object") {
return knownTypes.get(`${varName}.${fieldName}`) ?? null; return knownTypes.get(`${varName}.${fieldName}`) ?? null;
} }
if (rootType === "List") {
const fieldType = knownTypes.get(`${varName}.${fieldName}`) ?? null;
return projectedListType(fieldType);
}
} }
return null; return null;
} }
@@ -271,6 +277,11 @@ function inferMethodReturnType(method) {
return null; return null;
} }
} }
function projectedListType(fieldType) {
if (fieldType === "Number") return "NumberList";
if (fieldType === "String") return "StringList";
return "List";
}
function dedup(items) { function dedup(items) {
const seen = /* @__PURE__ */ new Set(); const seen = /* @__PURE__ */ new Set();
return items.filter((item) => { return items.filter((item) => {
@@ -340,12 +351,16 @@ function dexprCompletion(info) {
if (path.length === 1) return { type: rootType, path }; if (path.length === 1) return { type: rootType, path };
let currentType = rootType; let currentType = rootType;
for (let i = 1; i < path.length; i++) { for (let i = 1; i < path.length; i++) {
if (currentType !== "Object") { if (currentType === "Object") {
const key = `${path[i - 1]}.${path[i]}`;
currentType = varTypes.get(key) ?? null;
} else if (currentType === "List") {
const key = `${path[0]}.${path[i]}`;
const fieldType = varTypes.get(key) ?? null;
currentType = projectedListType(fieldType);
} else {
return { type: currentType, path }; return { type: currentType, path };
} }
const key = `${path[i - 1]}.${path[i]}`;
const fieldType = varTypes.get(key) ?? null;
currentType = fieldType;
} }
return { type: currentType, path }; return { type: currentType, path };
} }
@@ -376,8 +391,9 @@ function dexprCompletion(info) {
options = [...fieldItems, ...objMethods]; options = [...fieldItems, ...objMethods];
} else if (finalType === "List") { } else if (finalType === "List") {
const rootVarName = path[0]; const rootVarName = path[0];
const fieldItems = objectFieldCompletions.get(rootVarName) ?? [];
const listMethods = methodsByType["List"] ?? []; const listMethods = methodsByType["List"] ?? [];
options = [...listMethods]; options = [...fieldItems, ...listMethods];
} else if (finalType) { } else if (finalType) {
options = methodsByType[finalType] ?? allMethods; options = methodsByType[finalType] ?? allMethods;
} else { } else {
@@ -409,6 +425,7 @@ import { tags as tags2 } from "@lezer/highlight";
var dexprHighlightStyle = HighlightStyle.define([ var dexprHighlightStyle = HighlightStyle.define([
{ tag: tags2.keyword, color: "#7c3aed" }, { tag: tags2.keyword, color: "#7c3aed" },
{ tag: tags2.bool, color: "#d97706" }, { tag: tags2.bool, color: "#d97706" },
{ tag: tags2.null, color: "#d97706" },
{ tag: tags2.string, color: "#059669" }, { tag: tags2.string, color: "#059669" },
{ tag: tags2.number, color: "#2563eb" }, { tag: tags2.number, color: "#2563eb" },
{ tag: tags2.lineComment, color: "#9ca3af", fontStyle: "italic" }, { tag: tags2.lineComment, color: "#9ca3af", fontStyle: "italic" },
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@duhanbalci/codemirror-lang-dexpr", "name": "@duhanbalci/codemirror-lang-dexpr",
"version": "0.3.0", "version": "0.4.0",
"description": "CodeMirror 6 language support for dexpr", "description": "CodeMirror 6 language support for dexpr",
"type": "module", "type": "module",
"main": "dist/index.cjs", "main": "dist/index.cjs",
+1
View File
@@ -90,6 +90,7 @@ const KEYWORDS: Completion[] = [
{ label: "end", type: "keyword" }, { label: "end", type: "keyword" },
{ label: "true", type: "keyword", detail: "Boolean" }, { label: "true", type: "keyword", detail: "Boolean" },
{ label: "false", type: "keyword", detail: "Boolean" }, { label: "false", type: "keyword", detail: "Boolean" },
{ label: "null", type: "keyword", detail: "Null" },
{ label: "in", type: "keyword", detail: "membership test" }, { label: "in", type: "keyword", detail: "membership test" },
]; ];
+3
View File
@@ -43,6 +43,7 @@ expression[@isGroup=Expression] {
Number | Number |
String | String |
BooleanLiteral | BooleanLiteral |
NullLiteral |
ParenExpression | ParenExpression |
UnaryExpression | UnaryExpression |
BinaryExpression | BinaryExpression |
@@ -91,6 +92,8 @@ kw<term> { @extend[@name={term}]<identifier, term> }
BooleanLiteral { @extend[@name=BooleanLiteral]<identifier, "true" | "false"> } BooleanLiteral { @extend[@name=BooleanLiteral]<identifier, "true" | "false"> }
NullLiteral { @extend[@name=NullLiteral]<identifier, "null"> }
@tokens { @tokens {
space { $[ \t\n\r]+ } space { $[ \t\n\r]+ }
+1
View File
@@ -5,6 +5,7 @@ import type { Extension } from "@codemirror/state";
export const dexprHighlightStyle = HighlightStyle.define([ export const dexprHighlightStyle = HighlightStyle.define([
{ tag: tags.keyword, color: "#7c3aed" }, { tag: tags.keyword, color: "#7c3aed" },
{ tag: tags.bool, color: "#d97706" }, { tag: tags.bool, color: "#d97706" },
{ tag: tags.null, color: "#d97706" },
{ tag: tags.string, color: "#059669" }, { tag: tags.string, color: "#059669" },
{ tag: tags.number, color: "#2563eb" }, { tag: tags.number, color: "#2563eb" },
{ tag: tags.lineComment, color: "#9ca3af", fontStyle: "italic" }, { tag: tags.lineComment, color: "#9ca3af", fontStyle: "italic" },
+1
View File
@@ -6,6 +6,7 @@ import { parser } from "./parser.js";
const dexprHighlighting = styleTags({ const dexprHighlighting = styleTags({
"if then else end in elseIf": tags.keyword, "if then else end in elseIf": tags.keyword,
BooleanLiteral: tags.bool, BooleanLiteral: tags.bool,
NullLiteral: tags.null,
String: tags.string, String: tags.string,
Number: tags.number, Number: tags.number,
LineComment: tags.lineComment, LineComment: tags.lineComment,
+12 -12
View File
@@ -1,24 +1,24 @@
// This file was generated by lezer-generator. You probably shouldn't edit it. // This file was generated by lezer-generator. You probably shouldn't edit it.
import {LRParser} from "@lezer/lr" import {LRParser} from "@lezer/lr"
import {elseIfTokenizer} from "./tokens" import {elseIfTokenizer} from "./tokens"
const spec_identifier = {__proto__:null,if:11, true:21, false:21, in:43, then:69, else:71, end:73} const spec_identifier = {__proto__:null,if:11, true:21, false:21, null:25, in:47, then:73, else:75, end:77}
export const parser = LRParser.deserialize({ export const parser = LRParser.deserialize({
version: 14, version: 14,
states: "+^Q]QQOOOOQP'#Cb'#CbOOQP'#Ce'#CeOwQQO'#CiO`QQO'#CjO#TQRO'#DTO%bQRO'#D_OOQP'#D_'#D_O%iQRO'#D_OOQP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OiYOZw!O!R!W!Z![!^!_!a!bhTOZw!O!R!W!Z![!^!_!a!bQ]RQ_SQj[Ql`QmaQnbQocQpdQsfQvhQ!SzQ!Y!PQ!e!kQ!f!lQ!g!mQ!h!nQ!i!oR!j!pRuf", goto: "'p!VPPPP!WP!fPP#YP#YPPP#Y#YPP#YPPPPPPPPP#YP#z$QP$X#YPPP!WP!W${%g%mPPPP%wP&V'miYO[x!P!S!X![!]!_!`!b!chVO[x!P!S!X![!]!_!`!b!cu_ST]abcdegi{!Q!l!m!n!o!p!q!_WOST[]abcdegix{!P!Q!S!X![!]!_!`!b!c!l!m!n!o!p!qQsfRy!eShV_RzytWST]abcdegi{!Q!l!m!n!o!p!qiXO[x!P!S!X![!]!_!`!b!cQ[O[j[!P![!]!b!cQ!PxQ![!SQ!]!XQ!b!_R!c!`Q|tR!U|Q!OxS!V!O!YR!Y!PiZO[x!P!S!X![!]!_!`!b!chUO[x!P!S!X![!]!_!`!b!cQ^SQ`TQk]QmaQnbQocQpdQqeQtgQwiQ!T{Q!Z!QQ!f!lQ!g!mQ!h!nQ!i!oQ!j!pR!k!qRvg",
nodeNames: "⚠ LineComment BlockComment Program IfStatement if VariableName Number String BooleanLiteral BooleanLiteral ) ( ParenExpression UnaryExpression - ! BinaryExpression || && CompareOp in + * / % Power MethodCall . PropertyName ArgList , PropertyAccess FunctionCall then else end Assignment AssignOp ExprStatement", nodeNames: "⚠ LineComment BlockComment Program IfStatement if VariableName Number String BooleanLiteral BooleanLiteral NullLiteral NullLiteral ) ( ParenExpression UnaryExpression - ! BinaryExpression || && CompareOp in + * / % Power MethodCall . PropertyName ArgList , PropertyAccess FunctionCall then else end Assignment AssignOp ExprStatement",
maxTerm: 50, maxTerm: 52,
nodeProps: [ nodeProps: [
["group", -3,4,37,39,"Statement",-10,6,7,8,9,13,14,17,27,32,33,"Expression"], ["group", -3,4,39,41,"Statement",-11,6,7,8,9,11,15,16,19,29,34,35,"Expression"],
["openedBy", 11,"("], ["openedBy", 13,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*r!_!`*z!`!a*r!c!}+S#R#S+S#T#o+S#p#q+e~!uS!Q~XY!pYZ!p]^!ppq!p~#WPb~!_!`#Z~#`Of~~#cWOY#`Zr#`rs#{s#O#`#O#P$Q#P;'S#`;'S;=`$|<%lO#`~$QOW~~$TRO;'S#`;'S;=`$^;=`O#`~$aXOY#`Zr#`rs#{s#O#`#O#P$Q#P;'S#`;'S;=`$|;=`<%l#`<%lO#`~%PP;=`<%l#`~%XPk~!_!`%[~%aOx~~%dPvw%g~%lOe~~%oWOY%lZw%lwx#{x#O%l#O#P&X#P;'S%l;'S;=`'T<%lO%l~&[RO;'S%l;'S;=`&e;=`O%l~&hXOY%lZw%lwx#{x#O%l#O#P&X#P;'S%l;'S;=`'T;=`<%l%l<%lO%l~'WP;=`<%l%l~'`O^~~'eO]~~'jQi~z{'p!_!`%[~'uOl~~'zPh~!_!`%[~(SOq~~(XPa~!_!`%[~(aOn~~(fRj~z{(o!P!Q)p!_!`%[~(rTOz(oz{)R{;'S(o;'S;=`)j<%lO(o~)UTO!P(o!P!Q)e!Q;'S(o;'S;=`)j<%lO(o~)jOQ~~)mP;=`<%l(o~)uSP~OY)pZ;'S)p;'S;=`*R<%lO)p~*UP;=`<%l)p~*^QV~!O!P*d!Q![*X~*gP!Q![*j~*oPV~!Q![*j~*wPf~!_!`#Z~+PPx~!_!`#Z~+XS!S~!Q![+S!c!}+S#R#S+S#T#o+S~+hP#p#q+k~+pOd~",
tokenizers: [elseIfTokenizer, 0], tokenizers: [elseIfTokenizer, 0],
topRules: {"Program":[0,3]}, topRules: {"Program":[0,3]},
specialized: [{term: 48, get: (value) => spec_identifier[value] || -1}], specialized: [{term: 50, get: (value) => spec_identifier[value] || -1}],
tokenPrec: 1033 tokenPrec: 1063
}) })
+19 -18
View File
@@ -1,6 +1,6 @@
// This file was generated by lezer-generator. You probably shouldn't edit it. // This file was generated by lezer-generator. You probably shouldn't edit it.
export const export const
elseIf = 44, elseIf = 46,
LineComment = 1, LineComment = 1,
BlockComment = 2, BlockComment = 2,
Program = 3, Program = 3,
@@ -10,20 +10,21 @@ export const
Number = 7, Number = 7,
String = 8, String = 8,
BooleanLiteral = 10, BooleanLiteral = 10,
ParenExpression = 13, NullLiteral = 12,
UnaryExpression = 14, ParenExpression = 15,
BinaryExpression = 17, UnaryExpression = 16,
CompareOp = 20, BinaryExpression = 19,
_in = 21, CompareOp = 22,
Power = 26, _in = 23,
MethodCall = 27, Power = 28,
PropertyName = 29, MethodCall = 29,
ArgList = 30, PropertyName = 31,
PropertyAccess = 32, ArgList = 32,
FunctionCall = 33, PropertyAccess = 34,
then = 34, FunctionCall = 35,
_else = 35, then = 36,
end = 36, _else = 37,
Assignment = 37, end = 38,
AssignOp = 38, Assignment = 39,
ExprStatement = 39 AssignOp = 40,
ExprStatement = 41
+2 -1
View File
@@ -121,6 +121,7 @@ pub grammar parser() for str {
rule boolean_literal() -> Value rule boolean_literal() -> Value
= "true" { Value::Boolean(true) } = "true" { Value::Boolean(true) }
/ "false" { Value::Boolean(false) } / "false" { Value::Boolean(false) }
/ "null" { Value::Null }
pub rule expr_stmt() -> Stmt pub rule expr_stmt() -> Stmt
@@ -164,7 +165,7 @@ pub grammar parser() for str {
/ "%=" { Op::Mod } / "%=" { Op::Mod }
rule keyword() rule keyword()
= ("if" / "then" / "else" / "end" / "true" / "false" / "in") !['a'..='z' | 'A'..='Z' | '0'..='9' | '_'] = ("if" / "then" / "else" / "end" / "true" / "false" / "null" / "in") !['a'..='z' | 'A'..='Z' | '0'..='9' | '_']
rule identifier() -> SmolStr rule identifier() -> SmolStr
= !keyword() s:$(['a'..='z' | 'A'..='Z' | '_']['a'..='z' | 'A'..='Z' | '0'..='9' | '_']*) = !keyword() s:$(['a'..='z' | 'A'..='Z' | '_']['a'..='z' | 'A'..='Z' | '0'..='9' | '_']*)
+57 -14
View File
@@ -1,4 +1,5 @@
use crate::{ast::value::Value, bytecode::BytecodeReader, opcodes::OpCodeByte}; use crate::{ast::value::Value, bytecode::BytecodeReader, opcodes::OpCodeByte};
use std::cmp::Ordering;
use std::rc::Rc; use std::rc::Rc;
use micromap::Map; use micromap::Map;
use rust_decimal::{Decimal, MathematicalOps}; use rust_decimal::{Decimal, MathematicalOps};
@@ -208,12 +209,12 @@ impl<'a> VM<'a> {
"modulo", "modulo",
), ),
OpCodeByte::Pow => self.binary_op(|a, b| Ok(a.powd(b)), "power"), OpCodeByte::Pow => self.binary_op(|a, b| Ok(a.powd(b)), "power"),
OpCodeByte::Lt => self.compare_op(|a, b| a < b, "less than"), OpCodeByte::Lt => self.compare_op(|o| o == Ordering::Less, "less than"),
OpCodeByte::Lte => self.compare_op(|a, b| a <= b, "less than or equal"), OpCodeByte::Lte => self.compare_op(|o| o != Ordering::Greater, "less than or equal"),
OpCodeByte::Gt => self.compare_op(|a, b| a > b, "greater than"), OpCodeByte::Gt => self.compare_op(|o| o == Ordering::Greater, "greater than"),
OpCodeByte::Gte => self.compare_op(|a, b| a >= b, "greater than or equal"), OpCodeByte::Gte => self.compare_op(|o| o != Ordering::Less, "greater than or equal"),
OpCodeByte::Eq => self.compare_op(|a, b| a == b, "equal"), OpCodeByte::Eq => self.equality_op(false),
OpCodeByte::Neq => self.compare_op(|a, b| a != b, "not equal"), OpCodeByte::Neq => self.equality_op(true),
OpCodeByte::Contains => self.handle_contains(), OpCodeByte::Contains => self.handle_contains(),
OpCodeByte::And => self.handle_and(), OpCodeByte::And => self.handle_and(),
OpCodeByte::Or => self.handle_or(), OpCodeByte::Or => self.handle_or(),
@@ -893,11 +894,54 @@ impl<'a> VM<'a> {
Ok(()) Ok(())
} }
/// Helper for comparison operations /// Helper for equality operations (`==`, `!=`).
/// Works on every value type via structural equality; values of different
/// types are never equal (no error).
#[inline]
fn equality_op(&mut self, negate: bool) -> Result<(), VMError> {
let dest = self
.reader
.read_register()
.map_err(|e| VMError::BytecodeError(e))? as usize;
let a = self
.reader
.read_register()
.map_err(|e| VMError::BytecodeError(e))? as usize;
let b = self
.reader
.read_register()
.map_err(|e| VMError::BytecodeError(e))? as usize;
#[cfg(debug_assertions)]
if dest >= MAX_REGISTERS || a >= MAX_REGISTERS || b >= MAX_REGISTERS {
return Err(VMError::RuntimeError(format!(
"Invalid register: dest={}, a={}, b={}",
dest, a, b
)));
}
let equal = self.registers[a] == self.registers[b];
self.registers[dest] = Value::Boolean(equal != negate);
log_debug!(
self,
"{} r{} = r{} {} r{}",
if negate { "not equal" } else { "equal" },
dest,
a,
if negate { "!=" } else { "==" },
b
);
Ok(())
}
/// Helper for ordering comparisons (`<`, `<=`, `>`, `>=`).
/// Supported on Number/Number and String/String (lexicographic byte order).
#[inline] #[inline]
fn compare_op<F>(&mut self, op: F, op_name: &'static str) -> Result<(), VMError> fn compare_op<F>(&mut self, op: F, op_name: &'static str) -> Result<(), VMError>
where where
F: FnOnce(&Decimal, &Decimal) -> bool, F: FnOnce(Ordering) -> bool,
{ {
let dest = self let dest = self
.reader .reader
@@ -920,11 +964,9 @@ impl<'a> VM<'a> {
))); )));
} }
match (&self.registers[a], &self.registers[b]) { let ordering = match (&self.registers[a], &self.registers[b]) {
(Value::Number(a_num), Value::Number(b_num)) => { (Value::Number(a_num), Value::Number(b_num)) => a_num.cmp(b_num),
let result = op(a_num, b_num); (Value::String(a_str), Value::String(b_str)) => a_str.as_str().cmp(b_str.as_str()),
self.registers[dest] = Value::Boolean(result);
}
(a_val, b_val) => { (a_val, b_val) => {
return Err(VMError::InvalidOperation { return Err(VMError::InvalidOperation {
operation: op_name, operation: op_name,
@@ -932,7 +974,8 @@ impl<'a> VM<'a> {
right_type: b_val.type_name(), right_type: b_val.type_name(),
}); });
} }
} };
self.registers[dest] = Value::Boolean(op(ordering));
log_debug!(self, "{} r{} = r{} {} r{}", op_name, dest, a, op_name, b); log_debug!(self, "{} r{} = r{} {} r{}", op_name, dest, a, op_name, b);
+129
View File
@@ -1940,3 +1940,132 @@ fn test_invoice_full_scenario() {
]); ]);
assert_eq!(result, Value::Number(dec!(272760.00))); assert_eq!(result, Value::Number(dec!(272760.00)));
} }
// ==================== COMPARISON TESTS ====================
fn run_expr_err(code: &str, globals: Vec<(&str, Value)>) -> String {
let ast = parser::program(code).expect("Failed to parse");
let mut compiler = Compiler::new();
let bytecode = compiler.compile(ast).expect("Failed to compile");
let mut vm = VM::new(&bytecode);
for (name, value) in globals {
vm.set_global(name, value);
}
vm.execute().unwrap_err().to_string()
}
#[test]
fn test_compare_number_list_equality() {
let a = Value::NumberList(Rc::new(vec![dec!(1), dec!(2)]));
let b = Value::NumberList(Rc::new(vec![dec!(1), dec!(2)]));
let c = Value::NumberList(Rc::new(vec![dec!(1), dec!(3)]));
assert_eq!(
run_expr_with_globals("a == b", vec![("a", a.clone()), ("b", b.clone())]),
Value::Boolean(true)
);
assert_eq!(
run_expr_with_globals("a == c", vec![("a", a.clone()), ("c", c.clone())]),
Value::Boolean(false)
);
assert_eq!(
run_expr_with_globals("a != c", vec![("a", a), ("c", c)]),
Value::Boolean(true)
);
}
#[test]
fn test_compare_string_list_equality() {
let a = Value::StringList(Rc::new(vec![SmolStr::new("x"), SmolStr::new("y")]));
let b = Value::StringList(Rc::new(vec![SmolStr::new("x"), SmolStr::new("y")]));
let c = Value::StringList(Rc::new(vec![SmolStr::new("y"), SmolStr::new("x")]));
assert_eq!(
run_expr_with_globals("a == b", vec![("a", a.clone()), ("b", b)]),
Value::Boolean(true)
);
assert_eq!(
run_expr_with_globals("a == c", vec![("a", a), ("c", c)]),
Value::Boolean(false)
);
}
#[test]
fn test_compare_list_of_objects_equality() {
let mk = |n: i64| {
let mut m = IndexMap::new();
m.insert(SmolStr::new("id"), Value::Number(dec!(1) * rust_decimal::Decimal::from(n)));
Value::Object(Rc::new(m))
};
let a = Value::List(Rc::new(vec![mk(1), mk(2)]));
let b = Value::List(Rc::new(vec![mk(1), mk(2)]));
let c = Value::List(Rc::new(vec![mk(1)]));
assert_eq!(
run_expr_with_globals("a == b", vec![("a", a.clone()), ("b", b)]),
Value::Boolean(true)
);
assert_eq!(
run_expr_with_globals("a == c", vec![("a", a), ("c", c)]),
Value::Boolean(false)
);
}
#[test]
fn test_compare_different_types_never_equal() {
let list = Value::NumberList(Rc::new(vec![dec!(1)]));
assert_eq!(
run_expr_with_globals("l == 1", vec![("l", list.clone())]),
Value::Boolean(false)
);
assert_eq!(
run_expr_with_globals("l == \"1\"", vec![("l", list.clone())]),
Value::Boolean(false)
);
assert_eq!(
run_expr_with_globals("l == null", vec![("l", list)]),
Value::Boolean(false)
);
}
#[test]
fn test_compare_ordering_string_vs_number_errors() {
let err = run_expr_err("\"a\" < 1", vec![]);
assert!(err.contains("less than"), "got: {err}");
assert!(err.contains("String"), "got: {err}");
assert!(err.contains("Number"), "got: {err}");
}
#[test]
fn test_compare_ordering_boolean_errors() {
let err = run_expr_err("true > false", vec![]);
assert!(err.contains("greater than"), "got: {err}");
assert!(err.contains("Boolean"), "got: {err}");
}
#[test]
fn test_compare_ordering_null_errors() {
let err = run_expr_err("null <= 1", vec![]);
assert!(err.contains("less than or equal"), "got: {err}");
assert!(err.contains("Null"), "got: {err}");
}
#[test]
fn test_compare_ordering_lists_errors() {
let list = Value::NumberList(Rc::new(vec![dec!(1)]));
let err = run_expr_err("l >= l", vec![("l", list)]);
assert!(err.contains("greater than or equal"), "got: {err}");
}
#[test]
fn test_null_is_reserved_keyword() {
assert!(parser::program("null = 5").is_err());
// identifiers that merely start with "null" are still fine
assert_eq!(run_expr("nullable = 3\nnullable"), Value::Number(dec!(3)));
}
#[test]
fn test_string_compare_in_condition() {
let code = r#"
grade = "B"
result = 0
if grade == "A" then result = 100 else if grade == "B" then result = 80 else result = 0 end
"#;
assert_eq!(run_and_get_result(code), Value::Number(dec!(80)));
}
+174
View File
@@ -1284,5 +1284,179 @@
"maxPrice": { "type": "number", "value": "200" } "maxPrice": { "type": "number", "value": "200" }
}, },
"expected": { "type": "number", "value": "200" } "expected": { "type": "number", "value": "200" }
},
{
"name": "compare: string equality",
"code": "\"a\" == \"a\"",
"expected": { "type": "boolean", "value": true }
},
{
"name": "compare: string inequality",
"code": "\"a\" == \"b\"",
"expected": { "type": "boolean", "value": false }
},
{
"name": "compare: string not equal",
"code": "\"a\" != \"b\"",
"expected": { "type": "boolean", "value": true }
},
{
"name": "compare: string case sensitive",
"code": "\"A\" == \"a\"",
"expected": { "type": "boolean", "value": false }
},
{
"name": "compare: string less than",
"code": "\"a\" < \"b\"",
"expected": { "type": "boolean", "value": true }
},
{
"name": "compare: string greater than",
"code": "\"b\" > \"a\"",
"expected": { "type": "boolean", "value": true }
},
{
"name": "compare: string lte equal",
"code": "\"a\" <= \"a\"",
"expected": { "type": "boolean", "value": true }
},
{
"name": "compare: string gte",
"code": "\"abc\" >= \"abd\"",
"expected": { "type": "boolean", "value": false }
},
{
"name": "compare: string prefix ordering",
"code": "\"ab\" < \"abc\"",
"expected": { "type": "boolean", "value": true }
},
{
"name": "compare: boolean equality",
"code": "true == true",
"expected": { "type": "boolean", "value": true }
},
{
"name": "compare: boolean inequality",
"code": "true == false",
"expected": { "type": "boolean", "value": false }
},
{
"name": "compare: boolean not equal",
"code": "true != false",
"expected": { "type": "boolean", "value": true }
},
{
"name": "compare: null literal",
"code": "null",
"expected": { "type": "null" }
},
{
"name": "compare: null == null",
"code": "null == null",
"expected": { "type": "boolean", "value": true }
},
{
"name": "compare: null != null",
"code": "null != null",
"expected": { "type": "boolean", "value": false }
},
{
"name": "compare: number == null is false",
"code": "1 == null",
"expected": { "type": "boolean", "value": false }
},
{
"name": "compare: number != null",
"code": "1 != null",
"expected": { "type": "boolean", "value": true }
},
{
"name": "compare: string == number is false",
"code": "\"1\" == 1",
"expected": { "type": "boolean", "value": false }
},
{
"name": "compare: string != number",
"code": "\"1\" != 1",
"expected": { "type": "boolean", "value": true }
},
{
"name": "compare: boolean == number is false",
"code": "true == 1",
"expected": { "type": "boolean", "value": false }
},
{
"name": "compare: number equality still works",
"code": "1 == 1",
"expected": { "type": "boolean", "value": true }
},
{
"name": "compare: number decimal equality",
"code": "1.0 == 1",
"expected": { "type": "boolean", "value": true }
},
{
"name": "compare: string eq in if",
"code": "x = \"ok\"\nif x == \"ok\" then 1 else 2 end",
"expected": { "type": "number", "value": "1" }
},
{
"name": "compare: string in condition with globals",
"code": "if status == \"active\" then \"yes\" else \"no\" end",
"globals": {
"status": {"type": "string", "value": "active"}
},
"expected": { "type": "string", "value": "yes" }
},
{
"name": "compare: null global",
"code": "x == null",
"globals": {
"x": {"type": "null"}
},
"expected": { "type": "boolean", "value": true }
},
{
"name": "compare: non-null global vs null",
"code": "x == null",
"globals": {
"x": {"type": "number", "value": "5"}
},
"expected": { "type": "boolean", "value": false }
},
{
"name": "compare: object equality",
"code": "a == b",
"globals": {
"a": {"type": "object", "value": {"k": "1"}},
"b": {"type": "object", "value": {"k": "1"}}
},
"expected": { "type": "boolean", "value": true }
},
{
"name": "compare: object inequality",
"code": "a == b",
"globals": {
"a": {"type": "object", "value": {"k": "1"}},
"b": {"type": "object", "value": {"k": "2"}}
},
"expected": { "type": "boolean", "value": false }
},
{
"name": "compare: object field string eq",
"code": "o.name == \"ali\"",
"globals": {
"o": {"type": "object", "value": {"name": "ali"}}
},
"expected": { "type": "boolean", "value": true }
},
{
"name": "compare: object field string ordering",
"code": "o.name < \"b\"",
"globals": {
"o": {"type": "object", "value": {"name": "ali"}}
},
"expected": { "type": "boolean", "value": true }
} }
] ]
+2 -2
View File
@@ -141,7 +141,7 @@ dependencies = [
[[package]] [[package]]
name = "dexpr" name = "dexpr"
version = "0.1.0" version = "0.4.0"
dependencies = [ dependencies = [
"bumpalo", "bumpalo",
"indexmap", "indexmap",
@@ -159,7 +159,7 @@ dependencies = [
[[package]] [[package]]
name = "dexpr-wasm" name = "dexpr-wasm"
version = "0.1.0" version = "0.4.0"
dependencies = [ dependencies = [
"dexpr", "dexpr",
"getrandom 0.3.4", "getrandom 0.3.4",
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "dexpr-wasm" name = "dexpr-wasm"
version = "0.3.0" version = "0.4.0"
edition = "2021" edition = "2021"
[lib] [lib]