コード例 #1
0
        /// <summary>
        /// Some operations on the vector.
        /// </summary>
        /// <param name="expression"></param>
        /// <returns></returns>
        public override QsValue Execute(ParticleLexer.Token expression)
        {
            if (expression.TokenValue.Equals("length", StringComparison.OrdinalIgnoreCase))
            {
                return(this.Count.ToScalarValue());
            }

            return(base.Execute(expression));
        }
コード例 #2
0
        static void ReadCurrenciesJson()
        {
            if (!File.Exists(TodayChangeRatesFile))
            {
                // get the file from http://openexchangerates.org
                DownloadExchangeFile();
            }

            using (var rr = new System.IO.StreamReader(TodayChangeRatesFile))
            {
                CurrenciesJson = ParticleLexer.Token.ParseText(rr.ReadToEnd());
            }

            /*
             * json format is
             *
             * { "key": value,  "key": "other value", "key":{ "key":value }
             *
             * value is either string or number
             *
             */
            CurrenciesJson = CurrenciesJson.TokenizeTextStrings();
            CurrenciesJson = CurrenciesJson.MergeTokens <WordToken>();
            CurrenciesJson = CurrenciesJson.RemoveAnySpaceTokens();
            CurrenciesJson = CurrenciesJson.RemoveNewLineTokens();
            CurrenciesJson = CurrenciesJson.MergeTokens <NumberToken>();
            CurrenciesJson = CurrenciesJson.MergeSequenceTokens <MergedToken>(
                typeof(ParticleLexer.CommonTokens.TextStringToken),
                typeof(ColonToken),
                typeof(NumberToken)
                );


            Currs = new Dictionary <string, double>();

            // find rates key
            foreach (var tok in CurrenciesJson)
            {
                if (tok.TokenClassType == typeof(MergedToken))
                {
                    Currs.Add(tok[0].TrimTokens(1, 1).TokenValue, double.Parse(tok[2].TokenValue, CultureInfo.InvariantCulture));
                }
            }
        }
コード例 #3
0
 /// <summary>
 /// when executing object->method or property
 /// </summary>
 /// <param name="expression"></param>
 /// <returns></returns>
 public override QsValue Execute(ParticleLexer.Token expression)
 {
     return(ContentValue.Execute(expression));
 }