/// <summary>
        /// Initializes a new instance of the <see cref="StandardDialectBase" /> class.
        /// <remarks>
        /// This constructor is not actually called directly.
        /// </remarks>
        /// </summary>
        /// <param name="name">A human-readable name for the dialect.</param>
        /// <param name="culture">A <see cref="CultureInfo" /> object that drives the formatting and collation behavior of the dialect.</param>
        /// <param name="casing">A <see cref="DialectCasing" /> value that controls the dialect string casing behavior.</param>
        /// <exception cref="ArgumentNullException">Either argument <paramref name="name" /> or <paramref name="culture" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">Argument <paramref name="name" /> is an empty string.</exception>
        protected StandardDialectBase([NotNull] string name, [NotNull] CultureInfo culture, DialectCasing casing)
        {
            Expect.NotEmpty(nameof(name), name);
            Expect.NotNull(nameof(culture), culture);

            /* Build culture-aware values.*/
            Name           = name;
            Culture        = culture;
            _typeConverter = new FlexiblePrimitiveTypeConverter(Culture, this);
            _dialectCasing = casing;

            var casedUndefined = AdjustCasing("Undefined");

            Debug.Assert(casedUndefined != null);
            _dialectUndefinedSpecialIdentifier = casedUndefined;

            var comparer = StringComparer.Create(culture, casing == DialectCasing.IgnoreCase);

            IdentifierComparer    = comparer;
            StringLiteralComparer = comparer;
        }
Ejemplo n.º 2
0
        private CodeMonkeyDialect TestDialect(DialectCasing casing)
        {
            var dialect = new CodeMonkeyDialect(casing);

            Assert.IsInstanceOf <StandardSelfObject>(dialect.Self);
            Assert.AreEqual(dialect.Culture, CultureInfo.InvariantCulture);
            Assert.AreEqual('\'', dialect.EndStringLiteralCharacter);
            Assert.AreEqual('}', dialect.EndTagCharacter);
            Assert.AreEqual('.', dialect.NumberDecimalSeparatorCharacter);
            Assert.AreEqual('\'', dialect.StartStringLiteralCharacter);
            Assert.AreEqual('{', dialect.StartTagCharacter);
            Assert.AreEqual('\\', dialect.StringLiteralEscapeCharacter);

            Assert.NotNull(dialect.FlowSymbols);
            Assert.AreEqual("(", dialect.FlowSymbols.GroupOpen);
            Assert.AreEqual(")", dialect.FlowSymbols.GroupClose);
            Assert.AreEqual(",", dialect.FlowSymbols.Separator);
            Assert.AreEqual(".", dialect.FlowSymbols.MemberAccess);

            var expectedComparer = StringComparer.Create(dialect.Culture, casing == DialectCasing.IgnoreCase);

            Assert.AreEqual(dialect.IdentifierComparer, expectedComparer);
            Assert.AreEqual(dialect.StringLiteralComparer, expectedComparer);

            Func <string, string> transformer = input => input;

            if (casing == DialectCasing.LowerCase)
            {
                transformer = input => input.ToLowerInvariant();
            }

            Assert.AreEqual(5, dialect.SpecialKeywords.Count);
            Assert.IsTrue(
                dialect.SpecialKeywords.ContainsKey(transformer("TRUE")) &&
                dialect.SpecialKeywords[transformer("TRUE")].Equals(true));
            Assert.IsTrue(
                dialect.SpecialKeywords.ContainsKey(transformer("FALSE")) &&
                dialect.SpecialKeywords[transformer("FALSE")].Equals(false));
            Assert.IsTrue(
                dialect.SpecialKeywords.ContainsKey(transformer("UNDEFINED")) &&
                dialect.SpecialKeywords[transformer("UNDEFINED")] == null);
            Assert.IsTrue(
                dialect.SpecialKeywords.ContainsKey(transformer("NAN")) &&
                dialect.SpecialKeywords[transformer("NAN")].Equals(double.NaN));
            Assert.IsTrue(
                dialect.SpecialKeywords.ContainsKey(transformer("INFINITY")) && dialect
                .SpecialKeywords[transformer("INFINITY")].Equals(double.PositiveInfinity));

            Assert.AreEqual(9, dialect.Directives.Count);
            foreach (var directive in dialect.Directives)
            {
                if (directive is ConditionalInterpolationDirective)
                {
                    Assert.AreEqual(transformer("{$ IF $}"), directive.ToString());
                }
                else if (directive is UsingDirective)
                {
                    Assert.AreEqual(transformer("{? AS $}...{END}"), directive.ToString());
                }
                else if (directive is ForDirective)
                {
                    Assert.AreEqual(transformer("{FOR $}...{END}"), directive.ToString());
                }
                else if (directive is ForEachDirective)
                {
                    Assert.AreEqual(transformer("{FOR ? IN $}...{END}"), directive.ToString());
                }
                else if (directive is SeparatedForEachDirective)
                {
                    Assert.AreEqual(transformer("{FOR ? IN $}...{WITH}...{END}"), directive.ToString());
                }
                else if (directive is IfDirective)
                {
                    Assert.AreEqual(transformer("{IF $}...{END}"), directive.ToString());
                }
                else if (directive is IfElseDirective)
                {
                    Assert.AreEqual(transformer("{IF $}...{ELSE}...{END}"), directive.ToString());
                }
                else if (directive is InterpolationDirective)
                {
                    Assert.AreEqual("{$}", directive.ToString());
                }
                else if (directive is PreFormattedUnParsedTextDirective)
                {
                    Assert.AreEqual(transformer("{PRE}...{END}"), directive.ToString());
                }
                else
                {
                    Assert.Fail();
                }
            }

            Assert.AreEqual(24, dialect.Operators.Count);
            foreach (var @operator in dialect.Operators)
            {
                if (@operator is RelationalEqualsOperator)
                {
                    Assert.AreEqual("==", @operator.ToString());
                }
                else if (@operator is RelationalNotEqualsOperator)
                {
                    Assert.AreEqual("!=", @operator.ToString());
                }
                else if (@operator is RelationalGreaterThanOperator)
                {
                    Assert.AreEqual(">", @operator.ToString());
                }
                else if (@operator is RelationalGreaterThanOrEqualsOperator)
                {
                    Assert.AreEqual(">=", @operator.ToString());
                }
                else if (@operator is RelationalLowerThanOperator)
                {
                    Assert.AreEqual("<", @operator.ToString());
                }
                else if (@operator is RelationalLowerThanOrEqualsOperator)
                {
                    Assert.AreEqual("<=", @operator.ToString());
                }
                else if (@operator is LogicalAndOperator)
                {
                    Assert.AreEqual("&&", @operator.ToString());
                }
                else if (@operator is LogicalOrOperator)
                {
                    Assert.AreEqual("||", @operator.ToString());
                }
                else if (@operator is LogicalNotOperator)
                {
                    Assert.AreEqual("!", @operator.ToString());
                }
                else if (@operator is BitwiseAndOperator)
                {
                    Assert.AreEqual("&", @operator.ToString());
                }
                else if (@operator is BitwiseOrOperator)
                {
                    Assert.AreEqual("|", @operator.ToString());
                }
                else if (@operator is BitwiseXorOperator)
                {
                    Assert.AreEqual("^", @operator.ToString());
                }
                else if (@operator is BitwiseNotOperator)
                {
                    Assert.AreEqual("~", @operator.ToString());
                }
                else if (@operator is BitwiseShiftLeftOperator)
                {
                    Assert.AreEqual("<<", @operator.ToString());
                }
                else if (@operator is BitwiseShiftRightOperator)
                {
                    Assert.AreEqual(">>", @operator.ToString());
                }
                else if (@operator is ArithmeticDivideOperator)
                {
                    Assert.AreEqual("/", @operator.ToString());
                }
                else if (@operator is ArithmeticModuloOperator)
                {
                    Assert.AreEqual("%", @operator.ToString());
                }
                else if (@operator is ArithmeticMultiplyOperator)
                {
                    Assert.AreEqual("*", @operator.ToString());
                }
                else if (@operator is ArithmeticNegateOperator)
                {
                    Assert.AreEqual("-", @operator.ToString());
                }
                else if (@operator is ArithmeticNeutralOperator)
                {
                    Assert.AreEqual("+", @operator.ToString());
                }
                else if (@operator is ArithmeticSubtractOperator)
                {
                    Assert.AreEqual("-", @operator.ToString());
                }
                else if (@operator is ArithmeticSumOperator)
                {
                    Assert.AreEqual("+", @operator.ToString());
                }
                else if (@operator is SequenceOperator)
                {
                    Assert.AreEqual("..", @operator.ToString());
                }
                else if (@operator is FormatOperator)
                {
                    Assert.AreEqual(":", @operator.ToString());
                }
                else
                {
                    Assert.Fail();
                }
            }

            return(dialect);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CodeMonkeyDialect"/> class.
 /// </summary>
 /// <param name="casing">A <see cref="DialectCasing" /> value that controls the dialect string casing behavior.</param>
 public CodeMonkeyDialect(DialectCasing casing)
     : base("Code Monkey", CultureInfo.InvariantCulture, casing)
 {
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StandardDialect"/> class.
 /// </summary>
 /// <param name="name">A human-readable name for the dialect.</param>
 /// <param name="culture">A <see cref="CultureInfo" /> object that drives the formatting and collation behavior of the dialect.</param>
 /// <param name="casing">A <see cref="DialectCasing" /> value that controls the dialect string casing behavior.</param>
 /// <exception cref="ArgumentNullException">Either argument <paramref name="name" /> or <paramref name="culture" /> is <c>null</c>.</exception>
 /// <exception cref="ArgumentException">Argument <paramref name="name" /> is an empty string.</exception>
 protected StandardDialect([NotNull] string name, [NotNull] CultureInfo culture, DialectCasing casing)
     : base(name, culture, casing)
 {
     PreformattedStateObject = new object();
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StandardDialect"/> class.
 /// </summary>
 /// <param name="culture">A <see cref="CultureInfo" /> object that drives the formatting and collation behavior of the dialect.</param>
 /// <param name="casing">A <see cref="DialectCasing" /> value that controls the dialect string casing behavior.</param>
 /// <exception cref="ArgumentNullException">Argument <paramref name="culture" /> is <c>null</c>.</exception>
 public StandardDialect([NotNull] CultureInfo culture, DialectCasing casing)
     : this("Standard", culture, casing)
 {
 }