Skip to content

Commit b58e1d0

Browse files
author
Rajesh Jinaga
committed
Add support to use single (' ') and double (" ") quotes to represent string
1 parent 2f53960 commit b58e1d0

14 files changed

+197
-131
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ using Simpleflow;
2626
var script =
2727
@"
2828
# Declare and initialize variables
29-
let text = ""Hello, World! 🌄""
30-
let today = $GetCurrentDateTime ( timezone: ""Eastern Standard Time"" )
29+
let text = 'Hello, World! 🌄'
30+
let today = $GetCurrentDateTime ( timezone: 'Eastern Standard Time' )
3131
3232
# Write rules
3333
rule when arg.UniversalId == 2 and (arg.New or arg.Verified) then

src/Simpleflow/CodeGenerator/SimpleflowCodeVisitor.Helpers.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,12 @@ private Expression GetBoolExpression(string value)
3939
return Expression.Constant(Convert.ToBoolean(value), typeof(bool));
4040
}
4141

42-
private string GetUnquotedText(string @string)
42+
private string GetUnquotedEscapeText(string @string)
4343
{
44-
return @string.Substring(1, @string.Length - 2); // Trim first and last quotes
44+
var text = @string.Substring(1, @string.Length - 2); // Trim first and last quotes
45+
text = text.Replace("\\\"", "\"");
46+
text = text.Replace("\\'", "'");
47+
return text;
4548
}
4649

4750
private ParameterExpression GetVariable(string name)

src/Simpleflow/CodeGenerator/SimpleflowCodeVisitor.VisitLiterals.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public override Expression VisitStringLiteral([NotNull] SimpleflowParser.StringL
6060
{
6161
var targetType = TargetTypeParserContextAnnotation.Get(context);
6262

63-
var value = GetUnquotedText(context.String().GetText());
63+
var value = GetUnquotedEscapeText(context.String().GetText());
6464

6565
if (targetType == null || targetType == typeof(string))
6666
{
@@ -100,11 +100,12 @@ public override Expression VisitTemplateStringLiteral([NotNull] SimpleflowParser
100100
StringBuilder sb = new StringBuilder();
101101
int index = 1; // First and last characters are back ticks
102102

103-
while(index < context.children.Count-1)
103+
104+
while (index < context.children.Count-1)
104105
{
105106
var child = context.children[index];
106107

107-
if (child.GetChild(1) is SimpleflowParser.ObjectIdentifierContext)
108+
if (child.GetChild(1) is SimpleflowParser.ExpressionContext)
108109
{
109110
if (sb.Length > 0)
110111
{

src/Simpleflow/CodeGenerator/SimpleflowCodeVisitor.VistitSet.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ public override Expression VisitSetStmt(SimpleflowParser.SetStmtContext context)
3838

3939
// return expression
4040
return GetSetStmtExpression(context, variableName, variableExpression, valueExpression);
41-
4241
}
4342

4443
private Expression GetValueExpressionOfSetStmt(SimpleflowParser.SetStmtContext context,
@@ -114,24 +113,24 @@ private Expression AssignWithHandlingError(Expression variable, Expression right
114113

115114
// Add error variable without declare using let, error is exceptional case
116115
var errorVar = GetExistingOrAddVariableToGlobalScope(Expression.Variable(typeof(Exception), errorVariable));
117-
var varFortryExpression = Expression.Variable(tryExpression.Type);
116+
var varForTryExpression = Expression.Variable(tryExpression.Type);
118117

119118
// Declare before use
120-
DeclareVariable(varFortryExpression);
119+
DeclareVariable(varForTryExpression);
121120

122121
// Add variables
123122
if (variable == null)
124123
{
125124
return Expression.Block(
126-
Expression.Assign(varFortryExpression, tryExpression), // run expression with try catch and capture value
127-
Expression.Assign(errorVar, Expression.Field(varFortryExpression, "Error"))
125+
Expression.Assign(varForTryExpression, tryExpression), // run expression with try catch and capture value
126+
Expression.Assign(errorVar, Expression.Field(varForTryExpression, "Error"))
128127
);
129128
}
130129

131130
return Expression.Block(
132-
Expression.Assign(varFortryExpression, tryExpression), // run expression with try catch and capture value
133-
Expression.Assign(variable, Expression.Field(varFortryExpression, "Value")),
134-
Expression.Assign(errorVar, Expression.Field(varFortryExpression, "Error"))
131+
Expression.Assign(varForTryExpression, tryExpression), // run expression with try catch and capture value
132+
Expression.Assign(variable, Expression.Field(varForTryExpression, "Value")),
133+
Expression.Assign(errorVar, Expression.Field(varForTryExpression, "Error"))
135134
);
136135
}
137136

src/Simpleflow/Parser/Grammar/SimpleflowLexer.g4

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ True: 'true';
6868
False: 'false';
6969
Number: ('+'|'-')?[0-9]+('.'[0-9]+)?;
7070

71-
String: '"' ( '\\"' | ~["\r\n] )*? '"';
71+
String: '"' ( '\\"' | ~["\r\n] )*? '"'
72+
| '\'' ( '\\\'' | ~['\r\n] )*? '\'' ;
73+
7274
None: 'none' ;
7375

7476
Identifier: [_]*[a-zA-Z][_a-zA-Z0-9]* ;

src/Simpleflow/Parser/Grammar/SimpleflowParser.g4

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ templateStringLiteral
9494

9595
templateStringAtom
9696
: TemplateStringAtom
97-
| TemplateStringStartExpression objectIdentifier TemplateCloseBrace
97+
| TemplateStringStartExpression expression TemplateCloseBrace
9898
;
9999

100100
/** Function */
@@ -157,4 +157,3 @@ eos
157157
: EOF
158158
| {this.LineTerminatorAhead()}?
159159
;
160-

0 commit comments

Comments
 (0)