/////////////////////////////////////////////////////////////////////////// private void ParseMacro( int depth, IInput input, StringBuilder sb ) { // ****** char quoteStartChar = gc.SeqOpenQuote.FirstChar; // ****** while( true ) { // // first quote check // if( quoteStartChar == input.Peek() && gc.SeqOpenQuote.Starts(input) ) { // // GetQuotedText() strips the outer quotes but perserves inner quotes; but // first we need to eat the open quote // gc.SeqOpenQuote.Skip( input ); sb.Append( gc.GetQuotedText(input, true) ); } // ****** char ch = input.Next(); if( SC.NO_CHAR == ch ) { ThreadContext.MacroError( "defmacro/pushmacro: end of input before (#endmacro) found" ); } // ****** // // (#defmacro ... // (#pushmacro ... // if( SC.OPEN_PAREN == ch && input.StartsWith(BLOCK_FOREACH_START) ) { // // get recursive // input.Skip( BLOCK_FOREACH_START.Length ); if( ! char.IsWhiteSpace(input.Peek()) ) { ThreadContext.MacroError( "expected white space following \"(#defmacro\"" ); } sb.Append( BLOCK_FOREACH_INJECT ); ParseMacro( 1 + depth, input, sb ); sb.Append( BLOCK_ENDFOREACH_INJECT ); continue; } else if( SC.OPEN_PAREN == ch && input.StartsWith(BLOCK_FOREACH_END) ) { input.Skip( BLOCK_FOREACH_END.Length ); return; } else { sb.Append( ch ); } } }
private void ParseMacro( int depth, IInput input, StringBuilder sb ) { // ****** char quoteStartChar = gc.SeqOpenQuote.FirstChar; // ****** while( true ) { // // first quote check // if( quoteStartChar == input.Peek() && gc.SeqOpenQuote.Starts(input) ) { // // GetQuotedText() strips the outer quotes but perserves inner quotes; but // first we need to eat the open quote // gc.SeqOpenQuote.Skip( input ); sb.Append( gc.GetQuotedText(input, true) ); } // ****** char ch = input.Next(); // ****** if( SC.NO_CHAR == ch ) { ThreadContext.MacroError( "ExpandoBlock: end of input before \"##)\" found" ); } // ****** // // (## ... // if( SC.OPEN_PAREN == ch && input.StartsWith(EB_START) ) { // // get recursive // input.Skip( EB_START.Length ); sb.Append( EB_INJECT ); ParseMacro( 1 + depth, input, sb ); sb.Append( EBEND_INJECT ); continue; } else if( SC.HASH == ch && input.StartsWith(EBEND) ) { input.Skip( EBEND.Length ); return; } else { sb.Append( ch ); } } }
/////////////////////////////////////////////////////////////////////////// private void ParseMacro( IInput input, StringBuilder sb ) { // ****** char quoteStartChar = gc.SeqOpenQuote.FirstChar; // ****** while( true ) { // // first quote check - allows (#endarray) to be embedded in the text // if( quoteStartChar == input.Peek() && gc.SeqOpenQuote.Starts(input) ) { // // GetQuotedText() strips the outer quotes but perserves inner quotes; but // first we need to eat the open quote // gc.SeqOpenQuote.Skip( input ); sb.Append( gc.GetQuotedText(input, true) ); } // ****** char ch = input.Next(); if( SC.NO_CHAR == ch ) { ThreadContext.MacroError( "deflist: end of input before (#endlist) found" ); } if( SC.OPEN_PAREN == ch && input.StartsWith(ENDLIST) ) { input.Skip( ENDLIST.Length ); return; } else { sb.Append( ch ); } } }
private void ParseMacro( int depth, IInput input, StringBuilder sb ) { // ****** char quoteStartChar = gc.SeqOpenQuote.FirstChar; // ****** while( true ) { // // Text Blocks no longer require ballanced quotes // // first quote check // //if( quoteStartChar == input.Peek() && gc.SeqOpenQuote.Starts(input) ) { // // // // GetQuotedText() strips the outer quotes but perserves inner quotes; but // // first we need to eat the open quote // // // gc.SeqOpenQuote.Skip( input ); // sb.Append( gc.GetQuotedText(input, true) ); //} // ****** char ch = input.Next(); // ****** if( SC.NO_CHAR == ch ) { ThreadContext.MacroError( "textblock: end of input before (#tbend) found" ); } // ****** // // (#textblock ... // if( SC.OPEN_PAREN == ch && input.StartsWith(TB_START) ) { // // get recursive // input.Skip( TB_START.Length ); //if( ! char.IsWhiteSpace(input.Peek()) ) { // ThreadContext.MacroError( "expected white space following \"(#Textblock\"" ); //} sb.Append( TB_INJECT ); ParseMacro( 1 + depth, input, sb ); sb.Append( TBEND_INJECT ); continue; } else if( SC.OPEN_PAREN == ch && input.StartsWith(TBEND) ) { input.Skip( TBEND.Length ); return; } //else if( ThreadContext.SeqOpenQuote.FirstChar == ch && ThreadContext.SeqOpenQuote.Starts(input) ) { // // // // GetQuotedText() strips the outer quotes but perserves inner quotes; but // // first we need to eat the open quote // // // ThreadContext.SeqOpenQuote.Skip( input ); // sb.Append( ThreadContext.GetQuotedText(input, true) ); //} else { sb.Append( ch ); } } }
/////////////////////////////////////////////////////////////////////////// private void ParseMacro( int depth, IInput input, StringBuilder sb ) { // ****** char quoteStartChar = gc.SeqOpenQuote.FirstChar; // ****** while( true ) { // // first quote check // if( quoteStartChar == input.Peek() && gc.SeqOpenQuote.Starts(input) ) { // // GetQuotedText() strips the outer quotes but perserves inner quotes; but // first we need to eat the open quote // gc.SeqOpenQuote.Skip( input ); sb.Append( gc.GetQuotedText(input, true) ); } // ****** char ch = input.Next(); if( SC.NO_CHAR == ch ) { ThreadContext.MacroError( "defmacro/pushmacro: end of input before (#endmacro) found" ); } // ****** // // (#defmacro ... // (#pushmacro ... // if( SC.OPEN_PAREN == ch && input.StartsWith(DEFMACRO_START) ) { // // get recursive // input.Skip( DEFMACRO_START.Length ); if( ! char.IsWhiteSpace(input.Peek()) ) { ThreadContext.MacroError( "expected white space following \"(#defmacro\"" ); } sb.Append( DEFMACRO_INJECT ); ParseMacro( 1 + depth, input, sb ); sb.Append( ENDMACRO_INJECT ); continue; } // // easier / shorter way to do this - duping code from above // else if( SC.OPEN_PAREN == ch && input.StartsWith(PUSHMACRO_START) ) { // // get recursive // input.Skip( PUSHMACRO_START.Length ); if( ! char.IsWhiteSpace(input.Peek()) ) { ThreadContext.MacroError( "expected white space following \"(#defmacro\"" ); } sb.Append( PUSHMACRO_INJECT ); ParseMacro( 1 + depth, input, sb ); sb.Append( ENDMACRO_INJECT ); continue; } //case SC.EMBED_BEGIN_INBLOCK_EXPAND_CHAR: // if( 0 == depth ) { // // // // only for the outermost macro code // // // sb.Append( HandleEmbedMacroBlock(input) ); // continue; // } // break; else if( SC.OPEN_PAREN == ch && input.StartsWith(ENDMACRO) ) { input.Skip( ENDMACRO.Length ); return; } else { sb.Append( ch ); } } }
// (#if bool_expression ) // // ... (#elseif ...) / (#else) // // (#endif) // /////////////////////////////////////////////////////////////////////////// // // //string IfElseEndifPatterns = // //@"(?x)\A //( //\(\#if[ \t]| //\(\#elseif[ \t]| //\(\#else\)| //\(\#endif\)| // //) //"; // /////////////////////////////////////////////////////////////////////////// private StringBuilder IfProcessor( IInput input, bool processing, int depth ) { StringBuilder result = new StringBuilder(); bool inElse = false; bool done = false; /* processing says whether we are saving text or not text is only saved if processing is true depth is how may if statements deep we are into the process depth zero is the first level after examining the truth of the outermost if, at this level processing can be toggled by the else statement and NOT have an else token reinjected into the code at levels greather than zero if/else/endif tokens are reinjected into the code to be processed after the text has been pushed back onto the input and is scanned again */ // ****** char quoteStartChar = gc.SeqOpenQuote.FirstChar; // ****** while( true ) { // // first quote check // if( quoteStartChar == input.Peek() && gc.SeqOpenQuote.Starts(input) ) { // // GetQuotedText() strips the outer quotes but perserves inner quotes; but // first we need to eat the open quote // gc.SeqOpenQuote.Skip( input ); string text = gc.GetQuotedText( input, true ); if( processing ) { result.Append( text ); } } // ****** char ch = input.Next(); // ****** if( SC.NO_CHAR == ch ) { ThreadContext.MacroError( "IfHandler: end of input before (#endif) found" ); return result; } // ****** // // (#if ... // if( SC.OPEN_PAREN == ch && input.StartsWith(IF_START) ) { // // get recursive // input.Skip( IF_START.Length ); if( ! char.IsWhiteSpace(input.Peek()) ) { ThreadContext.MacroError( "expected white space following \"(#if\"" ); } if( processing ) { result.Append( IF_INJECT ); } result.Append( IfProcessor(input, processing, 1 + depth) ); continue; } // // (#elseif ... // else if( SC.OPEN_PAREN == ch && input.StartsWith(ELSEIF_START) ) { int argsStart = input.Index; input.Skip( ELSEIF_START.Length ); if( ! char.IsWhiteSpace(input.Peek()) ) { ThreadContext.MacroError( "expected white space following \"(#elseif\"" ); } if( inElse ) { ThreadContext.MacroError( "out of place (#elseif) in (#if ...) statement" ); } // ****** // // we're responsible for gather the arguments to `elseif' // NmpStringList strList = mp.Get<IScanner>().ArgScanner( input, RecognizedCharType.CloseParenChar ); int argsEnd = input.Index - 1; if( SC.NEWLINE == input.Peek() ) { input.Skip( 1 ); } // ****** if( processing ) { if( depth > DEPTH_ZERO ) { // // reinject elseif token and text: "[token] expression )" // string text = input.GetText(argsStart, argsEnd); result.AppendFormat( "({0}", text ); } else { // // else DEPTH_ZERO, need to stop processing // processing = false; done = true; } } else if( DEPTH_ZERO == depth && ! done ) { //// //// since we're plowing through the text ourselves we need to //// call out to have the `elseif' arguments evaluated //// //var ah = new ArgumentHandler( mp, "if processor" ); //ah.Initialize( new Type [] { typeof(bool) }, strList ); //processing = (bool) ah[ 0 ]; // // already evaluated when ArgScanner was run // processing = 0 == strList.Count ? false : Helpers.IsMacroTrue( strList[0] ); } continue; } // // (#else) // else if( SC.OPEN_PAREN == ch && input.StartsWith(ELSE) ) { input.Skip( ELSE.Length ); if( inElse ) { ThreadContext.MacroError( "out of place (#else) in (#if ..) statement" ); } if( SC.NEWLINE == input.Peek() ) { input.Skip( 1 ); } // ****** inElse = true; if( processing && depth > DEPTH_ZERO ) { // // reinject endif token // result.Append( ELSE_INJECT ); } // ****** // // toggle what we're doing // if( ! done && DEPTH_ZERO == depth ) { processing = ! processing; } continue; } // // (#endif) // else if( SC.OPEN_PAREN == ch && input.StartsWith(ENDIF) ) { // // in theory all done // input.Skip( ENDIF.Length ); if( SC.NEWLINE == input.Peek() ) { input.Skip( 1 ); } if( processing && depth > DEPTH_ZERO ) { // // reinject endif token // result.Append( ENDIF_INJECT ); } // ****** break; } // ****** if( processing ) { result.Append( ch ); } } // ****** return result; }
public void Do(IInput input, Stack stack, IGrammerRuleHandler ruleHandler) { input.Next(); stack.Push(stateId); }
///////////////////////////////////////////////////////////////////////////// public string GetText( IInput input, TokenMap tm ) { // ****** // // offset index + length spans the entire match // string text = input.Next( tm.MatchLength ); return text; }