Ejemplo n.º 1
0
        /// <summary>
        /// This can not handle all idtoken based expressions.
        /// </summary>
        /// <param name="current"></param>
        /// <returns></returns>
        public override bool CanHandle(Token current)
        {
            if (!(current.Kind == TokenKind.Ident))
            {
                return(false);
            }

            var next = _tokenIt.Peek(1, false);

            if (!(next.Token.Kind == TokenKind.Ident))
            {
                return(false);
            }

            // Check if multi-word function name.
            // e.g. "refill inventory"
            // 1. Is it a function call?
            var tokens = _tokenIt.PeekConsequetiveIdsAppendedWithTokenCounts(true, _tokenIt.LLK);

            _result = FluentHelper.MatchFunctionName(_parser.Context, tokens);

            // Validate.
            // 1. The function must exist.
            if (!_result.Exists)
            {
                return(false);
            }

            // 2. Only fluentscript functions support wildcard.
            if (_result.FunctionMode != MemberMode.FunctionScript)
            {
                return(false);
            }

            // 3. Has wildcard flag must be turned on.
            var sym  = _parser.Context.Symbols.GetSymbol(_result.Name) as SymbolFunction;
            var func = sym.FuncExpr as FunctionExpr;

            //var func = _parser.Context.Functions.GetByName(_result.Name);
            if (!func.Meta.HasWildCard)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        private bool CheckIfSingleIdentWildCard(List <Tuple <string, int> > tokens)
        {
            var first = tokens[0].Item1;

            if (_parser.Context.Functions.Contains(first))
            {
                var func = _parser.Context.Functions.GetByName(first);
                if (func.Meta.HasWildCard)
                {
                    _result = new FunctionLookupResult(true, first, MemberMode.FunctionScript)
                    {
                        TokenCount = 1
                    };
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This can not handle all idtoken based expressions.
        /// </summary>
        /// <param name="current"></param>
        /// <returns></returns>
        public override bool CanHandle(Token current)
        {
            if (!(current.Kind == TokenKind.Ident))
            {
                return(false);
            }

            var next = _tokenIt.Peek(1, false);

            if (!(next.Token.Kind == TokenKind.Ident))
            {
                return(false);
            }

            // Check if multi-word function name.
            var ids = _tokenIt.PeekConsequetiveIdsAppendedWithTokenCounts(true, _tokenIt.LLK);

            _result = FluentHelper.MatchFunctionName(_parser.Context, ids);
            return(_result.Exists);
        }
Ejemplo n.º 4
0
        private bool CheckIfSingleIdentWildCard(List <Tuple <string, int> > tokens)
        {
            var first  = tokens[0].Item1;
            var isfunc = _parser.Context.Symbols.IsFunc(first);

            if (isfunc)
            {
                var sym  = _parser.Context.Symbols.GetSymbol(_result.Name) as SymbolFunction;
                var func = sym.FuncExpr as FunctionExpr;
                //var func = _parser.Context.Functions.GetByName(first);
                if (func.Meta.HasWildCard)
                {
                    _result = new FunctionLookupResult(true, first, MemberMode.FunctionScript)
                    {
                        TokenCount = 1
                    };
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Finds a matching script function name from the list of strings representing identifiers.
        /// </summary>
        /// <param name="ctx">The context of the script</param>
        /// <param name="ids">List of strings representing identifier tokens</param>
        /// <returns></returns>
        public static FunctionLookupResult MatchFunctionName(Context ctx, List <Tuple <string, int> > ids)
        {
            var names         = ids;
            var foundFuncName = string.Empty;
            var found         = false;
            var tokenCount    = 0;
            var memberMode    = MemberMode.FunctionScript;

            for (var ndx = ids.Count - 1; ndx >= 0; ndx--)
            {
                // "refill inventory"
                var possible = ids[ndx];
                var funcName = possible.Item1;
                var funcNameWithUnderScores = funcName.Replace(' ', '_');

                // Case 1: "refill inventory" - exists with spaces
                if (ctx.Symbols.IsFunc(funcName))
                {
                    foundFuncName = funcName;
                }
                // Case 2: "refill_inventory" - replace space with underscore.
                else if (ctx.Symbols.IsFunc(funcNameWithUnderScores))
                {
                    foundFuncName = funcNameWithUnderScores;
                }
                // Case 3: Check external functions
                else if (ctx.ExternalFunctions.Contains(funcName))
                {
                    memberMode    = MemberMode.FunctionExternal;
                    foundFuncName = funcName;
                }

                if (!string.IsNullOrEmpty(foundFuncName))
                {
                    found      = true;
                    tokenCount = possible.Item2;
                    break;
                }
            }
            // CASE 1: Not found
            if (!found)
            {
                return(FunctionLookupResult.False);
            }

            // CASE 2: Single word function
            if ((found && tokenCount == 1) && memberMode == MemberMode.FunctionScript)
            {
                var sym  = ctx.Symbols.GetSymbol(foundFuncName) as SymbolFunction;
                var func = sym.FuncExpr as FunctionExpr;
                //var func = ctx.Functions.GetByName(foundFuncName);
                // If wildcard return true;
                if (func.Meta.HasWildCard)
                {
                    return new FunctionLookupResult(true, foundFuncName, memberMode)
                           {
                               TokenCount = tokenCount
                           }
                }
                ;
                else
                {
                    return(FunctionLookupResult.False);
                }
            }

            var result = new FunctionLookupResult()
            {
                Exists       = found,
                Name         = foundFuncName,
                FunctionMode = memberMode,
                TokenCount   = tokenCount
            };

            return(result);
        }