Incremental work on DSL

This commit is contained in:
Sipke Schoorstra 2022-03-29 13:16:06 +02:00
parent 488ea1ef98
commit 034bedfb46
16 changed files with 249 additions and 158 deletions

View file

@ -2,12 +2,14 @@ namespace Elsa.Models;
public abstract class Argument
{
protected Argument(){}
protected Argument(RegisterLocationReference locationReference, Func<object?, object?>? valueConverter = default)
{
LocationReference = locationReference;
ValueConverter = valueConverter;
}
public RegisterLocationReference LocationReference { get; set; }
public RegisterLocationReference LocationReference { get; set; } = default!;
public Func<object?, object?>? ValueConverter { get; set; }
}

View file

@ -143,7 +143,7 @@ public partial class ElsaParser : Parser {
State = 46;
ErrorHandler.Sync(this);
_la = TokenStream.LA(1);
while ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << NEW) | (1L << VARIABLE) | (1L << LET) | (1L << IF) | (1L << FOR) | (1L << RETURN) | (1L << MINUS) | (1L << PARENTHESES_OPEN) | (1L << BRACKET_OPEN) | (1L << CURLYBRACE_OPEN) | (1L << EXCLAMATION) | (1L << STRING_VAL) | (1L << BACKTICKSTRING_VAL) | (1L << LINE_COMMENT) | (1L << INTEGER_VAL) | (1L << ID))) != 0)) {
while ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << NEW) | (1L << VARIABLE) | (1L << LET) | (1L << IF) | (1L << FOR) | (1L << RETURN) | (1L << EXPRESSION_MARKER) | (1L << MINUS) | (1L << PARENTHESES_OPEN) | (1L << BRACKET_OPEN) | (1L << CURLYBRACE_OPEN) | (1L << EXCLAMATION) | (1L << STRING_VAL) | (1L << BACKTICKSTRING_VAL) | (1L << LINE_COMMENT) | (1L << INTEGER_VAL) | (1L << ID))) != 0)) {
{
State = 44;
ErrorHandler.Sync(this);
@ -154,6 +154,7 @@ public partial class ElsaParser : Parser {
case IF:
case FOR:
case RETURN:
case EXPRESSION_MARKER:
case MINUS:
case PARENTHESES_OPEN:
case BRACKET_OPEN:
@ -900,7 +901,7 @@ public partial class ElsaParser : Parser {
State = 134;
ErrorHandler.Sync(this);
_la = TokenStream.LA(1);
while ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << NEW) | (1L << VARIABLE) | (1L << LET) | (1L << IF) | (1L << FOR) | (1L << RETURN) | (1L << MINUS) | (1L << PARENTHESES_OPEN) | (1L << BRACKET_OPEN) | (1L << CURLYBRACE_OPEN) | (1L << EXCLAMATION) | (1L << STRING_VAL) | (1L << BACKTICKSTRING_VAL) | (1L << INTEGER_VAL) | (1L << ID))) != 0)) {
while ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << NEW) | (1L << VARIABLE) | (1L << LET) | (1L << IF) | (1L << FOR) | (1L << RETURN) | (1L << EXPRESSION_MARKER) | (1L << MINUS) | (1L << PARENTHESES_OPEN) | (1L << BRACKET_OPEN) | (1L << CURLYBRACE_OPEN) | (1L << EXCLAMATION) | (1L << STRING_VAL) | (1L << BACKTICKSTRING_VAL) | (1L << INTEGER_VAL) | (1L << ID))) != 0)) {
{
{
State = 131;
@ -1326,7 +1327,7 @@ public partial class ElsaParser : Parser {
State = 182;
ErrorHandler.Sync(this);
_la = TokenStream.LA(1);
if ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << NEW) | (1L << MINUS) | (1L << PARENTHESES_OPEN) | (1L << BRACKET_OPEN) | (1L << EXCLAMATION) | (1L << STRING_VAL) | (1L << BACKTICKSTRING_VAL) | (1L << INTEGER_VAL) | (1L << ID))) != 0)) {
if ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << NEW) | (1L << EXPRESSION_MARKER) | (1L << MINUS) | (1L << PARENTHESES_OPEN) | (1L << BRACKET_OPEN) | (1L << EXCLAMATION) | (1L << STRING_VAL) | (1L << BACKTICKSTRING_VAL) | (1L << INTEGER_VAL) | (1L << ID))) != 0)) {
{
State = 181;
expr(0);
@ -1684,6 +1685,18 @@ public partial class ElsaParser : Parser {
else return visitor.VisitChildren(this);
}
}
public partial class ExpressionMarkerExprContext : ExprContext {
[System.Diagnostics.DebuggerNonUserCode] public ExpressionMarkerContext expressionMarker() {
return GetRuleContext<ExpressionMarkerContext>(0);
}
public ExpressionMarkerExprContext(ExprContext context) { CopyFrom(context); }
[System.Diagnostics.DebuggerNonUserCode]
public override TResult Accept<TResult>(IParseTreeVisitor<TResult> visitor) {
IElsaParserVisitor<TResult> typedVisitor = visitor as IElsaParserVisitor<TResult>;
if (typedVisitor != null) return typedVisitor.VisitExpressionMarkerExpr(this);
else return visitor.VisitChildren(this);
}
}
public partial class BackTickStringValueExprContext : ExprContext {
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode BACKTICKSTRING_VAL() { return GetToken(ElsaParser.BACKTICKSTRING_VAL, 0); }
public BackTickStringValueExprContext(ExprContext context) { CopyFrom(context); }
@ -1718,6 +1731,9 @@ public partial class ElsaParser : Parser {
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode EQUALS() { return GetToken(ElsaParser.EQUALS, 0); }
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode GREATER() { return GetToken(ElsaParser.GREATER, 0); }
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode LESS() { return GetToken(ElsaParser.LESS, 0); }
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode NOT_EQUALS() { return GetToken(ElsaParser.NOT_EQUALS, 0); }
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode GREATER_EQUALS() { return GetToken(ElsaParser.GREATER_EQUALS, 0); }
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode LESS_EQUALS() { return GetToken(ElsaParser.LESS_EQUALS, 0); }
public CompareExprContext(ExprContext context) { CopyFrom(context); }
[System.Diagnostics.DebuggerNonUserCode]
public override TResult Accept<TResult>(IParseTreeVisitor<TResult> visitor) {
@ -1744,7 +1760,7 @@ public partial class ElsaParser : Parser {
int _alt;
EnterOuterAlt(_localctx, 1);
{
State = 229;
State = 230;
ErrorHandler.Sync(this);
switch ( Interpreter.AdaptivePredict(TokenStream,22,Context) ) {
case 1:
@ -1759,134 +1775,143 @@ public partial class ElsaParser : Parser {
break;
case 2:
{
_localctx = new ObjectExprContext(_localctx);
_localctx = new ExpressionMarkerExprContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
State = 208;
@object();
expressionMarker();
}
break;
case 3:
{
_localctx = new NewObjectExprContext(_localctx);
_localctx = new ObjectExprContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
State = 209;
newObject();
@object();
}
break;
case 4:
{
_localctx = new NegateExprContext(_localctx);
_localctx = new NewObjectExprContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
State = 210;
Match(MINUS);
State = 211;
expr(13);
newObject();
}
break;
case 5:
{
_localctx = new NotExprContext(_localctx);
_localctx = new NegateExprContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
State = 211;
Match(MINUS);
State = 212;
Match(EXCLAMATION);
State = 213;
expr(12);
expr(13);
}
break;
case 6:
{
_localctx = new IntegerValueExprContext(_localctx);
_localctx = new NotExprContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
State = 213;
Match(EXCLAMATION);
State = 214;
Match(INTEGER_VAL);
expr(12);
}
break;
case 7:
{
_localctx = new StringValueExprContext(_localctx);
_localctx = new IntegerValueExprContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
State = 215;
Match(STRING_VAL);
Match(INTEGER_VAL);
}
break;
case 8:
{
_localctx = new BackTickStringValueExprContext(_localctx);
_localctx = new StringValueExprContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
State = 216;
Match(BACKTICKSTRING_VAL);
Match(STRING_VAL);
}
break;
case 9:
{
_localctx = new ParenthesesExprContext(_localctx);
_localctx = new BackTickStringValueExprContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
State = 217;
Match(PARENTHESES_OPEN);
State = 219;
ErrorHandler.Sync(this);
_la = TokenStream.LA(1);
if ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << NEW) | (1L << MINUS) | (1L << PARENTHESES_OPEN) | (1L << BRACKET_OPEN) | (1L << EXCLAMATION) | (1L << STRING_VAL) | (1L << BACKTICKSTRING_VAL) | (1L << INTEGER_VAL) | (1L << ID))) != 0)) {
{
State = 218;
exprList();
}
}
State = 221;
Match(PARENTHESES_CLOSE);
Match(BACKTICKSTRING_VAL);
}
break;
case 10:
{
_localctx = new BracketsExprContext(_localctx);
_localctx = new ParenthesesExprContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
State = 222;
Match(BRACKET_OPEN);
State = 224;
State = 218;
Match(PARENTHESES_OPEN);
State = 220;
ErrorHandler.Sync(this);
_la = TokenStream.LA(1);
if ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << NEW) | (1L << MINUS) | (1L << PARENTHESES_OPEN) | (1L << BRACKET_OPEN) | (1L << EXCLAMATION) | (1L << STRING_VAL) | (1L << BACKTICKSTRING_VAL) | (1L << INTEGER_VAL) | (1L << ID))) != 0)) {
if ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << NEW) | (1L << EXPRESSION_MARKER) | (1L << MINUS) | (1L << PARENTHESES_OPEN) | (1L << BRACKET_OPEN) | (1L << EXCLAMATION) | (1L << STRING_VAL) | (1L << BACKTICKSTRING_VAL) | (1L << INTEGER_VAL) | (1L << ID))) != 0)) {
{
State = 223;
State = 219;
exprList();
}
}
State = 226;
Match(BRACKET_CLOSE);
State = 222;
Match(PARENTHESES_CLOSE);
}
break;
case 11:
{
_localctx = new MethodCallExprContext(_localctx);
_localctx = new BracketsExprContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
State = 223;
Match(BRACKET_OPEN);
State = 225;
ErrorHandler.Sync(this);
_la = TokenStream.LA(1);
if ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << NEW) | (1L << EXPRESSION_MARKER) | (1L << MINUS) | (1L << PARENTHESES_OPEN) | (1L << BRACKET_OPEN) | (1L << EXCLAMATION) | (1L << STRING_VAL) | (1L << BACKTICKSTRING_VAL) | (1L << INTEGER_VAL) | (1L << ID))) != 0)) {
{
State = 224;
exprList();
}
}
State = 227;
methodCall();
Match(BRACKET_CLOSE);
}
break;
case 12:
{
_localctx = new VariableExprContext(_localctx);
_localctx = new MethodCallExprContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
State = 228;
methodCall();
}
break;
case 13:
{
_localctx = new VariableExprContext(_localctx);
Context = _localctx;
_prevctx = _localctx;
State = 229;
Match(ID);
}
break;
}
Context.Stop = TokenStream.LT(-1);
State = 249;
State = 250;
ErrorHandler.Sync(this);
_alt = Interpreter.AdaptivePredict(TokenStream,24,Context);
while ( _alt!=2 && _alt!=global::Antlr4.Runtime.Atn.ATN.INVALID_ALT_NUMBER ) {
@ -1895,18 +1920,18 @@ public partial class ElsaParser : Parser {
TriggerExitRuleEvent();
_prevctx = _localctx;
{
State = 247;
State = 248;
ErrorHandler.Sync(this);
switch ( Interpreter.AdaptivePredict(TokenStream,23,Context) ) {
case 1:
{
_localctx = new MultiplyExprContext(new ExprContext(_parentctx, _parentState));
PushNewRecursionContext(_localctx, _startState, RULE_expr);
State = 231;
if (!(Precpred(Context, 11))) throw new FailedPredicateException(this, "Precpred(Context, 11)");
State = 232;
Match(STAR);
if (!(Precpred(Context, 11))) throw new FailedPredicateException(this, "Precpred(Context, 11)");
State = 233;
Match(STAR);
State = 234;
expr(12);
}
break;
@ -1914,11 +1939,11 @@ public partial class ElsaParser : Parser {
{
_localctx = new AddExprContext(new ExprContext(_parentctx, _parentState));
PushNewRecursionContext(_localctx, _startState, RULE_expr);
State = 234;
if (!(Precpred(Context, 10))) throw new FailedPredicateException(this, "Precpred(Context, 10)");
State = 235;
Match(PLUS);
if (!(Precpred(Context, 10))) throw new FailedPredicateException(this, "Precpred(Context, 10)");
State = 236;
Match(PLUS);
State = 237;
expr(11);
}
break;
@ -1926,11 +1951,11 @@ public partial class ElsaParser : Parser {
{
_localctx = new SubtractExprContext(new ExprContext(_parentctx, _parentState));
PushNewRecursionContext(_localctx, _startState, RULE_expr);
State = 237;
if (!(Precpred(Context, 9))) throw new FailedPredicateException(this, "Precpred(Context, 9)");
State = 238;
Match(MINUS);
if (!(Precpred(Context, 9))) throw new FailedPredicateException(this, "Precpred(Context, 9)");
State = 239;
Match(MINUS);
State = 240;
expr(10);
}
break;
@ -1938,18 +1963,18 @@ public partial class ElsaParser : Parser {
{
_localctx = new CompareExprContext(new ExprContext(_parentctx, _parentState));
PushNewRecursionContext(_localctx, _startState, RULE_expr);
State = 240;
if (!(Precpred(Context, 8))) throw new FailedPredicateException(this, "Precpred(Context, 8)");
State = 241;
if (!(Precpred(Context, 8))) throw new FailedPredicateException(this, "Precpred(Context, 8)");
State = 242;
_la = TokenStream.LA(1);
if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << GREATER) | (1L << EQUALS) | (1L << LESS))) != 0)) ) {
if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << GREATER) | (1L << EQUALS) | (1L << NOT_EQUALS) | (1L << GREATER_EQUALS) | (1L << LESS) | (1L << LESS_EQUALS))) != 0)) ) {
ErrorHandler.RecoverInline(this);
}
else {
ErrorHandler.ReportMatch(this);
Consume();
}
State = 242;
State = 243;
expr(9);
}
break;
@ -1957,9 +1982,9 @@ public partial class ElsaParser : Parser {
{
_localctx = new IncrementExprContext(new ExprContext(_parentctx, _parentState));
PushNewRecursionContext(_localctx, _startState, RULE_expr);
State = 243;
if (!(Precpred(Context, 15))) throw new FailedPredicateException(this, "Precpred(Context, 15)");
State = 244;
if (!(Precpred(Context, 15))) throw new FailedPredicateException(this, "Precpred(Context, 15)");
State = 245;
Match(INCREMENT);
}
break;
@ -1967,16 +1992,16 @@ public partial class ElsaParser : Parser {
{
_localctx = new DecrementExprContext(new ExprContext(_parentctx, _parentState));
PushNewRecursionContext(_localctx, _startState, RULE_expr);
State = 245;
if (!(Precpred(Context, 14))) throw new FailedPredicateException(this, "Precpred(Context, 14)");
State = 246;
if (!(Precpred(Context, 14))) throw new FailedPredicateException(this, "Precpred(Context, 14)");
State = 247;
Match(DECREMENT);
}
break;
}
}
}
State = 251;
State = 252;
ErrorHandler.Sync(this);
_alt = Interpreter.AdaptivePredict(TokenStream,24,Context);
}
@ -2025,21 +2050,21 @@ public partial class ElsaParser : Parser {
try {
EnterOuterAlt(_localctx, 1);
{
State = 252;
State = 253;
expr(0);
State = 257;
State = 258;
ErrorHandler.Sync(this);
_la = TokenStream.LA(1);
while (_la==COMMA) {
{
{
State = 253;
Match(COMMA);
State = 254;
Match(COMMA);
State = 255;
expr(0);
}
}
State = 259;
State = 260;
ErrorHandler.Sync(this);
_la = TokenStream.LA(1);
}
@ -2076,7 +2101,7 @@ public partial class ElsaParser : Parser {
private static char[] _serializedATN = {
'\x3', '\x608B', '\xA72A', '\x8133', '\xB9ED', '\x417C', '\x3BE7', '\x7786',
'\x5964', '\x3', '\x32', '\x107', '\x4', '\x2', '\t', '\x2', '\x4', '\x3',
'\x5964', '\x3', '\x32', '\x108', '\x4', '\x2', '\t', '\x2', '\x4', '\x3',
'\t', '\x3', '\x4', '\x4', '\t', '\x4', '\x4', '\x5', '\t', '\x5', '\x4',
'\x6', '\t', '\x6', '\x4', '\a', '\t', '\a', '\x4', '\b', '\t', '\b',
'\x4', '\t', '\t', '\t', '\x4', '\n', '\t', '\n', '\x4', '\v', '\t', '\v',
@ -2120,20 +2145,20 @@ public partial class ElsaParser : Parser {
'\x13', '\x3', '\x14', '\x3', '\x14', '\x3', '\x15', '\x3', '\x15', '\x3',
'\x15', '\x3', '\x15', '\x3', '\x15', '\x3', '\x15', '\x3', '\x15', '\x3',
'\x15', '\x3', '\x15', '\x3', '\x15', '\x3', '\x15', '\x3', '\x15', '\x3',
'\x15', '\x5', '\x15', '\xDE', '\n', '\x15', '\x3', '\x15', '\x3', '\x15',
'\x3', '\x15', '\x5', '\x15', '\xE3', '\n', '\x15', '\x3', '\x15', '\x3',
'\x15', '\x3', '\x15', '\x5', '\x15', '\xE8', '\n', '\x15', '\x3', '\x15',
'\x15', '\x3', '\x15', '\x5', '\x15', '\xDF', '\n', '\x15', '\x3', '\x15',
'\x3', '\x15', '\x3', '\x15', '\x5', '\x15', '\xE4', '\n', '\x15', '\x3',
'\x15', '\x3', '\x15', '\x3', '\x15', '\x5', '\x15', '\xE9', '\n', '\x15',
'\x3', '\x15', '\x3', '\x15', '\x3', '\x15', '\x3', '\x15', '\x3', '\x15',
'\x3', '\x15', '\x3', '\x15', '\x3', '\x15', '\x3', '\x15', '\x3', '\x15',
'\x3', '\x15', '\x3', '\x15', '\x3', '\x15', '\x3', '\x15', '\x3', '\x15',
'\a', '\x15', '\xFA', '\n', '\x15', '\f', '\x15', '\xE', '\x15', '\xFD',
'\v', '\x15', '\x3', '\x16', '\x3', '\x16', '\x3', '\x16', '\a', '\x16',
'\x102', '\n', '\x16', '\f', '\x16', '\xE', '\x16', '\x105', '\v', '\x16',
'\x3', '\x16', '\x3', 'j', '\x3', '(', '\x17', '\x2', '\x4', '\x6', '\b',
'\n', '\f', '\xE', '\x10', '\x12', '\x14', '\x16', '\x18', '\x1A', '\x1C',
'\x1E', ' ', '\"', '$', '&', '(', '*', '\x2', '\x4', '\x4', '\x2', '\xF',
'\x13', '\x30', '\x30', '\x5', '\x2', '\x4', '\x4', '\x1C', '\x1C', '\x1F',
'\x1F', '\x2', '\x120', '\x2', '\x30', '\x3', '\x2', '\x2', '\x2', '\x4',
'\x3', '\x15', '\a', '\x15', '\xFB', '\n', '\x15', '\f', '\x15', '\xE',
'\x15', '\xFE', '\v', '\x15', '\x3', '\x16', '\x3', '\x16', '\x3', '\x16',
'\a', '\x16', '\x103', '\n', '\x16', '\f', '\x16', '\xE', '\x16', '\x106',
'\v', '\x16', '\x3', '\x16', '\x3', 'j', '\x3', '(', '\x17', '\x2', '\x4',
'\x6', '\b', '\n', '\f', '\xE', '\x10', '\x12', '\x14', '\x16', '\x18',
'\x1A', '\x1C', '\x1E', ' ', '\"', '$', '&', '(', '*', '\x2', '\x4', '\x4',
'\x2', '\xF', '\x13', '\x30', '\x30', '\x4', '\x2', '\x4', '\x4', '\x1C',
' ', '\x2', '\x122', '\x2', '\x30', '\x3', '\x2', '\x2', '\x2', '\x4',
'\x33', '\x3', '\x2', '\x2', '\x2', '\x6', '\x37', '\x3', '\x2', '\x2',
'\x2', '\b', '\x45', '\x3', '\x2', '\x2', '\x2', '\n', 'O', '\x3', '\x2',
'\x2', '\x2', '\f', 'Y', '\x3', '\x2', '\x2', '\x2', '\xE', '\x65', '\x3',
@ -2144,7 +2169,7 @@ public partial class ElsaParser : Parser {
'\x3', '\x2', '\x2', '\x2', '\x1E', '\x93', '\x3', '\x2', '\x2', '\x2',
' ', '\x9B', '\x3', '\x2', '\x2', '\x2', '\"', '\xCA', '\x3', '\x2', '\x2',
'\x2', '$', '\xCC', '\x3', '\x2', '\x2', '\x2', '&', '\xCE', '\x3', '\x2',
'\x2', '\x2', '(', '\xE7', '\x3', '\x2', '\x2', '\x2', '*', '\xFE', '\x3',
'\x2', '\x2', '(', '\xE8', '\x3', '\x2', '\x2', '\x2', '*', '\xFF', '\x3',
'\x2', '\x2', '\x2', ',', '/', '\x5', '\"', '\x12', '\x2', '-', '/', '\a',
'.', '\x2', '\x2', '.', ',', '\x3', '\x2', '\x2', '\x2', '.', '-', '\x3',
'\x2', '\x2', '\x2', '/', '\x32', '\x3', '\x2', '\x2', '\x2', '\x30',
@ -2254,53 +2279,54 @@ public partial class ElsaParser : Parser {
'#', '\x3', '\x2', '\x2', '\x2', '\xCC', '\xCD', '\x5', '\"', '\x12',
'\x2', '\xCD', '%', '\x3', '\x2', '\x2', '\x2', '\xCE', '\xCF', '\x5',
'\"', '\x12', '\x2', '\xCF', '\'', '\x3', '\x2', '\x2', '\x2', '\xD0',
'\xD1', '\b', '\x15', '\x1', '\x2', '\xD1', '\xE8', '\x5', '\x14', '\v',
'\x2', '\xD2', '\xE8', '\x5', '\x4', '\x3', '\x2', '\xD3', '\xE8', '\x5',
'\x6', '\x4', '\x2', '\xD4', '\xD5', '\a', '\x1A', '\x2', '\x2', '\xD5',
'\xE8', '\x5', '(', '\x15', '\xF', '\xD6', '\xD7', '\a', '(', '\x2', '\x2',
'\xD7', '\xE8', '\x5', '(', '\x15', '\xE', '\xD8', '\xE8', '\a', '/',
'\x2', '\x2', '\xD9', '\xE8', '\a', ',', '\x2', '\x2', '\xDA', '\xE8',
'\a', '-', '\x2', '\x2', '\xDB', '\xDD', '\a', '\"', '\x2', '\x2', '\xDC',
'\xDE', '\x5', '*', '\x16', '\x2', '\xDD', '\xDC', '\x3', '\x2', '\x2',
'\x2', '\xDD', '\xDE', '\x3', '\x2', '\x2', '\x2', '\xDE', '\xDF', '\x3',
'\x2', '\x2', '\x2', '\xDF', '\xE8', '\a', '#', '\x2', '\x2', '\xE0',
'\xE2', '\a', '$', '\x2', '\x2', '\xE1', '\xE3', '\x5', '*', '\x16', '\x2',
'\xE2', '\xE1', '\x3', '\x2', '\x2', '\x2', '\xE2', '\xE3', '\x3', '\x2',
'\x2', '\x2', '\xE3', '\xE4', '\x3', '\x2', '\x2', '\x2', '\xE4', '\xE8',
'\a', '%', '\x2', '\x2', '\xE5', '\xE8', '\x5', '\x12', '\n', '\x2', '\xE6',
'\xE8', '\a', '\x30', '\x2', '\x2', '\xE7', '\xD0', '\x3', '\x2', '\x2',
'\x2', '\xE7', '\xD2', '\x3', '\x2', '\x2', '\x2', '\xE7', '\xD3', '\x3',
'\x2', '\x2', '\x2', '\xE7', '\xD4', '\x3', '\x2', '\x2', '\x2', '\xE7',
'\xD6', '\x3', '\x2', '\x2', '\x2', '\xE7', '\xD8', '\x3', '\x2', '\x2',
'\x2', '\xE7', '\xD9', '\x3', '\x2', '\x2', '\x2', '\xE7', '\xDA', '\x3',
'\x2', '\x2', '\x2', '\xE7', '\xDB', '\x3', '\x2', '\x2', '\x2', '\xE7',
'\xE0', '\x3', '\x2', '\x2', '\x2', '\xE7', '\xE5', '\x3', '\x2', '\x2',
'\x2', '\xE7', '\xE6', '\x3', '\x2', '\x2', '\x2', '\xE8', '\xFB', '\x3',
'\x2', '\x2', '\x2', '\xE9', '\xEA', '\f', '\r', '\x2', '\x2', '\xEA',
'\xEB', '\a', '\x1B', '\x2', '\x2', '\xEB', '\xFA', '\x5', '(', '\x15',
'\xE', '\xEC', '\xED', '\f', '\f', '\x2', '\x2', '\xED', '\xEE', '\a',
'\x19', '\x2', '\x2', '\xEE', '\xFA', '\x5', '(', '\x15', '\r', '\xEF',
'\xF0', '\f', '\v', '\x2', '\x2', '\xF0', '\xF1', '\a', '\x1A', '\x2',
'\x2', '\xF1', '\xFA', '\x5', '(', '\x15', '\f', '\xF2', '\xF3', '\f',
'\n', '\x2', '\x2', '\xF3', '\xF4', '\t', '\x3', '\x2', '\x2', '\xF4',
'\xFA', '\x5', '(', '\x15', '\v', '\xF5', '\xF6', '\f', '\x11', '\x2',
'\x2', '\xF6', '\xFA', '\a', '\x5', '\x2', '\x2', '\xF7', '\xF8', '\f',
'\x10', '\x2', '\x2', '\xF8', '\xFA', '\a', '\x6', '\x2', '\x2', '\xF9',
'\xE9', '\x3', '\x2', '\x2', '\x2', '\xF9', '\xEC', '\x3', '\x2', '\x2',
'\x2', '\xF9', '\xEF', '\x3', '\x2', '\x2', '\x2', '\xF9', '\xF2', '\x3',
'\x2', '\x2', '\x2', '\xF9', '\xF5', '\x3', '\x2', '\x2', '\x2', '\xF9',
'\xF7', '\x3', '\x2', '\x2', '\x2', '\xFA', '\xFD', '\x3', '\x2', '\x2',
'\x2', '\xFB', '\xF9', '\x3', '\x2', '\x2', '\x2', '\xFB', '\xFC', '\x3',
'\x2', '\x2', '\x2', '\xFC', ')', '\x3', '\x2', '\x2', '\x2', '\xFD',
'\xFB', '\x3', '\x2', '\x2', '\x2', '\xFE', '\x103', '\x5', '(', '\x15',
'\x2', '\xFF', '\x100', '\a', '\x18', '\x2', '\x2', '\x100', '\x102',
'\x5', '(', '\x15', '\x2', '\x101', '\xFF', '\x3', '\x2', '\x2', '\x2',
'\x102', '\x105', '\x3', '\x2', '\x2', '\x2', '\x103', '\x101', '\x3',
'\x2', '\x2', '\x2', '\x103', '\x104', '\x3', '\x2', '\x2', '\x2', '\x104',
'+', '\x3', '\x2', '\x2', '\x2', '\x105', '\x103', '\x3', '\x2', '\x2',
'\x2', '\x1C', '.', '\x30', '\x35', '=', '\x41', 'I', 'M', 'S', 'W', '\x65',
'j', 't', '}', '\x82', '\x88', '\x8F', '\x98', '\xA8', '\xB8', '\xCA',
'\xDD', '\xE2', '\xE7', '\xF9', '\xFB', '\x103',
'\xD1', '\b', '\x15', '\x1', '\x2', '\xD1', '\xE9', '\x5', '\x14', '\v',
'\x2', '\xD2', '\xE9', '\x5', '\xE', '\b', '\x2', '\xD3', '\xE9', '\x5',
'\x4', '\x3', '\x2', '\xD4', '\xE9', '\x5', '\x6', '\x4', '\x2', '\xD5',
'\xD6', '\a', '\x1A', '\x2', '\x2', '\xD6', '\xE9', '\x5', '(', '\x15',
'\xF', '\xD7', '\xD8', '\a', '(', '\x2', '\x2', '\xD8', '\xE9', '\x5',
'(', '\x15', '\xE', '\xD9', '\xE9', '\a', '/', '\x2', '\x2', '\xDA', '\xE9',
'\a', ',', '\x2', '\x2', '\xDB', '\xE9', '\a', '-', '\x2', '\x2', '\xDC',
'\xDE', '\a', '\"', '\x2', '\x2', '\xDD', '\xDF', '\x5', '*', '\x16',
'\x2', '\xDE', '\xDD', '\x3', '\x2', '\x2', '\x2', '\xDE', '\xDF', '\x3',
'\x2', '\x2', '\x2', '\xDF', '\xE0', '\x3', '\x2', '\x2', '\x2', '\xE0',
'\xE9', '\a', '#', '\x2', '\x2', '\xE1', '\xE3', '\a', '$', '\x2', '\x2',
'\xE2', '\xE4', '\x5', '*', '\x16', '\x2', '\xE3', '\xE2', '\x3', '\x2',
'\x2', '\x2', '\xE3', '\xE4', '\x3', '\x2', '\x2', '\x2', '\xE4', '\xE5',
'\x3', '\x2', '\x2', '\x2', '\xE5', '\xE9', '\a', '%', '\x2', '\x2', '\xE6',
'\xE9', '\x5', '\x12', '\n', '\x2', '\xE7', '\xE9', '\a', '\x30', '\x2',
'\x2', '\xE8', '\xD0', '\x3', '\x2', '\x2', '\x2', '\xE8', '\xD2', '\x3',
'\x2', '\x2', '\x2', '\xE8', '\xD3', '\x3', '\x2', '\x2', '\x2', '\xE8',
'\xD4', '\x3', '\x2', '\x2', '\x2', '\xE8', '\xD5', '\x3', '\x2', '\x2',
'\x2', '\xE8', '\xD7', '\x3', '\x2', '\x2', '\x2', '\xE8', '\xD9', '\x3',
'\x2', '\x2', '\x2', '\xE8', '\xDA', '\x3', '\x2', '\x2', '\x2', '\xE8',
'\xDB', '\x3', '\x2', '\x2', '\x2', '\xE8', '\xDC', '\x3', '\x2', '\x2',
'\x2', '\xE8', '\xE1', '\x3', '\x2', '\x2', '\x2', '\xE8', '\xE6', '\x3',
'\x2', '\x2', '\x2', '\xE8', '\xE7', '\x3', '\x2', '\x2', '\x2', '\xE9',
'\xFC', '\x3', '\x2', '\x2', '\x2', '\xEA', '\xEB', '\f', '\r', '\x2',
'\x2', '\xEB', '\xEC', '\a', '\x1B', '\x2', '\x2', '\xEC', '\xFB', '\x5',
'(', '\x15', '\xE', '\xED', '\xEE', '\f', '\f', '\x2', '\x2', '\xEE',
'\xEF', '\a', '\x19', '\x2', '\x2', '\xEF', '\xFB', '\x5', '(', '\x15',
'\r', '\xF0', '\xF1', '\f', '\v', '\x2', '\x2', '\xF1', '\xF2', '\a',
'\x1A', '\x2', '\x2', '\xF2', '\xFB', '\x5', '(', '\x15', '\f', '\xF3',
'\xF4', '\f', '\n', '\x2', '\x2', '\xF4', '\xF5', '\t', '\x3', '\x2',
'\x2', '\xF5', '\xFB', '\x5', '(', '\x15', '\v', '\xF6', '\xF7', '\f',
'\x11', '\x2', '\x2', '\xF7', '\xFB', '\a', '\x5', '\x2', '\x2', '\xF8',
'\xF9', '\f', '\x10', '\x2', '\x2', '\xF9', '\xFB', '\a', '\x6', '\x2',
'\x2', '\xFA', '\xEA', '\x3', '\x2', '\x2', '\x2', '\xFA', '\xED', '\x3',
'\x2', '\x2', '\x2', '\xFA', '\xF0', '\x3', '\x2', '\x2', '\x2', '\xFA',
'\xF3', '\x3', '\x2', '\x2', '\x2', '\xFA', '\xF6', '\x3', '\x2', '\x2',
'\x2', '\xFA', '\xF8', '\x3', '\x2', '\x2', '\x2', '\xFB', '\xFE', '\x3',
'\x2', '\x2', '\x2', '\xFC', '\xFA', '\x3', '\x2', '\x2', '\x2', '\xFC',
'\xFD', '\x3', '\x2', '\x2', '\x2', '\xFD', ')', '\x3', '\x2', '\x2',
'\x2', '\xFE', '\xFC', '\x3', '\x2', '\x2', '\x2', '\xFF', '\x104', '\x5',
'(', '\x15', '\x2', '\x100', '\x101', '\a', '\x18', '\x2', '\x2', '\x101',
'\x103', '\x5', '(', '\x15', '\x2', '\x102', '\x100', '\x3', '\x2', '\x2',
'\x2', '\x103', '\x106', '\x3', '\x2', '\x2', '\x2', '\x104', '\x102',
'\x3', '\x2', '\x2', '\x2', '\x104', '\x105', '\x3', '\x2', '\x2', '\x2',
'\x105', '+', '\x3', '\x2', '\x2', '\x2', '\x106', '\x104', '\x3', '\x2',
'\x2', '\x2', '\x1C', '.', '\x30', '\x35', '=', '\x41', 'I', 'M', 'S',
'W', '\x65', 'j', 't', '}', '\x82', '\x88', '\x8F', '\x98', '\xA8', '\xB8',
'\xCA', '\xDE', '\xE3', '\xE8', '\xFA', '\xFC', '\x104',
};
public static readonly ATN _ATN =

File diff suppressed because one or more lines are too long

View file

@ -479,6 +479,17 @@ public partial class ElsaParserBaseVisitor<Result> : AbstractParseTreeVisitor<Re
/// <return>The visitor result.</return>
public virtual Result VisitAddExpr([NotNull] ElsaParser.AddExprContext context) { return VisitChildren(context); }
/// <summary>
/// Visit a parse tree produced by the <c>expressionMarkerExpr</c>
/// labeled alternative in <see cref="ElsaParser.expr"/>.
/// <para>
/// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
/// on <paramref name="context"/>.
/// </para>
/// </summary>
/// <param name="context">The parse tree.</param>
/// <return>The visitor result.</return>
public virtual Result VisitExpressionMarkerExpr([NotNull] ElsaParser.ExpressionMarkerExprContext context) { return VisitChildren(context); }
/// <summary>
/// Visit a parse tree produced by the <c>backTickStringValueExpr</c>
/// labeled alternative in <see cref="ElsaParser.expr"/>.
/// <para>

View file

@ -308,6 +308,13 @@ public interface IElsaParserVisitor<Result> : IParseTreeVisitor<Result> {
/// <return>The visitor result.</return>
Result VisitAddExpr([NotNull] ElsaParser.AddExprContext context);
/// <summary>
/// Visit a parse tree produced by the <c>expressionMarkerExpr</c>
/// labeled alternative in <see cref="ElsaParser.expr"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
/// <return>The visitor result.</return>
Result VisitExpressionMarkerExpr([NotNull] ElsaParser.ExpressionMarkerExprContext context);
/// <summary>
/// Visit a parse tree produced by the <c>backTickStringValueExpr</c>
/// labeled alternative in <see cref="ElsaParser.expr"/>.
/// </summary>

View file

@ -94,24 +94,25 @@ elseStat
;
expr
: funcCall #functionExpr
| object #objectExpr
| newObject #newObjectExpr
| expr '++' #incrementExpr
| expr '--' #decrementExpr
| '-' expr #negateExpr
| '!' expr #notExpr
| expr '*' expr #multiplyExpr
| expr '+' expr #addExpr
| expr '-' expr #subtractExpr
| expr ('==' | '>' | '<') expr #compareExpr
| INTEGER_VAL #integerValueExpr
| STRING_VAL #stringValueExpr
| BACKTICKSTRING_VAL #backTickStringValueExpr
| '(' exprList? ')' #parenthesesExpr
| '[' exprList? ']' #bracketsExpr
| methodCall #methodCallExpr
| ID #variableExpr
: funcCall #functionExpr
| expressionMarker #expressionMarkerExpr
| object #objectExpr
| newObject #newObjectExpr
| expr '++' #incrementExpr
| expr '--' #decrementExpr
| '-' expr #negateExpr
| '!' expr #notExpr
| expr '*' expr #multiplyExpr
| expr '+' expr #addExpr
| expr '-' expr #subtractExpr
| expr ('==' | '>' | '<' | '!=' | '>=' | '<=') expr #compareExpr
| INTEGER_VAL #integerValueExpr
| STRING_VAL #stringValueExpr
| BACKTICKSTRING_VAL #backTickStringValueExpr
| '(' exprList? ')' #parenthesesExpr
| '[' exprList? ']' #bracketsExpr
| methodCall #methodCallExpr
| ID #variableExpr
;
exprList

View file

@ -1,7 +1,7 @@
print("What's your age?");
variable age = ReadLine;
if(age > 16)
if age > 16 then
{
print("Enjoy your driver's license!");
// delay(5000);

View file

@ -16,6 +16,7 @@ public partial class WorkflowDefinitionBuilderInterpreter
var expressionReference = new JavaScriptExpressionReference(expression);
var externalReference = new ExternalExpressionReference(expression, expressionReference);
_expressionValue.Put(context, externalReference);
_expressionValue.Put(context.Parent, externalReference);
return DefaultResult;
}

View file

@ -50,8 +50,8 @@ public partial class WorkflowDefinitionBuilderInterpreter
return (Input)Activator.CreateInstance(inputType, propertyValue)!;
}
var convertedValue = propertyValue.ConvertTo(underlyingType);
return (Input)Activator.CreateInstance(inputType, convertedValue)!;
return propertyValue is ExternalExpressionReference externalExpressionReference
? (Input)Activator.CreateInstance(inputType, externalExpressionReference.Expression, externalExpressionReference.Reference)!
: (Input)Activator.CreateInstance(inputType, propertyValue.ConvertTo(underlyingType))!;
}
}

View file

@ -0,0 +1 @@
WriteLine { Text:"Hello World!" };

View file

@ -0,0 +1,14 @@
//let name: Variable;
let readLine1 = ReadLine;
Sequence {
Activities: [
WriteLine { Text: "Please Enter your name" },
Sequence {
Activities: [
readLine1,
WriteLine { Text: js => `Hello ${readline1}` }
]
}
]
};

View file

@ -0,0 +1 @@
print("Hello World");

View file

@ -0,0 +1,16 @@
// Print a message.
print("What's your age?");
// Declare a workflow variable and assign the result of the ReadLine activity.
variable age = ReadLine; // Could also use the mapped function called `read()`.
// The `if` keyword is mapped to the If activity. The condition requires a JavaScript expression.
if age >= 18 then
{
print("Enjoy your driver's license!");
print("But be careful!");
}
else
print("Enjoy your bicycle!");
print("Goodbye.");

View file

@ -24,6 +24,10 @@
<ItemGroup>
<None Remove="Sample1.elsa" />
<EmbeddedResource Include="Demo1.elsa" />
<EmbeddedResource Include="Demo2.elsa" />
<EmbeddedResource Include="Demo3.elsa" />
<EmbeddedResource Include="Demo4.elsa" />
<EmbeddedResource Include="Sample1.elsa" />
</ItemGroup>

View file

@ -21,6 +21,7 @@ var typeSystem = serviceProvider.GetRequiredService<ITypeSystem>();
var dslEngine = serviceProvider.GetRequiredService<IDslEngine>();
var functionActivityRegistry = serviceProvider.GetRequiredService<IFunctionActivityRegistry>();
// Map .NET types to Elsa DSL. Optionally using an alias.
typeSystem.Register<int>("int");
typeSystem.Register<float>("float");
typeSystem.Register<string>("string");
@ -31,15 +32,21 @@ typeSystem.Register<WriteLine>();
typeSystem.Register<HttpEndpoint>();
typeSystem.Register<Timer>();
// Map functions to activities.
functionActivityRegistry.RegisterFunction("print", nameof(WriteLine), new[] { nameof(WriteLine.Text) });
functionActivityRegistry.RegisterFunction("read", nameof(ReadLine), new[] { nameof(ReadLine.Result) });
var assembly = Assembly.GetExecutingAssembly();
var resource = assembly.GetManifestResourceStream("Elsa.Samples.Console2.Sample1.elsa");
// Read text file containing Elsa DSL.
var scriptName = "Demo2";
var resource = assembly.GetManifestResourceStream($"Elsa.Samples.Console2.{scriptName}.elsa");
var script = await new StreamReader(resource!).ReadToEndAsync();
// Evaluate the DSL. The result will be an executable workflow definition.
var workflowDefinition = dslEngine.Parse(script);
// Run the workflow.
var workflowEngine = serviceProvider.GetRequiredService<IWorkflowRunner>();
await workflowEngine.RunAsync(workflowDefinition);

View file

@ -1,7 +1,7 @@
print("What's your age?");
variable age = ReadLine;
if(age > 16)
if age > 16 then
{
print("Enjoy your driver's license!");
// delay(5000);