Example #1
0
        /// <summary>
        /// Creates an instance of the type associated with theses methods from the arguments supplied. Repesents a constructor call
        /// </summary>
        /// <param name="args">The arguments used to construct the instance of this type</param>
        /// <returns></returns>
        public override LObject CreateFromArgs(object[] args)
        {
            var parameters = new List <object>();

            if (args != null && args.Length > 0)
            {
                foreach (var arg in args)
                {
                    if (arg is LObject)
                    {
                        parameters.Add(((LObject)arg).GetValue());
                    }
                }
            }
            args = parameters.ToArray();
            var time = DateTimeTypeHelper.CreateTimeFrom(args);

            return(new LTime(time));
        }
Example #2
0
        /// <summary>
        /// Check new expressions.
        /// </summary>
        /// <param name="semActs">The semantic analyser</param>
        /// <param name="exp">The newexpression</param>
        private void CheckNewExpression(SemActs semActs, NewExpr exp)
        {
            var typeName = exp.TypeName;

            // 1. Check # params to Date
            if (string.Compare(typeName, "Date", StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                if (!LDateType.CanCreateFrom(exp.ParamListExpressions.Count))
                {
                    AddError("Unexpected number of inputs when creating date", exp);
                }
            }
            // 2. Check # params to Time
            else if (string.Compare(typeName, "Time", StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                if (!DateTimeTypeHelper.CanCreateTimeFrom(exp.ParamListExpressions.Count))
                {
                    AddError("Unexpected number of inputs when creating time", exp);
                }
            }
        }
Example #3
0
        /// <summary>
        /// Whether or not this uri plugin can handle the current token.
        /// </summary>
        /// <param name="current"></param>
        /// <returns></returns>
        public override bool CanHandle(Token current)
        {
            _time   = TimeSpan.MinValue;
            _endPos = -1;
            // Case 1: noon, "afternoon, midnight
            if (_aliases.ContainsKey(current.Text))
            {
                _time = CloneTime(_aliases[current.Text]);
                return(true);
            }

            // Check 1: Make sure it's a number.
            if (current.Kind != TokenKind.LiteralNumber)
            {
                return(false);
            }

            var nextToken     = _lexer.PeekToken();
            var nextTokenText = nextToken.Token.Text.ToLower();

            // Check 2: End token?
            if (nextToken.Token == ComLib.Lang.Core.Tokens.EndToken)
            {
                return(false);
            }

            // Check 3: Time format is 9:30 am or 930 am
            // So if next token is not ':' then it has to be "am" or "pm"
            if (nextTokenText != ComLib.Lang.Core.Tokens.Colon.Text &&
                nextTokenText != "am" && nextTokenText != "pm")
            {
                return(false);
            }

            var text = Lexer.State.CurrentChar + _lexer.Scanner.PeekMaxChars(10);
            // 1. Check for am/pm ( required )
            var isAm      = true;
            var ndxAmOrPm = text.IndexOf("am", StringComparison.InvariantCultureIgnoreCase);

            if (ndxAmOrPm == -1)
            {
                ndxAmOrPm = text.IndexOf("pm", StringComparison.InvariantCultureIgnoreCase);
                if (ndxAmOrPm > -1)
                {
                    isAm = false;
                }
            }

            // Case 3: No am/pm designator so not applicable
            if (ndxAmOrPm == -1)
            {
                return(false);
            }

            // Case 4: 830pm
            if (text.IndexOf(":") < 0)
            {
                text    = current.Text + text.Substring(0, ndxAmOrPm + 2);
                _time   = DateTimeTypeHelper.ParseTimeWithoutColons(current.Text, isAm);
                _endPos = _lexer.State.Pos + ndxAmOrPm + 1;
                return(true);
            }
            // Note: the longest time string can only be 9 chars e.g. :30:45 am
            text = current.Text + text.Substring(0, ndxAmOrPm + 2);
            var result = DateTimeTypeHelper.ParseTime(text);

            // Was not a valid time string. maybe some other plguin can handle it.
            if (!result.Item2)
            {
                return(false);
            }

            _endPos = _lexer.State.Pos + ndxAmOrPm + 1;
            _time   = result.Item1;
            return(true);
        }