Example #1
0
        /// <summary>  init : we don't have to do much.  Init the tree (there
        /// shouldn't be one) and then see if interpolation is turned on.
        /// </summary>
        public override Object Init(IInternalContextAdapter context, Object data)
        {
            base.Init(context, data);

            /*
             *  the stringlit is set at template parse time, so we can
             *  do this here for now.  if things change and we can somehow
             * create stringlits at runtime, this must
             *  move to the runtime execution path
             *
             *  so, only if interpolation is turned on AND it starts
             *  with a " AND it has a  directive or reference, then we
             *  can  interpolate.  Otherwise, don't bother.
             */

            interpolate = FirstToken.Image.StartsWith("\"") &&
                          ((FirstToken.Image.IndexOf('$') != -1) ||
                           (FirstToken.Image.IndexOf('#') != -1));

            /*
             *  get the contents of the string, minus the '/" at each end
             */

            image = FirstToken.Image.Substring(1, (FirstToken.Image.Length - 1) - (1));

            /*
             * tack a space on the end (dreaded <MORE> kludge)
             */

            interpolateImage = string.Format("{0} ", image);

            if (interpolate)
            {
                /*
                 *  now parse and init the nodeTree
                 */
                TextReader br = new StringReader(interpolateImage);

                /*
                 * it's possible to not have an initialization context - or we don't
                 * want to trust the caller - so have a fallback value if so
                 *
                 *  Also, do *not* dump the VM namespace for this template
                 */

                nodeTree = runtimeServices.Parse(br, (context != null) ? context.CurrentTemplateName : "StringLiteral", false);

                /*
                 *  init with context. It won't modify anything
                 */

                nodeTree.Init(context, runtimeServices);
            }

            return(data);
        }
Example #2
0
        private object EvaluateInPlace(string content, IInternalContextAdapter context)
        {
            try
            {
                SimpleNode inlineNode = runtimeServices.Parse(new StringReader(content), context.CurrentTemplateName, false);

                inlineNode.Init(context, runtimeServices);

                return(Evaluate(inlineNode, context));
            }
            catch (Exception)
            {
                throw new ArgumentException(string.Format("Problem evaluating dictionary entry with content {0}", content));
            }
        }
Example #3
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(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;
			}
		}
		/// <summary>  init : we don't have to do much.  Init the tree (there
		/// shouldn't be one) and then see if interpolation is turned on.
		/// </summary>
		public override Object Init(IInternalContextAdapter context, Object data)
		{
			base.Init(context, data);

			/*
			*  the stringlit is set at template parse time, so we can 
			*  do this here for now.  if things change and we can somehow 
			* create stringlits at runtime, this must
			*  move to the runtime execution path
			*
			*  so, only if interpolation is turned on AND it starts 
			*  with a " AND it has a  directive or reference, then we 
			*  can  interpolate.  Otherwise, don't bother.
			*/

			interpolate = FirstToken.Image.StartsWith("\"") &&
			              ((FirstToken.Image.IndexOf('$') != - 1) ||
			               (FirstToken.Image.IndexOf('#') != - 1));

			/*
			*  get the contents of the string, minus the '/" at each end
			*/

			image = FirstToken.Image.Substring(1, (FirstToken.Image.Length - 1) - (1));
			/*
			* tack a space on the end (dreaded <MORE> kludge)
			*/

			interpolateimage = image + " ";

			if (interpolate)
			{
				/*
				*  now parse and init the nodeTree
				*/
				TextReader br = new StringReader(interpolateimage);

				/*
				* it's possible to not have an initialization context - or we don't
				* want to trust the caller - so have a fallback value if so
				*
				*  Also, do *not* dump the VM namespace for this template
				*/

				nodeTree = rsvc.Parse(br, (context != null) ? context.CurrentTemplateName : "StringLiteral", false);

				/*
				*  init with context. It won't modify anything
				*/

				nodeTree.Init(context, rsvc);
			}

			return data;
		}
			internal void parseTree(IInternalContextAdapter ica)
			{
				try
				{
					//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(macrobody);

					nodeTree = Enclosing_Instance.rsvc.Parse(br, "VM:" + macroname, true);
					nodeTree.Init(ica, null);
				}
				catch(System.Exception e)
				{
					Enclosing_Instance.rsvc.Error("VelocimacroManager.parseTree() : exception " + macroname + " : " + e);
				}
			}
            internal void parseTree(IInternalContextAdapter internalContextAdapter)
            {
                try
                {
                    //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(macroBody);

                    nodeTree = Enclosing_Instance.runtimeServices.Parse(br, string.Format("VM:{0}", macroName), true);
                    nodeTree.Init(internalContextAdapter, null);
                }
                catch(System.Exception e)
                {
                    Enclosing_Instance.runtimeServices.Error(
                        string.Format("VelocimacroManager.parseTree() : exception {0} : {1}", macroName, e));
                }
            }
Example #7
0
        /// <summary> Init : we don't have to do much. Init the tree (there shouldn't be one)
        /// and then see if interpolation is turned on.
        ///
        /// </summary>
        /// <param name="context">
        /// </param>
        /// <param name="data">
        /// </param>
        /// <returns> Init result.
        /// </returns>
        /// <throws>  TemplateInitException </throws>
        public override object Init(IInternalContextAdapter context, object data)
        {
            /*
             * simple habit... we prollie don't have an AST beneath us
             */

            base.Init(context, data);

            /*
             * the stringlit is set at template parse time, so we can do this here
             * for now. if things change and we can somehow create stringlits at
             * runtime, this must move to the runtime execution path
             *
             * so, only if interpolation is turned on AND it starts with a " AND it
             * has a directive or reference, then we can Interpolate. Otherwise,
             * don't bother.
             */

            interpolate = rsvc.GetBoolean(RuntimeConstants.INTERPOLATE_STRINGLITERALS, true) && FirstToken.Image.StartsWith("\"") && ((FirstToken.Image.IndexOf('$') != -1) || (FirstToken.Image.IndexOf('#') != -1));

            /*
             * Get the contents of the string, minus the '/" at each end
             */

            image = FirstToken.Image.Substring(1, (FirstToken.Image.Length - 1) - (1));
            if (FirstToken.Image.StartsWith("\""))
            {
                image = Unescape(image);
            }

            /**
             * note. A kludge on a kludge. The first part, Geir calls this the
             * dreaded <MORE> kludge. Basically, the use of the <MORE> token eats
             * the last character of an interpolated string. EXCEPT when a line
             * comment (##) is in the string this isn't an issue.
             *
             * So, to solve this we look for a line comment. If it isn't found we
             * Add a space here and remove it later.
             */

            /**
             * Note - this should really use a regexp to look for [^\]## but
             * apparently escaping of line comments isn't working right now anyway.
             */
            containsLineComment = (image.IndexOf("##") != -1);

            /*
             * if appropriate, tack a space on the end (dreaded <MORE> kludge)
             */

            if (!containsLineComment)
            {
                interpolateimage = image + " ";
            }
            else
            {
                interpolateimage = image;
            }

            if (interpolate)
            {
                /*
                 * now parse and Init the nodeTree
                 */
                StringReader br = new StringReader(interpolateimage);

                /*
                 * it's possible to not have an initialization context - or we don't
                 * want to trust the caller - so have a fallback value if so
                 *
                 * Also, do *not* dump the VM namespace for this template
                 */

                string templateName = (context != null) ? context.CurrentTemplateName : "StringLiteral";
                try
                {
                    nodeTree = rsvc.Parse(br, templateName, false);
                }
                catch (ParseException e)
                {
                    string msg = "Failed to parse String literal at " + Log.Log.FormatFileString(templateName, Line, Column);
                    throw new TemplateInitException(msg, e, templateName, Column, Line);
                }

                AdjTokenLineNums(nodeTree);

                /*
                 * Init with context. It won't modify anything
                 */

                nodeTree.Init(context, rsvc);
            }

            return(data);
        }