Esempio n. 1
0
        private Namespace GetNamespace(TextStream textStream, Document document)
        {
            Namespace ns = null;
            Dictionary <string, Namespace> lookup;

            List <string> parts = new List <string>();

            while (textStream.GoToPreviousToken() && textStream.Token.Key == "DotOperatorToken")
            {
                textStream.GoToPreviousToken();
                IToken token = textStream.PeekToken();
                if (token.Key != "IdentifierToken")
                {
                    break;
                }
                parts.Insert(0, document.GetTokenText(token));
            }
            foreach (string part in parts)
            {
                if (ns == null)
                {
                    lookup = m_scriptEngineDefinition.NamespaceLookup;
                }
                else
                {
                    lookup = ns.NamespaceLookup;
                }

                if (!lookup.TryGetValue(part, out ns))
                {
                    return(null);
                }
            }
            return(ns);
        }
Esempio n. 2
0
        private Function GetFunction(TextStream textStream, Document document)
        {
            int nesting = 0;

            while (nesting != -1)
            {
                if (textStream.TokenIndex == 0)
                {
                    return(null);
                }

                textStream.SeekToken(-1);

                switch (textStream.PeekToken().Key)
                {
                case "OpenParenthesisToken":
                    nesting--;
                    break;

                case "CloseParenthesisToken":
                    nesting++;
                    break;
                }
            }

            if (!textStream.GoToPreviousToken())
            {
                return(null);
            }

            string functionName;

            if (textStream.Token.Key == "IdentifierToken")
            {
                functionName = document.GetTokenText(textStream.Token);
            }
            else
            {
                return(null);
            }

            /*if (textStream.TokenIndex == 0)
             *      return null;
             *
             * textStream.SeekToken(-1);*/

            Namespace ns = GetNamespace(textStream, document);

            if (ns == null)
            {
                return(null);
            }

            foreach (Function f in ns.Functions)
            {
                if (f.Name == functionName)
                {
                    return(f);
                }
            }
            return(null);
        }