tylo

Au3Check.exe

292 posts in this topic

#1 ·  Posted (edited)

Au3Check - AutoIt3 syntax checking

Download: HERE

History

1.52 : change: -U outputs an improved linebased list. -u removed. #uses directive changed to #forceref.

1.51 : added: File name and pos ref to -u and -U. -u - and -U - sends to stdout. Other improvements.

1.50 : fixed: ReDim require prev decl and no init. "Not used vars" warning default off. Added -w 6 -w 7.

1.49 : added: option -u file. Added warning on local vars and params declared, but not used.

1.48 : added: allow empty expressions as COM method args. Allow multiple tabs/spaces before cont. char _.

1.47 :

- update: Require space/tab before, and allow comment after cont. char _.

- fixed: Disallow loops/branches after single line IFs.

1.46 : added: Support for Switch block and ContinueCase. Allow '' in include. Upd .dat and TextPad .syn file.

1.45 : added: Support for Default keyword. Updated .dat and .syn files

1.44 : fixed: Const ByRef parameters.

1.43 : fixed: Broken multidim array decl. Fixed include of full-path files.

1.42 : fixed: Broken check for multiple parameters with same name.

1.41 : fixed: Prevent redecl. of parameters bug. and Const array initialization.

1.40 : added: Const parameters. Array initialization. Prevent redecl. of parameters.

1.39 : fixed: bug in CLI options. Enum fixes. Made 'Local in global scope' be opt. warning.

1.38 : fixed: issues with Enums. Closing string char missed in error output.

1.37 : added: support True, False as default values in Func def. Internal new string class.

1.36 : fixed: COM issues.

1.35 : fixed: improved checking on assignment with new operators and COM objects. $var() call allowed.

1.34 : internal

1.33 : added: support for += -= *= /= &= operators. Support for True False keywords.

1.32 : fixed: white space after _ at end of line within strings was not accepted.

1.31 : fixed: made a generic way in the .dat file to check UDF refs in SetOnEvent type functions.

1.30 : added: check functions given in GUICtrlSetOnEvent, AdlibEnable, OnExitFunc.

1.29 : fixed: a single variable on a line was accepted.

1.28 : fixed: COM methods/attribs couldn't have keyword names. Enums wasn't set const.

1.27 : added: support for COM syntax, With .. EndWith, For .. In .. Next, Enum

1.26 : added: optional warning for multiple declared vars (except arrays - normally intended re-dim).

1.25 : obeys that For-loop declares counter (Local in funcs, Global outside). Changed warning nums.

1.24 : fixed: #include-once for relative paths. Added -w[-] to turn on/off individual warnings. (can be summed)

1.23 : fixed: didn't check declaration of counter var in For-Next. (1.22 did this, but wrongly).

1.22 : added: enable/disable var decl. check on Opt/AutoItSetOption("MustDeclareVars", 1/0) - file scope.

1.21 : added: command line option -d, which checks as Opt("MustDeclareVars", 1).

1.20 : fixed: a bug introduced in 1.17. Added check to not accept Consts to Byref params.

1.19 : internal

1.18 : added: check for already defined non-const var when declaring consts.

1.17 : added: Const keyword. Fixed variable scope bug. Changed .def to .dat

1.16 : fixed: didn't accept negative default values for opt. params.

1.15 : added: accept macro as default value for optional parameters

1.14 : added: also looks in old registry path for includes if new not exists.

1.13 : added: support for optional parameters. Changed registry lookup for includes.

1.12 : fixed: check string values for up to 4 parameters now. Added -q (quiet) option.

1.11 :

- added check for first string parameter Opt/ControlSendCommand/Mouse*

- improved error message for block structures missing closing keyword (if/select/while...)

- prints all output to stdout - not to stderr anymore

- prints number of errors/warning as summery.

- updated .def file.

1.10 : missing #ce outputs only a warning now. use -v 0 to supress it. -v 1 is now default.

1.09 : added support for optional [level] "argument" for ExitLoop.

1.08 : obeys #include-once. internal: added a simple string class.

1.07 : #include ".." seaches the std include dirs after current. added error on #ce without matching #cs

1.06 : readded -I <dir>, for additional include search paths.

1.05 : internal improvements, VC6 project files, and a minor bug fix.

1.04 : fixed: didn't accept chars after #ce directive, e.g. '#ce -- end comment'

1.03 : fixed error when block comment not close, fixed $1xx now allowed, ++

1.02 : fixed bug with #-lines. Cleaned up in error reporting.

1.01 : added std include paths, unknown lines with # ignored, changed return codes, and minor fixes.

1.00 : symbol tables: checks macros, variables, and function calls

0.62 : improved error reporting. (I'll start work on symbol tables now)

0.60 : exit code: number of errors (negative nums on usage/file open errors)

0.59 : fixed: error when file ends without newline.

0.58 : improved error reporting, fixed "" and '' within strings, fixed bug with Exit N.

0.56 : added multiple errors reporting, plus showing offended line and position arrow

0.55 : fixed variable declaration lists, added ReDim keyword.

0.54 : fixed a few issues with include paths

0.53 : added -I "path" for #include <xx> support. Also fixed #include "xx" to search from input file dir.

0.52 : fixed bug with ElseIf

0.51 : fixed bug with #include-once

0.50 : first alpha release

Status

Syntax checks the latest beta of Autoit3. Checks all symbols used:

  • Macros (defined in Au3Check.dat).

    Usage of non-defined macros are reported as errors.

  • Variables: (built-in variables ($CmdLine) are defined in Au3Check.dat)

    Au3Check issues warning if variables are used before they are seen. It is possible that the program is still correct, like the following:

    For $i=1 To 2
         If $i=2 Then msgbox(0, "ok", $hello);
         Local $hello = "Goodbye"
      Next

    However, this is bad programming style, and Au3Check will issue a warning that $hello is possible used before it is declared. Likewise, global variables declared in functions should best not be used in other functions. If one is used higher up in the code, a warning is issued. Finally, Au3Check issues an error if a variable is used, but never declared, explicitly or implicitly.

  • Functions: (built-in functions are defined in Au3Check.dat).

    Functions may be defined later than where they are called. Au3Check checks that all functions are called with the correct number of parameters. It also checks that ByRef parameters are called with variables (not l-values, expressions). Finally, non-defined functions are reported.

Usage

Simply add as a tool in TextPad.

Usage: Au3Check [-q] [-d] [-u file] [-w[-] n].. [-v[-] n].. [-I dir].. file.au3
            -q      : quiet (only error/warn output)
            -d      : as Opt("MustDeclareVars", 1)
            -I dir  : additional directories for searching include files
            -U -|file : output unreferenced UDFs and global variables
            -w 1      : already included file (on)
            -w 2      : missing #comments-end (on)
            -w 3      : already declared var (off)
            -w 4      : local var used in global scope (off)
            -w 5      : local var declared but not used (off)
            -w 6      : warn when using Dim (off)
            -v 1      : show include paths/files (off)
            -v 2      : show lexer tokens (off)
       Exit codes:
             0      : success - no errors or warnings
             1      : warning(s) only
             2      : syntax error(s)
             3      : usage or input error

You should set up regular expression (POSIX) like the following:

^([^(]+)\(([0-9]+),([0-9]+)\)

Argument 3 is column.

If you do not use POSIX RegEx, you must use \ in a different way on ()'s.

Files

Au3Check.exe - Au3 script syntax checker

Au3Check.dat - text file containing all built in symbols. Can be updated by user.

Au3Check.txt - this document

What is not checked?

Basically runtime information:

  • No checking is made for array dimensions, or indices. This can only be done runtime.
  • Logical errors, illegal parameters to functions, and division by zero.
Bug Report

Please, report if you find scripts that creates 'syntax error' which shouldn't, and vise versa.

Edited by tylo

blub

Share this post


Link to post
Share on other sites



I find it strange that so few find this tool interesting. It does a complete and accurate syntax check of your entire script + includes. You don't have to run and test the script to see if there are syntax errors (which can be very time consuming for a complex script).

The tool is written in C++ using Flex and Yacc, and is not related to the AutoIt code.

As I said in my first post, the tool does not yet check that functions exists when called, and if they are called with correct number of parameters. (it should also be possible to check that a ByRef variable is called with a variable, and not a value). It does not check that variables have been declared before usage, yet. The same for predefined macros.

This will be fairly easy to do. However, global variables will be a problem. They can be declared anywhere, so it is not possible to build up a useful symbol table of variable names, by scanning linearily through the script source. The good news is that for local variables, it will work! (thanks to structured language elements instead of GOTOs!).

Still, the problem mentioned will not be present if you write your scripts in the following (sensible) fashion, and do not declare global variables in functions (maybe unless they are to be used strictly within that function):

#include "myincs.au3"
Global $g_myVar1
Global $g_myVar2
...
main()
Exit

Func main()
EndFunc

Func myFunc1()
EndFunc

Func myFunc2()
EndFunc
...

blub

Share this post


Link to post
Share on other sites

It is useful, definitely. But you made it for v3.0.101 and I don't use that version.

Share this post


Link to post
Share on other sites

Think its very useful to have this since some syntax errors only show when a specify conditions is true.

Have tested a bit with it together with Scite and here are some observations:

- it shows the error in the outputpane and double clicking jump to the line in error.

- like the fact it shows the error position, but would it also be possible to show it like autoit does ?

C:\WINUtil\AutoIt3\programs\test\test4.au3 (9) : ==> Error in expression.:

$msg = GuiMsg(,0)

$msg = GuiMsg(^ ERROR

- would it be possible to show ALL errors in stead of only the first one, more or less like the VC6 complie does ?

Really believe this will be a big help to avoid syntaxs errors in your scripts when all items are included like you mentioned.

tnx


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

- I don't think there has been any GRAMMAR changes in the language since 3.0.101 (?), so you can use it on 102. If not, tell me.

- Printing the line and ^ for position for errors is planned.

- Showing all errors (or as many as possible) is planned.


blub

Share this post


Link to post
Share on other sites

- Printing the line and ^ for position for errors is planned.

- Showing all errors (or as many as possible) is planned.

:D Great ! :huh2:

Really useful and would like to incorporate it in the Scite install set we have going.

I was thinking of putting it under Ctrl+F5.


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Very nice tool! I started using it today. It doesn't seem to like array declaration (Global declare in my case). Great job!

=MX=

Edit1:

It gives a compile error in the following code:

Global $gaPkgInfo[8], $gsLogFile
Local $sRegKey, $sRegData, $sRegValue, $iReturn

Btw, I'm using your latest code, v0.54

Edited by midiaxe

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Thanks. I forgot that you can declare lists of variables. I'll update today + recognition of the new keyword ReDim.

/Add: already done.

Edited by tylo

blub

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

:D Excellent! Helps me find spelling mistakes before running the code!

BUG: If the AutoIt script does not end in a blank line, Au3Check always reports "error syntax error" on the last line:

tmp.au3
tmp.au3(1,55) : error syntax error
MsgBox(4096, "Example", "This is a single-line script")
------------------------------------------------------^
Edited by CyberSlug

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Tylo, have been testing with it and looking great so far.

Only found two other issues except the one CS found:

1. "" inside a Doublequoted string:

msgbox(0,"test","test:""test""......")

AutoIt3 Syntax Checker v0.56, Copyright (c) Tylo, 2004

C:\WINUtil\AutoIt3\programs\test\test6.au3
C:\WINUtil\AutoIt3\programs\test\test6.au3(1,24) : error: syntax error 
msgbox(0,"test","test:""test"
~~~~~~~~~~~~~~~~~~~~~~~^
The same for single quotes:
msgbox(0,"test",'test:''test''......')

2. also an issue with Exit 0

error: syntax error 
    Exit 0
~~~~~~~~^
Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Could you also have au3check returncode set it 1 in case of Errors like AutoIt3.exe does ?

This would enable the possibility to batch it together with AuotIt3.exe and only start AutoIt3 when the returncode is 0...


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Au3Check V1.00 is released.

With all the good stuff. Check first post, and read status...

Edited by tylo

blub

Share this post


Link to post
Share on other sites

Au3Check V1.00 is released.

With all the good stuff. Check first post, and read status...

@Tylo, it's looking really very nice ... :D

have tested it against several scripts with and without errors and didn't find any issue with it.

Only one NitPick in a warning message: ERROR: unresovled global variable:

Great job.....


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

@Tylo, it's looking really very nice ...  :D

have tested it against several scripts with and without errors and didn't find any issue with it.

Only one NitPick in a warning message: ERROR: unresovled global variable:

Great job.....

JdeB, how long before you use Lua to run this on the script first, then if no errors are found, run the compiler/interpreter for AutoIt? (os.execute() looks nice for this...)

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

JdeB, how long before you use Lua to run this on the script first, then if no errors are found, run the compiler/interpreter for AutoIt?  (os.execute() looks nice for this...)

I have Scite config/Helpfile ready for AU3check which is run with Ctrl+F5.

Didn't work on running them in sequence but Tylo put the return code in so that can be done.

Did you already look at it?

Edit: this is how it looks:

http://www.autoitscript.com/fileman/users/jdeb/test/syntaxcheck.png

Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

I have Scite config/Helpfile ready for AU3check which is run with Ctrl+F5.

Didn't work on running them in sequence but Tylo put the return code in so that can be done.

Did you already look at it?

looks great, does this mean there's a new version of scite available for download? With Au3Check bundled? :D I'd love to give it a shot, and it's soooo much cooler when I can just hit a key in Scite...

"I'm not even supposed to be here today!" -Dante (Hicks)

Share this post


Link to post
Share on other sites

@jdeb: you rock.

@tylo: it's detecting the # character in #region and #endregion as illegal characters... How would I fix that?


"I'm not even supposed to be here today!" -Dante (Hicks)

Share this post


Link to post
Share on other sites

@jdeb: you rock.

@tylo: it's detecting the # character in #region and #endregion as illegal characters...  How would I fix that?

As emmanuel said, this shouldn't generate a warning on any line starting with #. AutoIt safely ignores any line starting with # except #include, #include-once and the block comment stuff. I know that we (JdeB and myself) have exploited that to make a feature in SciTE work and I use that loophole for other stuff as well.

Also, while on the subject of warnings. Is there 3 return values? I would like to see the following set of return values so that Au3Check can be automated and the severity checked by a script or something:

Success - 0

Warnings, but no critical errors - 1

Critical errors that would cause the script to fail - 2

Or something similar to that.

Share this post


Link to post
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