allow unterminated strings

This commit is contained in:
Denis Molony 2021-01-16 08:10:19 +10:00
parent 112fbc086b
commit dacfb130cb
3 changed files with 73 additions and 13 deletions

View File

@ -241,7 +241,20 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons
if (Utility.isHighBitSet (b))
text.append (String.format (" %s ", ApplesoftConstants.tokens[b & 0x7F]));
else
text.append ((char) b);
switch (b)
{
case Utility.ASCII_CR:
text.append ("\n");
break;
case Utility.ASCII_BACKSPACE:
if (text.length () > 0)
text.deleteCharAt (text.length () - 1);
break;
default:
text.append ((char) b);
}
assert ptr == nextLine - loadAddress;
// ptr = nextLine - loadAddress;
@ -466,7 +479,7 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons
}
if (basicPreferences.showCalls && !callLines.isEmpty ())
showSymbolsLeft (fullText, callLines, "CALL");
showSymbolsLeftRight (fullText, callLines, " CALL");
}
// ---------------------------------------------------------------------------------//
@ -544,6 +557,38 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons
}
}
// ---------------------------------------------------------------------------------//
private void showSymbolsLeftRight (StringBuilder fullText,
Map<String, List<Integer>> map, String heading)
// ---------------------------------------------------------------------------------//
{
heading (fullText, formatLeft, heading);
for (String symbol : map.keySet ()) // left-justify strings
{
if (isNumeric (symbol))
appendLineNumbers (fullText, String.format (formatRight, symbol),
map.get (symbol));
else if (symbol.length () <= 7)
appendLineNumbers (fullText, String.format (formatLeft, symbol),
map.get (symbol));
else
appendLineNumbers (fullText, symbol + " ", map.get (symbol));
}
}
// ---------------------------------------------------------------------------------//
private boolean isNumeric (String value)
// ---------------------------------------------------------------------------------//
{
byte[] bytes = value.getBytes ();
int start = value.charAt (0) == Utility.ASCII_MINUS ? 1 : 0;
for (int i = start; i < bytes.length; i++)
if (!Utility.isPossibleNumber (bytes[i]))
return false;
return true;
}
// ---------------------------------------------------------------------------------//
private void showSymbolsRight (StringBuilder fullText, Map<Integer, List<Integer>> map,
String heading)

View File

@ -70,14 +70,14 @@ public class SourceLine implements ApplesoftConstants
break;
case TOKEN_REM:
if (ptr != startPtr + 1) // REM appears mid-line (should follow a colon)
{
System.out.println ("mid-line REM token");
if (ptr == startPtr + 1)
inRemark = true;
else
{ // REM appears mid-line (should follow a colon)
System.out.printf ("%5d %s%n", lineNumber, "mid-line REM token");
sublines.add (new SubLine (this, startPtr, (ptr - startPtr) - 1));
startPtr = ptr - 1;
}
else
inRemark = true;
break;

View File

@ -108,8 +108,7 @@ public class SubLine implements ApplesoftConstants
if (b == Utility.ASCII_QUOTE) // ignore strings
{
inQuote = false;
String s = new String (buffer, stringPtr - 1, ptr - stringPtr + 1);
stringsText.add (s);
addString (stringPtr, ptr);
}
continue;
}
@ -151,9 +150,20 @@ public class SubLine implements ApplesoftConstants
}
}
if (inQuote) // unterminated string
addString (stringPtr, ptr);
checkVar (var, (byte) 0);
}
// ---------------------------------------------------------------------------------//
private void addString (int stringPtr, int ptr)
// ---------------------------------------------------------------------------------//
{
String s = new String (buffer, stringPtr - 1, ptr - stringPtr + 1);
stringsText.add (s);
}
// ---------------------------------------------------------------------------------//
private void checkFunction (String var, byte terminator)
// ---------------------------------------------------------------------------------//
@ -342,7 +352,10 @@ public class SubLine implements ApplesoftConstants
continue;
b = (byte) chunk.charAt (0);
if (Utility.isDigit (b) || b == Utility.ASCII_MINUS || b == Utility.ASCII_DOT)
addNumber (chunk);
{
if (!addNumber (chunk))
stringsText.add (chunk);
}
else if (Utility.isLetter (b) || b == Utility.ASCII_QUOTE)
stringsText.add (chunk);
else
@ -354,7 +367,7 @@ public class SubLine implements ApplesoftConstants
}
// ---------------------------------------------------------------------------------//
private void addNumber (String var)
private boolean addNumber (String var)
// ---------------------------------------------------------------------------------//
{
try
@ -375,8 +388,10 @@ public class SubLine implements ApplesoftConstants
}
catch (NumberFormatException nfe)
{
System.out.printf ("NFE: %s%n", var);
// System.out.printf ("NFE1: %s%n", var);
return false;
}
return true;
}
// ---------------------------------------------------------------------------------//
@ -438,7 +453,7 @@ public class SubLine implements ApplesoftConstants
}
catch (NumberFormatException e)
{
System.out.printf ("NFE: %s%n", s);
System.out.printf ("NFE2: %s%n", s);
}
return lineNumbers;