private ArmElement ReadArmValue(JValue value) { switch (value.Type) { case JTokenType.Null: return(ArmNullLiteral.Value); case JTokenType.Boolean: return(ArmBooleanLiteral.FromBool(value.Value <bool>())); case JTokenType.Integer: return(new ArmIntegerLiteral(value.Value <long>())); default: return((ArmElement)ReadArmExpression(value)); } }
private ArmOperation ParseCallExpression(ref ArmExpressionTokenizer tokenizer, ArmExpressionIdentifierToken identifier) { var arguments = new List <ArmExpression>(); ArmExpressionToken token; bool sawCloseParen = false; while (!sawCloseParen) { token = tokenizer.NextToken(); switch (token.Type) { case ArmExpressionTokenType.Identifier: arguments.Add(ParseIdentifierExpression(ref tokenizer, (ArmExpressionIdentifierToken)token)); break; case ArmExpressionTokenType.String: arguments.Add(new ArmStringLiteral(token.CoerceToString())); break; case ArmExpressionTokenType.Integer: arguments.Add(new ArmIntegerLiteral(token.CoerceToLong())); break; case ArmExpressionTokenType.Boolean: arguments.Add(ArmBooleanLiteral.FromBool(token.CoerceToBool())); break; case ArmExpressionTokenType.CloseParen: if (arguments.Count == 0) { sawCloseParen = true; continue; } goto default; default: throw Error($"Expected an expression but instead got '{token}' in input '{tokenizer.Input}' at index {tokenizer.PreviousIndex}"); } token = tokenizer.NextToken(); switch (token.Type) { case ArmExpressionTokenType.Comma: break; case ArmExpressionTokenType.CloseParen: sawCloseParen = true; break; default: throw Error($"Expected an expression delimiter but instead got '{token}' in input '{tokenizer.Input}' at index {tokenizer.PreviousIndex}"); } } if (identifier.Identifier.Is(ParametersFunction)) { return(new ArmParameterReferenceExpression((IArmString)arguments[0])); } if (identifier.Identifier.Is(VariablesFunction)) { return(new ArmVariableReferenceExpression((IArmString)arguments[0])); } return(new ArmFunctionCallExpression(new ArmStringLiteral(identifier.Identifier), arguments.ToArray())); }