Exemplo n.º 1
0
 protected ValidationResult createTextError(string language,
                                            string templateName,
                                            TokenBase token)
 {
     return(new ValidationResult {
         HasError = true,
         Message = Localize(language, templateName) + ": " +
                   "…" + token.getSource() + "…" +
                   Localize(language, token.getError())
     });
 }
Exemplo n.º 2
0
 protected ValidationResult createTokenError(string language,
                                             string templateName,
                                             TokenBase token)
 {
     return(new ValidationResult {
         HasError = true,
         Message = Localize(language, templateName) + ": " +
                   Char.ToString(PLACEHOLDER_DELIMITERS[0]) +
                   token.getSource() +
                   Char.ToString(PLACEHOLDER_DELIMITERS[1]) +
                   Localize(language, token.getError())
     });
 }
Exemplo n.º 3
0
        /// <summary>
        /// Verify that tokens have no format specification and that they have a
        /// user-supplied, valid identifier as name. Offending tokens are replaced
        /// by error tokens. Everything else we leav to the interpreter to check
        /// in Execute().
        /// </summary>
        protected override ValidationResult validateTokens(string language,
                                                           string templateName,
                                                           ref List <TokenBase> templateTokens)
        {
            for (int i = 0; i < templateTokens.Count; i++)
            {
                TokenBase token = templateTokens[i];

                if (token.hasFormatOrMappings())
                {
                    templateTokens[i] = new ErrorToken(token.getSource(),
                                                       "HasFormatOrMappings");
                    return(createTokenError(language, templateName, templateTokens[i]));
                }
                if (token.hasDefaultName())
                {
                    templateTokens[i] = new ErrorToken(token.getSource(),
                                                       "HasDefaultName");
                    return(createTokenError(language, templateName, templateTokens[i]));
                }
                if (token is ConstStringToken csToken)
                {
                    string text = csToken.getText();
                    if (hasOutOfRangeRef(text, templateName))
                    {
                        templateTokens[i] = new ErrorToken(token.getSource(),
                                                           "HasOutOfRangeRef");
                        return(createTextError(language, templateName, templateTokens[i]));
                    }
                    if (hasAssignment(text))
                    {
                        templateTokens[i] = new ErrorToken(token.getSource(),
                                                           "HasAssignment");
                        return(createTextError(language, templateName, templateTokens[i]));
                    }
                }
                if (token is VarTokenBase varToken)
                {
                    if (!isIdentifier(varToken.getName()))
                    {
                        templateTokens[i] = new ErrorToken(token.getSource(),
                                                           "HasUnusableName");
                        return(createTokenError(language, templateName, templateTokens[i]));
                    }
                }
            }
            return(new ValidationResult {
                HasError = false
            });
        }