예제 #1
0
        public RichFunction(Stringe origin, RichActionBase body, RichGroup args)
            : base(origin)
        {
            List <string> argNames = new List <string>();

            if (args.Actions.Count > 0)
            {
                string lastArg = "";
                for (var i = 0; i < args.Actions.Count; i++)
                {
                    var action = args.Actions[i];
                    if (action is RichArgumentSeperator)
                    {
                        argNames.Add(lastArg);
                    }
                    else
                    {
                        lastArg = (action as RichVariable).Name;
                    }
                }
                argNames.Add(lastArg);
            }
            // reverse it, since things are popped from the object stack in reverse order
            argNames.Reverse();
            _argNames  = argNames.ToArray();
            _body      = body;
            Type       = ActionValueType.Function;
            Returnable = true;
        }
예제 #2
0
        public RichFunctionCall(Stringe token, RichActionBase function, RichGroup args, string _sourceName)
            : base(token)
        {
            _function = function;
            List <RichActionBase> argValues = new List <RichActionBase>();

            if (args.Actions.Count > 0)
            {
                RichActionBase lastArg = null;
                for (var i = 0; i < args.Actions.Count; i++)
                {
                    var action = args.Actions[i];
                    if (action is RichArgumentSeperator)
                    {
                        if (lastArg == null)
                        {
                            throw new RantCompilerException(_sourceName, Range, "Blank argument in function call.");
                        }
                        argValues.Add(lastArg);
                    }
                    else
                    {
                        lastArg = action;
                    }
                }
                argValues.Add(lastArg);
            }
            _argValues = argValues.ToArray();

            Returnable = true;
        }
예제 #3
0
		public RichFunctionCall(Stringe token, RichActionBase function, RichGroup args, string _sourceName)
			: base(token)
		{
			_function = function;
			List<RichActionBase> argValues = new List<RichActionBase>();
			if (args.Actions.Count > 0)
			{
				RichActionBase lastArg = null;
				for (var i = 0; i < args.Actions.Count; i++)
				{
					var action = args.Actions[i];
                    if (action is RichArgumentSeperator)
                    {
                        if (lastArg == null)
                            throw new RantCompilerException(_sourceName, Range, "Blank argument in function call.");
                        argValues.Add(lastArg);
                    }
                    else
                        lastArg = action;
				}
				argValues.Add(lastArg);
			}
			_argValues = argValues.ToArray();

            Returnable = true;
		}
예제 #4
0
 public RichIfStatement(Stringe token, RichActionBase expr, RichActionBase body, RichActionBase elseBody = null)
     : base(token)
 {
     _expression = expr;
     _body       = body;
     _elseBody   = elseBody;
 }
예제 #5
0
		public RichIfStatement(Stringe token, RichActionBase expr, RichActionBase body, RichActionBase elseBody = null)
			: base(token)
		{
			_expression = expr;
			_body = body;
            _elseBody = elseBody;
		}
		public RichObjectPropertyAssignment(Stringe origin, RichActionBase nameExp, RichActionBase obj, RichActionBase value)
			: base(origin)
		{
			Name = nameExp;
			_value = value;
			_object = obj;
		}
 public RichObjectPropertyAssignment(Stringe origin, RichActionBase nameExp, RichActionBase obj, RichActionBase value)
     : base(origin)
 {
     Name    = nameExp;
     _value  = value;
     _object = obj;
 }
예제 #8
0
파일: RichWhile.cs 프로젝트: W-h-a-t-s/Rant
        public RichWhile(Stringe token, RichActionBase test, RichActionBase body)
            : base(token)
        {
            _test = test;
            _body = body;

            Breakable = true;
        }
예제 #9
0
        public RichWhile(Stringe token, RichActionBase test, RichActionBase body)
            : base(token)
        {
            _test = test;
            _body = body;

            Breakable = true;
        }
예제 #10
0
 public RichFor(
     Stringe token,
     string indexName,
     RichActionBase body,
     RichActionBase expr)
     : base(token)
 {
     _expr      = expr;
     _body      = body;
     _indexName = indexName;
 }
예제 #11
0
파일: RichFor.cs 프로젝트: W-h-a-t-s/Rant
 public RichFor(
     Stringe token,
     string indexName,
     RichActionBase body,
     RichActionBase expr)
     : base(token)
 {
     _expr = expr;
     _body = body;
     _indexName = indexName;
 }
예제 #12
0
		public RichFunction(Stringe origin, RichActionBase body, RichGroup args)
			: base(origin)
		{
			List<string> argNames = new List<string>();
			if (args.Actions.Count > 0)
			{
				string lastArg = "";
				for (var i = 0; i < args.Actions.Count; i++)
				{
					var action = args.Actions[i];
					if (action is RichArgumentSeperator)
						argNames.Add(lastArg);
					else
						lastArg = (action as RichVariable).Name;
				}
				argNames.Add(lastArg);
			}
            // reverse it, since things are popped from the object stack in reverse order
            argNames.Reverse();
            _argNames = argNames.ToArray();
			_body = body;
			Type = ActionValueType.Function;
            Returnable = true;
		}
예제 #13
0
		public RichObjectProperty(Stringe origin, RichActionBase name, RichActionBase obj)
			: base(origin)
		{
			Name = name;
			_object = obj;
		}
예제 #14
0
 public RichObjectProperty(Stringe origin, RichActionBase name, RichActionBase obj)
     : base(origin)
 {
     Name    = name;
     _object = obj;
 }
예제 #15
0
		public RichReturn(Stringe origin, RichActionBase value)
			: base(origin)
		{
			_returnValue = value;
		}
예제 #16
0
 public RichReturn(Stringe origin, RichActionBase value)
     : base(origin)
 {
     _returnValue = value;
 }
        public override IEnumerator <RantAction> Run(Sandbox sb)
        {
            string name = null;

            if (Name is string)
            {
                name = Name as string;
            }
            else if (Name is RichActionBase)
            {
                yield return(Name as RichActionBase);

                name = sb.ScriptObjectStack.Pop().ToString();
            }
            else
            {
                yield break;
            }
            // variable assignment
            if (_object == null)
            {
                object value = null;
                if (_value != null)
                {
                    var count = sb.ScriptObjectStack.Count;
                    yield return(_value);

                    // no value was created, no value will be assigned
                    if (count >= sb.ScriptObjectStack.Count)
                    {
                        yield break;
                    }
                    value = sb.ScriptObjectStack.Pop();
                    if (Operator != null && sb.Objects[name] != null)
                    {
                        Operator.LeftSide  = Util.ConvertToAction(Range, sb.Objects[name].Value);
                        Operator.RightSide = Util.ConvertToAction(Range, value);
                        yield return(Operator);

                        value = sb.ScriptObjectStack.Pop();
                    }
                }
                sb.Objects[name] = ConvertValue(value);
                yield break;
            }
            yield return(_object);

            var obj = sb.ScriptObjectStack.Pop();

            if (obj is RichObject)
            {
                RichActionBase value = _value;
                if (Operator != null && (obj as RichObject).Values[name] != null)
                {
                    Operator.LeftSide  = (obj as RichObject).Values[name];
                    Operator.RightSide = _value;
                    yield return(Operator);

                    value = Util.ConvertToAction(Range, sb.ScriptObjectStack.Pop());
                }
                (obj as RichObject).Values[name] = value;
            }
            else if (obj is RichList)
            {
                int index = -1;
                if (!int.TryParse(name, out index))
                {
                    yield break;
                }
                RichActionBase value = _value;
                yield return(_value);

                value = Util.ConvertToAction(Range, sb.ScriptObjectStack.Pop());
                if (Operator != null && (obj as RichList).Items[index] != null)
                {
                    Operator.LeftSide  = (obj as RichList).Items[index];
                    Operator.RightSide = _value;
                    yield return(Operator);

                    value = Util.ConvertToAction(Range, sb.ScriptObjectStack.Pop());
                }
                (obj as RichList).ItemsChanged = true;
                if ((obj as RichList).InternalItems.Count <= index)
                {
                    for (var i = (obj as RichList).InternalItems.Count - 1; i < index + 1; i++)
                    {
                        (obj as RichList).InternalItems.Add(null);
                    }
                }
                (obj as RichList).InternalItems[index] = value;
                yield return(obj as RichList);

                obj = sb.ScriptObjectStack.Pop();
            }
            yield break;
        }
예제 #18
0
 public RichObjectKeyValue(Stringe token, RichActionBase value)
     : base(token)
 {
     Name  = Util.UnescapeConstantLiteral(token.Value);
     Value = value;
 }