agency-lang 0.0.25 → 0.0.27
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.
|
@@ -2,7 +2,7 @@ import { capture, captureCaptures, char, debug, many, many1, many1Till, many1Wit
|
|
|
2
2
|
import { accessExpressionParser, indexAccessParser } from "./access.js";
|
|
3
3
|
import { commentParser } from "./comment.js";
|
|
4
4
|
import { functionCallParser } from "./functionCall.js";
|
|
5
|
-
import { literalParser } from "./literals.js";
|
|
5
|
+
import { literalParser, promptParser } from "./literals.js";
|
|
6
6
|
import { matchBlockParser } from "./matchBlock.js";
|
|
7
7
|
import { optionalSemicolon } from "./parserUtils.js";
|
|
8
8
|
import { returnStatementParser } from "./returnStatement.js";
|
|
@@ -14,7 +14,7 @@ import { agencyArrayParser, agencyObjectParser } from "./dataStructures.js";
|
|
|
14
14
|
import { awaitParser } from "./await.js";
|
|
15
15
|
import { newLineParser } from "./newline.js";
|
|
16
16
|
export const assignmentParser = (input) => {
|
|
17
|
-
const parser = trace("assignmentParser", seqC(set("type", "assignment"), optionalSpaces, capture(many1WithJoin(varNameChar), "variableName"), optionalSpaces, optional(captureCaptures(seqC(char(":"), optionalSpaces, capture(variableTypeParser, "typeHint")))), optionalSpaces, char("="), optionalSpaces, capture(or(timeBlockParser, awaitParser, functionCallParser, indexAccessParser, accessExpressionParser, agencyArrayParser, agencyObjectParser, literalParser), "value"), optionalSemicolon));
|
|
17
|
+
const parser = trace("assignmentParser", seqC(set("type", "assignment"), optionalSpaces, capture(many1WithJoin(varNameChar), "variableName"), optionalSpaces, optional(captureCaptures(seqC(char(":"), optionalSpaces, capture(variableTypeParser, "typeHint")))), optionalSpaces, char("="), optionalSpaces, capture(or(timeBlockParser, awaitParser, promptParser, functionCallParser, indexAccessParser, accessExpressionParser, agencyArrayParser, agencyObjectParser, literalParser), "value"), optionalSemicolon));
|
|
18
18
|
return parser(input);
|
|
19
19
|
};
|
|
20
20
|
const trim = (s) => s.trim();
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { InterpolationSegment, Literal,
|
|
1
|
+
import { InterpolationSegment, Literal, NumberLiteral, PromptLiteral, StringLiteral, TextSegment, VariableNameLiteral } from "../types.js";
|
|
2
2
|
import { Parser } from "tarsec";
|
|
3
3
|
export declare const textSegmentParser: Parser<TextSegment>;
|
|
4
4
|
export declare const stringTextSegmentParser: Parser<TextSegment>;
|
|
5
5
|
export declare const interpolationSegmentParser: Parser<InterpolationSegment>;
|
|
6
|
+
export declare const promptParserBackticks: Parser<PromptLiteral>;
|
|
7
|
+
export declare const promptParserLlmFunction: Parser<PromptLiteral>;
|
|
6
8
|
export declare const promptParser: Parser<PromptLiteral>;
|
|
7
9
|
export declare const numberParser: Parser<NumberLiteral>;
|
|
8
10
|
export declare const stringParser: Parser<StringLiteral>;
|
|
9
|
-
export declare const multiLineStringParser: Parser<
|
|
11
|
+
export declare const multiLineStringParser: Parser<StringLiteral>;
|
|
10
12
|
export declare const variableNameParser: Parser<VariableNameLiteral>;
|
|
11
13
|
export declare const literalParser: Parser<Literal>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { backtick, varNameChar } from "./utils.js";
|
|
1
|
+
import { backtick, optionalSpaces, varNameChar } from "./utils.js";
|
|
2
2
|
import { capture, char, digit, letter, many, many1Till, many1WithJoin, manyTillStr, manyWithJoin, map, or, seq, seqC, set, str, } from "tarsec";
|
|
3
3
|
export const textSegmentParser = map(many1Till(or(backtick, char("$"))), (text) => ({
|
|
4
4
|
type: "text",
|
|
@@ -9,10 +9,15 @@ export const stringTextSegmentParser = map(many1Till(or(char('"'), char("$"))),
|
|
|
9
9
|
value: text,
|
|
10
10
|
}));
|
|
11
11
|
export const interpolationSegmentParser = seqC(set("type", "interpolation"), char("$"), char("{"), capture(manyTillStr("}"), "variableName"), char("}"));
|
|
12
|
-
export const
|
|
12
|
+
export const promptParserBackticks = seqC(set("type", "prompt"), backtick, capture(many(or(textSegmentParser, interpolationSegmentParser)), "segments"), backtick);
|
|
13
|
+
export const promptParserLlmFunction = (input) => {
|
|
14
|
+
const parser = seqC(set("type", "prompt"), str("llm("), optionalSpaces, capture(map(stringParser, (str) => str.segments), "segments"), optionalSpaces, char(")"));
|
|
15
|
+
return parser(input);
|
|
16
|
+
};
|
|
17
|
+
export const promptParser = or(promptParserBackticks, promptParserLlmFunction);
|
|
13
18
|
export const numberParser = seqC(set("type", "number"), capture(many1WithJoin(or(char("-"), char("."), digit)), "value"));
|
|
14
19
|
export const stringParser = seqC(set("type", "string"), char('"'), capture(many(or(stringTextSegmentParser, interpolationSegmentParser)), "segments"), char('"'));
|
|
15
|
-
export const multiLineStringParser = seqC(set("type", "
|
|
20
|
+
export const multiLineStringParser = seqC(set("type", "string"), str('"""'), capture(many(or(stringTextSegmentParser, interpolationSegmentParser)), "segments"), str('"""'));
|
|
16
21
|
export const variableNameParser = seq([
|
|
17
22
|
set("type", "variableName"),
|
|
18
23
|
capture(letter, "init"),
|