コード例 #1
0
ファイル: ArgumentsProcessor.cs プロジェクト: jmclain/Nmp
		/////////////////////////////////////////////////////////////////////////////

		protected ArgumentExpression EvaluateCastExpression( Expression parent, string str )
		{
			// ******
			//
			// calling SplitString() with 'splitCastMode' set to true, see the comments below where
			// we check the number of items returned
			//
			StringIndexer si = new StringIndexer( str );
			NmpStringList list = SplitString.Split( si, SplitString.END_OF_STRING, SplitString.END_OF_STRING, true );

			// ******
			if( 2 != list.Count ) {
				//
				// "()" 
				//

	// TODO: issue when called by ETB

				scanner.Error( null, "error atempting to cast expression: \"{0}\"", str );
			}

			// ******
			string rhs = list[ 1 ];
			if( ! string.IsNullOrEmpty(rhs) && SC.ATCHAR == rhs[0] ) {

				ArgumentExpression argExp = EvaluateAtExpression( parent, rhs.Substring(1) );

				string typeName = list[ 0 ];
				//Type type = Helpers.FindType( null, typeName.Substring(1, typeName.Length - 2), true );
				Type type = TypeLoader.GetType( typeName.Substring( 1, typeName.Length - 2 ) );
				if( null == type ) {

	// TODO: issue when called by ETB

					scanner.Error( null, "unknown type \"{0}\" while generating cast expression: \"{1}\", note: use full type name including namespaces", typeName, str );
				}

				argExp.SetCastType( type );
				return argExp;
			}
			else {
				try {
					object obj = Arguments.CastArg( list, str );
					return new ArgumentExpression( parent, obj );
				}
				catch {////( ArgumentCastException ex ) {

	// TODO: issue when called by ETB

					//scanner.Error( null, ex.Message );
				}

				return null;
			}
		}
コード例 #2
0
ファイル: RazorOptions.cs プロジェクト: jmclain/Nmp
		/////////////////////////////////////////////////////////////////////////////

		private static void ReadToEOL( StringIndexer reader )
		{
			while( true ) {
				char ch = reader.NextChar();
				
				if( SC.CR == ch || SC.NEWLINE == ch || SC.NO_CHAR == ch ) {
					if( SC.CR == ch && SC.NEWLINE == reader.Peek() ) {
						//
						// skip the newline if preceeded by cr
						//
						reader.Skip( 1 );
					}
						
					return;
				}
			}
		}
コード例 #3
0
		/////////////////////////////////////////////////////////////////////////////
		
		public string GetQuotedText( StringIndexer input, bool keepQuotes )
		{
			// ******
			StringBuilder sb = new StringBuilder();
			if( keepQuotes ) {
				sb.Append( SeqOpenQuote.Sequence );
			}
		
			// ******
			while( true ) {
				char ch = input.Peek();

				if( SeqOpenQuote.FirstChar == ch && SeqOpenQuote.Starts(input) ) {
					SeqOpenQuote.Skip( input );

					// ******
					sb.Append( GetQuotedText(input, true) );
				}

				else if( SeqCloseQuote.FirstChar == ch && SeqCloseQuote.Starts(input) ) {
					SeqCloseQuote.Skip( input );

					// ******
					if( keepQuotes ) {
						sb.Append( SeqCloseQuote.Sequence );
					}
					return sb.ToString();
				}
				else if( SC.NO_CHAR == ch ) {

	// TODO: need file/line/col number for use with MPError

					ThreadContext.MacroError( "end of data: unbalanced quotes" );

				}
				else {
					input.Skip( 1 );
					sb.Append( ch );
				}
			}
		}
コード例 #4
0
ファイル: CharSequence.cs プロジェクト: jmclain/Nmp
		/////////////////////////////////////////////////////////////////////////////

		public bool Starts( StringIndexer input )
		{
			return input.StartsWith( Sequence );
		}
コード例 #5
0
ファイル: CharSequence.cs プロジェクト: jmclain/Nmp
		/////////////////////////////////////////////////////////////////////////////

		public void Skip( StringIndexer input )
		{
			// ******
			if( FirstChar == input.Peek() && input.StartsWith(Sequence) ) {
				input.Skip( Sequence.Length );
			}
			else {
				throw new Exception( string.Format("input buffer does not begin with \"{1}\"", Sequence) );
			}
		}
コード例 #6
0
ファイル: SplitString.cs プロジェクト: jmclain/Nmp
		/////////////////////////////////////////////////////////////////////////////

		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;
		}
コード例 #7
0
ファイル: Arguments.cs プロジェクト: jmclain/Nmp
		///////////////////////////////////////////////////////////////////////////////
		//
		//private static string regExStr = @"\(\s*?(.*?)\s*?\)\s*(.*?)\s*$";
		//private static Regex regex;
		//
		//private static object _CastArg( string s )
		//{
		//	// ******
		//	if( null == regex ) {
		//		regex = new Regex( regExStr );
		//	}
		//
		//	// ******
		//	Match match = regex.Match( s );
		//
		//	if( match.Groups.Count < 3 ) {
		//		return s;
		//	}
		//
		//	// ******
		//	string castType = match.Groups[1].ToString().ToLower();
		//	string castValue = match.Groups[2].ToString();
		//
		//	object value = SubstMatch( castType, castValue );
		//	if( null == value ) {
		//		value = s;
		//	}
		//	
		//	// ******
		//	return value;
		//}
		//

		/////////////////////////////////////////////////////////////////////////////

		public static object CastArg( string s )
		{
			// ******
			Debug.Assert( '(' == s[0], "Helpers.CastArg: cast or list string does not begin with a '('" );

			// ******
			//
			// calling SplitString() with 'splitCastMode' set to true, see the comments below where
			// we check the number of items returned
			//
			StringIndexer si = new StringIndexer( s );
			NmpStringList list = SplitString.Split( si, SplitString.END_OF_STRING, SplitString.END_OF_STRING, true );

			return CastArg( list, s );
		}
コード例 #8
0
ファイル: RazorOptions.cs プロジェクト: jmclain/Nmp
		/////////////////////////////////////////////////////////////////////////////

		public static void CallerOptions(	string textIn, 
																			StringBuilder textOut, 
																			List<string> targets, 
																			Action<string, string, StringBuilder> handler
																		)
		{
			// ******
			if( null == handler ) {
				throw new ArgumentNullException( "handler" );
			}

			// ******
			var reader = new StringIndexer( textIn );

			while( ! reader.AtEnd ) {
				foreach( string target in targets ) {
					if( reader.StartsWith(target) ) {
						reader.Skip( target.Length );
						string remainder = GetText( reader ).Trim();
						handler( target, remainder, textOut );
					}
					else {
						if( null != textOut ) {
							textOut.Append( GetText(reader) );
							textOut.Append( SC.NEWLINE );
						}
					}
				}

			}

		}
コード例 #9
0
ファイル: RazorOptions.cs プロジェクト: jmclain/Nmp
		/////////////////////////////////////////////////////////////////////////////

		public string GetOptions( string textIn )
		{


/*

	we should split the text into lines and then do our checks

	the caller can call us to reassemble the line


*/

			// ******
			//
			// NOTE: the text assigned to the StringIndexer has NOT been "fixed" as
			// it would be in NMP so we have to deal with "\r\n" instead of just
			// newlines
			//
			StringIndexer reader = new StringIndexer( textIn );

			while( true ) {
				//
				// if the line starts with a dask or hash it goes way!
				//
				//if( SC.DASH == reader.Peek() || SC.HASH == reader.Peek() ) {
				//	ReadToEOL( reader );
				//}

				//
				// a space or a pair of commas also make it go away
				//
				//else if( char.IsWhiteSpace(reader.Peek()) || reader.StartsWith(START_SINGLE_LINE_COMMENT) ) {
				//	ReadToEOL( reader );
				//}

				if( reader.StartsWith( START_SINGLE_LINE_COMMENT ) ) {
					ReadToEOL( reader );
				}



				else if( reader.StartsWith(RAZOR_ASMINC) ) {
					reader.Skip( RAZOR_ASMINC.Length );
					GetAssemblyName( reader );
				}

				else if( reader.StartsWith(RAZOR_ASMINC2) ) {
					reader.Skip( RAZOR_ASMINC2.Length );
					GetAssemblyName( reader );
				}

				else if( reader.StartsWith(KEEP_TEMPS) ) {
					ReadToEOL( reader );
					KeepTempFiles = true;
				}

				else if( reader.StartsWith(RAZOR_DEBUG) ) {
					ReadToEOL( reader );
					Debug = true;
				}

				//else if( reader.StartsWith(ASSERT_DATA_NAME) ) {
				//	ReadToEOL( reader );
				//	AssertDataName = true;
				//}
				//
				//else if( reader.StartsWith(ASSERT_DATA_FULLNAME) ) {
				//	ReadToEOL( reader );
				//	AssertDataFullName = true;
				//}
				//
				//else if( reader.StartsWith(ASSERT_ENUM_NAME) ) {
				//	ReadToEOL( reader );
				//	AssertEnumDataName = true;
				//}
				//
				//else if( reader.StartsWith(ASSERT_ENUM_FULLNAME) ) {
				//	ReadToEOL( reader );
				//	AssertEnumDataFullName = true;
				//}


				//else if( reader.StartsWith(TYPE_OF_DATA) ) {
				//	reader.Next( TYPE_OF_DATA.Length );
				//	TypeOfData = GetTypeOfData( "@TypeOfData", reader );
				//}
				//
				//else if( reader.StartsWith(TYPE_OF_ENUMDATA) ) {
				//	reader.Next( TYPE_OF_ENUMDATA.Length );
				//	TypeOfEnumData = GetTypeOfData( "@TypeOfEnumData", reader );
				//}
				//
				//else if( reader.StartsWith(NO_NULL_DATA) ) {
				//	ReadToEOL( reader );
				//	AllowNullData = false;
				//}
				//
				//else if( reader.StartsWith(NO_NULL_ENUMDATA) ) {
				//	ReadToEOL( reader );
				//	AllowNullEnumData = false;
				//}


				else if( reader.StartsWith(CODE_NAMESPACE) ) {
					reader.Skip( CODE_NAMESPACE.Length );
					Namespace = GetText( reader ).Trim();
				}

				else if( reader.StartsWith(CODE_CLASSNAME) ) {
					reader.Skip( CODE_CLASSNAME.Length );
					ClassName = GetText( reader ).Trim();
				}


				else if( reader.StartsWith(INJECT) ) {
					ReadToEOL( reader );
					Inject = true;
				}
				

				else if( reader.StartsWith(PREPROCESS) ) {
					ReadToEOL( reader );
					PreProcess = true;
				}
				
				else if( reader.StartsWith(POSTPROCESS) ) {
					ReadToEOL( reader );
					PostProcess = true;
				}

				else if( reader.StartsWith(COMMENTS_FULL_REMOVE) ) {
					ReadToEOL( reader );
					CommentsFullRemove = true;
				}
				
				else {
					//return reader.Remainder;
					return CleanComments( reader );
				}
			}
		}
コード例 #10
0
ファイル: RazorOptions.cs プロジェクト: jmclain/Nmp
		///////////////////////////////////////////////////////////////////////////////
		//
		//private Type GetTypeOfData( string description, StringIndexer reader )
		//{
		//	// ******
		//	string typeName = GetText( reader ).Trim();
		//	if( string.IsNullOrEmpty(typeName) ) {
		//		CSX.WriteWarning( "empty type name processing {0}", description );
		//	}
		//
		//	// ******
		//	int pos = typeName.IndexOf( '.' );
		//	bool fullTypeName = pos >= 0;
		//	if( 0 == pos ) {
		//		//
		//		// if a dot is the first char the intent is that this
		//		// is a full type name search and the type we're looking
		//		// for does NOT live in a namespace
		//		//
		//		typeName = typeName.Substring( 1 );
		//	}
		//
		//	// ******
		//	Type type = TypeLoader.GetType( typeName );
		//	if( null != type ) {
		//		return type;
		//	}
		//
		//	// ******
		//	foreach( var path in RefAssemblies ) {
		//		TypeList list = TypeLoader.GetType( path, typeName, fullTypeName );
		//		if( list.Count > 0 ) {
		//			return list[ 0 ];
		//		}
		//	}
		//
		//	// ******
		//	return null;
		//}
		//

		/////////////////////////////////////////////////////////////////////////////

		private string CleanComments( StringIndexer reader )
		{
			// ******
			if( PreProcess ) {
				//
				// let Nmp remove any single line comments - we leave
				// the end of line behind, Nmp will remove the entire
				// line
				//
				return reader.Remainder;
			}

			// ******
			var sb = new StringBuilder();

			while( ! reader.AtEnd ) {
				//
				// a space or a pair of commas also make it go away
				//
				if( reader.StartsWith(START_SINGLE_LINE_COMMENT) ) {
					ReadToEOL( reader );
					if( CommentsFullRemove ) {
						//
						// remove the whole thing - do not add end of line
						//
						continue;
					}
				}
				else {
					sb.Append( GetText(reader) );
				}

				//
				// GetText() does not return an end-of-line so we need to add it,
				// also we want to leave a blank line where the comment was stripped
				// out so line counts remain the same as the source
				//
				sb.AppendLine();

			}

			// ******
			return sb.ToString();
		}
コード例 #11
0
ファイル: RazorOptions.cs プロジェクト: jmclain/Nmp
		/////////////////////////////////////////////////////////////////////////////

		private void GetAssemblyName( StringIndexer reader )
		{
			//// ******
			//var sb = new StringBuilder();
			//
			//// ******
			//while( true ) {
			//	char ch = reader.Next();
			//	
			//	if( SC.CR == ch || SC.NEWLINE == ch || SC.NO_CHAR == ch ) {
			//		if( SC.CR == ch && SC.NEWLINE == reader.Peek() ) {
			//			//
			//			// skip the newline if preceeded by cr
			//			//
			//			reader.Next();
			//		}
			//			
			//		break;
			//	}
			//
			//	sb.Append( ch );
			//}
			//
			//// ******
			//RefAssemblies.Add( sb.ToString() );
			
			// ******
			RefAssemblies.Add( GetText(reader).Trim() );
		}
コード例 #12
0
ファイル: RazorOptions.cs プロジェクト: jmclain/Nmp
		/////////////////////////////////////////////////////////////////////////////

		private static string GetText( StringIndexer reader )
		{
			// ******
			var sb = new StringBuilder();
			
			// ******
			while( true ) {
				char ch = reader.NextChar();
				
				if( SC.CR == ch || SC.NEWLINE == ch || SC.NO_CHAR == ch ) {
					if( SC.CR == ch && SC.NEWLINE == reader.Peek() ) {
						//
						// skip the newline if preceeded by cr
						//
						reader.Skip( 1 );
					}
						
					break;
				}

				sb.Append( ch );
			}

			// ******
			return sb.ToString();
		}