GraphView.GraphViewParser.ParseMatchPathEdge C# (CSharp) Method

ParseMatchPathEdge() private static method

private static ParseMatchPathEdge ( IList tokens, int &nextToken, WEdgeColumnReferenceExpression &result, int &farestError ) : bool
tokens IList
nextToken int
result WEdgeColumnReferenceExpression
farestError int
return bool
        private static bool ParseMatchPathEdge(
            IList<TSqlParserToken> tokens,
            ref int nextToken,
            ref WEdgeColumnReferenceExpression result,
            ref int farestError)
        {
            var currentToken = nextToken;
            Identifier edgeIdentifier = null;
            if (!ParseQuotedIdentifier(tokens, ref currentToken, ref edgeIdentifier, ref farestError))
                return false;

            int line = tokens[currentToken].Line;
            nextToken = currentToken;
            string alias = null;
            int maxLen = 1;
            int minLen = 1;

            string errorKey = "";
            var edgeTokens = LexicalAnalyzer.Tokenize(edgeIdentifier.Value, ref errorKey);
            if (!string.IsNullOrEmpty(errorKey))
                throw new SyntaxErrorException(line, errorKey);
            int curEdgeToken = 0;
            int edgeFareastError = 0;
            string edgeName = null;
            string strValue = null;
            Dictionary<string, string> attributeValueDict = null;

            // Gets edge name
            if (!ReadToken(edgeTokens, AnnotationTokenType.NameToken, ref curEdgeToken, ref edgeName, ref edgeFareastError))
                throw new SyntaxErrorException(line, edgeTokens[edgeFareastError].value);
            edgeIdentifier.Value = edgeName;

            // Gets path info
            if (ReadToken(edgeTokens, "*", ref curEdgeToken, ref strValue, ref edgeFareastError))
            {
                string lengStr = "";

                // Gets path minimal length
                if (ReadToken(edgeTokens, AnnotationTokenType.Integer, ref curEdgeToken, ref lengStr,
                    ref edgeFareastError))
                {
                    if (!int.TryParse(lengStr, out minLen) || minLen<0)
                        throw new SyntaxErrorException(line, lengStr, "Min length should be an integer no less than zero");
                    for (int i = 0; i < 2; i++)
                    {
                        if (!ReadToken(edgeTokens, ".", ref curEdgeToken, ref strValue,
                            ref edgeFareastError))
                            throw new SyntaxErrorException(line, lengStr,
                                "Two dots should be followed by the minimal length integer");
                    }

                    // Gets path maximal length
                    if (!ReadToken(edgeTokens, AnnotationTokenType.Integer, ref curEdgeToken, ref lengStr,
                        ref edgeFareastError) || !int.TryParse(lengStr, out maxLen) || maxLen < minLen)
                        throw new SyntaxErrorException(line, lengStr,
                            "Max length should be an integer no less than the min length");
                }
                else
                {
                    minLen = 0;
                    maxLen = -1;
                }
                // Gets edge alias
                if (ReadToken(edgeTokens, "as", ref curEdgeToken, ref strValue, ref edgeFareastError))
                {
                    if (!ReadToken(edgeTokens, AnnotationTokenType.NameToken, ref curEdgeToken, ref alias, ref edgeFareastError))
                        throw new SyntaxErrorException(line, edgeTokens[edgeFareastError].value);
                }

                // Gets predicates on attributes
                NestedObject jsonNestedObject = null;
                int braceToken = curEdgeToken;
                if (ReadToken(edgeTokens, AnnotationTokenType.LeftBrace, ref curEdgeToken, ref strValue,
                    ref edgeFareastError))
                {
                    if (!ParseNestedObject(edgeTokens, ref braceToken, ref jsonNestedObject, ref edgeFareastError, true))
                        throw new SyntaxErrorException(line, "{", "Invalid json string");
                    else
                        attributeValueDict =
                            (jsonNestedObject as CollectionObject).Collection.ToDictionary(e => e.Key.ToLower(),
                                e =>
                                    (e.Value is StringObject)
                                        ? "'" + ((StringObject) e.Value).Value + "'"
                                        : (e.Value as NormalObject).Value);
                }
            }

            // Gets edge alias
            if (ReadToken(edgeTokens, "as", ref curEdgeToken, ref strValue, ref edgeFareastError))
            {
                if (!ReadToken(edgeTokens, AnnotationTokenType.NameToken, ref curEdgeToken, ref alias, ref edgeFareastError))
                    throw new SyntaxErrorException(line, edgeTokens[edgeFareastError].value);
            }

            result = new WEdgeColumnReferenceExpression
            {
                ColumnType = ColumnType.Regular,
                Alias = alias,
                LastTokenIndex = currentToken - 1,
                FirstTokenIndex = currentToken - 1,
                MaxLength = maxLen,
                MinLength = minLen,
                MultiPartIdentifier = new WMultiPartIdentifier(edgeIdentifier),
                AttributeValueDict = attributeValueDict
            };
            return true;
        }