Esempio n. 1
0
        private object Evaluate(SimpleNode inlineNode, IInternalContextAdapter context)
        {
            var values = new ArrayList();

            for (var i = 0; i < inlineNode.ChildrenCount; i++)
            {
                var node = inlineNode.GetChild(i);

                if (node.Type == ParserTreeConstants.TEXT)
                {
                    values.Add(((ASTText)node).Text);
                }
                else
                {
                    values.Add(node.Value(context));
                }
            }

            if (values.Count == 0)
            {
                return(null);
            }
            else if (values.Count == 1)
            {
                return(values[0]);
            }
            else
            {
                var sb = new StringBuilder();
                foreach (var value in values)
                {
                    sb.Append(value);
                }
                return(sb.ToString());
            }
        }
Esempio n. 2
0
        /// <summary>  does the housekeeping upon creating.  If a dynamic type
        /// it needs to make an AST for further get()/set() operations
        /// Anything else is constant.
        /// </summary>
        private void setup()
        {
            switch (type)
            {
            case ParserTreeConstants.INTEGER_RANGE:
            case ParserTreeConstants.REFERENCE:
            case ParserTreeConstants.OBJECT_ARRAY:
            case ParserTreeConstants.STRING_LITERAL:
            case ParserTreeConstants.TEXT:
            {
                /*
                 *  dynamic types, just render
                 */

                constant = false;

                try
                {
                    /*
                     *  fakie : wrap in  directive to get the parser to treat our args as args
                     *   it doesn't matter that #include() can't take all these types, because we
                     *   just want the parser to consider our arg as a Directive/VM arg rather than
                     *   as if inline in schmoo
                     */

                    String buff = string.Format("#include({0} ) ", callerReference);

                    //ByteArrayInputStream inStream = new ByteArrayInputStream( buff.getBytes() );

                    //UPGRADE_ISSUE: The equivalent of constructor 'java.io.BufferedReader.BufferedReader' is incompatible with the expected type in C#. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1109"'
                    TextReader br = new StringReader(buff);

                    nodeTree = runtimeServices.Parse(br, string.Format("VMProxyArg:{0}", callerReference), true);

                    /*
                     *  now, our tree really is the first DirectiveArg(), and only one
                     */

                    nodeTree = (SimpleNode)nodeTree.GetChild(0).GetChild(0);

                    /*
                     * sanity check
                     */

                    if (nodeTree != null && nodeTree.Type != type)
                    {
                        runtimeServices.Error("VMProxyArg.setup() : programmer error : type doesn't match node type.");
                    }

                    /*
                     *  init.  We can do this as they are only references
                     */

                    nodeTree.Init(null, runtimeServices);
                }
                catch (System.Exception e)
                {
                    runtimeServices.Error(string.Format("VMProxyArg.setup() : exception {0} : {1}", callerReference, e));
                }

                break;
            }

            case ParserTreeConstants.TRUE:
            {
                constant     = true;
                staticObject = true;
                break;
            }

            case ParserTreeConstants.FALSE:
            {
                constant     = true;
                staticObject = false;
                break;
            }

            case ParserTreeConstants.NUMBER_LITERAL:
            {
                constant     = true;
                staticObject = Int32.Parse(callerReference);
                break;
            }

            case ParserTreeConstants.WORD:
            {
                /*
                 *  this is technically an error...
                 */

                runtimeServices.Error(
                    string.Format(
                        "Unsupported arg type : {0}  You most likely intended to call a VM with a string literal, so enclose with ' or \" characters. (VMProxyArg.setup())",
                        callerReference));
                constant     = true;
                staticObject = new String(callerReference.ToCharArray());

                break;
            }

            default:
            {
                runtimeServices.Error(string.Format(" VMProxyArg.setup() : unsupported type : {0}", callerReference));
            }
            break;
            }
        }