jaberwacky Posted July 31, 2013 Share Posted July 31, 2013 (edited) This will format your au3 source. It removes spaces between braces. It inserts spaces between operators and after commas. Tidy will do this and yes I have used Tidy. But Tidy also removes extra whitespace which misaligns sections of code which I have aligned particularly. I did ask for this feature in Tidy but for some reason or another it wasn't put in there. You can uncheck to not tidy the spaces but also doesn't insert spaces in the aforementioned areas. I made an au3 parser because I wanted the learning experience. It was also fun. There is the official tidy which does more than this but this won't strip away spaces and plus I plan add more features which would not be useful to the majority of AutoIt users. Thus, I made the Baroque AutoIt3 Parser. N.B. that this is never intended to replace the official Tidy. I could 1) never fill Jos' shoes and 2) never compete with flex and yacc -- I'm pretty sure those are used in Tidy. Just use this as either a curio, a discussion springboard or a learning experience. Updated: Works with ternary syntax now. expandcollapse popup#include-once Func baroque_autoit_parser(Const $au3_source) #region ; Tokens Local Const $space = ' ' Local Const $double_quote = Chr(34) Local Const $single_quote = Chr(39) Local Const $underscore = '_' Local Const $hash = '#' Local Const $comma = ',' Local Const $semicolon = ';' Local Const $equal = '=' Local Const $ampersand = '&' Local Const $plus = '+' Local Const $minus = '-' Local Const $asterisk = '*' Local Const $forward_slash = '/' Local Const $caret = '^' Local Const $open_bracket = '[' Local Const $close_bracket = ']' Local Const $open_parens = '(' Local Const $close_parens = ')' Local Const $open_angle_bracket = '<' Local Const $close_angle_bracket = '>' Local Const $question = '?' Local Const $colon = ':' #endregion Local Const $au3_length = StringLen($au3_source) Local $formatted_au3 = '' Local $within_double_quote_string = False Local $within_single_quote_string = False Local $within_comment = False Local $within_preprocessor = False Local $token = '' Local $previous_token = '' Local $next_token = '' Local $comment_token = '' Local $tmp_token = '' Local $line = 0 For $i = 1 To $au3_length $token = StringMid($au3_source, $i, 1) $previous_token = StringMid($au3_source, $i - 1, 1) $next_token = StringMid($au3_source, $i + 1, 1) ; increment the line count Switch $token Case @LF $line += 1 EndSwitch ; This switch structure tries to determine if the formatter is currently in a string section. Switch $token Case $double_quote $within_double_quote_string = Not $within_double_quote_string Case $single_quote $within_single_quote_string = Not $within_single_quote_string EndSwitch ; This switch structure tries to determine if the formatter is currently in a comment section. Switch $token Case $semicolon Switch (Not $within_double_quote_string) And (Not $within_single_quote_string) And (Not $within_comment) Case True $within_comment = True Switch $i <> 1 ; skip the semicolon on the first line Case True Switch $previous_token <> $space And $previous_token <> @LF Case True $token = $space & $token EndSwitch Switch $next_token <> $space Case True $token &= $space EndSwitch EndSwitch ; skip ahead until EOL For $j = $i + 1 To $au3_length $comment_token = StringMid($au3_source, $j, 1) Switch $comment_token Case @LF $within_comment = False $i = $j ExitLoop Case Else $token &= $comment_token EndSwitch Next EndSwitch Case $hash Select Case StringMid($au3_source, $i + 1, 14) = "comments-start" $within_comment = True ; skip to end of line For $j = $i + 1 To $au3_length Local $tmp_token = StringMid($au3_source, $j, 1) Switch $tmp_token Case @LF ExitLoop Case Else $i += 1 $token &= $tmp_token EndSwitch Next Case StringMid($au3_source, $i + 1, 2) = "cs" $within_comment = True ; skip to end of line For $j = $i + 1 To $au3_length Local $tmp_token = StringMid($au3_source, $j, 1) Switch $tmp_token Case @LF ExitLoop Case Else $i += 1 $token &= $tmp_token EndSwitch Next Case StringMid($au3_source, $i + 1, 12) = "comments-end" $within_comment = False ; skip to end of line For $j = $i + 1 To $au3_length Local $tmp_token = StringMid($au3_source, $j, 1) Switch $tmp_token Case @LF ExitLoop Case Else $i += 1 $token &= $tmp_token EndSwitch Next Case StringMid($au3_source, $i + 1, 2) = "ce" $within_comment = False ; skip to end of line For $j = $i + 1 To $au3_length Local $tmp_token = StringMid($au3_source, $j, 1) Switch $tmp_token Case @LF ExitLoop Case Else $i += 1 $token &= $tmp_token EndSwitch Next EndSelect EndSwitch ; This switch structure is where the formatting happens. Switch (Not $within_double_quote_string) And (Not $within_single_quote_string) And (Not $within_comment) Case True Switch $token Case $space Select Case $next_token = $comma ContinueLoop EndSelect Case $comma Select Case $previous_token = $space And $next_token <> $space $token = $token & $space Case $next_token <> $space $token = $token & $space EndSelect Case $equal Select Case $next_token = $equal ; if == $jump_two_tokens = StringMid($au3_source, $i + 2, 1) Select Case $previous_token <> $space And $jump_two_tokens <> $space ; if "==" $token = $space & $equal & $equal & $space $i += 1 Case $previous_token = $space And $jump_two_tokens <> $space ; if "== " $token = $equal & $equal & $space $i += 1 Case $previous_token <> $space And $jump_two_tokens = $space ; if ; " ==" $token = $space & $equal & $equal $i += 1 EndSelect Case $next_token <> $equal And $previous_token <> $open_angle_bracket And $previous_token <> $close_angle_bracket ; '=' Select Case $previous_token <> $space And $next_token <> $space $token = $space & $token & $space Case $previous_token <> $space And $next_token = $space $token = $space & $token Case $previous_token = $space And $next_token <> $space $token = $token & $space EndSelect EndSelect Case $semicolon Local $temp_token = '' For $i =($i + 1) To ($au3_length - 1) $temp_token = StringMid($au3_source, $i, 1) Switch $temp_token Case $space $i += 1 ContinueLoop Case Not $space ExitLoop EndSwitch Next Select Case $previous_token <> $space And $next_token <> $space ; ";" $token = $space & $token & $space Case $previous_token = $space And $next_token <> $space ; " ;" $token = $token & $space Case $previous_token <> $space And $next_token = $space ; "; " $token = $space & $token Case $previous_token <> $space And $previous_token <> @LF And $next_token <> $space $token = $space & $token & $space EndSelect Case $ampersand, $plus, $minus, $asterisk, $forward_slash, $caret Switch $next_token <> $equal Case True Select Case $previous_token <> $space And $next_token <> $space $token = $space & $token & $space Case $previous_token = $space And $next_token <> $space $token = $token & $space Case $previous_token <> $space And $next_token = $space $token = $space & $token EndSelect Case False $jump_two_tokens = StringMid($au3_source, $i + 2, 1) Select Case $previous_token = $space And $jump_two_tokens = $space $token = $token & $equal $i += 1 Case $previous_token <> $space And $jump_two_tokens <> $space $token = $space & $token & $equal & $space $i += 1 Case $previous_token = $space And $jump_two_tokens <> $space $token = $token & $equal & $space $i += 1 Case $previous_token <> $space And $jump_two_tokens = $space $token = $space & $token & $equal $i += 1 EndSelect EndSwitch Case $open_angle_bracket Switch $within_preprocessor Case True Select Case $previous_token <> $space $token = $space & $token EndSelect ; skip all of the spaces For $j = $i + 1 To $au3_length $tmp_token = StringMid($au3_source, $j, 1) Select Case $tmp_token = $space $i += 1 Case $tmp_token = $close_angle_bracket $within_preprocessor = False ExitLoop Case $tmp_token <> $space $i += 1 $token &= $tmp_token EndSelect Next EndSwitch Select Case $next_token = $equal $jump_two_tokens = StringMid($au3_source, $i + 2, 1) Select Case $previous_token <> $space And $jump_two_tokens <> $space $token = $space & $token & $next_token & $space $i += 1 Case $previous_token <> $space And $jump_two_tokens = $space $token = $space & $token & $next_token $i += 1 Case $previous_token = $space And $jump_two_tokens <> $space $token = $token & $next_token & $space $i += 1 EndSelect Case $next_token = $close_angle_bracket $jump_two_tokens = StringMid($au3_source, $i + 2, 1) Select Case $previous_token <> $space And $jump_two_tokens <> $space $token = $space & $token & $next_token & $space $i += 1 Case $previous_token <> $space And $jump_two_tokens = $space $token = $space & $token & $next_token $i += 1 Case $previous_token = $space And $jump_two_tokens <> $space $token = $token & $next_token & $space $i += 1 EndSelect EndSelect Case $close_angle_bracket Select Case $next_token = $equal $jump_two_tokens = StringMid($au3_source, $i + 2, 1) Select Case $previous_token <> $space And $jump_two_tokens <> $space $token = $space & $token & $next_token & $space $i += 1 Case $previous_token <> $space And $jump_two_tokens = $space $token = $space & $token & $next_token $i += 1 Case $previous_token = $space And $jump_two_tokens <> $space $token = $token & $next_token & $space $i += 1 EndSelect EndSelect Case $open_parens Select Case $next_token = $space $i += 1 EndSelect Case $close_parens Select Case $previous_token = $space And StringMid($au3_source, $i - 2, 1) <> $open_parens $formatted_au3 = StringTrimRight($formatted_au3, 1) EndSelect Case $open_bracket Select Case $next_token = $space $i += 1 EndSelect Case $close_bracket Select Case $previous_token = $space And StringMid($au3_source, $i - 2, 1) <> $open_bracket $formatted_au3 = StringTrimRight($formatted_au3, 1) EndSelect Case $question, $colon Select Case $previous_token <> $space And $next_token <> $space $token = $space & $token & $space Case $previous_token = $space And $next_token <> $space $token = $token & $space Case $previous_token <> $space And $next_token = $space $token = $space & $token EndSelect Case $hash $within_preprocessor = True Select Case StringMid($au3_source, $i + 1, 12) = "include-once" ; skip to end of line For $j = $i + 1 To $au3_length $tmp_token = StringMid($au3_source, $j, 1) Switch $tmp_token Case @LF $within_preprocessor = False ExitLoop Case Else $i += 1 $token &= $tmp_token EndSwitch Next Case StringMid($au3_source, $i + 1, 14) = "AutoIt3Wrapper" ; skip to end of line For $j = $i + 1 To $au3_length Local $tmp_token = StringMid($au3_source, $j, 1) Switch $tmp_token Case @LF $within_preprocessor = False ExitLoop Case Else $i += 1 $token &= $tmp_token EndSwitch Next EndSelect EndSwitch EndSwitch $formatted_au3 &= $token Next Return $formatted_au3 EndFunc How to use this: #include <Baroque AutoIt Parser.au3> Global Const $au3_source = FileRead([FILEPATH]) Global Const $formatted_autoit = baroque_autoit_parser($au3_source) ; Write $formatted_autoit to a file, the clipboard, to the console, etc. Turn this hot ratchet mess: expandcollapse popup#include-once #include<TEST.au3> #include< TEST.au3> #include<TEST.au3 > #include< TEST.au3 > ;COMMENT LINE! Nothing on this line should be ; formatted. $test=1+2-3*4/5 ; COMMENT LINE! Nothing on this line should be formatted. $test=$test>=$test ; COMMENT LINE! Nothing on this line should be formatted. $test=$test<=$test ;COMMENT LINE! Nothing on this line should be formatted. $test=$test-=$test Local $sSource=$vExpression?True:False ConsoleWrite(baroque_autoit_parser($sSource)&@CRLF) $test="This string 'should' ""remain"" untouched. ; $test=1+2-3*4/5 $test=$test-=$test $test=$test+=$test $test=$test/=$test" $test="This string 'should' remain untouched. ; $test=$test>=$test $test=$test-=$test $test=$test+=$test $test=$test/=$test" $test="This string 'should' remain untouched. ; $test=$test<=$test $test=$test-=$test $test=$test+=$test $test=$test/=$test" $test="This string 'should' remain untouched. ; $test=$test+=$test $test=$test-=$test $test=$test+=$test $test=$test/=$test" $test = 1 + 2 - 3 * 4 / 5 $test=1+2-3*4/5 $test= 1+ 2- 3* 4/ 5 $test =1 +2 -3 *4 /5 $test = $test <> $test $test = $test<>$test $test = $test<> $test $test = $test <>$test $test = $test >= $test $test=$test>=$test $test= $test>= $test $test =$test >=$test $test = $test <= $test $test=$test<=$test $test= $test<= $test $test =$test <=$test $test = $test += $test $test=$test+=$test $test= $test+= $test $test =$test +=$test $test = $test -= $test $test=$test-=$test $test= $test-= $test $test =$test -=$test $test = $test *= $test $test=$test*=$test $test= $test*= $test $test =$test *=$test $test = $test /= $test $test=$test/=$test $test= $test/= $test $test =$test /=$test $fEnd=TimerDiff($t) + 1000 $fEnd=TimerDiff($t ) -1000 $fEnd=TimerDiff( $t)* 1000 $fEnd=TimerDiff( $t )/1000 _MyFunction( $1 , $2 , $3 , ... ) _MyFunction( $1 , _ $2 , _ $3 , _ ... ) Global Const $TEST=$TEST;$TEST=0,$TEST=0 Global Const $TEST =$TEST ;$TEST =0,$TEST= 0 Global Const $TEST= $TEST; $TEST= 0,$TEST =0 Global Const $TEST= $TEST; $TEST= 0 ,$TEST = 0 Global Const $TEST= $TEST; $TEST= 0, $TEST =0 MsgBox ( 0, "TEST","") MsgBox (0, "TEST"," " ) MsgBox ( 0, "TEST","""" ) Global COnst $TEST[10]=[ ""," ",' ' ,'' , '', '' ] Global COnst $TEST[10] =[ "a","s","d" ,"e" , "f", "g" ] Global COnst $TEST[10]= [ '1','2','3' ,'4' , '5', '6' ] If $TEST==$TEST Then $TEST If $TEST ==$TEST Then $TEST If $TEST== $TEST Then $TEST Into this: expandcollapse popup#include-once #include <TEST.au3> #include <TEST.au3> #include <TEST.au3> #include <TEST.au3> ; COMMENT LINE! Nothing on this line should be ; formatted. $test=1+2-3*4/5 ; COMMENT LINE! Nothing on this line should be formatted. $test=$test>=$test ; COMMENT LINE! Nothing on this line should be formatted. $test=$test<=$test ; COMMENT LINE! Nothing on this line should be formatted. $test=$test-=$test Local $sSource = $vExpression ? True : False ConsoleWrite(baroque_autoit_parser($sSource) & @CRLF) $test = "This string 'should' ""remain"" untouched. ; $test=1+2-3*4/5 $test=$test-=$test $test=$test+=$test $test=$test/=$test" $test = "This string 'should' remain untouched. ; $test=$test>=$test $test=$test-=$test $test=$test+=$test $test=$test/=$test" $test = "This string 'should' remain untouched. ; $test=$test<=$test $test=$test-=$test $test=$test+=$test $test=$test/=$test" $test = "This string 'should' remain untouched. ; $test=$test+=$test $test=$test-=$test $test=$test+=$test $test=$test/=$test" $test = 1 + 2 - 3 * 4 / 5 $test = 1 + 2 - 3 * 4 / 5 $test = 1 + 2 - 3 * 4 / 5 $test = 1 + 2 - 3 * 4 / 5 $test = $test <> $test $test = $test <> $test $test = $test <> $test $test = $test <> $test $test = $test >= $test $test = $test >= $test $test = $test >= $test $test = $test >= $test $test = $test <= $test $test = $test <= $test $test = $test <= $test $test = $test <= $test $test = $test += $test $test = $test += $test $test = $test += $test $test = $test += $test $test = $test -= $test $test = $test -= $test $test = $test -= $test $test = $test -= $test $test = $test *= $test $test = $test *= $test $test = $test *= $test $test = $test *= $test $test = $test /= $test $test = $test /= $test $test = $test /= $test $test = $test /= $test $fEnd = TimerDiff($t) + 1000 $fEnd = TimerDiff($t) - 1000 $fEnd = TimerDiff($t) * 1000 $fEnd = TimerDiff($t) / 1000 _MyFunction($1, $2, $3, ...) _MyFunction($1, _ $2, _ $3, _ ...) Global Const $TEST = $TEST ; $TEST=0,$TEST=0 Global Const $TEST = $TEST ; $TEST =0,$TEST= 0 Global Const $TEST = $TEST ; $TEST= 0,$TEST =0 Global Const $TEST = $TEST ; $TEST= 0 ,$TEST = 0 Global Const $TEST = $TEST ; $TEST= 0, $TEST =0 MsgBox (0, "TEST", "") MsgBox (0, "TEST", " ") MsgBox (0, "TEST", """") Global COnst $TEST[10] = ["", " ", ' ', '', '', ''] Global COnst $TEST[10] = ["a", "s", "d", "e", "f", "g"] Global COnst $TEST[10] = ['1', '2', '3', '4', '5', '6'] If $TEST == $TEST Then $TEST If $TEST == $TEST Then $TEST If $TEST == $TEST Then $TEST Edited August 15, 2013 by jaberwocky6669 czardas 1 Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
guinness Posted August 1, 2013 Share Posted August 1, 2013 I tested with this and nothing changed...I mean the test script was exactly the same. #include 'baroque_autoit_parser.au3' ClipPut(FileRead(baroque_autoit_parser('Example.au3'))) UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
jaberwacky Posted August 1, 2013 Author Share Posted August 1, 2013 (edited) Oh right, it just returns the changed source. Oopsy, forgot to mention it. Should I alter it to work like you demonstrated? I'm not sure I like to write to a file from a function. It might be best to output the formatted source and then feed that into a filewrite(). (??) Oh also, call strip_trailing_whitespace before baroque_autoit_parser. Actually, I think I will add that into the parser. Edited August 1, 2013 by jaberwocky6669 Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
guinness Posted August 1, 2013 Share Posted August 1, 2013 No, how should it be called? UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
jaberwacky Posted August 1, 2013 Author Share Posted August 1, 2013 For now the way to call it is like this: #include <Baroque AutoIt Parser.au3> Global Const $au3_source = FileRead([FILEPATH]) Global Const $stripped_whitespace = strip_trailing_whitespace($au3_source) Global Const $formatted_autoit = baroque_autoit_parser($stripped_whitespace) FileWrite([FILEHANDLE], $formatted_autoit) Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
guinness Posted August 1, 2013 Share Posted August 1, 2013 Ah, OK. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
czardas Posted August 1, 2013 Share Posted August 1, 2013 (edited) I had no problem with this. it returns a modified code string, as I would have expected. Nice work jaberwocky6669 - I like it. I notice what I think is a bug though. [] [ ] becomes [] ] Edited August 1, 2013 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
jaberwacky Posted August 1, 2013 Author Share Posted August 1, 2013 Thanks Czardas. I think I fixed it with the latest update. Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
czardas Posted August 1, 2013 Share Posted August 1, 2013 I think I fixed it with the latest update. So you did. I'm curious what these additional features only you are likely to use might be. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
jaberwacky Posted August 1, 2013 Author Share Posted August 1, 2013 (edited) One goal is to split a long parameter list into this: _MyFunction($1, $2, $3, ...) _MyFunction($1, _ $2, _ $3, _ ...) I promise I'll start using the preview button from now on. Edited August 1, 2013 by jaberwocky6669 Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
czardas Posted August 1, 2013 Share Posted August 1, 2013 That's a good idea for inserting end of line comments. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
jaberwacky Posted August 1, 2013 Author Share Posted August 1, 2013 Sorry, I don't follow. Explain like I'm five. Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
czardas Posted August 1, 2013 Share Posted August 1, 2013 I simply mean commenting each parameter. _MyFunction($1, _ ; This has some meaning $2, _ ; $2 comes before $3 $3, _ ; $3 may or may not be related to $1 and $2 ...) ; ... pseudo code operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
jaberwacky Posted August 1, 2013 Author Share Posted August 1, 2013 ohhhhh, k. I was like totally confuzed and stuff. Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
guinness Posted August 1, 2013 Share Posted August 1, 2013 (edited) I see you merged it all into one function, which is easier to understand. I didn't realise strip_trailing_whitespace() had to be called before. Hope someone learns from this. I know Mat has a feature complete Au3 parser. Edited August 1, 2013 by guinness UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
jaberwacky Posted August 1, 2013 Author Share Posted August 1, 2013 I know Mat has a feature complete Au3 parser. Oh cool, I'll check it out right now and compare to see how I did. Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
jaberwacky Posted August 1, 2013 Author Share Posted August 1, 2013 I just realized after looking at Mat's parser that I may have misnamed this. This isn't meant to ever be something that can execute AutoIt, just format it. Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
Developers Jos Posted August 1, 2013 Developers Share Posted August 1, 2013 (edited) Yes, I did ask for this feature in Tidy but for some reason or another it wasn't put in there. Yes, you can uncheck to not tidy the spaces but also doesn't insert spaces in the aforementioned areas. Can't remember anymore when this was or what I have said about it, but in general do not ignore requests. I made an au3 parser because I wanted the learning experience. It was also fun. There is the official tidy which does more than this but this won't strip away spaces and plus I plan add more features which would not be useful to the majority of AutoIt users. Thus, I made the Baroque AutoIt3 Parser. N.B. that this is never intended to replace the official Tidy. I could 1) never fill Jos' shoes and 2) never compete with flex and yacc -- I'm pretty sure those are used in Tidy. Just use this as either a curio, a discussion springboard or a learning experience. AU3Check is written in Flex&YACC. Tidy is originally written in AutoIt3 as a practice for me and later converted into BCX for Speed. Don't be too sure about the shoes bit. I am not a programmer by profession. Did that for 3 years (some 30 years ago) and knew quickly that it wasn't my cup of tea. So only do this as hobby. Jos Edited August 1, 2013 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
guinness Posted August 1, 2013 Share Posted August 1, 2013 I just realized after looking at Mat's parser that I may have misnamed this. This isn't meant to ever be something that can execute AutoIt, just format it. Mat's doesn't execute it either, just parses the Au3 Script for easier editing and adjusting. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
jaberwacky Posted August 1, 2013 Author Share Posted August 1, 2013 Maybe I looked at the wrong one. I saw Pratt's Parser. I'll search again. Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now