示例#1
0
        public bool Parse(Accessibility accessibility, string str)
        {
            m_strSpec       = str;
            m_accessibility = accessibility;

            // Create a scanner
            StringScanner s = new StringScanner(str);

            // Parse target spec
            if (s.current != '.')
            {
                m_specTarget = new IdentifierSpec();
                if (!m_specTarget.Parse(s))
                {
                    return(false);
                }
            }

            // Parse member spec
            if (s.current == '.')
            {
                s.SkipForward(1);

                if (!s.eof)
                {
                    // Parse rhs
                    m_specMember = new IdentifierSpec();
                    if (!m_specMember.Parse(s))
                    {
                        return(false);
                    }
                }
            }
            else
            {
                if (m_specTarget != null)
                {
                    m_specNonMember = m_specTarget;
                    m_specTarget    = null;
                }
                else
                {
                    return(false);
                }
            }

            if (!s.eof)
            {
                return(false);
            }

            return(true);
        }
示例#2
0
        public bool Parse(StringScanner s)
        {
            // Can't be empty
            if (s.eof)
                return false;

            // Regex?
            if (s.current == '/')
            {
                s.SkipForward(1);
                s.Mark();

                while (s.current != '/')
                {
                    if (s.eof)
                        return false;

                    if (s.current == '\\')
                        s.SkipForward(2);
                    else
                        s.SkipForward(1);
                }

                try
                {
                    m_regex = new System.Text.RegularExpressions.Regex(s.Extract());
                    s.SkipForward(1);
                    return true;
                }
                catch (Exception)
                {
                    return false;
                }
            }

            // Wildcard or explicit
            bool bWildcard = false;
            bool bLeading = true;
            s.Mark();
            while (!s.eof && s.current != '.')
            {
                // Wildcard?
                if (s.current == '?' || s.current == '*')
                {
                    bWildcard = true;
                    s.SkipForward(1);
                    bLeading=false;
                    continue;
                }

                // Valid identifier character?
                if (bLeading)
                {
                    if (!Tokenizer.IsIdentifierLeadChar(s.current))
                        return false;
                }
                else
                {
                    if (!Tokenizer.IsIdentifierChar(s.current))
                        return false;
                }

                // Next
                s.SkipForward(1);

                bLeading = false;
            }

            // Extract it
            string str = s.Extract();

            // If it ends with an asterix, it's a wildcard
            if (bWildcard)
            {
                str = str.Replace("*", "(.*)");
                str = str.Replace("?", "(.)");
                m_regex = new System.Text.RegularExpressions.Regex("^" + str + "$");
                return true;
            }

            /// Store it
            m_identifier = str;
            return true;
        }
示例#3
0
        public bool Parse(Accessibility accessibility, string str)
        {
            m_strSpec = str;
            m_accessibility = accessibility;

            // Create a scanner
            StringScanner s = new StringScanner(str);

            // Parse target spec
            if (s.current != '.')
            {
                m_specTarget = new IdentifierSpec();
                if (!m_specTarget.Parse(s))
                    return false;
            }

            // Parse member spec
            if (s.current == '.')
            {
                s.SkipForward(1);

                if (!s.eof)
                {
                    // Parse rhs
                    m_specMember = new IdentifierSpec();
                    if (!m_specMember.Parse(s))
                        return false;
                }
            }
            else
            {
                if (m_specTarget != null)
                {
                    m_specNonMember = m_specTarget;
                    m_specTarget = null;
                }
                else
                    return false;
            }

            if (!s.eof)
                return false;

            return true;
        }
示例#4
0
        public bool Parse(StringScanner s)
        {
            // Can't be empty
            if (s.eof)
            {
                return(false);
            }

            // Regex?
            if (s.current == '/')
            {
                s.SkipForward(1);
                s.Mark();

                while (s.current != '/')
                {
                    if (s.eof)
                    {
                        return(false);
                    }

                    if (s.current == '\\')
                    {
                        s.SkipForward(2);
                    }
                    else
                    {
                        s.SkipForward(1);
                    }
                }

                try
                {
                    m_regex = new System.Text.RegularExpressions.Regex(s.Extract());
                    s.SkipForward(1);
                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }

            // Wildcard or explicit
            bool bWildcard = false;
            bool bLeading  = true;

            s.Mark();
            while (!s.eof && s.current != '.')
            {
                // Wildcard?
                if (s.current == '?' || s.current == '*')
                {
                    bWildcard = true;
                    s.SkipForward(1);
                    bLeading = false;
                    continue;
                }

                // Valid identifier character?
                if (bLeading)
                {
                    if (!Tokenizer.IsIdentifierLeadChar(s.current))
                    {
                        return(false);
                    }
                }
                else
                {
                    if (!Tokenizer.IsIdentifierChar(s.current))
                    {
                        return(false);
                    }
                }

                // Next
                s.SkipForward(1);

                bLeading = false;
            }

            // Extract it
            string str = s.Extract();

            // If it ends with an asterix, it's a wildcard
            if (bWildcard)
            {
                str     = str.Replace("*", "(.*)");
                str     = str.Replace("?", "(.)");
                m_regex = new System.Text.RegularExpressions.Regex("^" + str + "$");
                return(true);
            }

            /// Store it
            m_identifier = str;
            return(true);
        }