Beispiel #1
0
 internal virtual void Validate(SrgsGrammar grammar)
 {
     SrgsElement[] children = Children;
     foreach (SrgsElement srgsElement in children)
     {
         srgsElement.Validate(grammar);
     }
 }
        public SrgsDocument(GrammarBuilder builder)
        {
            Helpers.ThrowIfNull(builder, "builder");
            _grammar         = new SrgsGrammar();
            _grammar.Culture = builder.Culture;
            IElementFactory elementFactory = new SrgsElementFactory(_grammar);

            builder.CreateGrammar(elementFactory);
        }
 internal override void Validate(SrgsGrammar grammar)
 {
     if (grammar.TagFormat == SrgsTagFormat.Default)
     {
         grammar.TagFormat |= SrgsTagFormat.W3cV1;
     }
     else if (grammar.TagFormat == SrgsTagFormat.KeyValuePairs)
     {
         XmlParser.ThrowSrgsException(SRID.SapiPropertiesAndSemantics);
     }
 }
        internal void Load(XmlReader srgsGrammar)
        {
            _grammar = new SrgsGrammar();
            _grammar.PhoneticAlphabet = AlphabetType.Sapi;
            XmlParser xmlParser = new XmlParser(srgsGrammar, null);

            xmlParser.ElementFactory = new SrgsElementFactory(_grammar);
            xmlParser.Parse();
            if (!string.IsNullOrEmpty(srgsGrammar.BaseURI))
            {
                _baseUri = new Uri(srgsGrammar.BaseURI);
            }
        }
Beispiel #5
0
        void IElementFactory.AddScript(IGrammar grammar, string sRule, string code)
        {
            SrgsGrammar srgsGrammar = (SrgsGrammar)grammar;
            SrgsRule    srgsRule    = srgsGrammar.Rules[sRule];

            if (srgsRule != null)
            {
                srgsRule.Script += code;
            }
            else
            {
                srgsGrammar.AddScript(sRule, code);
            }
        }
        internal override void Validate(SrgsGrammar grammar)
        {
            switch (grammar.TagFormat)
            {
            case SrgsTagFormat.KeyValuePairs:
                break;

            case SrgsTagFormat.Default:
                grammar.TagFormat |= SrgsTagFormat.KeyValuePairs;
                break;

            default:
                XmlParser.ThrowSrgsException(SRID.SapiPropertiesAndSemantics);
                break;
            }
        }
Beispiel #7
0
        internal void Validate(SrgsGrammar grammar)
        {
            bool flag = HasCode || _onInit != null || _onParse != null || _onError != null || _onRecognition != null || _baseclass != null;

            grammar._fContainsCode   |= flag;
            grammar.HasSapiExtension |= flag;
            if (_dynamic != RuleDynamic.NotSet)
            {
                grammar.HasSapiExtension = true;
            }
            if (OnInit != null && Scope != 0)
            {
                XmlParser.ThrowSrgsException(SRID.OnInitOnPublicRule, "OnInit", Id);
            }
            if (OnRecognition != null && Scope != 0)
            {
                XmlParser.ThrowSrgsException(SRID.OnInitOnPublicRule, "OnRecognition", Id);
            }
            foreach (SrgsElement element in _elements)
            {
                element.Validate(grammar);
            }
        }
        internal override void Validate(SrgsGrammar grammar)
        {
            if (_pronunciation != null || _display != null)
            {
                grammar.HasPronunciation = true;
            }
            if (_pronunciation != null)
            {
                int num  = 0;
                int num2 = 0;
                while (num < _pronunciation.Length)
                {
                    num2 = _pronunciation.IndexOf(';', num);
                    if (num2 == -1)
                    {
                        num2 = _pronunciation.Length;
                    }
                    string text = _pronunciation.Substring(num, num2 - num);
                    switch (grammar.PhoneticAlphabet)
                    {
                    case AlphabetType.Sapi:
                        PhonemeConverter.ConvertPronToId(text, grammar.Culture.LCID);
                        break;

                    case AlphabetType.Ups:
                        PhonemeConverter.UpsConverter.ConvertPronToId(text);
                        break;

                    case AlphabetType.Ipa:
                        PhonemeConverter.ValidateUpsIds(text.ToCharArray());
                        break;
                    }
                    num = num2 + 1;
                }
            }
            base.Validate(grammar);
        }
        internal override void Validate(SrgsGrammar grammar)
        {
            bool flag = _params != null || _semanticKey != null;

            grammar._fContainsCode   |= flag;
            grammar.HasSapiExtension |= flag;
            if (_uri != null)
            {
                string text = _uri.ToString();
                if (text[0] == '#')
                {
                    bool flag2 = false;
                    if (text.IndexOf("#grammar:dictation", StringComparison.Ordinal) == 0 || text.IndexOf("#grammar:dictation#spelling", StringComparison.Ordinal) == 0)
                    {
                        flag2 = true;
                    }
                    else
                    {
                        text = text.Substring(1);
                        foreach (SrgsRule rule in grammar.Rules)
                        {
                            if (rule.Id == text)
                            {
                                flag2 = true;
                                break;
                            }
                        }
                    }
                    if (!flag2)
                    {
                        XmlParser.ThrowSrgsException(SRID.UndefRuleRef, text);
                    }
                }
            }
            base.Validate(grammar);
        }
 public SrgsDocument()
 {
     _grammar = new SrgsGrammar();
 }
 internal override void Validate(SrgsGrammar grammar)
 {
     grammar.HasSapiExtension = true;
     base.Validate(grammar);
 }
Beispiel #12
0
 internal SrgsElementFactory(SrgsGrammar grammar)
 {
     _grammar = grammar;
 }
Beispiel #13
0
        void IElementFactory.AddScript(IGrammar grammar, string script, string filename, int line)
        {
            SrgsGrammar srgsGrammar = (SrgsGrammar)grammar;

            srgsGrammar.AddScript(null, script);
        }