Example #1
0
		/////////////////////////////////////////////////////////////////////////////

		public static NmpStringList Split( StringIndexer input, char openChar, char closeChar, bool splitCastMode = false )
		{
			// ******
			NmpStringList subStrings = new NmpStringList();

			// ******
			StringBuilder sb = new StringBuilder();
			char ch;

			while( true ) {
				ch = input.NextChar();

				// ******
				if( ESCAPE_CHAR == ch ) {
					ch = input.NextChar();

					if( END_OF_STRING == ch ) {
						continue;
					}
					else if( escapeChars.IndexOf(ch) >= 0 || openChar == ch || closeChar == ch ) {
						sb.Append( ch );
						continue;
					}

					//
					// not a valid escape char so add escape into output and fall thru to handle
					// ch
					//
					sb.Append( ESCAPE_CHAR );
				}

				// ******
				if( END_OF_STRING == ch || SPLIT_CHAR == ch || closeChar == ch ) {
					subStrings.Add( sb.ToString().Trim() );
					sb.Length = 0;

					if( END_OF_STRING == ch || closeChar == ch ) {
						break;
					}
				}
				else if( OPEN_BRACKET == ch || OPEN_PAREN == ch || openChar == ch ) {
					char closer;

					switch( ch ) {
						case OPEN_BRACKET:
							closer = CLOSE_BRACKET;
							break;

						case OPEN_PAREN:
							closer = CLOSE_PAREN;
							break;

						default:
							closer = closeChar;
							break;
					}
					
					// ******
					NmpStringList s = Split( input, ch, closer );

					sb.Append( ch );
					sb.Append( s.Join(';') );
					sb.Append( closer );

					// ******
					if( OPEN_PAREN == ch && splitCastMode ) {
						//
						// once we've seen a complete parenthesized chunk of text we:
						//
						//		add it to the list
						//		then add the remainder of the text to the next entry
						//		and return
						//
						subStrings.Add( sb.ToString() );
						subStrings.Add( input.Remainder.Trim() );
						return subStrings;
					}
				}
				else {
					sb.Append( ch );
				}
			}

			// ******
			//
			// did not find terminating character
			//
			if( END_OF_STRING != closeChar && END_OF_STRING == ch ) {
				throw ExceptionHelpers.CreateException( "Helpers.SplitString: unbalanced string, could not locate closing character '{0}'", closeChar );
			}

			// ******
			return subStrings;
		}
Example #2
0
		public object getMacroNames()
		{
			// ******
			var array = new NmpArray();

			// ******
			var list = mp.GetMacros( false );

			var names = new NmpStringList();
			foreach( IMacro macro in list ) {
				names.Add( macro.Name );
			}

			array.Add( "unsorted", names );
			names.Sort();
			array.Add( "sorted", names );
			
			
			list.Sort( ( a, b ) => string.Compare( a.Name, b.Name ) );


			// ******

//		Builtin,
//		Object,
//		Text,

			names = new NmpStringList();
			foreach( IMacro macro in list ) {
				if( MacroType.Builtin == macro.MacroType ) {
					names.Add( macro.Name );
				}
			}

			array.Add( "builtin", names );

			names = new NmpStringList();
			foreach( IMacro macro in list ) {
				if( MacroType.Object == macro.MacroType ) {
					names.Add( macro.Name );
				}
			}

			array.Add( "object", names );

			names = new NmpStringList();
			foreach( IMacro macro in list ) {
				if( MacroType.Text == macro.MacroType ) {
					names.Add( macro.Name );
				}
			}

			array.Add( "text", names );

			// ******
			return array;
		}
Example #3
0
		/////////////////////////////////////////////////////////////////////////////

		public RazorRunner( IMacroProcessor mp )
		{
			// ******
			this.mp = mp;
			this.assemblyPaths = ThreadContext.RazorAssemblyPaths;

			// ******
			string codeBase = LibInfo.CodeBase;
			if( ! assemblyPaths.Contains(codeBase) ) {
				assemblyPaths.Add( codeBase );
			}

			codeBase = string.Format( "{0}\\Nmp.dll", Path.GetDirectoryName(codeBase) );
			if( ! assemblyPaths.Contains(codeBase) ) {
				assemblyPaths.Add( codeBase );
			}
		}
Example #4
0
		public string [] Extract( string regExStr, int maxItems )
		{
			// ******
			NmpStringList list = new NmpStringList();

			try {
				Regex rx = new Regex( regExStr );
				MatchCollection mc = rx.Matches( theString );
				
				//
				// find all the matches for a regular expression and return the match or
				// if there is at least one subexpression return the subexpression
				//

				foreach( Match match in mc ) {
					if( match.Groups.Count > 1 ) {
						//
						// if there are subexpressions then we return the first one (outer most)
						//
						list.Add( match.Groups[1].Value );
					}
					else {
						list.Add( match.Value );
					}
					
					//
					// note: we are NOT inhibiting Matches from generating as many matches as it
					// can, only limiting the number we return
					//

					if( 0 == --maxItems ) {
						break;
					}
				}
			}
			catch ( ArgumentException ex ) {
				ThreadContext.MacroError( "while executing Extract(): {0}", ex.Message );
			}
			
			// ******
			return list.ToArray();
		}
Example #5
0
		/////////////////////////////////////////////////////////////////////////////

		public static ICollection GetNamespaces( Assembly assembly )
		{
			// ******
			NmpStringList list = new NmpStringList( unique: true );

			foreach( Type t in assembly.GetTypes() ) {
				string ns = t.Namespace;

				if( IsNetValidIdentifier(ns, allowDots : true) ) {
					list.Add( ns );
				}
			}

			// ******
			return list;
		}
Example #6
0
File: ETB.cs Project: jmclain/Nmp
		/////////////////////////////////////////////////////////////////////////////

		protected void ParseMacroOptions( IInput input, NmpStringList instructions )
		{
			//MacroInstructions = argScanner( input, RecognizedCharType.CloseBracketChar );
			NmpStringList list = scanner.ArgScanner( input, RecognizedCharType.CloseBracketChar );
			instructions.Add( list );
		}
Example #7
0
		/////////////////////////////////////////////////////////////////////////////

		public string Foreach_TextChunk( object objToEnumerate, string macroText, object [] extraArgs )
		{
			// ******
			//
			//	list: `value', `index', `lastIndex', `count', `type'
			//
			var argNames = new NmpStringList( "value", "index", "lastIndex", "count", "type" );

			//
			// extra0 ... extraN
			//
			for( int i = 0; i < extraArgs.Length; i++ ) {
				argNames.Add( string.Format( "extra{0}", i ) );
			}

			// ******
			IMacro target = mp.AddTextMacro( mp.GenerateMacroName("$.foreach"), macroText, argNames );
			string result = ForeachTextMacro( target, objToEnumerate, extraArgs );
			mp.DeleteMacro( target );

			// ******
			return result;
		}
Example #8
0
			/////////////////////////////////////////////////////////////////////////////

			public string Make( string rspPath )
			{
				// ******
				try {
					if( string.IsNullOrEmpty(rspPath) ) {
						ThreadContext.MacroError( "the response file path argument to #makersp is empty" );
					}

					// ******
					if( ! Path.IsPathRooted(rspPath) ) {
						rspPath = Path.Combine( mp.GrandCentral.GetDirectoryStack().Peek(), rspPath );
					}

					string responseFileDirectory = Path.GetDirectoryName( rspPath );

					if( ! File.Exists(rspPath) ) {
						ThreadContext.MacroError( "#makersp could not locate the response file \"{0}\"", rspPath );
					}

					// ******
					string dllPath = null;
					var filesToCheck = new NmpStringList();

					// ******
					string [] linesOfText = File.ReadAllLines( rspPath );

					foreach( string _text in linesOfText ) {
						var text = _text.Trim().ToLower();

						// ******
						if( string.IsNullOrEmpty(text) ) {
							continue;
						}

						// ******
						if( text.StartsWith("/out:") ) {
							dllPath = text.Substring( 5 ).Trim();
							continue;
						}

						// ******
						char chFirst = text[0];

						if( '/' == chFirst || '#' == chFirst ) {
							continue;
						}

						// ******
						filesToCheck.Add( text );
					}

					// ******
					if( null == dllPath ) {
						ThreadContext.MacroError( "#makersp was unable to locate the \"/out:\" argument in the response file" );
					}

					if( string.IsNullOrEmpty(dllPath) ) {
						ThreadContext.MacroError( "#makersp: the \"/out:\" argument in the response file is empty" );
					}

					if( ! Path.IsPathRooted(dllPath) ) {
						dllPath = Path.Combine( responseFileDirectory, dllPath );
					}

					// ******
					if( 0 == linesOfText.Count() ) {
						ThreadContext.MacroError( "#makersp was unable to locate any source file paths in the response file" );
					}

					// ******
					if( ! UptoDate(dllPath, rspPath, responseFileDirectory, filesToCheck) ) {
						Update( rspPath, dllPath );
					}

					// ******
					return dllPath;
				}
				catch ( Exception ex ) {
					if( ex is ExitException ) {
						throw ex;
					}
					//
					// never returns
					//
					ThreadContext.MacroError( "exception in macro #makersp: {0}", ex.Message );
					//
					// make the compiler happy
					//
					throw ex;
				}
			}
Example #9
0
		/////////////////////////////////////////////////////////////////////////////

		public string Forloop_TextChunk( int start, int end, int increment, string macroText, object [] extraArgs )
		{
			// ******
			//
			//	`index', `lastIndex', `increment' [, extra0, extra1, ...]
			//
			var argNames = new NmpStringList( "index", "lastIndex", "increment" );
			//
			// extra0 ... extraN
			//
			for( int i = 0; i < extraArgs.Length; i++ ) {
				argNames.Add( string.Format( "extra{0}", i ) );
			}

			// ******
			IMacro target = mp.AddTextMacro( mp.GenerateMacroName("$.forloop"), macroText, argNames );
			string result = ProcessForLoop( target, start, end, increment, extraArgs );
			mp.DeleteMacro( target );

			// ******
			return result;
		}
Example #10
0
		/////////////////////////////////////////////////////////////////////////////

		public static NmpStringList CoreAssemblies( IList<string> moreAssemblies )
		{
			// ******
			var assemblies = new NmpStringList( unique : true );
			
			assemblies.Add( "System.dll" );
			assemblies.Add( "System.Core.dll" );
			assemblies.Add( "Microsoft.CSharp.dll" );

	/*

		things to watch out for:

			o		the compile (and razor) code is currently in Csx.exe but it will be
					moved to NmpBase when it is all smoothed out and running

						so, at some point DefaultRazorTemplateBase will NOT be in the
						same assembly as this code


	*/

//			assemblies.Add( Assembly.GetExecutingAssembly().CodeBase.Substring( 8 ) );
//
//			//
//			// this get NmpBase.dll
//			//
//			assemblies.Add( typeof(NmpStringList).Assembly.CodeBase.Substring( 8 ) );

			if( null != moreAssemblies ) {
				assemblies.AddRange( moreAssemblies );
			}

			// ******
			assemblies.Sort();
			return assemblies;
		}
Example #11
0
		/////////////////////////////////////////////////////////////////////////////

		public static NmpStringList DefCompilerOptions( TargetType tt )
		{
			var options = new NmpStringList();

			// ******
			//options.Add( "/platform:" + PlatformName(pt) );
			options.Add( "/target:" + TargetTypeExtension(tt) );

			// ******
			return options;
		}