Author: rafael
Date: 2005-03-25 11:55:57 -0500 (Fri, 25 Mar 2005)
New Revision: 42251

Modified:
   trunk/mcs/mbas/ChangeLog
   trunk/mcs/mbas/driver.cs
   trunk/mcs/mbas/genericparser.cs
Log:
2005-03-25:2 Rafael Teixeira <[EMAIL PROTECTED]>
        * genericparser.cs: another static Parse overload to support specifying 
encoding when parsing from a file.
        * driver.cs: obsoletes --tokenize, record currentEncoding for each 
source-file to be processed, call the new Parse overload
                Implement support for a --codepage option similar to mcs. 
Example: 
                        mono mbas.exe --codepage:1252 WindowsANSI.vb 
--codepage:utf8 UTF8.vb --codepage:reset currentcharset.vb


Modified: trunk/mcs/mbas/ChangeLog
===================================================================
--- trunk/mcs/mbas/ChangeLog    2005-03-25 16:50:13 UTC (rev 42250)
+++ trunk/mcs/mbas/ChangeLog    2005-03-25 16:55:57 UTC (rev 42251)
@@ -1,9 +1,15 @@
-2005-03-25 Rafael Teixeira <[EMAIL PROTECTED]>
+2005-03-25:2 Rafael Teixeira <[EMAIL PROTECTED]>
+       * genericparser.cs: another static Parse overload to support specifying 
encoding when parsing from a file.
+       * driver.cs: obsoletes --tokenize, record currentEncoding for each 
source-file to be processed, call the new Parse overload
+               Implement support for a --codepage option similar to mcs. 
Example: 
+                       mono mbas.exe --codepage:1252 WindowsANSI.vb 
--codepage:utf8 UTF8.vb --codepage:reset currentcharset.vb
+
+2005-03-25:1 Rafael Teixeira <[EMAIL PROTECTED]>
        * genericparser.cs: another Parse overload to support specifying 
encoding when parsing from a file.
        Preparing to implement support for a /codepage option similar to mcs
 
 2005-03-24 Manjula GHM <[EMAIL PROTECTED]>
-          * mb-tokenizer.cs: To fix parser error for ExternalSource Directives
+       * mb-tokenizer.cs: To fix parser error for ExternalSource Directives
 
 2005-03-24 Satya Sudha K <[EMAIL PROTECTED]>
        * mb-parser.jay : 

Modified: trunk/mcs/mbas/driver.cs
===================================================================
--- trunk/mcs/mbas/driver.cs    2005-03-25 16:50:13 UTC (rev 42250)
+++ trunk/mcs/mbas/driver.cs    2005-03-25 16:55:57 UTC (rev 42251)
@@ -15,6 +15,7 @@
        using System.Collections;
        using System.Diagnostics;
        using System.IO;
+       using System.Text;
        using System.Globalization;
        using System.Reflection;
        using System.Reflection.Emit;
@@ -30,6 +31,22 @@
                Binary, Text
        };
        
+       struct FileToCompile {
+               public string Filename;
+               public Encoding Encoding;
+               
+               public FileToCompile(string filename, Encoding encoding)
+               {
+                       this.Filename = filename;
+                       this.Encoding = encoding;       
+               }
+               
+               public void Process()
+               {
+                       GenericParser.Parse(this.Filename, this.Encoding);
+               }
+       }
+       
        /// <summary>
        ///    The compiler driver.
        /// </summary>
@@ -39,7 +56,7 @@
                [Option("[Mono] Only parses the source file (for debugging the 
tokenizer)", "parse", SecondLevelHelp = true)]
                public bool parse_only = false;
 
-               [Option("[Mono] Only tokenizes source files", SecondLevelHelp = 
true)]
+               [Option("[IGNORED] Only tokenizes source files", 
SecondLevelHelp = true)]
                public bool tokenize = false;
 
                [Option("[Mono] Shows stack trace at Error location", 
SecondLevelHelp = true)]
@@ -79,6 +96,33 @@
                        return 
ReferencePackage(packageName)?WhatToDoNext.GoAhead:WhatToDoNext.AbandonProgram;
                }
 
+               private Encoding currentEncoding = null;
+               
+               [Option(-1, "Select codepage by {ID} (number, 'utf8' or 
'reset') to process following source files", "codepage")]
+               public string CurrentCodepage {
+                       set {
+                               switch (value.ToLower()) {
+                                       case "reset": 
+                                               currentEncoding = null; 
+                                               break;
+                                       case "utf8": case "utf-8":
+                                               currentEncoding = Encoding.UTF8;
+                                               break;
+                                       default:
+                                               try {
+                                                       currentEncoding = 
Encoding.GetEncoding(int.Parse(value));
+                                               } catch (NotSupportedException) 
{
+                                                       
Console.WriteLine("Ignoring unsupported codepage number {0}.", value);
+                                               } catch (Exception) {
+                                                       
Console.WriteLine("Ignoring unsupported codepage ID {0}.", value);
+                                               }
+                                               break;
+                               }                                       
+                       }
+               }
+
+
+
                [Option("[Mono] Don\'t assume the standard library", 
"nostdlib", SecondLevelHelp = true)]
                public bool NoStandardLibraries { set { RootContext.StdLib = 
!value; } }
 
@@ -301,7 +345,19 @@
 //             [Option("[NOT IMPLEMENTED YET]Create bug report {file}")]
                public string bugreport;
 
+               [ArgumentProcessor]
+               public void AddFile(string fileName)
+               {
+                       string f = fileName;
+                       if (firstSourceFile == null)
+                               firstSourceFile = f;
 
+                       if (source_files.Contains(f))
+                               Report.Error(1516, "Source file '" + f + "' 
specified multiple times");
+                       else
+                               source_files.Add(f, new FileToCompile(fileName, 
currentEncoding));
+               }
+
                ArrayList defines = new ArrayList();
                ArrayList references = new ArrayList();
                ArrayList soft_references = new ArrayList();
@@ -638,27 +694,6 @@
                                        soft_references.Add(def);
                }
 
-               [ArgumentProcessor]
-               public void AddFile(string fileName)
-               {
-                       string f = fileName;
-                       if (firstSourceFile == null)
-                               firstSourceFile = f;
-
-                       if (source_files.Contains(f))
-                               Report.Error(1516, "Source file '" + f + "' 
specified multiple times");
-                       else
-                               source_files.Add(f, f);
-               }
-
-               void ProcessSourceFile(string filename)
-               {
-                       if (tokenize)
-                               GenericParser.Tokenize(filename);
-                       else
-                               GenericParser.Parse(filename);
-               }
-
                string outputFile_Name = null;
 
                string outputFileName {
@@ -684,15 +719,13 @@
 
                bool ParseAll() // Phase 1
                {
-                       if (firstSourceFile == null) {
-                               Report.Error(2008, "No files to compile were 
specified");
+                       if (tokenize)
                                return false;
-                       }
+                               
+                       foreach(FileToCompile file in source_files.Values)
+                               file.Process();
 
-                       foreach(string filename in source_files.Values)
-                               ProcessSourceFile(filename);
-
-                       if (tokenize || parse_only || (Report.Errors > 0))
+                       if (parse_only || (Report.Errors > 0))
                                return false;           
 
                        return true; // everything went well go ahead

Modified: trunk/mcs/mbas/genericparser.cs
===================================================================
--- trunk/mcs/mbas/genericparser.cs     2005-03-25 16:50:13 UTC (rev 42250)
+++ trunk/mcs/mbas/genericparser.cs     2005-03-25 16:55:57 UTC (rev 42251)
@@ -184,41 +184,11 @@
                        return defaultParser;
                }
 
-               
+
+               [Obsolete]              
                public static int Tokenize(string fileName)
                {
-                       GenericParser parser = GetSpecificParserFor(fileName);
-                                               
-                       if (parser == null)
-                       {
-                               Console.WriteLine("Do not know how to compile " 
+ fileName);
-                               return 1;
-                       }
-
-/*                     Stream input;
-
-                       try {
-                               input = File.OpenRead (input_file);
-
-                       } catch {
-                               Report.Error (2001, "Source file '" + 
input_file + "' could not be opened");
-                               return 1;
-                       }
-
-                       using (input){
-                               Tokenizer lexer = new Tokenizer (input, 
input_file, defines);
-                               int token, tokens = 0, errors = 0;
-
-                               while ((token = lexer.token ()) != Token.EOF){
-                                       Location l = lexer.Location;
-                                       tokens++;
-                                       if (token == Token.ERROR)
-                                               errors++;
-                               }
-                               Console.WriteLine ("Tokenized: " + tokens + " 
found " + errors + " errors");
-                       }
-*/                     
-                       return 0;
+                       return 1;
                }
 
 
@@ -226,9 +196,20 @@
                /// Find the descendant parser that knows how to parse the 
specified file
                /// based on the files extension, and parses it using the 
chosen parser
                /// </summary>
-               /// <param name="fileName">Name of the file to be parsed</param>
-               /// <param name="context">Context to output the parsed 
tree</param>
+               /// <param name="fileName">Name of the file to be parsed</param>
+               [Obsolete]
                public static int Parse(string fileName)
+               {
+                       return Parse(fileName, null);
+               }
+               
+               /// <summary>
+               /// Find the descendant parser that knows how to parse the 
specified file
+               /// based on the files extension, and parses it using the 
chosen parser
+               /// </summary>
+               /// <param name="fileName">Name of the file to be parsed</param>
+               /// <param name="encoding">Encoding of the file to be 
parsed</param>
+               public static int Parse(string fileName, Encoding encoding)
                {
                        int errors;
                        GenericParser parser = GetSpecificParserFor(fileName);
@@ -238,10 +219,13 @@
                                Console.WriteLine("Do not know how to compile " 
+ fileName);
                                return 1;
                        }
-                       
+                       
+                       if (encoding == null)
+                               encoding = Encoding.Default;
+                               
                        try 
                        {
-                               errors = parser.ParseFile(fileName);
+                               errors = parser.ParseFile(fileName, encoding);
                        } 
                        catch (FileNotFoundException)
                        {

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to