agency-lang 0.0.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/README.md +7 -0
- package/dist/backends/baseGenerator.js +194 -0
- package/dist/backends/graphGenerator.integration.test.js +119 -0
- package/dist/backends/graphGenerator.js +308 -0
- package/dist/backends/index.js +3 -0
- package/dist/backends/typescriptGenerator/builtins.js +46 -0
- package/dist/backends/typescriptGenerator/typeToString.js +36 -0
- package/dist/backends/typescriptGenerator/typeToZodSchema.js +54 -0
- package/dist/backends/typescriptGenerator.integration.test.js +119 -0
- package/dist/backends/typescriptGenerator.js +340 -0
- package/dist/backends/typescriptGenerator.test.js +763 -0
- package/dist/backends/utils.js +6 -0
- package/dist/generate-graph-file.js +25 -0
- package/dist/generate-ts-file.js +26 -0
- package/dist/index.js +3 -0
- package/dist/parser.js +38 -0
- package/dist/parser.test.js +306 -0
- package/dist/parsers/access.js +19 -0
- package/dist/parsers/access.test.js +929 -0
- package/dist/parsers/assignment.js +8 -0
- package/dist/parsers/body.test.js +106 -0
- package/dist/parsers/comment.js +6 -0
- package/dist/parsers/comment.test.js +100 -0
- package/dist/parsers/dataStructures.js +14 -0
- package/dist/parsers/dataStructures.test.js +660 -0
- package/dist/parsers/function.js +22 -0
- package/dist/parsers/function.test.js +591 -0
- package/dist/parsers/functionCall.js +10 -0
- package/dist/parsers/functionCall.test.js +119 -0
- package/dist/parsers/importStatement.js +3 -0
- package/dist/parsers/importStatement.test.js +290 -0
- package/dist/parsers/literals.js +12 -0
- package/dist/parsers/literals.test.js +639 -0
- package/dist/parsers/matchBlock.js +24 -0
- package/dist/parsers/matchBlock.test.js +506 -0
- package/dist/parsers/parserUtils.js +2 -0
- package/dist/parsers/returnStatement.js +8 -0
- package/dist/parsers/tools.js +3 -0
- package/dist/parsers/tools.test.js +170 -0
- package/dist/parsers/typeHints.js +59 -0
- package/dist/parsers/typeHints.test.js +2754 -0
- package/dist/parsers/utils.js +5 -0
- package/dist/parsers/whileLoop.test.js +342 -0
- package/dist/templates/backends/graphGenerator/builtinTools.js +36 -0
- package/dist/templates/backends/graphGenerator/conditionalEdge.js +10 -0
- package/dist/templates/backends/graphGenerator/edge.js +10 -0
- package/dist/templates/backends/graphGenerator/goToNode.js +9 -0
- package/dist/templates/backends/graphGenerator/graphNode.js +15 -0
- package/dist/templates/backends/graphGenerator/imports.js +47 -0
- package/dist/templates/backends/graphGenerator/node.js +18 -0
- package/dist/templates/backends/graphGenerator/promptNode.js +16 -0
- package/dist/templates/backends/graphGenerator/startNode.js +10 -0
- package/dist/templates/backends/typescriptGenerator/builtinFunctions/fetch.js +17 -0
- package/dist/templates/backends/typescriptGenerator/builtinFunctions/fetchJSON.js +17 -0
- package/dist/templates/backends/typescriptGenerator/builtinFunctions/input.js +21 -0
- package/dist/templates/backends/typescriptGenerator/builtinFunctions/read.js +13 -0
- package/dist/templates/backends/typescriptGenerator/builtinTools.js +36 -0
- package/dist/templates/backends/typescriptGenerator/functionDefinition.js +11 -0
- package/dist/templates/backends/typescriptGenerator/imports.js +25 -0
- package/dist/templates/backends/typescriptGenerator/promptFunction.js +76 -0
- package/dist/templates/backends/typescriptGenerator/tool.js +23 -0
- package/dist/templates/backends/typescriptGenerator/toolCall.js +35 -0
- package/dist/types/access.js +1 -0
- package/dist/types/dataStructures.js +1 -0
- package/dist/types/function.js +1 -0
- package/dist/types/graphNode.js +1 -0
- package/dist/types/importStatement.js +1 -0
- package/dist/types/literals.js +1 -0
- package/dist/types/matchBlock.js +1 -0
- package/dist/types/returnStatement.js +1 -0
- package/dist/types/tools.js +1 -0
- package/dist/types/typeHints.js +1 -0
- package/dist/types/whileLoop.js +1 -0
- package/dist/types.js +11 -0
- package/dist/utils.js +18 -0
- package/package.json +52 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { optionalSpaces, varNameChar } from "./utils.js";
|
|
2
|
+
import { capture, captureCaptures, char, count, digit, many1Till, many1WithJoin, or, sepBy, seqC, seqR, set, space, spaces, str, trace, } from "tarsec";
|
|
3
|
+
import { optionalSemicolon } from "./parserUtils.js";
|
|
4
|
+
export const primitiveTypeParser = trace("primitiveTypeParser", seqC(set("type", "primitiveType"), capture(or(str("number"), str("string"), str("boolean")), "value")));
|
|
5
|
+
export const typeAliasVariableParser = trace("typeAliasVariableParser", seqC(set("type", "typeAliasVariable"), capture(many1WithJoin(varNameChar), "aliasName")));
|
|
6
|
+
export const arrayTypeParser = (input) => {
|
|
7
|
+
const parser = trace("arrayTypeParser", seqC(set("type", "arrayType"), capture(or(objectTypeParser, primitiveTypeParser), "elementType"), capture(count(str("[]")), "arrayDepth")));
|
|
8
|
+
const result = parser(input);
|
|
9
|
+
if (result.success) {
|
|
10
|
+
// Wrap the elementType in ArrayType according to arrayDepth
|
|
11
|
+
let wrappedType = result.result.elementType;
|
|
12
|
+
for (let i = 0; i < result.result.arrayDepth; i++) {
|
|
13
|
+
wrappedType = {
|
|
14
|
+
type: "arrayType",
|
|
15
|
+
elementType: wrappedType,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
success: true,
|
|
20
|
+
rest: result.rest,
|
|
21
|
+
result: wrappedType,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
};
|
|
26
|
+
export const angleBracketsArrayTypeParser = trace("angleBracketsArrayTypeParser", seqC(set("type", "arrayType"), str("array"), char("<"), capture(primitiveTypeParser, "elementType"), char(">")));
|
|
27
|
+
export const stringLiteralTypeParser = trace("stringLiteralTypeParser", seqC(set("type", "stringLiteralType"), char('"'), capture(many1Till(char('"')), "value"), char('"')));
|
|
28
|
+
export const numberLiteralTypeParser = trace("numberLiteralTypeParser", seqC(set("type", "numberLiteralType"), capture(many1WithJoin(or(char("-"), char("."), digit)), "value")));
|
|
29
|
+
export const booleanLiteralTypeParser = trace("booleanLiteralTypeParser", seqC(set("type", "booleanLiteralType"), capture(or(str("true"), str("false")), "value")));
|
|
30
|
+
export const objectPropertyDelimiter = seqR(optionalSpaces, char(";"), optionalSpaces);
|
|
31
|
+
export const objectPropertyParser = trace("objectPropertyParser", (input) => {
|
|
32
|
+
const parser = seqC(capture(many1WithJoin(varNameChar), "key"), optionalSpaces, char(":"), optionalSpaces, capture(variableTypeParser, "value"));
|
|
33
|
+
return parser(input);
|
|
34
|
+
});
|
|
35
|
+
export const objectPropertyDescriptionParser = seqC(char("#"), optionalSpaces, capture(many1Till(char(";")), "description"));
|
|
36
|
+
export const objectPropertyWithDescriptionParser = trace("objectPropertyWithDescriptionParser", seqC(captureCaptures(objectPropertyParser), spaces, captureCaptures(objectPropertyDescriptionParser)));
|
|
37
|
+
export const objectTypeParser = trace("objectTypeParser", (input) => {
|
|
38
|
+
const parser = seqC(set("type", "objectType"), char("{"), optionalSpaces, capture(sepBy(objectPropertyDelimiter, or(objectPropertyWithDescriptionParser, objectPropertyParser)), "properties"), optionalSpaces, char("}"));
|
|
39
|
+
return parser(input);
|
|
40
|
+
});
|
|
41
|
+
export const unionItemParser = trace("unionItemParser", or(objectTypeParser, angleBracketsArrayTypeParser, arrayTypeParser, stringLiteralTypeParser, numberLiteralTypeParser, booleanLiteralTypeParser, primitiveTypeParser, typeAliasVariableParser));
|
|
42
|
+
const pipe = seqR(optionalSpaces, str("|"), optionalSpaces);
|
|
43
|
+
export const _unionTypeParser = (input) => {
|
|
44
|
+
const parser = seqC(set("type", "unionType"), capture(sepBy(pipe, unionItemParser), "types"));
|
|
45
|
+
const result = parser(input);
|
|
46
|
+
// Union types must have at least 2 types (i.e., at least one "|")
|
|
47
|
+
if (result.success && result.result.types.length < 2) {
|
|
48
|
+
return {
|
|
49
|
+
success: false,
|
|
50
|
+
rest: input,
|
|
51
|
+
message: "Union type must have at least 2 types",
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return result;
|
|
55
|
+
};
|
|
56
|
+
export const unionTypeParser = trace("unionTypeParser", _unionTypeParser);
|
|
57
|
+
export const variableTypeParser = trace("variableTypeParser", or(unionTypeParser, arrayTypeParser, objectTypeParser, angleBracketsArrayTypeParser, stringLiteralTypeParser, numberLiteralTypeParser, booleanLiteralTypeParser, primitiveTypeParser, typeAliasVariableParser));
|
|
58
|
+
export const typeHintParser = trace("typeHintParser", seqC(set("type", "typeHint"), capture(many1Till(space), "variableName"), optionalSpaces, str("::"), optionalSpaces, capture(variableTypeParser, "variableType"), optionalSemicolon));
|
|
59
|
+
export const typeAliasParser = trace("typeAliasParser", seqC(set("type", "typeAlias"), str("type"), spaces, capture(many1WithJoin(varNameChar), "aliasName"), optionalSpaces, str("="), optionalSpaces, capture(variableTypeParser, "aliasedType"), optionalSemicolon));
|