Exemplo n.º 1
0
            public void Execute(IExecutor[] executors)
            {
                tokenCommand = executors[1].ResultToStr;
                tokenSrc     = executors[2].ResultToStr;
                tokenDest    = executors[3].ResultToStr;
                tokenValue   = executors[4].ResultToInt;
                tokenWeight  = executors[5].ResultToInt;

                if (string.IsNullOrEmpty(tokenCommand) ||
                    string.IsNullOrEmpty(tokenSrc) ||
                    string.IsNullOrEmpty(tokenDest))
                {
                    throw new InvalidOperationException("invaild finish result: token is null");
                }

                if (Object.ReferenceEquals(Constants.IF, tokenCommand))
                {
                    token = TokenFactory.Create(TokenFlag.Read, tokenSrc, tokenDest, tokenValue, tokenWeight);
                }
                else if (Object.ReferenceEquals(Constants.AND, tokenCommand))
                {
                    token = token.AND(tokenSrc, tokenDest, tokenValue, tokenWeight);
                }
                else if (Object.ReferenceEquals(Constants.OR, tokenCommand))
                {
                    token = token.OR(tokenSrc, tokenDest, tokenValue, tokenWeight);
                }
                else if (Object.ReferenceEquals(Constants.ACT, tokenCommand))
                {
                    token = token.ACT(tokenSrc, tokenDest, tokenValue, tokenWeight);
                }
            }
        public void TestCreatesToken()
        {
            var actual = _sut.Create(It.IsAny <ClientCredential>(), It.IsAny <string>(),
                                     It.IsAny <string>());

            Assert.IsInstanceOfType(actual, typeof(Token));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Rely on the error handler for this parser but, if no tokens are consumed
        /// to recover, add an error node.
        /// </summary>
        /// <remarks>
        /// Rely on the error handler for this parser but, if no tokens are consumed
        /// to recover, add an error node. Otherwise, nothing is seen in the parse
        /// tree.
        /// </remarks>
        protected internal virtual void Recover(RecognitionException e)
        {
            int i = _input.Index;

            ErrorHandler.Recover(this, e);
            if (_input.Index == i)
            {
                // no input consumed, better add an error node
                if (e is InputMismatchException)
                {
                    InputMismatchException ime = (InputMismatchException)e;
                    IToken tok = e.OffendingToken;
                    int    expectedTokenType = ime.GetExpectedTokens().MinElement;
                    // get any element
                    IToken errToken = TokenFactory.Create(Tuple.Create(tok.TokenSource, tok.TokenSource.InputStream), expectedTokenType, tok.Text, TokenConstants.DefaultChannel, -1, -1, tok.Line, tok.Column);
                    // invalid start/stop
                    _ctx.AddErrorNode(errToken);
                }
                else
                {
                    // NoViableAlt
                    IToken tok      = e.OffendingToken;
                    IToken errToken = TokenFactory.Create(Tuple.Create(tok.TokenSource, tok.TokenSource.InputStream), TokenConstants.InvalidType, tok.Text, TokenConstants.DefaultChannel, -1, -1, tok.Line, tok.Column);
                    // invalid start/stop
                    _ctx.AddErrorNode(errToken);
                }
            }
        }
Exemplo n.º 4
0
        public void Create(string item)
        {
            string param = item.ToLower();

            if (tokenFactory.Contains(param))
            {
                IToken token = tokenFactory.Create(param, AST[AST.Count - 2], AST[AST.Count - 1]);
                if (AST.Count < 2)
                {
                    throw new Exception("not enough tokens !");
                }
                AST.RemoveAt(AST.Count - 2);
                AST.RemoveAt(AST.Count - 1);
                AST.Add(token);
                return;
            }

            if (treeModifierFactory.Contains(param))
            {
                ITreeModifier treeModif = treeModifierFactory.Create(param);
                AST = treeModif.Modify(AST);
                return;
            }
            //need to handle error with int.tryparse
            try {
                AST.Add(new Operand(int.Parse(item)));
            } catch (Exception) {
                Console.Clear();
                Console.WriteLine("erreur le charactère rentré n'est pas reconnu comme symbole valide !");
                Console.WriteLine("appuyez sur entrée pour recommencer...");
                Console.ReadLine();
                Console.Clear();
                this.AST = new List <IToken>();
            }
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Login([FromBody] LoginDTO login)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid Model"));
            }

            var user = await userManager.FindByEmailAsync(login.EmailId);

            if (user is null)
            {
                return(BadRequest("User NOT EXISTS"));
            }

            var response = await signInManager.PasswordSignInAsync(login.EmailId, login.Password, false, true);

            if (!response.Succeeded)
            {
                return(Unauthorized("Either username or password is incorrect"));
            }
            var roles = await userManager.GetRolesAsync(user);

            var claims = await userManager.GetClaimsAsync(user);

            return(Ok(new { token = TokenFactory.Create(tokenOptions, user.UserName, roles, claims) }));
        }
Exemplo n.º 6
0
 protected void emitDot()
 {
     _pendingTokens.Enqueue(TokenFactory.Create(new Tuple <ITokenSource, ICharStream>(this, (ICharStream)InputStream),
                                                MySQLLexer.DOT_SYMBOL, ".", Channel, TokenStartCharIndex, TokenStartCharIndex, TokenStartLine,
                                                TokenStartLine));
     Text = Text.Substring(1);
 }
        public string CreateAccount(string username, string password, bool requiresConfirmation)
        {
            var hash  = _encryptor.Encrypt(password);
            var token = requiresConfirmation ? TokenFactory.Create() : string.Empty;

            _factory.Create(username, GetHashSalt(hash), GetHashPassword(hash), token);
            return(token);
        }
Exemplo n.º 8
0
        public TokenExpectation <T> Expect(Action <TokenFactory <T> > configure)
        {
            var factory = new TokenFactory <T>(position);

            configure(factory);
            position = factory.NextTokenStart;
            expected.Add(factory.Create());

            return(this);
        }
Exemplo n.º 9
0
        public void TokenFactoryTest()
        {
            string       key   = "Slot_1";
            string       value = "hello eden";
            TokenFactory tf    = new TokenFactory();
            KeyValuePair <string, string> kv;
            int cover;

            cover = tf.Create(out kv, "-" + key, value);
            Assert.AreEqual(cover, 2);
            Assert.AreEqual(kv.Key, key);
            Assert.AreEqual(kv.Value, value);
        }
Exemplo n.º 10
0
        public IEnumerable <IToken> Tokenize(string sourceCode, LexerFlag flags)
        {
            _scanner = _createScannerFunc(sourceCode);
            _flags   = flags;

            var tokenInfo = default(TokenInfo);

            while (ScanToken(ref tokenInfo))
            {
                var token = TokenFactory.Create(ref tokenInfo, ref _flags);
                yield return(token);
            }
        }
Exemplo n.º 11
0
        protected void CategorizeIdentifier()
        {
            if (Text.StartsWith("."))
            {
                // If we see an identifier that starts with a dot, we push back the identifier
                // minus the dot back into the input stream.
                var source = new Tuple <ITokenSource, ICharStream>(this, (ICharStream)InputStream);
                var length = Text.Length;

                Token = TokenFactory.Create(
                    source,
                    ImpalaLexerInternal.DOT,
                    ".",
                    Channel,
                    TokenStartCharIndex,
                    TokenStartCharIndex,
                    TokenStartLine,
                    TokenStartColumn);

                InputStream.Seek(TokenStartCharIndex + 1);
                Interpreter.Column -= length - 1;
                return;
            }

            if (Dialect.KeywordMap.TryGetValue(Text.ToLower(), out var keywordId))
            {
                Type = keywordId;
            }
            else if (Dialect.IsReserved(Text))
            {
                Type = ImpalaLexerInternal.UNUSED_RESERVED_WORD;
            }
            else
            {
                Type = ImpalaLexerInternal.IDENT;
            }
        }
Exemplo n.º 12
0
 public Token IF_ALWAYS()
 {
     return(TokenFactory.Create(TokenFlag.None));
 }
Exemplo n.º 13
0
 public Token IF(string src, string dest, int value, int weight)
 {
     return(TokenFactory.Create(TokenFlag.Read | TokenFlag.Enter, src, dest, value, weight));
 }
Exemplo n.º 14
0
 public Token IF(string src, string dest)
 {
     return(TokenFactory.Create(TokenFlag.Read | TokenFlag.Enter, src, dest));
 }
Exemplo n.º 15
0
        public void TokenFactoryCreateTestNullHeadersThrows()
        {
            Action act = () => _sut.Create(null);

            act.Should().Throw <ArgumentNullException>();
        }
Exemplo n.º 16
0
 IToken CreateToken(string tokenName) => TokenFactory.Create(GetTokenType(tokenName), "");