Exemple #1
0
        private void loadFullQualifiedRules(JSGFRuleGrammar jsgfruleGrammar)
        {
            Iterator iterator = jsgfruleGrammar.getRuleNames().iterator();

            while (iterator.hasNext())
            {
                string ruleName = (string)iterator.next();
                string text     = jsgfruleGrammar.getRule(ruleName).toString();
                int    i        = 0;
                while (i < String.instancehelper_length(text))
                {
                    i = String.instancehelper_indexOf(text, 60, i);
                    if (i < 0)
                    {
                        break;
                    }
                    JSGFRuleName jsgfruleName = new JSGFRuleName(String.instancehelper_trim(String.instancehelper_substring(text, i + 1, String.instancehelper_indexOf(text, 62, i + 1))));
                    i = String.instancehelper_indexOf(text, 62, i) + 1;
                    if (jsgfruleName.getFullGrammarName() != null)
                    {
                        string          fullGrammarName  = jsgfruleName.getFullGrammarName();
                        JSGFRuleGrammar jsgfruleGrammar2 = this.getNamedRuleGrammar(fullGrammarName);
                        if (jsgfruleGrammar2 == null)
                        {
                            jsgfruleGrammar2 = this.loadNamedGrammar(fullGrammarName);
                        }
                        if (jsgfruleGrammar2 != null)
                        {
                            this.loadImports(jsgfruleGrammar2);
                        }
                    }
                }
            }
        }
Exemple #2
0
        private JSGFGrammar.GrammarGraph processRuleName(JSGFRuleName jsgfruleName)
        {
            this.logger.fine(new StringBuilder().append("parseRuleName: ").append(jsgfruleName).toString());
            JSGFGrammar.GrammarGraph grammarGraph = this.__ruleStack.contains(jsgfruleName.getRuleName());
            if (grammarGraph != null)
            {
                return(grammarGraph);
            }
            grammarGraph = new JSGFGrammar.GrammarGraph(this);
            this.__ruleStack.push(jsgfruleName.getRuleName(), grammarGraph);
            JSGFRuleName jsgfruleName2 = this.ruleGrammar.resolve(jsgfruleName);

            if (jsgfruleName2 == JSGFRuleName.__NULL)
            {
                grammarGraph.getStartNode().add(grammarGraph.getEndNode(), 0f);
            }
            else if (jsgfruleName2 != JSGFRuleName.__VOID)
            {
                if (jsgfruleName2 == null)
                {
                    string message = new StringBuilder().append("Can't resolve ").append(jsgfruleName).append(" g ").append(jsgfruleName.getFullGrammarName()).toString();

                    throw new JSGFGrammarException(message);
                }
                JSGFRuleGrammar jsgfruleGrammar = this.manager.retrieveGrammar(jsgfruleName2.getFullGrammarName());
                if (jsgfruleGrammar == null)
                {
                    string message2 = new StringBuilder().append("Can't resolve grammar name ").append(jsgfruleName2.getFullGrammarName()).toString();

                    throw new JSGFGrammarException(message2);
                }
                JSGFRule rule = jsgfruleGrammar.getRule(jsgfruleName2.getSimpleRuleName());
                if (rule == null)
                {
                    string message3 = new StringBuilder().append("Can't resolve rule: ").append(jsgfruleName2.getRuleName()).toString();

                    throw new JSGFGrammarException(message3);
                }
                JSGFGrammar.GrammarGraph grammarGraph2 = this.processRule(rule);
                if (grammarGraph != grammarGraph2)
                {
                    grammarGraph.getStartNode().add(grammarGraph2.getStartNode(), 0f);
                    grammarGraph2.getEndNode().add(grammarGraph.getEndNode(), 0f);
                }
            }
            this.__ruleStack.pop();
            return(grammarGraph);
        }
        public virtual JSGFRuleName resolve(JSGFRuleName ruleName)
        {
            JSGFRuleName jsgfruleName      = new JSGFRuleName(ruleName.getRuleName());
            string       simpleRuleName    = jsgfruleName.getSimpleRuleName();
            string       simpleGrammarName = jsgfruleName.getSimpleGrammarName();
            string       packageName       = jsgfruleName.getPackageName();
            string       fullGrammarName   = jsgfruleName.getFullGrammarName();

            if (packageName != null && simpleGrammarName == null)
            {
                string message = new StringBuilder().append("Error: badly formed rulename ").append(jsgfruleName).toString();

                throw new JSGFGrammarException(message);
            }
            if (String.instancehelper_equals(ruleName.getSimpleRuleName(), "NULL"))
            {
                return(JSGFRuleName.__NULL);
            }
            if (String.instancehelper_equals(ruleName.getSimpleRuleName(), "VOID"))
            {
                return(JSGFRuleName.__VOID);
            }
            if (fullGrammarName == null && this.getRule(simpleRuleName) != null)
            {
                return(new JSGFRuleName(new StringBuilder().append(this.name).append('.').append(simpleRuleName).toString()));
            }
            if (fullGrammarName != null)
            {
                JSGFRuleGrammar jsgfruleGrammar = this.manager.retrieveGrammar(fullGrammarName);
                if (jsgfruleGrammar != null && jsgfruleGrammar.getRule(simpleRuleName) != null)
                {
                    return(new JSGFRuleName(new StringBuilder().append(fullGrammarName).append('.').append(simpleRuleName).toString()));
                }
            }
            ArrayList arrayList  = new ArrayList();
            ArrayList arrayList2 = new ArrayList(this.__imports);
            List      list       = arrayList2;

            list.add(new JSGFRuleName(new StringBuilder().append(this.name).append(".*").toString()));
            Iterator iterator = arrayList2.iterator();

            while (iterator.hasNext())
            {
                JSGFRuleName jsgfruleName2      = (JSGFRuleName)iterator.next();
                string       simpleRuleName2    = jsgfruleName2.getSimpleRuleName();
                string       simpleGrammarName2 = jsgfruleName2.getSimpleGrammarName();
                string       fullGrammarName2   = jsgfruleName2.getFullGrammarName();
                if (fullGrammarName2 == null)
                {
                    string message2 = new StringBuilder().append("Error: badly formed import ").append(ruleName).toString();

                    throw new JSGFGrammarException(message2);
                }
                JSGFRuleGrammar jsgfruleGrammar2 = this.manager.retrieveGrammar(fullGrammarName2);
                if (jsgfruleGrammar2 == null)
                {
                    [email protected](new StringBuilder().append("Warning: import of unknown grammar ").append(ruleName).append(" in ").append(this.name).toString());
                }
                else if (!String.instancehelper_equals(simpleRuleName2, "*") && jsgfruleGrammar2.getRule(simpleRuleName2) == null)
                {
                    [email protected](new StringBuilder().append("Warning: import of undefined rule ").append(ruleName).append(" in ").append(this.name).toString());
                }
                else if (String.instancehelper_equals(fullGrammarName2, fullGrammarName) || String.instancehelper_equals(simpleGrammarName2, fullGrammarName))
                {
                    if (String.instancehelper_equals(simpleRuleName2, "*"))
                    {
                        if (jsgfruleGrammar2.getRule(simpleRuleName) != null)
                        {
                            List list2 = arrayList;
                            list2.add(new JSGFRuleName(new StringBuilder().append(fullGrammarName2).append('.').append(simpleRuleName).toString()));
                        }
                    }
                    else if (String.instancehelper_equals(simpleRuleName2, simpleRuleName))
                    {
                        List list3 = arrayList;
                        list3.add(new JSGFRuleName(new StringBuilder().append(fullGrammarName2).append('.').append(simpleRuleName).toString()));
                    }
                }
                else if (fullGrammarName == null)
                {
                    if (String.instancehelper_equals(simpleRuleName2, "*"))
                    {
                        if (jsgfruleGrammar2.getRule(simpleRuleName) != null)
                        {
                            List list4 = arrayList;
                            list4.add(new JSGFRuleName(new StringBuilder().append(fullGrammarName2).append('.').append(simpleRuleName).toString()));
                        }
                    }
                    else if (String.instancehelper_equals(simpleRuleName2, simpleRuleName))
                    {
                        List list5 = arrayList;
                        list5.add(new JSGFRuleName(new StringBuilder().append(fullGrammarName2).append('.').append(simpleRuleName).toString()));
                    }
                }
            }
            int num = arrayList.size();

            if (num == 0)
            {
                return(null);
            }
            if (num == 1)
            {
                return((JSGFRuleName)arrayList.get(0));
            }
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.append("Warning: ambiguous reference ").append(jsgfruleName).append(" in ").append(this.name).append(" to ");
            Iterator iterator2 = arrayList.iterator();

            while (iterator2.hasNext())
            {
                JSGFRuleName jsgfruleName3 = (JSGFRuleName)iterator2.next();
                stringBuilder.append(jsgfruleName3).append(" and ");
            }
            stringBuilder.setLength(stringBuilder.length() - 5);
            string message3 = stringBuilder.toString();

            throw new JSGFGrammarException(message3);
        }