Пример #1
0
Файл: ETB.cs Проект: jmclain/Nmp
		///////////////////////////////////////////////////////////////////////////////
		//
		//public static MacroExpression CreateMacroCallExpression( string macroName, object [] args )
		//{
		//	//return new MethodCallExpression( macroName, new ArgumentList(args) );
		//
		//	// ******
		//	if( null == args ) {
		//		args = new object[ 0 ];
		//	}
		//
		//	// ******
		//	var list = new MacroExpression( new NmpStringList() );
		//	list.Add( new MethodCallExpression( macroName, new ArgumentList(args) ) );
		//	return list;
		//}
		//

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

		public static MacroExpression CreateNullExpression()
		{
			//return new MethodCallExpression( macroName, new ArgumentList(args) );

			var list = new MacroExpression( new NmpStringList() );
			list.Add( new NullExpression() );
			return list;
		}
Пример #2
0
Файл: ETB.cs Проект: jmclain/Nmp
		/////////////////////////////////////////////////////////////////////////////

		public static MacroExpression CreateMacroCallExpression( IMacro macro, object [] args )
		{
			// ******
			if( null == macro ) {
				throw new ArgumentNullException( "macro" );
			}

			// ******
			var argList = new ArgumentList( null == args ? new object [0] : args );
			var list = new MacroExpression( new NmpStringList() );

			// ******
			if( MacroType.Builtin == macro.MacroType || MacroType.Text == macro.MacroType ) {
				list.Add( new MethodCallExpression( macro.Name, argList) );
			}
			else {
				//
				// its an object, if it's not a MethodInvoker instance or a delegate
				// it will error when the invocation fails
				//
				list.Add( new UnnamedMemberAccessExpression(macro.Name) );
				list.Add( new UnnamedMethodCallExpression(argList) );
			}

			// ******
			return list;
		}
Пример #3
0
Файл: ETB.cs Проект: jmclain/Nmp
		/////////////////////////////////////////////////////////////////////////////

		public MacroExpression ParseExpression( IInput input )
		{
			// ******
			var exList = new MacroExpression( new NmpStringList() );

			// ******
			//
			// first token is the name of the macro
			//
			string	token = rootName;
			bool		haveFreshToken = true;

			// ******
			while( true ) {
				bool isRootNode = 0 == exList.Count;
				bool allDone = false;

				char ch = input.Peek();

				if( haveFreshToken ) {
					allDone = HandleFreshToken( isRootNode, token, char.IsWhiteSpace(ch), exList, input );
					haveFreshToken = false;
				}
				
				if( SC.DOT == ch ) {
					//
					// '.'
					//
					input.Skip( 1 );
					token = GetToken( input );
				
					if( string.IsNullOrEmpty(token) ) {
						//
						// does not return
						//
						UnexpectedCharacter( input.Peek(), "expecting identifier (member name)" );
					}
				
					// ******
					haveFreshToken = true;
				}

// jpm 11 April 13; change back to NOT check for (# because its more correct that what
// we ended up with - that is, without the check its possible for the user to create a
// macro (across multiple lines using '-' at end of line and comments ;;) where we
// get "something()(#defmacro..)" glued together as the result of a macro atempting to
// call a method - not what was intended
//
				//else if( SC.OPEN_PAREN == ch && SC.HASH != input.Peek(1) ) {
				else if( SC.OPEN_PAREN == ch ) {
					//
					// '(' NOT "(#"
					//
					input.Skip( 1 );
					exList.Add( MethodCall(isRootNode, token, haveFreshToken, input) );
					haveFreshToken = false;
				}

				else if( SC.OPEN_BRACKET == ch ) {
					//
					// '['
					//
					input.Skip( 1 );
					exList.Add( IndexMember(isRootNode, token, haveFreshToken, input) );
					haveFreshToken = false;                                               
				}

				else if( SC.ATCHAR == ch && SC.OPEN_BRACKET == input.Peek(1) ) {
					input.Skip( 2 );
					ParseMacroOptions( input, exList.MacroInstructions );
				}
				else {
					//
					// end of expression
					//

					/*	

						should put whatever we do here just before the end of the
						method - get it out of here for cleanthlyness sake


						if is altInvocationExpression and we did not detect it as a method in HandleFreshToken()
							
							we've hit ')' or some char we don't know what to do with

						we could gather up "... )" and add to MacroOptions

							or error

							or just eat it
					*/

					//if( isAltInvocationExpression && ! allDone ) {
					//	//NmpStringList strArgs = argScanner( input, RecognizedCharType.CloseParenChar );
					//	NmpStringList strArgs = scanner.ArgScanner( input, RecognizedCharType.CloseParenChar );
					//}

					if( isAltInvocationExpression ) {
						if( ! allDone ) {
							NmpStringList strArgs = scanner.ArgScanner( input, RecognizedCharType.CloseParenChar );
						}

						if( SC.ATCHAR == input.Peek() && SC.OPEN_BRACKET == input.Peek(1) ) {
							input.Skip( 2 );
							ParseMacroOptions( input, exList.MacroInstructions );
						}

					}

					break;
				}

				// ******
				//
				// since there is no member/token name for the result of an operation
				// we need to create one in case of cascading operations
				//
				if( !haveFreshToken ) {
					token = "result of " + token;
				}
			}

			// ******
			//return 1 == exList.Count ? exList[0] : exList;
			return exList;
		}
Пример #4
0
Файл: ETB.cs Проект: jmclain/Nmp
		/////////////////////////////////////////////////////////////////////////////

		public static MacroExpression CreateMacroCallExpression( string name, object [] args )
		{
			// ******
			if( string.IsNullOrEmpty(name) ) {
				throw new ArgumentNullException( "name" );
			}

			// ******
			var argList = new ArgumentList( null == args ? new object [ 0 ] : args );
			var list = new MacroExpression( new NmpStringList() );

			// ******
			list.Add( new MethodCallExpression( name, argList ) );

			// ******
			return list;
		}
Пример #5
0
Файл: ETB.cs Проект: jmclain/Nmp
		/////////////////////////////////////////////////////////////////////////////

		private bool HandleFreshToken( bool isRootNode, string token, bool nextIsWhiteSpace, MacroExpression exList, IInput input )
		{
			//
			// where extList is empty and isAltInvocationExpression is
			// true then we have (#someMacro ...) and we have to treat 
			// it as a method invocation IF THE NEXT CHAR IS WHITE-SPACE,
			// but only if it's white space - dont do it for (#someMacro.thing ), 
			// or (#someMacro() ) which is weird
			//
			if( 0 == exList.Count && isAltInvocationExpression && nextIsWhiteSpace ) {
				exList.Add( MethodCall(isRootNode, token, true, input) );
				return true;	// done
			}
			else {
				exList.Add( MemberAccess(isRootNode, token, input) );
				return false;
			}
		}