Syntax check on the fly

Deploying to Windows? Utilizing VB Script execution? This is the place to ask Windows-specific questions.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
byrones15
Posts: 6
Joined: Wed Apr 06, 2016 1:56 pm

Syntax check on the fly

Post by byrones15 » Wed Apr 06, 2016 2:03 pm

My app allows the user to enter LiveCode code in order to control some of the screen elements and objects that are exposed. I have searched but can't find a way to validate the code before executing it. Is there a hook into the syntax checker that would allow me to determine and let the user know if they have entered invalid code? I often write the code snippets for them, but the users are typically engineers with programming expertise and they like to try writing code themselves occasionally.

Klaus
Posts: 13793
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Syntax check on the fly

Post by Klaus » Wed Apr 06, 2016 2:21 pm

Hi byrones15,

1. welcome to the forum! :D

2. Not sure, but you could TRY to do the user entered script, depends on how you execute it?
Something like this:

Code: Select all

...
put fld "user script" into tScript
try
  do tScript

## If an error occurs, this part of the handerl wil be executed!
## So you could catch any errors caused by invalid syntax.
catch errornum
  answer "No valid synstax!"
end try
...
Best

Klaus

byrones15
Posts: 6
Joined: Wed Apr 06, 2016 1:56 pm

Re: Syntax check on the fly

Post by byrones15 » Wed Apr 06, 2016 3:26 pm

Klaus,

Thanks for the idea! Unfortunately, the DO command does not execute or evaluate all of the code. For example, if I have a syntax error in the else section of an if/then/else statement and the if conditional evaluates as true the else section's code is not executed and a syntax error is not generated.

This partially solves the problem but I will keep looking. Also, I don't want to go down the path of stripping out all of the if, else, and end if statements from the script (that could get ugly). I guess I could run the script multiple times - once with the statements and once without. But I would also have to do the same with loops, etc. and it seems like a bottomless pit.

Byron

Klaus
Posts: 13793
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Syntax check on the fly

Post by Klaus » Wed Apr 06, 2016 4:57 pm

How do you execute the user entered script(s) then?

Unfortunately I do not know of a way to "pre-compile" that text in a standalone as the script editor in the IDE does.

byrones15
Posts: 6
Joined: Wed Apr 06, 2016 1:56 pm

Re: Syntax check on the fly

Post by byrones15 » Wed Apr 06, 2016 9:54 pm

I execute the script with the "do" command. I have been doing this for a couple years. It provides great flexibility for users to customize the system without me having to write custom apps. I just need to document the internal objects and screen controls.

The issue is that the engineer writes the script and does SOME testing and then end-users run the app and scripts on a daily basis. If there is a syntax error that happens to the end-user that wasn't caught by the engineer input data could be lost :oops: . And the engineer then has to fix the problem and re-publish the script. It is trial and error process because they don't have access to the LiveCode IDE. It would be a lot easier to catch any syntax errors up front while they are writing the script. It isn't a showstopper, but it would improve the system.

What I would really like is to be able to submit a chunk of code to the syntax engine and have it tell me if it is valid. That would be a great enhancement to the system.

Thank you Klaus for your feedback and help.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9801
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Syntax check on the fly

Post by FourthWorld » Wed Apr 06, 2016 10:18 pm

byrones15 wrote:The issue is that the engineer writes the script and does SOME testing and then end-users run the app and scripts on a daily basis. If there is a syntax error that happens to the end-user that wasn't caught by the engineer input data could be lost :oops: . And the engineer then has to fix the problem and re-publish the script. It is trial and error process because they don't have access to the LiveCode IDE.
Why not? If they're coding in LC having the Dictionary and a script editor dedicated to the task would seem welcome, no? Coordination with your app could be done via a plugin.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Syntax check on the fly

Post by Thierry » Thu Apr 07, 2016 3:22 am

byrones15 wrote: What I would really like is to be able to submit a chunk of code to the syntax engine and have it tell me if it is valid. That would be a great enhancement to the system.
Ok, if I understand correctly,
this should make you happy:

Code: Select all

on mouseUp
   local textScript
   --  your user script
   put fld "Fcode" into textScript
   -- make this button invisible or off screen
   set the script of button "B4try" to textScript
   if the result is not empty then
      -- syntax errors..
      answer "Error in your script!" & cr& the result
   else
      -- should be fine (compil)
      answer "Done!"
   end if
end mouseUp
HTH,

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

Klaus
Posts: 13793
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Syntax check on the fly

Post by Klaus » Thu Apr 07, 2016 3:15 pm

Code: Select all

...
set the script of button "B4try" to textScript
if the result is not empty then
...
Ah, clever idea! :D

byrones15
Posts: 6
Joined: Wed Apr 06, 2016 1:56 pm

Re: Syntax check on the fly

Post by byrones15 » Fri Apr 08, 2016 2:29 pm

Sweet! You guys rock! Thanks so much.

Post Reply

Return to “Windows”