Jump to content

Baroque AutoIt3 Code Formatter - 08/15/2013


jaberwacky
 Share

Recommended Posts

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.
 

#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:

#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:

#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 by jaberwocky6669
Link to comment
Share on other sites

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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

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 by jaberwocky6669
Link to comment
Share on other sites

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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

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)
Link to comment
Share on other sites

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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

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 by jaberwocky6669
Link to comment
Share on other sites

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 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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • Developers

  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 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

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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...