/// <summary> /// Gets the entity arg. /// </summary> /// <param name="parentNode">The parent node.</param> /// <param name="pos">The child node index containing the argument.</param> /// <param name="type">The type of entity expected.</param> /// <returns>The entity. Or the first one, if there are multiple matches. Or null if there was no match.</returns> internal T GetEntityArg <T>(ParseTreeNode parentNode, int pos, EntityType type) where T : class, IEntity { // Get the identifier name ParseTreeNode nameNode = parentNode.ChildNodes[pos]; string codeName = GetIdentifierArg(parentNode, pos); // Get the entity IEntity entity; if (type.Alias == "core:type") { long typeEntityId = ExternalServices.ScriptNameResolver.GetTypeByName(codeName); if (typeEntityId == 0) { throw ParseExceptionHelper.New(string.Format("The name '{0}' could not be matched.", codeName), nameNode); } entity = ExternalServices.EntityRepository.Get(typeEntityId); } else { entity = ExternalServices.ScriptNameResolver.GetInstance(codeName, type.Id); if (entity == null) { throw ParseExceptionHelper.New(string.Format("The name '{0}' could not be matched.", codeName), nameNode); } } // Cast to expected type T castedEntity = entity.Cast <T>(); return(castedEntity); }
/// <summary> /// Checks the parse tree for errors. /// </summary> /// <param name="parseTree">The parse tree.</param> /// <exception cref="ParseException">Thrown if there are any parse errors.</exception> public void CheckParseTreeOk(ParseTree parseTree) { if (parseTree == null || parseTree.ParserMessages.Count == 0) { return; } if (parseTree.ParserMessages.Count == 1) { string message = parseTree.ParserMessages[0].Message; if (message.StartsWith("Syntax error, expected")) { message = "Invalid script syntax."; } throw ParseExceptionHelper.New(message, parseTree.ParserMessages[0].Location); } throw new ParseException(string.Join(", ", parseTree.ParserMessages.Select(m => string.Format("{0} pos {1}", m.Message, m.Location.Position)))); }
public string GetCompareOperator(ExpressionType exprType) { switch (exprType) { case ExpressionType.GreaterThan: return(" > "); case ExpressionType.GreaterThanOrEqual: return(" >= "); case ExpressionType.LessThan: return(" < "); case ExpressionType.LessThanOrEqual: return(" <= "); default: ParseExceptionHelper.ThrowNotSupportedExpression(exprType); return(string.Empty); } }
public override void OnStaticValidation(BuilderSettings settings, Irony.Parsing.ParseTreeNode exceptionNode) { switch (DateTimePart) { case DateTimeParts.Hour: case DateTimeParts.Minute: case DateTimeParts.Second: if (InputType.Type == DataType.Date) { throw ParseExceptionHelper.New(string.Format("Cannot use '{0}' with date data.", DateTimePart), exceptionNode.ChildNodes[1]); } break; default: if (InputType.Type == DataType.Time) { throw ParseExceptionHelper.New(string.Format("Cannot use '{0}' with time data.", DateTimePart), exceptionNode.ChildNodes[1]); } break; } }