mlld
Version:
mlld: a modular prompt scripting language
436 lines (422 loc) • 16.9 kB
JavaScript
import { __name, __publicField } from './chunk-OMKLS24H.mjs';
// core/types/guards.ts
function isInterpolatableValueArray(value) {
return Array.isArray(value) && (value.length === 0 || value[0] && typeof value[0] === "object" && "type" in value[0] && (value[0].type === "Text" || value[0].type === "VariableReference"));
}
__name(isInterpolatableValueArray, "isInterpolatableValueArray");
function isTextNode(node) {
return node.type === "Text";
}
__name(isTextNode, "isTextNode");
function isDirectiveNode(node) {
return node.type === "Directive";
}
__name(isDirectiveNode, "isDirectiveNode");
function isCodeFenceNode(node) {
return node.type === "CodeFence";
}
__name(isCodeFenceNode, "isCodeFenceNode");
function isCommentNode(node) {
return node.type === "Comment";
}
__name(isCommentNode, "isCommentNode");
function isVariableReferenceNode(node) {
return node.type === "VariableReference";
}
__name(isVariableReferenceNode, "isVariableReferenceNode");
function isLiteralNode(node) {
return node.type === "Literal";
}
__name(isLiteralNode, "isLiteralNode");
function isDotSeparatorNode(node) {
return node.type === "DotSeparator";
}
__name(isDotSeparatorNode, "isDotSeparatorNode");
function isPathSeparatorNode(node) {
return node.type === "PathSeparator";
}
__name(isPathSeparatorNode, "isPathSeparatorNode");
function isFileReferenceNode(node) {
return node.type === "FileReference";
}
__name(isFileReferenceNode, "isFileReferenceNode");
function isImportDirective(node) {
return node.kind === "import";
}
__name(isImportDirective, "isImportDirective");
function isImportAllDirective(node) {
return node.kind === "import" && node.subtype === "importAll";
}
__name(isImportAllDirective, "isImportAllDirective");
function isImportSelectedDirective(node) {
return node.kind === "import" && node.subtype === "importSelected";
}
__name(isImportSelectedDirective, "isImportSelectedDirective");
function isWildcardImport(node) {
return node.valueType === "import" && node.identifier === "*";
}
__name(isWildcardImport, "isWildcardImport");
function isExecInvocation(node) {
return node?.type === "ExecInvocation";
}
__name(isExecInvocation, "isExecInvocation");
function hasWithClause(directive) {
return directive?.values?.withClause !== void 0;
}
__name(hasWithClause, "hasWithClause");
function isNegationNode(node) {
return node?.type === "Negation";
}
__name(isNegationNode, "isNegationNode");
function isBinaryExpression(node) {
return node?.type === "BinaryExpression";
}
__name(isBinaryExpression, "isBinaryExpression");
function isTernaryExpression(node) {
return node?.type === "TernaryExpression";
}
__name(isTernaryExpression, "isTernaryExpression");
function isUnaryExpression(node) {
return node?.type === "UnaryExpression";
}
__name(isUnaryExpression, "isUnaryExpression");
// core/types/errors.ts
var ParseErrorCode = /* @__PURE__ */ function(ParseErrorCode2) {
ParseErrorCode2["INVALID_SYNTAX"] = "INVALID_SYNTAX";
ParseErrorCode2["INVALID_NODE"] = "INVALID_NODE";
ParseErrorCode2["UNEXPECTED_TOKEN"] = "UNEXPECTED_TOKEN";
ParseErrorCode2["MISSING_REQUIRED_FIELD"] = "MISSING_REQUIRED_FIELD";
ParseErrorCode2["INVALID_DIRECTIVE"] = "INVALID_DIRECTIVE";
return ParseErrorCode2;
}({});
var _MlldAstError = class _MlldAstError extends Error {
constructor(message, code, location) {
super(message);
__publicField(this, "code");
__publicField(this, "location");
this.code = code, this.location = location;
this.name = "MlldAstError";
}
};
__name(_MlldAstError, "MlldAstError");
var MlldAstError = _MlldAstError;
// core/types/show.ts
function isShowDirectiveNode(node) {
return node.kind === "show";
}
__name(isShowDirectiveNode, "isShowDirectiveNode");
function isShowPathDirectiveNode(node) {
return isShowDirectiveNode(node) && node.subtype === "showPath";
}
__name(isShowPathDirectiveNode, "isShowPathDirectiveNode");
function isShowTemplateDirectiveNode(node) {
return isShowDirectiveNode(node) && node.subtype === "showTemplate";
}
__name(isShowTemplateDirectiveNode, "isShowTemplateDirectiveNode");
function isShowVariableDirectiveNode(node) {
return isShowDirectiveNode(node) && node.subtype === "showVariable";
}
__name(isShowVariableDirectiveNode, "isShowVariableDirectiveNode");
function isShowPathSectionDirectiveNode(node) {
return isShowDirectiveNode(node) && node.subtype === "showPathSection";
}
__name(isShowPathSectionDirectiveNode, "isShowPathSectionDirectiveNode");
// core/types/exe.ts
function isExeDirectiveNode(node) {
return node.kind === "exe";
}
__name(isExeDirectiveNode, "isExeDirectiveNode");
function isExeCommandDirective(node) {
return node.subtype === "exeCommand";
}
__name(isExeCommandDirective, "isExeCommandDirective");
function isExeCodeDirective(node) {
return node.subtype === "exeCode";
}
__name(isExeCodeDirective, "isExeCodeDirective");
// core/types/path.ts
function isPathDirective(node) {
return node.kind === "path";
}
__name(isPathDirective, "isPathDirective");
function isPathAssignmentDirective(node) {
return isPathDirective(node) && node.subtype === "pathAssignment";
}
__name(isPathAssignmentDirective, "isPathAssignmentDirective");
function hasSpecialVariablePath(node) {
if (node.values.path.length > 0) {
const firstComponent = node.values.path[0];
if (firstComponent.type === "string" && (firstComponent.value.startsWith("$HOMEPATH") || firstComponent.value.startsWith("$~") || firstComponent.value.startsWith("$PROJECTPATH") || firstComponent.value.startsWith("$."))) {
return true;
}
if (firstComponent.type === "interpolated" && firstComponent.components && firstComponent.components.length > 0 && firstComponent.components[0].type === "specialVariable") {
return true;
}
}
return false;
}
__name(hasSpecialVariablePath, "hasSpecialVariablePath");
// core/types/run.ts
function isRunCommandDirective(node) {
return node.subtype === "runCommand";
}
__name(isRunCommandDirective, "isRunCommandDirective");
function isRunCodeDirective(node) {
return node.subtype === "runCode";
}
__name(isRunCodeDirective, "isRunCodeDirective");
function isRunExecDirective(node) {
return node.subtype === "runExec";
}
__name(isRunExecDirective, "isRunExecDirective");
// core/types/output.ts
function isOutputDirective(node) {
return node.type === "Directive" && node.kind === "output";
}
__name(isOutputDirective, "isOutputDirective");
function isOutputDocumentDirective(node) {
return isOutputDirective(node) && node.subtype === "outputDocument";
}
__name(isOutputDocumentDirective, "isOutputDocumentDirective");
function isOutputFileDirective(node) {
return isOutputDirective(node) && node.subtype === "outputFile";
}
__name(isOutputFileDirective, "isOutputFileDirective");
function isOutputStreamDirective(node) {
return isOutputDirective(node) && node.subtype === "outputStream";
}
__name(isOutputStreamDirective, "isOutputStreamDirective");
function isOutputEnvDirective(node) {
return isOutputDirective(node) && node.subtype === "outputEnv";
}
__name(isOutputEnvDirective, "isOutputEnvDirective");
function isOutputResolverDirective(node) {
return isOutputDirective(node) && node.subtype === "outputResolver";
}
__name(isOutputResolverDirective, "isOutputResolverDirective");
function isFileTarget(target) {
return target.type === "file";
}
__name(isFileTarget, "isFileTarget");
function isStreamTarget(target) {
return target.type === "stream";
}
__name(isStreamTarget, "isStreamTarget");
function isEnvTarget(target) {
return target.type === "env";
}
__name(isEnvTarget, "isEnvTarget");
function isResolverTarget(target) {
return target.type === "resolver";
}
__name(isResolverTarget, "isResolverTarget");
// core/types/when.ts
function isWhenSimpleNode(node) {
return node.kind === "when" && node.subtype === "whenSimple";
}
__name(isWhenSimpleNode, "isWhenSimpleNode");
function isWhenBlockNode(node) {
return node.kind === "when" && node.subtype === "whenBlock";
}
__name(isWhenBlockNode, "isWhenBlockNode");
function isWhenMatchNode(node) {
return node.kind === "when" && node.subtype === "whenMatch";
}
__name(isWhenMatchNode, "isWhenMatchNode");
function isWhenNode(node) {
return node.kind === "when";
}
__name(isWhenNode, "isWhenNode");
// core/types/var.ts
function isVarDirectiveNode(node) {
return node && typeof node === "object" && node.type === "Directive" && node.kind === "var";
}
__name(isVarDirectiveNode, "isVarDirectiveNode");
function isVarExecDefinition(value) {
return typeof value === "object" && value !== null && !Array.isArray(value) && "type" in value && value.type === "varExec";
}
__name(isVarExecDefinition, "isVarExecDefinition");
function isNestedDirective(content) {
return typeof content === "object" && content !== null && !Array.isArray(content) && "kind" in content;
}
__name(isNestedDirective, "isNestedDirective");
function isDataObject(value) {
return typeof value === "object" && value !== null && !Array.isArray(value) && "type" in value && value.type === "object";
}
__name(isDataObject, "isDataObject");
function isDataArray(value) {
return typeof value === "object" && value !== null && !Array.isArray(value) && "type" in value && value.type === "array";
}
__name(isDataArray, "isDataArray");
function isPrimitiveValue(value) {
return value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean";
}
__name(isPrimitiveValue, "isPrimitiveValue");
function isDirectiveValue(value) {
return typeof value === "object" && value !== null && "type" in value && value.type === "Directive" && "kind" in value;
}
__name(isDirectiveValue, "isDirectiveValue");
function isVariableReferenceValue(value) {
if (!Array.isArray(value)) return false;
return value.some((node) => typeof node === "object" && node !== null && "type" in node && node.type === "VariableReference");
}
__name(isVariableReferenceValue, "isVariableReferenceValue");
function isTemplateValue(value) {
if (!Array.isArray(value)) return false;
return value.some((node) => typeof node === "object" && node !== null && "type" in node && (node.type === "Text" || node.type === "VariableReference"));
}
__name(isTemplateValue, "isTemplateValue");
function isDataObjectValue(value) {
return typeof value === "object" && value !== null && !Array.isArray(value) && "type" in value && value.type === "object";
}
__name(isDataObjectValue, "isDataObjectValue");
function isDataArrayValue(value) {
return typeof value === "object" && value !== null && !Array.isArray(value) && "type" in value && value.type === "array";
}
__name(isDataArrayValue, "isDataArrayValue");
function isEmbedDirectiveValue(value) {
return isDirectiveValue(value) && value.kind === "embed";
}
__name(isEmbedDirectiveValue, "isEmbedDirectiveValue");
function isRunDirectiveValue(value) {
return isDirectiveValue(value) && value.kind === "run";
}
__name(isRunDirectiveValue, "isRunDirectiveValue");
function isNestedEmbedDirective(content) {
return isDirectiveValue(content) && content.kind === "embed";
}
__name(isNestedEmbedDirective, "isNestedEmbedDirective");
function isNestedRunDirective(content) {
return isDirectiveValue(content) && content.kind === "run";
}
__name(isNestedRunDirective, "isNestedRunDirective");
function isContentNodes(value) {
return Array.isArray(value);
}
__name(isContentNodes, "isContentNodes");
function isForeachExpression(value) {
return typeof value === "object" && value !== null && !Array.isArray(value) && "type" in value && (value.type === "foreach-command" || value.type === "foreach-section");
}
__name(isForeachExpression, "isForeachExpression");
// core/types/for.ts
function isForDirective(node) {
return node.kind === "for" && node.subtype === "for";
}
__name(isForDirective, "isForDirective");
function isForExpression(node) {
return node.type === "ForExpression";
}
__name(isForExpression, "isForExpression");
// core/types/variables.ts
var VariableValueType = /* @__PURE__ */ function(VariableValueType2) {
VariableValueType2["TEXT"] = "text";
VariableValueType2["DATA"] = "data";
VariableValueType2["PATH"] = "path";
VariableValueType2["EXEC"] = "exec";
VariableValueType2["IMPORT"] = "import";
VariableValueType2["VAR_INTERPOLATION"] = "varInterpolation";
VariableValueType2["VAR_IDENTIFIER"] = "varIdentifier";
return VariableValueType2;
}({});
var VALID_VARIABLE_TYPES = [
// Core types
"text",
"data",
"path",
"exec",
"import",
// New universal types
"varInterpolation",
"varIdentifier"
];
function isValidVariableType(type) {
return VALID_VARIABLE_TYPES.includes(type);
}
__name(isValidVariableType, "isValidVariableType");
function createVariableReferenceNode(identifier, valueType, fields, format, location) {
return {
type: "VariableReference",
identifier,
valueType,
fields,
isVariableReference: true,
nodeId: "generated-" + Date.now() + "-" + Math.random(),
...format && {
format
},
...location && {
location
}
};
}
__name(createVariableReferenceNode, "createVariableReferenceNode");
// core/types/executable.ts
function isCommandExecutable(def) {
return def.type === "command";
}
__name(isCommandExecutable, "isCommandExecutable");
function isCommandRefExecutable(def) {
return def.type === "commandRef";
}
__name(isCommandRefExecutable, "isCommandRefExecutable");
function isCodeExecutable(def) {
return def.type === "code";
}
__name(isCodeExecutable, "isCodeExecutable");
function isTemplateExecutable(def) {
return def.type === "template";
}
__name(isTemplateExecutable, "isTemplateExecutable");
function isSectionExecutable(def) {
return def.type === "section";
}
__name(isSectionExecutable, "isSectionExecutable");
function isResolverExecutable(def) {
return def.type === "resolver";
}
__name(isResolverExecutable, "isResolverExecutable");
function isExecSourced(def) {
return def.sourceDirective === "exec";
}
__name(isExecSourced, "isExecSourced");
function isTextSourced(def) {
return def.sourceDirective === "text";
}
__name(isTextSourced, "isTextSourced");
// core/types/index.ts
function astLocationToSourceLocation(astLocation, filePath) {
if (!astLocation) return void 0;
return {
line: astLocation.start.line,
column: astLocation.start.column,
offset: astLocation.start.offset,
filePath
};
}
__name(astLocationToSourceLocation, "astLocationToSourceLocation");
function isExtendedVariable(variable) {
return variable !== null && typeof variable === "object" && "type" in variable;
}
__name(isExtendedVariable, "isExtendedVariable");
function createPreciseLocation(line, column, filePath, offset) {
return {
filePath,
line,
column,
offset
};
}
__name(createPreciseLocation, "createPreciseLocation");
function createFileLocation(filePath) {
return {
filePath
};
}
__name(createFileLocation, "createFileLocation");
function isPreciseLocation(location) {
return typeof location.line === "number" && typeof location.column === "number";
}
__name(isPreciseLocation, "isPreciseLocation");
export { MlldAstError, ParseErrorCode, VALID_VARIABLE_TYPES, VariableValueType, astLocationToSourceLocation, createFileLocation, createPreciseLocation, createVariableReferenceNode, hasSpecialVariablePath, hasWithClause, isBinaryExpression, isCodeExecutable, isCodeFenceNode, isCommandExecutable, isCommandRefExecutable, isCommentNode, isContentNodes, isDataArray, isDataArrayValue, isDataObject, isDataObjectValue, isDirectiveNode, isDirectiveValue, isDotSeparatorNode, isEmbedDirectiveValue, isEnvTarget, isExeCodeDirective, isExeCommandDirective, isExeDirectiveNode, isExecInvocation, isExecSourced, isExtendedVariable, isFileReferenceNode, isFileTarget, isForDirective, isForExpression, isForeachExpression, isImportAllDirective, isImportDirective, isImportSelectedDirective, isInterpolatableValueArray, isLiteralNode, isNegationNode, isNestedDirective, isNestedEmbedDirective, isNestedRunDirective, isOutputDirective, isOutputDocumentDirective, isOutputEnvDirective, isOutputFileDirective, isOutputResolverDirective, isOutputStreamDirective, isPathAssignmentDirective, isPathDirective, isPathSeparatorNode, isPreciseLocation, isPrimitiveValue, isResolverExecutable, isResolverTarget, isRunCodeDirective, isRunCommandDirective, isRunDirectiveValue, isRunExecDirective, isSectionExecutable, isShowDirectiveNode, isShowPathDirectiveNode, isShowPathSectionDirectiveNode, isShowTemplateDirectiveNode, isShowVariableDirectiveNode, isStreamTarget, isTemplateExecutable, isTemplateValue, isTernaryExpression, isTextNode, isTextSourced, isUnaryExpression, isValidVariableType, isVarDirectiveNode, isVarExecDefinition, isVariableReferenceNode, isVariableReferenceValue, isWhenBlockNode, isWhenMatchNode, isWhenNode, isWhenSimpleNode, isWildcardImport };
//# sourceMappingURL=chunk-6BOVVHHZ.mjs.map
//# sourceMappingURL=chunk-6BOVVHHZ.mjs.map