src/modules/Elsa.Dsl.ElsaScript/README.md
This document provides an overview of the ElsaScript DSL implementation for Elsa Workflows.
ElsaScript is a JavaScript-inspired textual DSL for authoring Elsa 3 workflows. It provides a concise, code-centric alternative to C# WorkflowBuilder APIs and JSON workflow definitions.
ElsaScriptParser)The parser uses a simplified regex-based approach to parse ElsaScript source code into an Abstract Syntax Tree (AST).
Supported Syntax:
use statements for namespaces and expression language configurationworkflow "Name" { ... } declarationsvar, let, const=>, js =>, cs =>, py =>, liquid =>)listen keyword for workflow triggers (partial support)Complete set of AST node types:
WorkflowNode - Root workflow definitionStatementNode base class with implementations:
VariableDeclarationNodeActivityInvocationNodeBlockNode (for sequences)IfNode, ForEachNode, ForNode, WhileNode, SwitchNodeFlowchartNode, ListenNodeExpressionNode base class with implementations:
LiteralNode, IdentifierNode, ArrayLiteralNodeElsaExpressionNode (with language support)TemplateStringNode, BinaryExpressionNode, UnaryExpressionNodeArgumentNode for activity parametersUseNode for import/configuration statementsElsaScriptCompiler)Compiles AST to Elsa workflow activities:
SequenceVariable instancesIActivityRegistryIntegration with Elsa's module system:
ElsaScriptFeature for service registrationModuleExtensions.UseElsaScript() for easy setupIElsaScriptParser and IElsaScriptCompiler servicesuse Elsa.Activities.Console;
use expressions js;
workflow "HelloWorld" {
var greeting = "Hello";
WriteLine(=> greeting + " World");
WriteLine("Great to meet you!");
}
Six integration tests demonstrate the implementation:
This is a foundation implementation with several areas for future enhancement:
let result = Activity())Current tests focus on:
Additional testing needed for:
The simplified regex-based parser was chosen to deliver a working proof-of-concept quickly. While less robust than a full Parlot implementation, it demonstrates the DSL concept and can be replaced with a more sophisticated parser later.
The separation allows for:
Rather than creating a new expression language, ElsaScript wraps Elsa's existing expression providers (JavaScript, C#, Python, Liquid). This provides:
src/modules/Elsa.Dsl.ElsaScript/
Ast/ - AST node definitionsCompiler/ - AST to Elsa workflow compilerContracts/ - Service interfacesExtensions/ - DI extension methodsFeatures/ - Elsa feature moduleParser/ - ElsaScript parserElsa.Dsl.ElsaScript.csproj - Project filetest/integration/Elsa.Dsl.ElsaScript.IntegrationTests/
ParserTests.cs - Parser integration testsCompilerTests.cs - Compiler integration testsElsa.Dsl.ElsaScript.IntegrationTests.csproj - Test projectDirectory.Packages.props - Added Parlot package referenceThe ElsaScript DSL provides a solid foundation for text-based workflow authoring in Elsa 3. While this initial implementation has limitations, it demonstrates the core concepts and provides a framework for future enhancements. The modular architecture integrates cleanly with Elsa's existing systems and can be extended incrementally.