@graffiticode/parser 1.2.2 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +3 -1
- package/package.json +2 -2
- package/src/folder.js +3 -2
- package/src/index.js +1 -0
- package/src/parser.spec.js +31 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graffiticode/parser",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -22,6 +22,6 @@
|
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"description": "",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@graffiticode/basis": "^1.6.
|
|
25
|
+
"@graffiticode/basis": "^1.6.4"
|
|
26
26
|
}
|
|
27
27
|
}
|
package/src/folder.js
CHANGED
|
@@ -202,12 +202,13 @@ export class Folder {
|
|
|
202
202
|
}
|
|
203
203
|
} else if (word.cls === "function") {
|
|
204
204
|
const elts = [];
|
|
205
|
-
|
|
205
|
+
const argc = word.arity !== undefined ? word.arity : word.length;
|
|
206
|
+
for (let i = 0; i < argc; i++) {
|
|
206
207
|
const elt = Ast.pop(ctx);
|
|
207
208
|
assertErr(
|
|
208
209
|
ctx,
|
|
209
210
|
elt,
|
|
210
|
-
`Too few arguments for ${word.name}. Expected ${
|
|
211
|
+
`Too few arguments for ${word.name}. Expected ${argc}.`,
|
|
211
212
|
node.coord
|
|
212
213
|
);
|
|
213
214
|
elts.push(elt);
|
package/src/index.js
CHANGED
package/src/parser.spec.js
CHANGED
|
@@ -2,6 +2,7 @@ import { jest } from "@jest/globals";
|
|
|
2
2
|
import { buildParser, parser } from "./parser.js";
|
|
3
3
|
import { mockPromiseValue, mockPromiseError } from "./testing/index.js";
|
|
4
4
|
import { lexicon as basisLexicon } from "@graffiticode/basis";
|
|
5
|
+
import { unparse } from "./unparse.js";
|
|
5
6
|
|
|
6
7
|
describe("lang/parser", () => {
|
|
7
8
|
const log = jest.fn();
|
|
@@ -547,6 +548,36 @@ describe("parser integration tests", () => {
|
|
|
547
548
|
expect(strNode.elts[0]).toBe("Price: ${amount}");
|
|
548
549
|
});
|
|
549
550
|
|
|
551
|
+
it("should parse and unparse a tag node", async () => {
|
|
552
|
+
// Arrange - use an empty lexicon so "foo" is not recognized as a function
|
|
553
|
+
const emptyLexicon = {};
|
|
554
|
+
|
|
555
|
+
// Act - parse "foo.." where "foo" is not in the lexicon, producing a TAG node
|
|
556
|
+
const result = await parser.parse(0, "foo..", emptyLexicon);
|
|
557
|
+
|
|
558
|
+
// Assert - find the TAG node
|
|
559
|
+
expect(result).toHaveProperty("root");
|
|
560
|
+
|
|
561
|
+
let tagNode = null;
|
|
562
|
+
for (const key in result) {
|
|
563
|
+
if (key !== "root") {
|
|
564
|
+
const node = result[key];
|
|
565
|
+
if (node.tag === "TAG" && node.elts[0] === "foo") {
|
|
566
|
+
tagNode = node;
|
|
567
|
+
break;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
expect(tagNode).not.toBeNull();
|
|
573
|
+
expect(tagNode.tag).toBe("TAG");
|
|
574
|
+
expect(tagNode.elts).toEqual(["foo"]);
|
|
575
|
+
|
|
576
|
+
// Unparse should reproduce the original source
|
|
577
|
+
const source = unparse(result, emptyLexicon);
|
|
578
|
+
expect(source).toBe("foo..");
|
|
579
|
+
});
|
|
580
|
+
|
|
550
581
|
it("should parse strings with mixed escape sequences", async () => {
|
|
551
582
|
// Arrange & Act
|
|
552
583
|
const result = await parser.parse(0, '"Line 1\\nTab\\t\\"Quote\\""..', basisLexicon);
|