Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit ed92272

Browse files
committed
[[ Bug 21245 ]] SE indent errors with inline block comments
There are 2 related errors in the lineStripComments / __StripComment handlers in the revsecommoneditorbehavior.livecodescript code. The first error is that "/*" is assumed to run to the end of the current line. Since it is possible to have multiple inline block comments on a single line, a recursive call to __StripBlockComment is used to remove these comments. The second error is that the loop that goes through the current line does not exit when a true comment to the end of the line is encountered. The loop uses quotes to ensure that it isn't capturing comment characters in a string, but fails to exit. Added an additional return value (pass by reference variable) indicating comment status of the current chunk.
1 parent 4436800 commit ed92272

2 files changed

Lines changed: 30 additions & 9 deletions

File tree

Toolset/palettes/script editor/behaviors/revsecommoneditorbehavior.livecodescript

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ end __GetPreference
334334

335335
-- Text Formatting Code
336336
command textFormatInitialize
337-
-- permit use in environment witn no dependencies
337+
-- permit use in environment with no dependencies
338338
local tTabDepth
339339
put __GetPreference("editor,tabdepth", 3) into tTabDepth
340340

@@ -2614,35 +2614,55 @@ end dragEnd
26142614

26152615
# Description
26162616
## Returns a line stripped of comments at the end of the line
2617+
## and inline comments ( /* ... */ )
26172618
private function lineStripComments pLine
2618-
local tLine
2619+
local tLine, tInComment
26192620
split pLine by quote
26202621

2622+
put false into tInComment
26212623
repeat with tIndex = 1 to the number of elements of pLine step 2
2622-
local tDecommented
2623-
put __StripComment(pLine[tIndex]) into tDecommented
2624-
put tDecommented after tLine
2625-
if pLine[tIndex] is tDecommented and \
2626-
tIndex is not the number of elements of pLine then
2624+
put __StripComment(pLine[tIndex], tInComment) after tLine
2625+
if tInComment then exit repeat
2626+
if tIndex is not the number of elements of pLine then
26272627
put quote & pLine[tIndex+1] & quote after tLine
26282628
end if
26292629
end repeat
26302630

26312631
return tLine
26322632
end lineStripComments
26332633

2634-
private function __StripComment pLine
2634+
private function __StripComment pLine, @xInComment
26352635
local tOffset
2636-
repeat for each word tComment in "# -- // /*"
2636+
repeat for each word tComment in "# -- //"
26372637
put offset(tComment, pLine) into tOffset
26382638
if tOffset is not 0 then
26392639
delete char tOffset to -1 of pLine
2640+
put true into xInComment
26402641
end if
26412642
end repeat
2643+
2644+
put __StripBlockComment(pLine, xInComment) into pLine
26422645

26432646
return pLine
26442647
end __StripComment
26452648

2649+
private function __StripBlockComment pline, @xInComment
2650+
local tOffset, tOffsetEnd
2651+
put offset("/*", pLine) into tOffset
2652+
if tOffset is not 0 then
2653+
put offset("*/", pLine, tOffset) into tOffsetEnd
2654+
if tOffsetEnd is not 0 then
2655+
delete char tOffset to tOffset + tOffsetEnd of pLine
2656+
put __StripBlockComment(pLine, xInComment) into pLine
2657+
else
2658+
delete char tOffset to -1 of pLine
2659+
put true into xInComment
2660+
end if
2661+
end if
2662+
2663+
return pLine
2664+
end __StripBlockComment
2665+
26462666
################################################################################
26472667

26482668
command actionCopy

notes/bugfix-21245.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# SE indent errors with inline block comments and line continuation

0 commit comments

Comments
 (0)