Exemple #1
0
        /**
         * newGrammarFromURL
         */
        public static JSGFRuleGrammar NewGrammarFromJSGF(URL url, JSGFRuleGrammarFactory factory)
        {
            TextReader     reader;
            BufferedStream stream   = new BufferedStream(url.OpenStream(), 256);
            JSGFEncoding   encoding = GetJSGFEncoding(stream);

            if ((encoding != null) && (encoding.Encoding != null))
            {
                Console.WriteLine("Grammar Character Encoding \"" + encoding.Encoding + "\"");
                reader = new StreamReader(stream, encoding.GetEncoding);
            }
            else
            {
                if (encoding == null)
                {
                    Console.WriteLine("WARNING: Grammar missing self identifying header");
                }
                reader = new StreamReader(stream);
            }
            return(NewGrammarFromJSGF(reader, factory));
        }
Exemple #2
0
 // This main method simply checks the syntax of a jsgf Grammar
 //
 public static void Main(String[] args)
 {
     if (args.Length == 0)
     {
         Console.WriteLine("JSGF Parser Version " + Version + ":  Reading from standard input . . .");
         _parser = new JSGFParser(Console.In);
     }
     else if (args.Length > 0)
     {
         Console.WriteLine("JSGF Parser Version " + Version + ":  Reading from file " + args[0] + " . . .");
         try
         {
             FileInfo codeBase = null;
             String   path     = Directory.GetCurrentDirectory() + "/" + args[0];
             try
             {
                 codeBase = new FileInfo(path);
             }
             catch (UriFormatException e)
             {
                 Console.WriteLine("Could not get URL for current directory " + e);
                 return;
             }
             BufferedStream i        = new BufferedStream(codeBase.OpenRead(), 256);
             JSGFEncoding   encoding = GetJSGFEncoding(i);
             TextReader     rdr;
             if ((encoding != null) && (encoding.Encoding != null))
             {
                 Console.WriteLine("Grammar Character Encoding \"" + encoding.Encoding + "\"");
                 rdr = new StreamReader(i, encoding.GetEncoding);
             }
             else
             {
                 if (encoding == null)
                 {
                     Console.WriteLine("WARNING: Grammar missing self identifying header");
                 }
                 rdr = new StreamReader(i);
             }
             _parser = new JSGFParser(rdr);
         }
         catch (Exception e)
         {
             Console.WriteLine("JSGF Parser Version " + Version + ":  File " + args[0] + " not found.");
             return;
         }
     }
     else
     {
         Console.WriteLine("JSGF Parser Version " + Version + ":  Usage is one of:");
         Console.WriteLine("         java JSGFParser < inputfile");
         Console.WriteLine("OR");
         Console.WriteLine("         java JSGFParser inputfile");
         return;
     }
     try
     {
         _parser.GrammarUnit(new JSGFRuleGrammarFactory(new JSGFRuleGrammarManager()));
         Console.WriteLine("JSGF Parser Version " + Version + ":  JSGF Grammar parsed successfully.");
     }
     catch (ParseException e)
     {
         Console.WriteLine("JSGF Parser Version " + Version + ":  Encountered errors during parse." + e.Message);
     }
 }