Skip to content

Commit

Permalink
Allow liquid parsing to be relaxed when parsing custom tags (although…
Browse files Browse the repository at this point in the history
… we can't handle wild syntaxes for tag arguments)
  • Loading branch information
xoofx committed Nov 10, 2017
1 parent 6097e39 commit 131fd03
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 1 @@
text(3,4) : error : Expecting the expression `end` to be in an object section `{{ ... }}`
text(1,4) : error : Error while parsing if statement: The `endif statement` was not found in: if <expression> ... end|else|else if
Original file line number Diff line number Diff line change
@@ -1,2 1 @@
text(4,4) : error : Expecting the expression `end` to be in an object section `{{ ... }}`
text(2,4) : error : Error while parsing if statement: The `endif statement` was not found in: if <expression> ... end|else|else if
41 changes: 23 additions & 18 deletions src/Scriban/Parsing/Parser.Statements.Liquid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 53,7 @@ private void ParseLiquidStatement(string identifier, ScriptStatement parent, ref

case "endfor":
startStatement = FindFirstStatementExpectingEnd() as ScriptForStatement;
pendingStart = "`unless`";
pendingStart = "`for`";
break;

case "endcase":
Expand Down Expand Up @@ -298,25 298,30 @@ private ScriptStatement ParseLiquidExpressionStatement(ScriptStatement parent)
CheckNotInCase(parent, startToken);
var expressionStatement = ParseExpressionStatement();

var functionCall = expressionStatement.Expression as ScriptFunctionCall;
var statement = expressionStatement;

// Otherwise it is an expression statement
if (functionCall != null)
{
if (!_isLiquidTagSection)
{
LogError(startToken, $"The `{functionCall}` statement must be in a tag section `{{% ... %}}`");
}
}
else if (_isLiquidTagSection)
{
LogError(startToken, $"Expecting the expression `{GetAsText(startToken)}` to be in an object section `{{{{ ... }}}}`");
}
else if (!(expressionStatement.Expression is IScriptVariablePath || expressionStatement.Expression is ScriptPipeCall))
{
LogError(statement, $"The <{expressionStatement.Expression}> is not allowed in this context");
}
// NOTE: We were previously performing the following checks
// but as liquid doesn't have a strict syntax, we are instead not enforcing anykind of rules
// so that the parser can still read custom liquid tags/object expressions, assuming that
// they are not using fancy argument syntaxes (which are unfortunately allowed in liquid)

//var functionCall = expressionStatement.Expression as ScriptFunctionCall;
//// Otherwise it is an expression statement
//if (functionCall != null)
//{
// if (!_isLiquidTagSection)
// {
// LogError(startToken, $"The `{functionCall}` statement must be in a tag section `{{% ... %}}`");
// }
//}
//else if (_isLiquidTagSection)
//{
// LogError(startToken, $"Expecting the expression `{GetAsText(startToken)}` to be in an object section `{{{{ ... }}}}`");
//}
//else if (!(expressionStatement.Expression is IScriptVariablePath || expressionStatement.Expression is ScriptPipeCall))
//{
// LogError(statement, $"The <{expressionStatement.Expression}> is not allowed in this context");
//}
return statement;
}

Expand Down

0 comments on commit 131fd03

Please sign in to comment.