Пример #1
0
        private static StringBuilder Token(StringBuilder result, IList <NamedToken> tokens, string pre, string handle, int id)
        {
            NamedToken token = null;

            // search backwards for the token
            for (int i = (id < tokens.Count) ? id : tokens.Count - 1; i >= 0; i--)
            {
                token = tokens[i];
                if (token.Id() == id)
                {
                    break;                              // found
                }
                if (token.Id() < id)
                {
                    token = null;                              // not found
                    break;
                }
            }
            if (token != null)
            {
                string name = token.Name();
                result.Append(pre).Append(name).Append(" [").Append(handle).Append("Id=").Append(token.Id()).Append(']');
            }
            else
            {
                result.Append(handle).Append("Id=").Append(id);
            }
            return(result);
        }
Пример #2
0
 private void AddNamesToCollection(IEnumerator <NamedToken> labelIterator, IDictionary <int, string> collection)
 {
     while (labelIterator.MoveNext())
     {
         NamedToken label = labelIterator.Current;
         collection[label.Id()] = label.Name();
     }
 }
Пример #3
0
        private void ParseVariableNameToken(NamedToken namedToken, Scope.Node node,
                                            ImmutableDictionary <Scope, Dictionary <string, object> > symbolTable, IDictionary <string, object> dict)
        {
            Dictionary <string, object> innerDict = ParseScope(node.InnerScope, symbolTable);

            // if the variable is specified by only one token, we treat this as
            // a "renaming" action and surpress the additional inner wrapper
            dict.Add(namedToken.Name, innerDict.Count == 1 ? innerDict.Values.First() : innerDict);
        }
Пример #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public org.neo4j.internal.kernel.api.NamedToken getTokenById(int id) throws TokenNotFoundException
        public override NamedToken GetTokenById(int id)
        {
            NamedToken result = TokenRegistry.getToken(id);

            if (result == null)
            {
                throw new TokenNotFoundException("Token for id " + id);
            }
            return(result);
        }
Пример #5
0
        private void AddNamedToken(NamedToken token)
        {
            // only search the current scope to allow variable shadowing
            if (_namedTokens.ContainsKey(token.Name))
            {
                throw new GrammarException($"Semantic error: The named token '{token.Name}' was declared multiple times.");
            }

            _namedTokens.Add(token.Name, token);
        }
Пример #6
0
        private void PutAndEnsureUnique(IDictionary <string, int> nameToId, NamedToken token)
        {
            int?previous = nameToId.putIfAbsent(token.Name(), token.Id());

            if (previous != null && previous.Value != token.Id())
            {
                // since we optimistically put token into a map before, now we need to remove it.
                _idToToken.Remove(token.Id(), token);
                throw new NonUniqueTokenException(_tokenType, token.Name(), token.Id(), previous.Value);
            }
        }
Пример #7
0
 protected internal override T fetchNextOrNull()
 {
     while (outerInstance.tokens.MoveNext())
     {
         NamedToken token = outerInstance.tokens.Current;
         if (this.access.InUse(_transaction, _schemaReadCore, token.Id()))
         {
             return(this.access.Token(token));
         }
     }
     outerInstance.close();
     return(default(T));
 }
Пример #8
0
        public override void ConfigureConnectionFactory(ConnectionFactory factory, Exchange exchange)
        {
            NamedToken token = GetNamedToken();

            base.ConfigureConnectionFactory(factory, exchange);

            if (_secureConnectionFactory != null)
            {
                _secureConnectionFactory.ConfigureConnectionFactory(factory, exchange);
            }

            factory.AuthMechanisms = new AuthMechanismFactory[] { new PlainMechanismFactory() };
            factory.UserName       = token.Identity;
            factory.Password       = token.Token;
        }
Пример #9
0
        public override bool Equals(object o)
        {
            if (this == o)
            {
                return(true);
            }
            if (o == null || this.GetType() != o.GetType())
            {
                return(false);
            }

            NamedToken that = ( NamedToken )o;

            return(_id == that._id && _name.Equals(that._name));
        }
Пример #10
0
        private void ParseNamedToken(NamedToken namedToken, IDictionary <string, object> dict)
        {
            ParseNamedToken(namedToken, out object result);
            if (!namedToken.HasStructuredName)
            {
                dict.Add(namedToken.Name, result);
            }
            else
            {
                IDictionary <string, object> innerDict = dict;
                foreach (string name in namedToken.StructuredName.Take(namedToken.StructuredName.Length - 1))
                {
                    if (innerDict.TryGetValue(name, out object obj))
                    {
                        // append value to inner dictionary
                        if (obj is Dictionary <string, object> newInnerDict)
                        {
                            innerDict = newInnerDict;
                        }
                        else
                        {
                            throw new ParserException($"Structured named token '{namedToken.Name}' can not be set, because the " +
                                                      $"inner key '{name}' is already set to a non-object type.");
                        }
                    }
                    else
                    {
                        // create a new inner dictionary
                        var newInnerDict = new Dictionary <string, object>();
                        innerDict.Add(name, newInnerDict);
                        innerDict = newInnerDict;
                    }
                }

                innerDict.Add(namedToken.StructuredName.Last(), result);
            }
        }
Пример #11
0
 internal override string token(NamedToken token)
 {
     return(token.Name());
 }
Пример #12
0
 internal override Label token(NamedToken token)
 {
     return(label(token.Name()));
 }
Пример #13
0
 internal override RelationshipType token(NamedToken token)
 {
     return(RelationshipType.withName(token.Name()));
 }
Пример #14
0
 public NamedTreeSyntax(Syntax left, NamedToken tokenClass, IToken part, Syntax right)
     : base(left, part, right) { _tokenClass = tokenClass; }
Пример #15
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void addToken(org.neo4j.internal.kernel.api.NamedToken token) throws NonUniqueTokenException
        public override void AddToken(NamedToken token)
        {
            TokenRegistry.put(token);
        }
Пример #16
0
        private void ParseNamedToken(NamedToken namedToken, out object result)
        {
            string input = NextInputToken();

            switch (namedToken.Type)
            {
            case TokenType.Auto:
                if (int.TryParse(input, out int autoInt))
                {
                    result = autoInt;
                }
                else if (long.TryParse(input, out long autoLong))
                {
                    result = autoLong;
                }
                else if (TryParseDouble(input, out double autoDouble))
                {
                    result = autoDouble;
                }
                else if (bool.TryParse(input, out bool autoBool))
                {
                    result = autoBool;
                }
                else
                {
                    result = input;
                }
                break;

            case TokenType.Int:
                if (int.TryParse(input, out int parsedInt))
                {
                    result = parsedInt;
                }
                else if (long.TryParse(input, out long autoLong))
                {
                    result = autoLong;
                }
                else
                {
                    throw new ParserException($"Could not parse '{input}' to expected type {TokenType.Int}.");
                }
                break;

            case TokenType.Bool:
                if (bool.TryParse(input, out bool parsedBool))
                {
                    result = parsedBool;
                }
                else
                {
                    throw new ParserException($"Could not parse '{input}' to expected type {TokenType.Bool}.");
                }
                break;

            case TokenType.Double:
                if (TryParseDouble(input, out double parsedDouble))
                {
                    result = parsedDouble;
                }
                else
                {
                    throw new ParserException($"Could not parse '{input}' to expected type {TokenType.Double}.");
                }
                break;

            case TokenType.String:
                result = input;
                break;

            default:
                throw new ParserException($"Unexpected type '{namedToken.Type}' for named token.");
            }
        }
Пример #17
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void put(org.neo4j.internal.kernel.api.NamedToken token) throws NonUniqueTokenException
        public virtual void Put(NamedToken token)
        {
            _idToToken[token.Id()] = token;
            PutAndEnsureUnique(_nameToId, token);
        }
Пример #18
0
 internal abstract R Token(NamedToken token);