private List<GraphDataModificationAnnotation> FindReplaceGraphModificationStatements(ref IList<ParseError> errors)
{
var ret = new List<GraphDataModificationAnnotation>();
var currentToken = 0;
var farestError = 0;
while (currentToken < _tokens.Count)
{
var nextToken = currentToken;
if (ReadToken(_tokens, "insert", ref nextToken, ref farestError))
{
var pos = nextToken;
if (ReadToken(_tokens, "node", ref nextToken, ref farestError))
{
ret.Add(new InsertNodeAnnotation { Position = pos });
_tokens[pos].TokenType = TSqlTokenType.MultilineComment;
_tokens[pos].Text = "/*__GRAPHVIEW_INSERT_NODE*/";
}
else if (ReadToken(_tokens, "edge", ref nextToken, ref farestError))
{
var identifiers = new WMultiPartIdentifier();
if (!ReadToken(_tokens, "into", ref nextToken, ref farestError) ||
!ParseMultiPartIdentifier(_tokens, ref nextToken, ref identifiers, ref farestError))
{
var error = _tokens[farestError];
errors.Add(new ParseError(0, error.Offset, error.Line, error.Column, "Incorrect syntax near edge"));
return null;
}
ret.Add(new InsertEdgeAnnotation
{
Position = pos,
EdgeColumn = identifiers.Identifiers.Last(),
});
var lastColumnIndex = identifiers.Identifiers.Last().LastTokenIndex;
_tokens[pos].TokenType = TSqlTokenType.MultilineComment;
_tokens[pos].Text = "/*__GRAPHVIEW_INSERT_EDGE*/";
if (identifiers.Identifiers.Count == 1)
{
_tokens[lastColumnIndex].TokenType = TSqlTokenType.MultilineComment;
_tokens[lastColumnIndex].Text = "/*__GRAPHVIEW_INSERT_EDGE*/";
}
else
{
var firstColumnIndex =
identifiers.Identifiers[identifiers.Identifiers.Count - 2].LastTokenIndex + 1;
for (var i = firstColumnIndex; i <= lastColumnIndex; ++i)
{
_tokens[i].TokenType = TSqlTokenType.MultilineComment;
_tokens[i].Text = "/*__GRAPHVIEW_INSERT_EDGE*/";
}
}
}
currentToken = nextToken;
}
else if (ReadToken(_tokens, "delete", ref nextToken, ref farestError))
{
var pos = nextToken;
if (ReadToken(_tokens, "node", ref nextToken, ref farestError))
{
ret.Add(new DeleteNodeAnnotation { Position = pos });
_tokens[pos].TokenType = TSqlTokenType.MultilineComment;
_tokens[pos].Text = "/*__GRAPHVIEW_DELETE_NODE*/";
currentToken = nextToken;
}
else if (ReadToken(_tokens, "edge", ref nextToken, ref farestError))
{
WMatchPath path = null;
if (!ParseMatchPath(_tokens, ref nextToken, ref path, ref farestError))
{
var error = _tokens[farestError];
errors.Add(new ParseError(0, error.Offset, error.Line, error.Column, ""));
return null;
}
else if (path.PathEdgeList.Count != 1)
{
var error = _tokens[nextToken];
errors.Add(new ParseError(0, error.Offset, error.Line, error.Column,
"Incorrect Syntax Near edge: 1-Height Pattern should be used in Delete Edge statement"));
return null;
}
ret.Add(new DeleteEdgeAnnotation
{
Position = currentToken,
Path = path
});
_tokens[currentToken].TokenType = TSqlTokenType.Select;
_tokens[currentToken].Text = "SELECT";
_tokens[pos].TokenType = TSqlTokenType.Identifier;
_tokens[pos].Text = path.PathEdgeList[0].Item1.BaseIdentifier.Value;
_tokens[pos + 1].TokenType = TSqlTokenType.Comma;
_tokens[pos + 1].Text = ",";
_tokens[pos + 2].TokenType = TSqlTokenType.Identifier;
_tokens[pos + 2].Text = path.Tail.BaseIdentifier.Value;
for (var i = path.FirstTokenIndex + 1; i < path.LastTokenIndex; ++i)
{
_tokens[i].TokenType = TSqlTokenType.MultilineComment;
_tokens[i].Text = "/*__GRAPHVIEW_DELETE_EDGE*/";
}
currentToken = nextToken;
}
}
currentToken++;
}
return ret;
}