Added multi-line parsing
This commit is contained in:
parent
087d8d0754
commit
ac6a192fb0
@ -88,20 +88,35 @@ namespace Assignment_1
|
||||
long initSourceLength = source.Length;
|
||||
if ((byte)source.ReadByte() == '{')
|
||||
{
|
||||
long lastLinePos = 0;
|
||||
long initPos = 0;
|
||||
bool cont = false;
|
||||
while (true)
|
||||
{
|
||||
if (dynamicInput)
|
||||
{
|
||||
Console.WriteLine("Enter a command: ");
|
||||
lastLinePos = source.Position;
|
||||
if (!cont)
|
||||
{
|
||||
Console.WriteLine("Enter a command: ");
|
||||
}
|
||||
string s = Console.ReadLine();
|
||||
long pos = source.Position;
|
||||
source.Write(Encoding.UTF8.GetBytes(s));
|
||||
source.Position = pos;
|
||||
|
||||
}
|
||||
// parse the statement or list of statements;
|
||||
// This is done by reading the next word
|
||||
if (!cont)
|
||||
{
|
||||
initPos = source.Position;
|
||||
}
|
||||
else
|
||||
{
|
||||
source.Position = initPos;
|
||||
}
|
||||
SkipWhitespace(source);
|
||||
long initPos = source.Position;
|
||||
long position = FindNextWord(source, out string word);
|
||||
try
|
||||
{
|
||||
@ -165,6 +180,7 @@ namespace Assignment_1
|
||||
if (IsNextEoS(source))
|
||||
{
|
||||
// Increment the source pos past the semi-colon
|
||||
cont = false;
|
||||
source.Position++;
|
||||
if (dynamicInput)
|
||||
{
|
||||
@ -173,6 +189,13 @@ namespace Assignment_1
|
||||
}
|
||||
result();
|
||||
}
|
||||
else if(source.Position != lastLinePos)
|
||||
{
|
||||
// In the case that we expect some more data, we must keep tabs of our current line, and keep accumulating data until we're finished
|
||||
cont = true;
|
||||
source.WriteByte((byte)' ');
|
||||
Console.Write(">");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ParserException("expected a semi-colon", 0, source.Position);
|
||||
|
Loading…
x
Reference in New Issue
Block a user