Exemplo n.º 1
0
		/////////////////////////////////////////////////////////////////////////////

		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) );
			}
		}
Exemplo n.º 2
0
		/////////////////////////////////////////////////////////////////////////////

		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;
				}
			}
		}
Exemplo n.º 3
0
		/////////////////////////////////////////////////////////////////////////////

		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 );
						}
					}
				}

			}

		}
Exemplo n.º 4
0
		/////////////////////////////////////////////////////////////////////////////

		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 );
				}
			}
		}
Exemplo n.º 5
0
		/////////////////////////////////////////////////////////////////////////////

		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();
		}
Exemplo n.º 6
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 );
				}
			}
		}