~/paste/19960
~/paste/19960
~/paste/19960

  1. #Author: Raven0 @ buxville.net
  2.  
  3. *:/generate_AC_xml = >>>
  4.  
  5.     /* Create file to write into */
  6.         @file = "MethodScript.xml";
  7.         try(read(@file),chd_create(@file));
  8.        
  9.     /* Prepare start of the file */
  10.         @file_Write = array(
  11.             "<?xml version=\"1.0\" encoding=\"Windows-1252\" ?>",
  12.             "<!-- author: Raven0 \@ www.buxville.net -->",
  13.             "<NotepadPlus>",
  14.             "   <AutoComplete language=\"MethodScript\">",
  15.             "        <Environment ignoreCase=\"no\" startFunc=\"(\" stopFunc=\")\" paramSeparator=\",\" terminal=\";\"/>"
  16.         );
  17.     /* Prepare JSON file, as we will use it to quickly get rid of some escapes */
  18.         @file_JSON_prep = array();
  19.         @file_JSON_prep["functions"] = array();
  20.         @file_JSON_prep["events"] = array();
  21.        
  22.     /* Grab extensions */
  23.         @CH_extensions = extension_info();
  24.    
  25.     /* START OF THE PROCESSING TO JSON FILE */
  26.         for(@x = 0, @x < array_size(@CH_extensions),@x++){
  27.        
  28.         /* Define extension name and version */
  29.             @extension_Name = array_keys(@CH_extensions)[@x];
  30.             @extension_Version = @CH_extensions[@extension_Name]['version'];
  31.         /* Define extension functions and events */
  32.             @functions = @CH_extensions[@extension_Name]['functions'];
  33.             @events    = @CH_extensions[@extension_Name]['events'];
  34.            
  35.          /* Catch all functions and prepare for JSON */
  36.             for(@y = 0, @y < array_size(@functions), @y++){
  37.                 @function_Name   = @functions[@y];
  38.                 if(!string_starts_with(@function_Name,"_")){
  39.                     try {
  40.                     /* Declare function and it's arguments */
  41.                        @file_JSON_prep["functions"][@function_Name]                = array();
  42.                        @file_JSON_prep["functions"][@function_Name]['args']        = reflect_docs(@function_Name,"args");
  43.                        @file_JSON_prep["functions"][@function_Name]['return']      = reflect_docs(@function_Name,"return");
  44.                        @file_JSON_prep["functions"][@function_Name]['description'] = reflect_docs(@function_Name,"description");
  45.                    } catch(FormatException @ex) {console(colorize("&eCould not show information for function: &a".@function_Name."&r"),false);}
  46.                }
  47.            }
  48.            
  49.        /* Catch all events and prepare for JSON */
  50.            for(@z = 0, @z < array_size(@events), @z++){
  51.                @event_Name   = @events[@z];
  52.                if(!string_starts_with(@event_Name,"_")){
  53.                    try {
  54.                    /* Declare event and it's arguments */
  55.                         @file_JSON_prep["events"][] = @event_Name;
  56.                     } catch(FormatException @ex) {console(colorize("&eCould not show information for event: &a".@event_Name."&r"),false);}
  57.                 }
  58.             }
  59.         }
  60.     /* ENCODE TO JSON FORMAT */
  61.         @file_JSON_prep1 = json_encode(@file_JSON_prep);
  62.         @file_JSON = json_decode(@file_JSON_prep1);
  63.        
  64.     /* Start of the processing from JSON to XML */
  65.         /* FUNCTIONS */
  66.             @process_Functions = @file_JSON["functions"];
  67.            
  68.             foreach(@function: @function_Args in @process_Functions){
  69.             /* FUNCTION NAME */
  70.                 /* Process function name and write to XML */
  71.                     @process_Function_Name = @function;
  72.                     @file_Write[]          = "        <KeyWord name=\"".@process_Function_Name."\" func=\"yes\">";
  73.                    
  74.             /* FUNCTION RETURNS & DESCRIPTION */
  75.                 /* RETURNS */
  76.                     @process_Function_Return      = @function_Args["return"];
  77.                 /* DESCRIPTION */
  78.                     @process_Function_Description = @function_Args["description"];
  79.                    
  80.                     /* REMOVE UNNECESSARY CHARACTERS/TAGS/ETC FROM DESCRIPTION */
  81.                         # List of unwanted onesin order of removal: <code> <\/code> \u0003 <li> <\/li> <pre> <\/pre> <ul> <\/ul>
  82.                         @process_Function_Description_prep_1 = replace(replace(replace(replace(replace(replace(replace(replace(replace(@process_Function_Description,"<code>",""),"<\\//code>",""),"\u0003",""),"<li>",""),"<\\//li>",""),"<pre>",""),"<\\//pre>",""),"<ul>",""),"<\\//ul>","");
  83.                    
  84.                     /* REPLACE end of line and escape some characters */
  85.                         # List in order of replacement: \n -> &#x0a, @ -> \@, \/ -> \//, < -> &lt;, > -> &gt;, ' -> &apos;, " -> &quot;
  86.                         @process_Function_Description_prep_2 = replace(replace(replace(replace(replace(replace(@process_Function_Description_prep_1,"\n","&#x0a;"),"\@","\\@"),">","&gt;"),"<","&lt;"),"'","&apos;"),'"',"&quot;");
  87.                    
  88.                     /* REPLACE all {{function|some_name}} description tags meant for forum links */
  89.                         @find_Code_prep      = reg_match('\\{\\{function\\|.+\\}\\}',@process_Function_Description_prep_2)
  90.                         if(array_index_exists(@find_Code_prep,0)){
  91.                             @find_Code = @find_Code_prep[0];
  92.                             @find_CodeValue = reg_match('(?<=\\|)(.*)(?=.\\})',@find_Code)[0];
  93.                             @process_Function_Description_prep_3 = replace(@process_Function_Description_prep_2,@find_Code,@find_CodeValue);
  94.                         }
  95.                         else{
  96.                             @process_Function_Description_prep_3 = @process_Function_Description_prep_2;
  97.                         }
  98.                        
  99.                     /* GET RID of all way too long descriptions, which may have html tables/tags in them */
  100.                         /* Long descriptions that start with ----  */
  101.                             if(string_position(@process_Function_Description_prep_3,"----") != -1){
  102.                                 @newString = substr(@process_Function_Description_prep_3,0,string_position(@process_Function_Description_prep_3,"----"));
  103.                                 @process_Function_Description_prep_4 = @newString;
  104.                             } else{ @process_Function_Description_prep_4 = @process_Function_Description_prep_3; }
  105.                            
  106.                         /* HTML bb codes for table */
  107.                             if(string_position(@process_Function_Description_prep_4,"{|") != -1 && string_position(@process_Function_Description_prep_4,"|}") != -1){
  108.                                 @newString2 = substr(@process_Function_Description_prep_4,0,string_position(@process_Function_Description_prep_4,"{|")).substr(@process_Function_Description_prep_4,(string_position(@process_Function_Description_prep_4,"|}") + 1));
  109.                                 @process_Function_Description_prep_5 = @newString2;
  110.                             } else{ @process_Function_Description_prep_5 = @process_Function_Description_prep_4; }
  111.                            
  112.                     /* Simply aesthetic, but replace single dot as end of line */
  113.                         @process_Function_Description_prep_6 = replace(@process_Function_Description_prep_5,". ",".&#x0a;");
  114.                        
  115.                     /* Replace next line triggers with nothing if on the end of description */
  116.                         if(string_ends_with(@process_Function_Description_prep_6,"&#x0a;")){
  117.                             @process_Function_Description_prepared = replace(@process_Function_Description_prep_6,"&#x0a;","");
  118.                         }
  119.                         else { @process_Function_Description_prepared = @process_Function_Description_prep_6;}
  120.                        
  121.                     /* WRITE TO XML */
  122.                         @file_Write[] = "            <Overload retVal=\"".@process_Function_Return."\" descr=\"".@process_Function_Description_prepared."\">";
  123.                        
  124.             /* FUNCTION ARGS */
  125.                 /* Process function arguments and write to XML */
  126.                     @process_Function_Args = @function_Args["args"];
  127.                    
  128.                 /* Prepare counters, as we will split parentheses from other arguments */
  129.                     @open_parentheses   = 0;
  130.                     @closed_parentheses = 0;
  131.                     @word = 0;
  132.                     @arguments = array();
  133.                    
  134.                 /* Process arguments */
  135.                     @processArgs = @process_Function_Args;
  136.                     for(@countChar = 0, @countChar < length(@processArgs), @countChar++){
  137.                         @character = @processArgs[@countChar];
  138.                         if(@character == ","){
  139.                             if(@open_parentheses != @closed_parentheses){ @skipWrite = false; }
  140.                             else{ @word++; @skipWrite = true;}
  141.                         }
  142.                         else if(@character == "[") { @open_parentheses++; @skipWrite = false; }
  143.                         else if(@character == "]") { @closed_parentheses++; @skipWrite = false; }
  144.                         else { @skipWrite = false; }
  145.                        
  146.                         if(@skipWrite == false) {
  147.                             if(!array_index_exists(@arguments,@word)){ array_set(@arguments,@word,@character); }
  148.                             else{ @arguments[@word] .= @character; }
  149.                         }
  150.                     }
  151.                 /* Push arguments into XML */
  152.                     foreach(@argument in @arguments){
  153.                         @file_Write[] = "                <Param name=\"".@argument."\"/>";
  154.                     }
  155.             /* WRITE REST OF XML PORTION for function */
  156.                 @file_Write[] = "            </Overload>"
  157.                 @file_Write[] = "        </KeyWord>"
  158.                
  159.             }
  160.         /* EVENTS */
  161.             @process_Events = @file_JSON["events"];
  162.            
  163.             foreach(@event in @process_Events){
  164.             /* EVENT NAME */
  165.                 /* Process event name and write to XML */
  166.                     @process_Event_Name = @event;
  167.                     @file_Write[] = "        <KeyWord name=\"".@process_Event_Name."\" func=\"yes\">";
  168.  
  169.             /* WRITE REST OF XML PORTION for event */
  170.                 @file_Write[] = "            <Overload retVal=\"mixed\" descr=\"One of CH&apos;s or extension events.&#x0a;Consult it&apos;s wiki for further information.\">";
  171.                 @file_Write[] = "                <Param name=\"eventData\"/>";
  172.                 @file_Write[] = "            </Overload>"
  173.                 @file_Write[] = "        </KeyWord>"
  174.             }
  175.     /* Finish XML writing */
  176.         @file_Write[] = "   </AutoComplete>";
  177.         @file_Write[] = "</NotepadPlus>";
  178.     /* Write XML file  */
  179.         @writeFile = "";
  180.         foreach(@stringLine in @file_Write){
  181.             @writeFile .= @stringLine."\n";
  182.         }
  183.         chd_write(@file,@writeFile,"OVERWRITE");
  184.         console(colorize("All done! AutoComplete XML file is generated!"),false);
  185. <<<
Language: commandhelper
Posted by Raven0 at 08 Dec 2016, 06:25:34 UTC