Detecting if a script line has a line continuation character
Posted: Wed Jul 13, 2016 9:45 am
I'm wondering if anyone has any clever ideas on how to check for a given line of script whether the parser will treat the following line as a continuation.
Currently the script editor uses
which will work in a large number of cases. However, the following bugs are examples where it doesn't:
http://quality.livecode.com/show_bug.cgi?id=8228 (because the \ is followed by a comment)
http://quality.livecode.com/show_bug.cgi?id=8328 (because the last word of is
Moreover it will not work in the following case
The latter two examples would be fixed using , but I'm wondering if there's any way that covers all cases.
The char method has issues with this:
This is the best I can come up with:
Obviously this is rather heavyweight, and would fail in the case that the actual script occurred in comments:
That example seems to be immune to any further tweaks to finding the offset of the tokens in the original line. Any ideas?
Currently the script editor uses
Code: Select all
function lineIsContinued pLine
return word -1 of pLine is "\"
end lineIsContinued
http://quality.livecode.com/show_bug.cgi?id=8228 (because the \ is followed by a comment)
http://quality.livecode.com/show_bug.cgi?id=8328 (because the last word of
Code: Select all
(" something ") \
Code: Select all
") \
Code: Select all
put "a" &\
"b" into tVar
Code: Select all
char -1 of word -1 of pLine
The char method has issues with this:
Code: Select all
put "a" into tVar --don't continue this line! \
put "b" into tVar2
This is the best I can come up with:
Code: Select all
function lineIsContinued pLine
local tTokens, tFirstChar
put token 1 to -1 of pLine into tTokens
put offset(tTokens, pLine) into tFirstChar
put "get a" into char tFirstChar to tFirstChar + length(tTokens) of pLine
put return & "& b" after pLine
compileCheck pLine
return the result
end lineIsContinued
on compileCheck pScript
local tCompileTest, tCompileResult
--checks to see if the message compiles
lock messages
create script only stack "compilationTest"
put "on compileTest" & cr & pScript & cr & "end compileTest" into tCompileTest
set the script of stack "compilationTest" to tCompileTest
put the result into tCompileResult
delete stack "compilationTest"
unlock messages
return tCompileResult is not empty
end compileCheck
Code: Select all
/* put "a" into */ put "a" into /* put "a" into */ /
tVar