internal static Options CreateVBScriptParserOptions(ILog log) { var options = new Options(log); options.CaseSensitive = false; options.LineWrap = TokenComparison.VBScriptLineWrap( log, options); return(options); }
//TODO this is not fully tested. needs a new feature to allow repeats // - "repeated comparison" // - also doesn't work inside quotes. needs a state // I think state ment list should have a state member // <script ..>function blah end function </script> public static string WrapFunctionsInScriptBlock( ILog log, string input) { // The parser object that will do the work Parser parser = new Parser(log); //// Parser options Options parserOptions = new Options(log); parserOptions.CaseSensitive = false; // Line wrap parserOptions.LineWrap = TokenComparison.VBScriptLineWrap( log, parserOptions); // State List <State> stateList = VBScriptState(log, parserOptions); // The main statement list StatementList mainStatements = new StatementList(log); // Begins with whitespace (don't capture the space) CharDelegateComparison isWhitespace = new CharDelegateComparison(log, Char.IsWhiteSpace); mainStatements.Add(isWhitespace); // Skip whitespace (don't capture the space) mainStatements.Add(TokenComparison.SkipWhitespace(log)); // Capturing Dictionary <string, Capture> capturing = new Dictionary <string, Capture>(); // The capture Capture capture = new Capture(log); capture.Name = "capture"; capturing.Add("functionDefinition", capture); mainStatements.Add(capture); // Capture statements StatementList captureStatements = new StatementList(log); capture.Comparison = captureStatements; // Function or sub OrComparison functionOrSub = new OrComparison(log); functionOrSub.Add(new StringComparison(log, parserOptions, "function")); functionOrSub.Add(new StringComparison(log, parserOptions, "sub")); captureStatements.Add(functionOrSub); // Whitespace captureStatements.Add(isWhitespace); // Line wrap captureStatements.Add(parserOptions.SkipLineWrapOperation); //// Name of function/sub // End is either whitespace or ( OrComparison whiteSpaceOrOpenParen = new OrComparison(log); whiteSpaceOrOpenParen.Add(isWhitespace); whiteSpaceOrOpenParen.Add(new CharComparison(log, parserOptions, '(')); var funcName = TokenComparison.CreateIdentifier( parserOptions, end: whiteSpaceOrOpenParen, exclusion: null, name: null, log: log); captureStatements.Add(funcName); //// Find the end of the sub/function StatementList functionEnd = new StatementList(log); // Whitespace functionEnd.Add(isWhitespace); // 'end' functionEnd.Add(new StringComparison(log, parserOptions, "end")); // Whitespace functionEnd.Add(isWhitespace); // Skip the line wrap functionEnd.Add(parserOptions.SkipLineWrapOperation); // Function or sub functionEnd.Add(functionOrSub); // Whitespace or %> OrComparison whitespaceOrPageDirective = new OrComparison(log); whitespaceOrPageDirective.Add(isWhitespace); whitespaceOrPageDirective.Add(new CompareNoAdvance(log, new StringComparison(log, parserOptions, "%>"))); functionEnd.Add(whitespaceOrPageDirective); // Skip till find the function name captureStatements.Add(new AdvanceUntilComparison(log, functionEnd)); //const string replaceWith = "'funcName'('funcArgs')"; string replaceWith = string.Format( "{0}<script language=\"VB\" runat=\"Server\">{0}'functionDefinition'{0}</script>{0}", Environment.NewLine); string replaced = parser.Replace(input, replaceWith, mainStatements, capturing, stateList); return(replaced); }