protected virtual FunctionSet InitFunctions()
 {
     if ((this.Options & ExpressiveOptions.IgnoreCaseForParsing) > 0)
     {
         return(FunctionSet.CreateDefaultSet(StringComparer.OrdinalIgnoreCase));
     }
     else
     {
         return(FunctionSet.CreateDefaultSet(StringComparer.Ordinal));
     }
 }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Context"/> class with the specified <paramref name="options"/>.
        /// </summary>
        /// <param name="options">The <see cref="ExpressiveOptions"/> to use when evaluating.</param>
        /// <param name="mainCurrentCulture">The <see cref="CultureInfo"/> for use in general parsing/conversions.</param>
        /// <param name="decimalCurrentCulture">The <see cref="CultureInfo"/> for use in decimal parsing/conversions.</param>
        public Context(ExpressiveOptions options, CultureInfo mainCurrentCulture, CultureInfo decimalCurrentCulture, FunctionSet functions, OperatorSet operators)
        {
            Options = options;

            this.CurrentCulture = mainCurrentCulture ?? throw new ArgumentNullException(nameof(mainCurrentCulture));
            // For now we will ignore any specific cultures but keeping it in a single place to simplify changing later if required.
            this.DecimalCurrentCulture = decimalCurrentCulture ?? throw new ArgumentNullException(nameof(decimalCurrentCulture));

            DecimalSeparator         = Convert.ToChar(this.DecimalCurrentCulture.NumberFormat.NumberDecimalSeparator, this.DecimalCurrentCulture);
            this.registeredFunctions = functions ?? throw new ArgumentNullException(nameof(functions));
            this.registeredOperators = operators ?? throw new ArgumentNullException(nameof(operators));
        }
        public string BuildCommand(string dccAddress, FunctionSet dccFunctions, bool locomotiveOn)
        {
            var output = "";

            var value = 128;

            if (dccFunctions.F1)
            {
                value += 1;
            }
            if (dccFunctions.F2)
            {
                value += 2;
            }
            if (dccFunctions.F3)
            {
                value += 4;
            }
            if (dccFunctions.F4)
            {
                value += 8;
            }
            if (locomotiveOn)
            {
                value += 16;
            }

            output = AddCommand(output, "<f " + dccAddress + " " + value + ">");

            value = 176;
            if (dccFunctions.F5)
            {
                value += 1;
            }
            if (dccFunctions.F6)
            {
                value += 2;
            }
            if (dccFunctions.F7)
            {
                value += 4;
            }
            if (dccFunctions.F8)
            {
                value += 8;
            }

            output = AddCommand(output, "<f " + dccAddress + " " + value + ">");
            return(output);
        }
        public void BuildCommandShouldBuildCorrectFunctionsCommand(string dccAddress, bool locomotiveOn, bool f1,
                                                                   bool f2, bool f3, bool f4, bool f5, bool f6, bool f7, bool f8, string expected)
        {
            var functionSet = new FunctionSet
            {
                F1 = f1,
                F2 = f2,
                F3 = f3,
                F4 = f4,
                F5 = f5,
                F6 = f6,
                F7 = f7,
                F8 = f8
            };
            var actual = _sut.BuildCommand(dccAddress, functionSet, locomotiveOn);

            actual.Should().Be(expected);
        }
예제 #5
0
 public static bool IsFunction(string cmd)
 {
     return(FunctionSet.Contains(cmd));
 }
예제 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Context"/> class with the specified <paramref name="options"/>.
 /// </summary>
 /// <param name="options">The <see cref="ScryberOptions"/> to use when evaluating.</param>
 /// <param name="functions">All the standard functions</param>
 /// <param name="operators">All The standard Operators</param>
 public Context(ExpressiveOptions options, FunctionSet functions, OperatorSet operators)
     : this(options, CultureInfo.CurrentCulture, CultureInfo.InvariantCulture, functions, operators)
 {
 }