Syntax check on the fly
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Syntax check on the fly
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.
Re: Syntax check on the fly
Hi byrones15,
1. welcome to the forum!
2. Not sure, but you could TRY to do the user entered script, depends on how you execute it?
Something like this:
Best
Klaus
1. welcome to the forum!
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
...
Klaus
Re: Syntax check on the fly
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
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
Re: Syntax check on the fly
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.
Unfortunately I do not know of a way to "pre-compile" that text in a standalone as the script editor in the IDE does.
Re: Syntax check on the fly
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 . 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.
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 . 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.
-
- VIP Livecode Opensource Backer
- Posts: 9857
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Syntax check on the fly
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.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 . 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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Syntax check on the fly
Ok, if I understand correctly,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.
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
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
Re: Syntax check on the fly
Code: Select all
...
set the script of button "B4try" to textScript
if the result is not empty then
...
Re: Syntax check on the fly
Sweet! You guys rock! Thanks so much.