preparing to change alignment

This commit is contained in:
Denis Molony 2021-02-26 08:16:14 +10:00
parent a20f026cf2
commit d71075a16c
2 changed files with 63 additions and 22 deletions

View File

@ -304,7 +304,7 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons
}
// Are we joining REM lines with the previous subline?
if (!basicPreferences.splitRem && subline.isJoinableRem ())
if (joinableRem (subline))
{
// Join this REM statement to the previous line, so no indenting
fullText.deleteCharAt (fullText.length () - 1); // remove newline
@ -781,8 +781,12 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons
if (subline.equalsPosition == 0) // if the line has no equals sign
return 0; // reset it
if (currentAlignPosition == 0)
currentAlignPosition = findHighest (subline); // examine following sublines
if (currentAlignPosition == 0) // examine following sublines
{
Alignment alignment = new Alignment (subline);
findHighest (subline, alignment);
currentAlignPosition = alignment.equalsPosition;
}
return currentAlignPosition;
}
@ -790,11 +794,11 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons
// The IF processing is so that any assignment that is being aligned doesn't continue
// to the next full line (because the indentation has changed).
// ---------------------------------------------------------------------------------//
private int findHighest (SubLine startSubline)
private void findHighest (SubLine startSubline, Alignment alignment)
// ---------------------------------------------------------------------------------//
{
boolean started = false;
int highestAssign = startSubline.equalsPosition;
// int highestAssign = startSubline.equalsPosition;
outerLoop: for (int i = sourceLines.indexOf (startSubline.parent); i < sourceLines
.size (); i++)
@ -809,8 +813,10 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons
if (subline.equalsPosition == 0 && !joinableRem (subline))
break outerLoop;
if (subline.equalsPosition > highestAssign)
highestAssign = subline.equalsPosition;
// if (subline.equalsPosition > highestAssign)
// highestAssign = subline.equalsPosition;
if (subline.equalsPosition > 0)
alignment.check (subline);
}
else if (subline == startSubline)
started = true;
@ -822,7 +828,10 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons
break; // don't continue with following SourceLine
}
return highestAssign;
System.out.printf (" %d %d%n",
alignment.equalsPosition, alignment.targetLength);
// return highestAssign;
// return alignment;
}
// ---------------------------------------------------------------------------------//
@ -1134,4 +1143,29 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons
lines.add (lineNumber);
}
}
// ---------------------------------------------------------------------------------//
private class Alignment
// ---------------------------------------------------------------------------------//
{
int equalsPosition;
int targetLength;
Alignment (SubLine subline)
{
check (subline);
}
void check (SubLine subline)
{
System.out.printf ("%-20s %d %d%n", subline, subline.equalsPosition,
subline.endPosition - subline.equalsPosition);
if (equalsPosition < subline.equalsPosition)
equalsPosition = subline.equalsPosition;
int temp = subline.endPosition - subline.equalsPosition;
if (targetLength < temp)
targetLength = temp;
}
}
}

View File

@ -38,6 +38,7 @@ public class SubLine implements ApplesoftConstants
String forVariable = "";
int equalsPosition; // used for aligning the equals sign
int endPosition; // not sure yet
String functionArgument;
String functionName;
@ -81,7 +82,7 @@ public class SubLine implements ApplesoftConstants
}
else
{
ptr = startPtr;
// ptr = startPtr;
if (isDigit (firstByte)) // split IF xx THEN nnn
{
addXref (getLineNumber (buffer, startPtr), gotoLines);
@ -325,6 +326,7 @@ public class SubLine implements ApplesoftConstants
chunk = chunk.trim ();
if (chunk.isEmpty ())
continue;
b = (byte) chunk.charAt (0);
if (isPossibleNumber (b) || b == ASCII_MINUS)
{
@ -457,15 +459,20 @@ public class SubLine implements ApplesoftConstants
private void setEqualsPosition ()
// ---------------------------------------------------------------------------------//
{
int p = startPtr;
int max = startPtr + length;
// int p = startPtr;
// int max = startPtr + length;
while (++p < max)
if (buffer[p] == TOKEN_EQUALS)
{
equalsPosition = toString ().indexOf ('='); // use expanded line
break;
}
// while (++p < max)
// if (buffer[p] == TOKEN_EQUALS)
// {
String expandedLine = toString ();
equalsPosition = expandedLine.indexOf ('=');
endPosition = expandedLine.length ();
if (expandedLine.endsWith (":"))
endPosition--;
// break;
// }
assert equalsPosition > 0;
}
// ---------------------------------------------------------------------------------//
@ -500,14 +507,13 @@ public class SubLine implements ApplesoftConstants
boolean has (byte token)
// ---------------------------------------------------------------------------------//
{
int ptr = startPtr + 1;
int ptr = startPtr;
int max = startPtr + length;
while (ptr < max)
{
if (buffer[ptr++] == token)
while (++ptr < max)
if (buffer[ptr] == token)
return true;
}
return false;
}
@ -614,6 +620,7 @@ public class SubLine implements ApplesoftConstants
StringBuilder line = toStringBuilder (); // get line
// insert spaces before '=' until it lines up with the other assignment lines
if (!is (TOKEN_REM))
while (alignEqualsPos-- > equalsPosition)
line.insert (equalsPosition, ' ');