Exemplo n.º 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);
        }
Exemplo n.º 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 (System.Exception)
            {
                throw new ArgumentException(string.Format("Problem evaluating dictionary entry with content {0}", content));
            }
        }
Exemplo n.º 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(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;
			}
		}
			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));
				}
			}
		/// <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;
		}