2005-07-13 Maverson Eduardo Schulze Rosa <maverson@gmail.com>
[mono.git] / mcs / mbas / genericparser.cs
index 17cd1739c62bf9e46e571274a00276315fc41361..54037a0b441a3bfea255124b79b58c7fe73e095c 100644 (file)
@@ -13,7 +13,8 @@ namespace Mono.Languages
        using System;\r
        using System.Reflection;\r
        using System.Collections;\r
-       using System.IO;\r
+       using System.IO;
+       using System.Text;\r
        using Mono.MonoBASIC;\r
 \r
        /// <summary>\r
@@ -78,7 +79,6 @@ namespace Mono.Languages
                /// Initializes this parser from a file and parses it\r
                /// </summary>\r
                /// <param name="fileName">Name of the file to be parsed</param>\r
-               /// <param name="context">Context to output the parsed tree</param>\r
                public int ParseFile(string fileName)\r
                {\r
                        // file exceptions must be caught by caller\r
@@ -93,12 +93,29 @@ namespace Mono.Languages
                        return parse();\r
                }\r
 \r
+               /// <summary>\r
+               /// Initializes this parser from a file and parses it\r
+               /// </summary>\r
+               /// <param name="fileName">Name of the file to be parsed</param>\r
+               /// <param name="encoding">Specific encoding to use in parsing</param>\r
+               public int ParseFile(string fileName, Encoding encoding)\r
+               {\r
+                       // file exceptions must be caught by caller\r
+\r
+                       global_errors = 0;\r
+                       name = fileName;\r
+                       // TODO: Encoding switching as needed\r
+                       //   We are here forcing StreamReader to assume an specific encoding\r
+                       input = new StreamReader(fileName, encoding); \r
+                       //rc = context;\r
+                       return parse();\r
+               }\r
+\r
                /// <summary>\r
                /// Initializes this parser from a string and parses it\r
                /// </summary>\r
                /// <param name="source">String to be parsed</param>\r
                /// <param name="sourceName">Name of the source to be parsed (just for error reporting)</param>\r
-               /// <param name="context">Context to output the parsed tree</param>\r
                public int ParseString(string source, string sourceName)\r
                {\r
                        global_errors = 0;\r
@@ -167,41 +184,11 @@ namespace Mono.Languages
                        return defaultParser;\r
                }\r
 \r
-               \r
+
+               [Obsolete]              \r
                public static int Tokenize(string fileName)\r
                {\r
-                       GenericParser parser = GetSpecificParserFor(fileName);\r
-                                               \r
-                       if (parser == null)\r
-                       {\r
-                               Console.WriteLine("Do not know how to compile " + fileName);\r
-                               return 1;\r
-                       }\r
-\r
-/*                     Stream input;\r
-\r
-                       try {\r
-                               input = File.OpenRead (input_file);\r
-\r
-                       } catch {\r
-                               Report.Error (2001, "Source file '" + input_file + "' could not be opened");\r
-                               return 1;\r
-                       }\r
-\r
-                       using (input){\r
-                               Tokenizer lexer = new Tokenizer (input, input_file, defines);\r
-                               int token, tokens = 0, errors = 0;\r
-\r
-                               while ((token = lexer.token ()) != Token.EOF){\r
-                                       Location l = lexer.Location;\r
-                                       tokens++;\r
-                                       if (token == Token.ERROR)\r
-                                               errors++;\r
-                               }\r
-                               Console.WriteLine ("Tokenized: " + tokens + " found " + errors + " errors");\r
-                       }\r
-*/                     \r
-                       return 0;\r
+                       return 1;\r
                }\r
 \r
 \r
@@ -209,9 +196,20 @@ namespace Mono.Languages
                /// Find the descendant parser that knows how to parse the specified file\r
                /// based on the files extension, and parses it using the chosen parser\r
                /// </summary>\r
-               /// <param name="fileName">Name of the file to be parsed</param>\r
-               /// <param name="context">Context to output the parsed tree</param>\r
+               /// <param name="fileName">Name of the file to be parsed</param>
+               [Obsolete]\r
                public static int Parse(string fileName)\r
+               {
+                       return Parse(fileName, null);
+               }
+               \r
+               /// <summary>\r
+               /// Find the descendant parser that knows how to parse the specified file\r
+               /// based on the files extension, and parses it using the chosen parser\r
+               /// </summary>\r
+               /// <param name="fileName">Name of the file to be parsed</param>\r
+               /// <param name="encoding">Encoding of the file to be parsed</param>\r
+               public static int Parse(string fileName, Encoding encoding)\r
                {\r
                        int errors;\r
                        GenericParser parser = GetSpecificParserFor(fileName);\r
@@ -221,10 +219,13 @@ namespace Mono.Languages
                                Console.WriteLine("Do not know how to compile " + fileName);\r
                                return 1;\r
                        }\r
-                       \r
+                       
+                       if (encoding == null)
+                               encoding = Encoding.Default;
+                               \r
                        try \r
                        {\r
-                               errors = parser.ParseFile(fileName);\r
+                               errors = parser.ParseFile(fileName, encoding);\r
                        } \r
                        catch (FileNotFoundException)\r
                        {\r