From f1ed16ed4217fa1cd939c7c45c881f9b1e8cfe74 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Fri, 8 Sep 2023 02:29:06 +0200 Subject: [PATCH] scriptinfo_utils.as: formatting, commented-out DBG logs --- resources/scripts/scriptinfo_utils.as | 99 +++++++++++++++------------ 1 file changed, 54 insertions(+), 45 deletions(-) diff --git a/resources/scripts/scriptinfo_utils.as b/resources/scripts/scriptinfo_utils.as index 52b78e958d..c15ef484fa 100644 --- a/resources/scripts/scriptinfo_utils.as +++ b/resources/scripts/scriptinfo_utils.as @@ -1,7 +1,7 @@ /// \title SCRIPT INFO PARSER /// \brief Extracts info from '///' doc comments in .as files. /// Recognized commands are `\title`, `\brief`. -// Doc comments must start as the first thing on top of the file. +/// Doc comments must start as the first thing on top of the file. /// Usage: /// `#include ` ~~ adds the utils to your script /// `ScriptInfo sinfo = ExtractScriptInfo(scriptstring);` ~~ Processes the script string @@ -17,7 +17,7 @@ class ScriptInfo ScriptInfo@ ExtractScriptInfo(string body) { - ScriptInfoHelper h; + ScriptInfoHelper h; // find the annotations ScriptInfo scriptinfo; int state = 0; //-1 DONE, 0 = start of line, 1/2/3=number of slashes at start of line, 4=blanks after slashes, @@ -27,55 +27,64 @@ ScriptInfo@ ExtractScriptInfo(string body) while (state != -1 && pos < body.length()) { - h.c = body[pos]; - game.log("DBG scriptinfo: state="+state+", capture_startpos="+capture_startpos+", c="+body.substr(pos, 1)); - switch (state) { - case 0: // line start - case 1: // / - case 2: // // ... - if (h.ischar('/')){ state++; } else {state=-1;} - break; - case 3: - if ( h.isblank() ) { state=4; } - else if (h.ischar('\\')) { capture_startpos = pos; state=5; } - else { capture_startpos = pos; state=8; } - break; - case 4: // blanks after slashes - if (!h.isblank()) { if (h.ischar('\\')) { capture_startpos = pos; state=5; } else { capture_startpos = pos; state=8; } } - else if (h.isEol()) { state=0; } - break; - case 5: // cmd, like '\file' - if (h.isblank()) { - string cmd = body.substr(capture_startpos, pos-capture_startpos); game.log('cmd: "'+cmd+'"'); - if (h.isEol()) {state=0;} else if (cmd=='\\title') { state=6; capture_startpos = pos; } else if (cmd=='\\brief') {state=7;capture_startpos = pos; } else {state=8;capture_startpos = pos; } } - break; - case 6: - if (h.isEol()) { state=0; string cmd = body.substr(capture_startpos, pos-capture_startpos); ; scriptinfo.title=h.trimStart(cmd); } - break; - case 7: - if (h.isEol()) {state=0;string cmd = body.substr(capture_startpos, pos-capture_startpos); scriptinfo.brief=h.trimStart(cmd); } - break; - case 8: - if (h.isEol()) {state=0; string cmd = body.substr(capture_startpos, pos-capture_startpos); scriptinfo.text+=cmd+' '; } - break; - - } - pos++; + h.c = body[pos]; + //game.log("DBG scriptinfo: state="+state+", capture_startpos="+capture_startpos+", c="+body.substr(pos, 1)); + switch (state) + { + case 0: // line start + case 1: // / + case 2: // // ... + if (h.ischar('/')){ state++; } else {state=-1;} + break; + case 3: + if ( h.isblank() ) { state=4; } + else if (h.ischar('\\')) { capture_startpos = pos; state=5; } + else { capture_startpos = pos; state=8; } + break; + case 4: // blanks after slashes + if (!h.isblank()) { + if (h.ischar('\\')) { capture_startpos = pos; state=5; } else { capture_startpos = pos; state=8; } } + else if (h.isEol()) { state=0;} + break; + case 5: // cmd, like '\file' + if (h.isblank()) { + string cmd = body.substr(capture_startpos, pos-capture_startpos); + //game.log('DBG cmd: "'+cmd+'"'); + if (h.isEol()) {state=0;} + else if (cmd=='\\title') { state=6; capture_startpos = pos; } + else if (cmd=='\\brief') {state=7;capture_startpos = pos; } + else {state=8;capture_startpos = pos; } } + break; + case 6: + if (h.isEol()) {state=0; string cmd = body.substr(capture_startpos, pos-capture_startpos); scriptinfo.title=h.trimStart(cmd); } + break; + case 7: + if (h.isEol()) {state=0;string cmd = body.substr(capture_startpos, pos-capture_startpos); scriptinfo.brief=h.trimStart(cmd); } + break; + case 8: + if (h.isEol()) {state=0; string cmd = body.substr(capture_startpos, pos-capture_startpos); scriptinfo.text+=cmd+' '; } + break; + } + pos++; } return scriptinfo; } class ScriptInfoHelper { - uint c; - bool ischar(string s) { for (uint i=0; i 0) { return s.substr(found);} - else{ return s;} } + uint c; + bool ischar(string s) { for (uint i=0; i 0) { + return s.substr(found); + } else { + return s; + } + } } /*