зеркало из https://github.com/microsoft/prepose.git
Add PreposeParserException class, in order to get the last good token position on failure
Replace Contract assertion and ArgumentException by parser exception, to get the text location
This commit is contained in:
Родитель
1e13c01b6f
Коммит
057d974a4d
|
@ -0,0 +1,48 @@
|
|||
using Antlr4.Runtime;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PreposeGestures
|
||||
{
|
||||
public class PreposeParserException : Exception
|
||||
{
|
||||
private readonly int startLineNumber;
|
||||
private readonly int startColumnNumber;
|
||||
|
||||
private readonly int endLineNumber;
|
||||
private readonly int endColumnNumber;
|
||||
|
||||
public int StartLineNumber
|
||||
{
|
||||
get { return this.startLineNumber; }
|
||||
}
|
||||
|
||||
public int StartColumnNumber
|
||||
{
|
||||
get { return this.startColumnNumber; }
|
||||
}
|
||||
|
||||
public int EndLineNumber
|
||||
{
|
||||
get { return this.endLineNumber; }
|
||||
}
|
||||
|
||||
public int EndColumnNumber
|
||||
{
|
||||
get { return this.endColumnNumber; }
|
||||
}
|
||||
|
||||
public PreposeParserException(string message, ParserRuleContext currentContext)
|
||||
: base(message)
|
||||
{
|
||||
this.startLineNumber = currentContext.start.Line;
|
||||
this.startColumnNumber = currentContext.start.Column;
|
||||
|
||||
this.endLineNumber = currentContext.stop.Line;
|
||||
this.endColumnNumber = currentContext.stop.Column;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -155,7 +155,10 @@ namespace PreposeGestures.Parser
|
|||
{
|
||||
Contract.Assert(s != null);
|
||||
var w = this.Visit(s);
|
||||
Contract.Assert(w != null);
|
||||
if (w == null)
|
||||
{
|
||||
throw new PreposeParserException("Failed to parse statement", s);
|
||||
}
|
||||
var statement = w.GetValue();
|
||||
if (statement != null)
|
||||
{
|
||||
|
@ -171,14 +174,14 @@ namespace PreposeGestures.Parser
|
|||
continue;
|
||||
}
|
||||
|
||||
throw new ArgumentException("Wrong return type");
|
||||
throw new PreposeParserException("Invalid return type", s);
|
||||
}
|
||||
}
|
||||
|
||||
var pose = new Pose(context.ID().GetText(), bt, br);
|
||||
if (this.Poses.ContainsKey(pose.Name))
|
||||
{
|
||||
throw new ArgumentException("Pose " + pose.Name + " has been previosly seen.");
|
||||
throw new PreposeParserException("Pose " + pose.Name + " has been previously seen.", context);
|
||||
}
|
||||
|
||||
this.Poses.Add(pose.Name, pose);
|
||||
|
|
|
@ -117,6 +117,7 @@
|
|||
<Compile Include="Parser\PreposeGesturesLexer.cs" />
|
||||
<Compile Include="Parser\PreposeGesturesListener.cs" />
|
||||
<Compile Include="Parser\PreposeGesturesParser.cs" />
|
||||
<Compile Include="Parser\PreposeParserException.cs" />
|
||||
<Compile Include="Parser\PreposeGesturesVisitor.cs" />
|
||||
<Compile Include="Gestures\Pose.cs" />
|
||||
<Compile Include="Parser\Visitor.cs" />
|
||||
|
|
Загрузка…
Ссылка в новой задаче