Ejemplo n.º 1
0
        //------------------------------------------------------------
        // CNameManager.IsKeyword (1)
        //
        /// <summary>
        /// <para>Determine that the specified string is a keyword.</para>
        /// <para>This is IsNameKeyword in sscli.
        /// (In sscli, IsKeyword only calls IsNameKeyword.)</para>
        /// </summary>
        /// <param name="name"></param>
        /// <param name="langVer">Specifiy whether according to ECMA standard or not.</param>
        /// <param name="index">If the string is a keyword, its index is set to.</param>
        /// <returns></returns>
        //------------------------------------------------------------
        internal bool IsKeyword(string name, LangVersionEnum langVer, out int index)
        {
            index = -1;
            TOKENID tid;

            if (name == null)
            {
                return(false);
            }

            if (!keywordsDictionary.TryGetValue(name, out tid))
            {
                return(false);
            }

            TOKINFO tok = CParser.GetTokenInfo(tid);

            if (tok == null)
            {
                return(false);
            }

            if ((langVer != LangVersionEnum.ECMA1) || (tok.Flags & TOKFLAGS.F_MSKEYWORD) == 0)
            {
                index = (int)tid;
                return(true);
            }
            return(false);
        }
Ejemplo n.º 2
0
        //------------------------------------------------------------
        // CNameManager.IsValidIdentifier (1)
        //
        /// <summary>
        /// <para>Checks for a valid identifier.
        /// The definition of a valid identifier can change depending on what flags are passed.</para>
        /// <para>Specifically,
        /// <list type="bullet">
        /// <item>If AllowAtIdentifiers is set in flags, '@' in the beginning is valid.</item>
        /// <item>Determine if an invalid character is in.</item>
        /// <item>Determine if the name is of a keyword.</item>
        /// </list>
        /// </para>
        /// </summary>
        /// <param name="name"></param>
        /// <param name="langVer">Specifiy whether according to ECMA standard or not.</param>
        /// <param name="flags"></param>
        /// <returns></returns>
        //------------------------------------------------------------
        internal bool IsValidIdentifier(
            string name,
            LangVersionEnum langVer,
            CheckIdentifierFlagsEnum flags)
        {
            if (name == null || name.Length == 0)
            {
                return(false);
            }
            int idx = 0;

            bool atKeyword = false;

            if (name[idx] == '@')
            {
                if ((flags & CheckIdentifierFlagsEnum.AllowAtIdentifiers) == 0)
                {
                    return(false);
                }
                atKeyword = true;
                if (name.Length <= 1)
                {
                    return(false);
                }
                ++idx;
            }

            for (; idx < name.Length; ++idx)
            {
                if (!CharUtil.IsIdentifierCharOrDigit(name[idx]))
                {
                    return(false);
                }
            }

            if ((flags & CheckIdentifierFlagsEnum.CheckKeywords) == 0 || atKeyword)
            {
                return(true);
            }

            int dummy;

            return(!IsKeyword(name, langVer, out dummy));
        }
Ejemplo n.º 3
0
 //------------------------------------------------------------
 // CNameManager.IsValidIdentifier (2)
 //
 /// <summary>
 /// Checks for a valid identifier.
 /// </summary>
 /// <param name="name"></param>
 /// <param name="langVer">Specifiy whether according to ECMA standard or not.</param>
 /// <returns></returns>
 //------------------------------------------------------------
 virtual internal bool IsValidIdentifier(string name, LangVersionEnum langVer)
 {
     return(IsValidIdentifier(name, langVer, CheckIdentifierFlagsEnum.StandardSource));
 }