Ejemplo n.º 1
0
        //	Just before
        public void autoCastArguments()
        {
            ProseObject[] pattern = AssociatedPattern;
            for (int i = 0; i < pattern.Length; i++)
            {
                PNode componentStart, componentEnd;
                componentStart = getArgumentBounds(i, out componentEnd);

                //	Check for auto-formatting of text expression into string

                //	Auto-cast a text expression into a string by evaluating it.
                if (pattern[i] == runtime.@string &&
                    Matching[i].value == runtime.Quadquote)
                {
                    PNode textStart = componentStart;
                    PNode textEnd   = componentEnd;
                    //	Create a StringLiteralObject to substitute
                    string textAsString = runtime.parseTextExpressionIntoString(textStart, textEnd);
                    PNode  literal      = new PNode(new StringLiteralObject(textAsString));

                    //	Splice in this literal
                    literal.prev = textStart.prev;
                    if (textStart.prev != null)
                    {
                        textStart.prev.next = literal;
                    }
                    literal.next = textEnd;
                    if (textEnd != null)
                    {
                        textEnd.prev = literal;
                    }

                    //	Correct the match list.
                    Matching[i] = literal;
                    continue;
                }

                //	Auto-cast a prose expression by unwrapping {}
                if (pattern[i] == runtime.@prose &&
                    componentStart.value == runtime.LeftCurlyBracket &&
                    componentEnd.prev.value == runtime.RightCurlyBracket)
                {
                    PNode leftCurly  = componentStart;
                    PNode rightCurly = componentEnd.prev;
                    //	Correct the match list
                    Matching[i] = leftCurly.next;
                    //	Eliminate the curly brackets
                    leftCurly.removeSelf();
                    rightCurly.removeSelf();
                    continue;
                }
            }
        }