Skip to content

Commit

Permalink
Make indent level only increase once per line; closes #176
Browse files Browse the repository at this point in the history
  • Loading branch information
FellippeHeitor committed Sep 30, 2021
1 parent 1a3f3f5 commit 1e67962
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion source/qb64.bas
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,8 @@ DIM SHARED everycasenewcase AS LONG


DIM SHARED controllevel AS INTEGER '0=not in a control block
DIM SHARED softcontrollevel AS INTEGER
DIM SHARED controllevelLastLine AS INTEGER
DIM SHARED controltype(1000) AS INTEGER
'1=IF (awaiting END IF)
'2=FOR (awaiting NEXT)
Expand Down Expand Up @@ -1445,6 +1447,7 @@ everycasenewcase = 0
qberrorhappened = 0: qberrorcode = 0: qberrorline = 0
FOR i = 1 TO 27: defineaz(i) = "SINGLE": defineextaz(i) = "!": NEXT
controllevel = 0
softcontrollevel = 0: controllevelLastLine = 0
findidsecondarg$ = "": findanotherid = 0: findidinternal = 0: currentid = 0
linenumber = 0
wholeline$ = ""
Expand Down Expand Up @@ -2960,7 +2963,8 @@ DO

layoutoriginal$ = a3$
layoutcomment$ = "" 'clear any previous layout comment
lhscontrollevel = controllevel
IF softcontrollevel < 0 THEN softcontrollevel = 0
lhscontrollevel = controllevel - softcontrollevel

linefragment = "[INFORMATION UNAVAILABLE]"
IF LEN(a3$) = 0 THEN GOTO finishednonexec
Expand All @@ -2984,6 +2988,7 @@ DO
ExecCounter = ExecCounter - 1
layout$ = SCase$("$End If")
controltype(controllevel) = 0
softcontrollevel = softcontrollevel - 1
controllevel = controllevel - 1
GOTO finishednonexec
END IF
Expand Down Expand Up @@ -3018,6 +3023,10 @@ DO
END IF

controllevel = controllevel + 1
IF linenumber = controllevelLastLine THEN
softcontrollevel = softcontrollevel + 1
END IF
controllevelLastLine = linenumber
controltype(controllevel) = 6
IF temp = 0 THEN layout$ = SCase$("$If ") + temp$ + SCase$(" Then"): GOTO finishednonexec 'no = sign in the $IF statement, so we're going to assume the user is doing something like $IF flag
l$ = RTRIM$(LEFT$(temp$, temp - 1)): r$ = LTRIM$(MID$(temp$, temp + LEN(tempOp$)))
Expand Down Expand Up @@ -4777,6 +4786,10 @@ DO

IF ideindentsubs THEN
controllevel = controllevel + 1
IF linenumber = controllevelLastLine THEN
softcontrollevel = softcontrollevel + 1
END IF
controllevelLastLine = linenumber
controltype(controllevel) = 32
controlref(controllevel) = linenumber
END IF
Expand Down Expand Up @@ -5294,6 +5307,7 @@ DO

IF controltype(controllevel) = 32 AND ideindentsubs THEN
controltype(controllevel) = 0
softcontrollevel = softcontrollevel - 1
controllevel = controllevel - 1
END IF

Expand Down Expand Up @@ -5584,6 +5598,7 @@ DO
END IF
PRINT #12, "}"
PRINT #12, "fornext_exit_" + str2$(controlid(controllevel)) + ":;"
softcontrollevel = softcontrollevel - 1
controllevel = controllevel - 1
IF n = 1 THEN EXIT FOR
v$ = ""
Expand Down Expand Up @@ -5614,6 +5629,10 @@ DO
END IF

controllevel = controllevel + 1
IF linenumber = controllevelLastLine THEN
softcontrollevel = softcontrollevel + 1
END IF
controllevelLastLine = linenumber
controlref(controllevel) = linenumber
controltype(controllevel) = 5
controlid(controllevel) = uniquenumber
Expand Down Expand Up @@ -5649,6 +5668,7 @@ DO
PRINT #12, "ww_continue_" + str2$(controlid(controllevel)) + ":;"
PRINT #12, "}"
PRINT #12, "ww_exit_" + str2$(controlid(controllevel)) + ":;"
softcontrollevel = softcontrollevel - 1
controllevel = controllevel - 1
l$ = SCase$("Wend")
layoutdone = 1: IF LEN(layout$) THEN layout$ = layout$ + sp + l$ ELSE layout$ = l$
Expand All @@ -5670,6 +5690,10 @@ DO
END IF

controllevel = controllevel + 1
IF linenumber = controllevelLastLine THEN
softcontrollevel = softcontrollevel + 1
END IF
controllevelLastLine = linenumber
controlref(controllevel) = linenumber
l$ = SCase$("Do")
IF n >= 2 THEN
Expand Down Expand Up @@ -5750,6 +5774,7 @@ DO
END IF
END IF
PRINT #12, "dl_exit_" + str2$(controlid(controllevel)) + ":;"
softcontrollevel = softcontrollevel - 1
controllevel = controllevel - 1
layoutdone = 1: IF LEN(layout$) THEN layout$ = layout$ + sp + l$ ELSE layout$ = l$
IF n = 1 THEN GOTO finishednonexec '***no error causing code, event checking done by DO***
Expand Down Expand Up @@ -5777,6 +5802,10 @@ DO
END IF

controllevel = controllevel + 1
IF linenumber = controllevelLastLine THEN
softcontrollevel = softcontrollevel + 1
END IF
controllevelLastLine = linenumber
controlref(controllevel) = linenumber
controltype(controllevel) = 2
controlid(controllevel) = uniquenumber
Expand Down Expand Up @@ -6040,6 +6069,10 @@ DO
IF iftype = 0 THEN a$ = "Expected IF expression THEN/GOTO": GOTO errmes

controllevel = controllevel + 1
IF linenumber = controllevelLastLine THEN
softcontrollevel = softcontrollevel + 1
END IF
controllevelLastLine = linenumber
controlref(controllevel) = linenumber
controltype(controllevel) = 1
controlvalue(controllevel) = 0 'number of extra closing } required at END IF
Expand Down Expand Up @@ -6088,6 +6121,7 @@ DO
FOR i = 1 TO controlvalue(controllevel)
PRINT #12, "}"
NEXT
softcontrollevel = softcontrollevel - 1
controllevel = controllevel - 1
GOTO finishednonexec '***no error causing code, event checking done by IF***
END IF
Expand All @@ -6114,6 +6148,7 @@ DO
FOR i = 1 TO controlvalue(controllevel)
PRINT #12, "}"
NEXT
softcontrollevel = softcontrollevel - 1
controllevel = controllevel - 1
GOTO finishednonexec '***no error causing code, event checking done by IF***
END IF
Expand Down Expand Up @@ -6162,6 +6197,10 @@ DO
u = uniquenumber

controllevel = controllevel + 1
IF linenumber = controllevelLastLine THEN
softcontrollevel = softcontrollevel + 1
END IF
controllevelLastLine = linenumber
controlvalue(controllevel) = 0 'id

t$ = ""
Expand Down Expand Up @@ -6240,11 +6279,13 @@ DO
IF controltype(controllevel) = 18 THEN
everycasenewcase = everycasenewcase + 1
PRINT #12, "sc_ec_" + str2$(everycasenewcase) + "_end:;"
softcontrollevel = softcontrollevel - 1
controllevel = controllevel - 1
IF EveryCaseSet(SelectCaseCounter) = 0 THEN PRINT #12, "goto sc_" + str2$(controlid(controllevel)) + "_end;"
PRINT #12, "}"
END IF
IF controltype(controllevel) = 19 THEN
softcontrollevel = softcontrollevel - 1
controllevel = controllevel - 1
IF EveryCaseSet(SelectCaseCounter) THEN PRINT #12, "} /* End of SELECT EVERYCASE ELSE */"
END IF
Expand All @@ -6264,6 +6305,7 @@ DO
END IF
END IF

softcontrollevel = softcontrollevel - 1
controllevel = controllevel - 1
SelectCaseCounter = SelectCaseCounter - 1
l$ = SCase$("End" + sp + "Select")
Expand All @@ -6289,6 +6331,7 @@ DO
IF controltype(controllevel) = 19 THEN a$ = "Expected END SELECT": GOTO errmes
IF controltype(controllevel) = 18 THEN
lhscontrollevel = lhscontrollevel - 1
softcontrollevel = softcontrollevel - 1
controllevel = controllevel - 1
everycasenewcase = everycasenewcase + 1
PRINT #12, "sc_ec_" + str2$(everycasenewcase) + "_end:;"
Expand Down Expand Up @@ -6362,6 +6405,10 @@ DO
IF getelement$(a$, 2) = "C-EL" THEN
IF EveryCaseSet(SelectCaseCounter) THEN PRINT #12, "if (sc_" + str2$(controlid(controllevel)) + "_var==0) {"
controllevel = controllevel + 1: controltype(controllevel) = 19
IF linenumber = controllevelLastLine THEN
softcontrollevel = softcontrollevel + 1
END IF
controllevelLastLine = linenumber
controlref(controllevel) = controlref(controllevel - 1)
l$ = l$ + sp + SCase$("Else")
layoutdone = 1: IF LEN(layout$) THEN layout$ = layout$ + sp + l$ ELSE layout$ = l$
Expand Down Expand Up @@ -6540,6 +6587,10 @@ DO

layoutdone = 1: IF LEN(layout$) THEN layout$ = layout$ + sp + l$ ELSE layout$ = l$
controllevel = controllevel + 1
IF linenumber = controllevelLastLine THEN
softcontrollevel = softcontrollevel + 1
END IF
controllevelLastLine = linenumber
controlref(controllevel) = controlref(controllevel - 1)
controltype(controllevel) = 18
GOTO finishedline
Expand Down

0 comments on commit 1e67962

Please sign in to comment.