comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: idl syntax validation
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: idl syntax validation [message #50666] Sun, 15 October 2006 10:00
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
Michael Galloy wrote:
> The below routines have to be in separate files, named
> validate_syntax.pro and validate_syntax_helper.pro. Then
>
> IDL> print, validate_syntax('foo')
> 0
> IDL> print, validate_syntax('validate_syntax')
> 1
>
> My "normal" trick of using EXECUTE(..., 1) didn't work, so I had to up
> the ante to the IDL_IDLBridge.
>
> Mike

Also, you'll want to rework this a bit since you don't want to start a
new IDL_IDLBridge for each routine check if you are checking a lot of
routines.

One last caveat, you can't check VALIDATE_SYNTAX_HELPER (well, you can,
but compiling a routine while executing that routine is an error,
VALIDATE_SYNTAX_HELPER will return 0 when checking itself).

Mike
--
www.michaelgalloy.com
Re: idl syntax validation [message #50667 is a reply to message #50666] Fri, 13 October 2006 18:16 Go to previous message
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
The below routines have to be in separate files, named
validate_syntax.pro and validate_syntax_helper.pro. Then

IDL> print, validate_syntax('foo')
0
IDL> print, validate_syntax('validate_syntax')
1

My "normal" trick of using EXECUTE(..., 1) didn't work, so I had to up
the ante to the IDL_IDLBridge.

Mike
--
www.michaelgalloy.com


function validate_syntax, routineName
compile_opt strictarr, hidden

catch, error
if (error ne 0) then return, 0

o = obj_new('IDL_IDLBridge')
cmd = 'result = validate_syntax_helper(''' + routineName + ''')'
o->execute, cmd
result = o->getVar('result')
obj_destroy, o
return, result
end


function validate_syntax_helper, routineName
compile_opt strictarr, hidden

catch, error
if (error ne 0) then return, 0

resolve_routine, routineName, /either, /compile_full_file
return, 1
end


Dometz wrote:
> Hi JD,
>
> Thanks you for your help... it works pretty well, but I still get some
> errors that I am not able to catch... well, I am able to catch them but
> it prints an error message. How can I get rid of that error message /
> meaning that it wont print any error message?
>
> IDL> validate_routine, ["valid"]
> 1
> IDL> validate_routine, ["foo"]
>
> read_png()
> ^
> % Syntax error.
> At: /home/dometz/test_cases/idl/foo.pro, Line 8
> 0
> IDL> exit
>
>
> function validate_syntax, ROUTINE
> COMPILE_OPT HIDDEN
> CATCH, ERROR
> IF (ERROR NE 0) THEN RETURN, 0
> RESOLVE_ROUTINE, ROUTINE, /EITHER, /COMPILE_FULL_FILE
> RETURN, 1
> END
>
> pro FOO
> read_png()
> END
>
>
> any ideas?
>
> dometz
>
>
>
> JD Smith wrote:
>> On Wed, 11 Oct 2006 15:11:05 -0700, Dometz wrote:
>>
>>> I guess I wasnt clear enough... I mean something that I can run in a
>>> bash script to test if a .pro file has valid syntax.
>>>
>>> something like:
>>> echo '.compile foo.pro' | idl
>>> and then checking if there are any syntax error messages and if there
>>> are act accordingly.
>>>
>>> But is there a better way than using .compile for this?
>> I guess I didn't do all your homework for you ;). You could use this
>> idea to write a function called check_syntax, ala:
>>
>> function check_syntax,routine
>> catch,err
>> if err ne 0 then return,err
>> resolve_routine,routine,/EITHER,/COMPILE_FULL_FILE
>> return,0
>> end
>>
>> Then a batch file which uses this function, like do_check.pro:
>>
>> ;================
>> status=check_syntax((command_line_args())[0])
>> if status ne 0 then print,!ERROR_STATE.MSG
>> exit,STATUS=status
>> ;================
>>
>> then call, from your shell script:
>>
>> idl -arg routine do_check.pro
>>
>> and check the exit status. You might need to monkey IDL_PATH to ensure
>> it attempts to compile the correct version of the routine, like:
>>
>> idl -IDL_PATH "$(pwd):+/other/libs:<IDL_DEFAULT>" -arg routine do_check.pro
>>
>> JD
>
Re: idl syntax validation [message #50668 is a reply to message #50667] Fri, 13 October 2006 17:58 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Dominic writes:

> Hahahaha, yeah, that would help... but then what would I use my fancy
> function for?
>
> Any ideas on how to suppress this error message?

!QUIET = 1

Suppresses the hell out of them! :-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: idl syntax validation [message #50669 is a reply to message #50668] Fri, 13 October 2006 17:33 Go to previous message
Dominic[1] is currently offline  Dominic[1]
Messages: 13
Registered: October 2006
Junior Member
Hahahaha, yeah, that would help... but then what would I use my fancy
function for?

Any ideas on how to suppress this error message?

dometz


David Fanning wrote:
> Dometz writes:
>
>> Thanks you for your help... it works pretty well, but I still get some
>> errors that I am not able to catch... well, I am able to catch them but
>> it prints an error message. How can I get rid of that error message /
>> meaning that it wont print any error message?
>>
>> IDL> validate_routine, ["valid"]
>> 1
>> IDL> validate_routine, ["foo"]
>>
>> read_png()
>> ^
>> % Syntax error.
>> At: /home/dometz/test_cases/idl/foo.pro, Line 8
>> 0
>> IDL> exit
>>
>>
>> function validate_syntax, ROUTINE
>> COMPILE_OPT HIDDEN
>> CATCH, ERROR
>> IF (ERROR NE 0) THEN RETURN, 0
>> RESOLVE_ROUTINE, ROUTINE, /EITHER, /COMPILE_FULL_FILE
>> RETURN, 1
>> END
>>
>> pro FOO
>> read_png()
>> END
>>
>>
>> any ideas?
>
> I have an obvious one: use the correct IDL syntax for READ_PNG.
> That should help. :-)
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming: http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: idl syntax validation [message #50670 is a reply to message #50669] Fri, 13 October 2006 17:08 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Dometz writes:

> Thanks you for your help... it works pretty well, but I still get some
> errors that I am not able to catch... well, I am able to catch them but
> it prints an error message. How can I get rid of that error message /
> meaning that it wont print any error message?
>
> IDL> validate_routine, ["valid"]
> 1
> IDL> validate_routine, ["foo"]
>
> read_png()
> ^
> % Syntax error.
> At: /home/dometz/test_cases/idl/foo.pro, Line 8
> 0
> IDL> exit
>
>
> function validate_syntax, ROUTINE
> COMPILE_OPT HIDDEN
> CATCH, ERROR
> IF (ERROR NE 0) THEN RETURN, 0
> RESOLVE_ROUTINE, ROUTINE, /EITHER, /COMPILE_FULL_FILE
> RETURN, 1
> END
>
> pro FOO
> read_png()
> END
>
>
> any ideas?

I have an obvious one: use the correct IDL syntax for READ_PNG.
That should help. :-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: idl syntax validation [message #50671 is a reply to message #50670] Fri, 13 October 2006 16:58 Go to previous message
Dominic Metzger is currently offline  Dominic Metzger
Messages: 30
Registered: August 2006
Member
Hi JD,

Thanks you for your help... it works pretty well, but I still get some
errors that I am not able to catch... well, I am able to catch them but
it prints an error message. How can I get rid of that error message /
meaning that it wont print any error message?

IDL> validate_routine, ["valid"]
1
IDL> validate_routine, ["foo"]

read_png()
^
% Syntax error.
At: /home/dometz/test_cases/idl/foo.pro, Line 8
0
IDL> exit


function validate_syntax, ROUTINE
COMPILE_OPT HIDDEN
CATCH, ERROR
IF (ERROR NE 0) THEN RETURN, 0
RESOLVE_ROUTINE, ROUTINE, /EITHER, /COMPILE_FULL_FILE
RETURN, 1
END

pro FOO
read_png()
END


any ideas?

dometz



JD Smith wrote:
> On Wed, 11 Oct 2006 15:11:05 -0700, Dometz wrote:
>
>> I guess I wasnt clear enough... I mean something that I can run in a
>> bash script to test if a .pro file has valid syntax.
>>
>> something like:
>> echo '.compile foo.pro' | idl
>> and then checking if there are any syntax error messages and if there
>> are act accordingly.
>>
>> But is there a better way than using .compile for this?
>
> I guess I didn't do all your homework for you ;). You could use this
> idea to write a function called check_syntax, ala:
>
> function check_syntax,routine
> catch,err
> if err ne 0 then return,err
> resolve_routine,routine,/EITHER,/COMPILE_FULL_FILE
> return,0
> end
>
> Then a batch file which uses this function, like do_check.pro:
>
> ;================
> status=check_syntax((command_line_args())[0])
> if status ne 0 then print,!ERROR_STATE.MSG
> exit,STATUS=status
> ;================
>
> then call, from your shell script:
>
> idl -arg routine do_check.pro
>
> and check the exit status. You might need to monkey IDL_PATH to ensure
> it attempts to compile the correct version of the routine, like:
>
> idl -IDL_PATH "$(pwd):+/other/libs:<IDL_DEFAULT>" -arg routine do_check.pro
>
> JD
Re: idl syntax validation [message #50718 is a reply to message #50671] Wed, 11 October 2006 18:29 Go to previous message
JD Smith is currently offline  JD Smith
Messages: 850
Registered: December 1999
Senior Member
On Wed, 11 Oct 2006 15:11:05 -0700, Dometz wrote:

> I guess I wasnt clear enough... I mean something that I can run in a
> bash script to test if a .pro file has valid syntax.
>
> something like:
> echo '.compile foo.pro' | idl
> and then checking if there are any syntax error messages and if there
> are act accordingly.
>
> But is there a better way than using .compile for this?

I guess I didn't do all your homework for you ;). You could use this
idea to write a function called check_syntax, ala:

function check_syntax,routine
catch,err
if err ne 0 then return,err
resolve_routine,routine,/EITHER,/COMPILE_FULL_FILE
return,0
end

Then a batch file which uses this function, like do_check.pro:

;================
status=check_syntax((command_line_args())[0])
if status ne 0 then print,!ERROR_STATE.MSG
exit,STATUS=status
;================

then call, from your shell script:

idl -arg routine do_check.pro

and check the exit status. You might need to monkey IDL_PATH to ensure
it attempts to compile the correct version of the routine, like:

idl -IDL_PATH "$(pwd):+/other/libs:<IDL_DEFAULT>" -arg routine do_check.pro

JD
Re: idl syntax validation [message #50734 is a reply to message #50718] Wed, 11 October 2006 15:11 Go to previous message
Dominic Metzger is currently offline  Dominic Metzger
Messages: 30
Registered: August 2006
Member
I guess I wasnt clear enough... I mean something that I can run in a
bash script to test if a .pro file has valid syntax.

something like:
echo '.compile foo.pro' | idl
and then checking if there are any syntax error messages and if there
are act accordingly.

But is there a better way than using .compile for this?

dometz


JD Smith wrote:
> On Wed, 11 Oct 2006 13:41:12 -0700, Dometz wrote:
>
>> Hi,
>>
>> Is there way to validate idl syntax? So, something like the .compile
>> command on the command line but which only checks if the syntax is
>> valid and then exits and reports the errors.
>
> catch,err
> if err ne 0 then begin
> print,'caught compile error for ',routine
> catch,/cancel
> endif else resolve_routine,routine,/EITHER
>
> JD
Re: idl syntax validation [message #50737 is a reply to message #50734] Wed, 11 October 2006 14:21 Go to previous message
JD Smith is currently offline  JD Smith
Messages: 850
Registered: December 1999
Senior Member
On Wed, 11 Oct 2006 13:41:12 -0700, Dometz wrote:

> Hi,
>
> Is there way to validate idl syntax? So, something like the .compile
> command on the command line but which only checks if the syntax is
> valid and then exits and reports the errors.

catch,err
if err ne 0 then begin
print,'caught compile error for ',routine
catch,/cancel
endif else resolve_routine,routine,/EITHER

JD
Re: idl syntax validation [message #50739 is a reply to message #50737] Wed, 11 October 2006 13:45 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Dometz writes:

> Is there way to validate idl syntax? So, something like the .compile
> command on the command line but which only checks if the syntax is
> valid and then exits and reports the errors.

This still that spy thing you are working on? :-)

Cheers,

David

P.S. I think you are thinking about some other language.
IDL is pretty, uh, free-form.

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Opening a .isv file
Next Topic: Basic format code question

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:48:16 PDT 2025

Total time taken to generate the page: 0.00328 seconds