Commit 70ee2603 authored by Jesse McGrew's avatar Jesse McGrew

Zilf.Language.Parser: Better handling for some syntax errors, e.g. "!<>!" or "4 :".

parent 465739e1505a
......@@ -332,44 +332,52 @@ namespace Zilf.Language
System.Diagnostics.Debug.Assert(po.Object != null);
if (!SkipWhitespace(chars))
return po;
try
{
if (!SkipWhitespace(chars))
return po;
var c = chars.Current;
var c = chars.Current;
if (c != ':' && c != Bang.Colon)
{
chars.PushBack(c);
return po;
}
if (c != ':' && c != Bang.Colon)
{
chars.PushBack(c);
return po;
}
ParserOutput po2;
do
{
po2 = ParseOneNonAdecl(chars, out _);
// TODO: store comment somewhere? (set SourceLine if so)
} while (po2.IsIgnorable);
ParserOutput po2;
do
{
po2 = ParseOneNonAdecl(chars, out _);
// TODO: store comment somewhere? (set SourceLine if so)
} while (po2.IsIgnorable);
switch (po2.Type)
{
case ParserOutputType.EndOfInput:
throw new ExpectedButFound("object after ':'", "<EOF>");
switch (po2.Type)
{
case ParserOutputType.EndOfInput:
throw new ExpectedButFound("object after ':'", "<EOF>");
case ParserOutputType.Object:
var adecl = new ZilAdecl(po.Object, po2.Object);
return po.Type == ParserOutputType.Comment
? ParserOutput.FromComment(adecl)
: ParserOutput.FromObject(adecl);
case ParserOutputType.Object:
var adecl = new ZilAdecl(po.Object, po2.Object); // TODO: set source line
return po.Type == ParserOutputType.Comment
? ParserOutput.FromComment(adecl)
: ParserOutput.FromObject(adecl);
case ParserOutputType.SyntaxError:
return po2;
case ParserOutputType.SyntaxError:
return po2;
case ParserOutputType.Terminator:
chars.MoveNext();
throw new ExpectedButFound("object after ':'", $"'{chars.Current.Rebang()}'");
case ParserOutputType.Terminator:
chars.MoveNext();
throw new ExpectedButFound("object after ':'", $"'{chars.Current.Rebang()}'");
default:
throw new UnhandledCaseException("object after ':'");
default:
throw new UnhandledCaseException("object after ':'");
}
}
catch (ParserException ex)
{
sourceLine = new FileSourceLine(site.CurrentFilePath, line);
return ParserOutput.FromException(ex);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment