X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fmbas%2Fgenericparser.cs;h=54037a0b441a3bfea255124b79b58c7fe73e095c;hb=0799426c96b85f3b346de122a02b76fc9a01a966;hp=17cd1739c62bf9e46e571274a00276315fc41361;hpb=0abc2e6270020edc4a5b4c66f93b4ae582815f20;p=mono.git
diff --git a/mcs/mbas/genericparser.cs b/mcs/mbas/genericparser.cs
index 17cd1739c62..54037a0b441 100644
--- a/mcs/mbas/genericparser.cs
+++ b/mcs/mbas/genericparser.cs
@@ -13,7 +13,8 @@ namespace Mono.Languages
using System;
using System.Reflection;
using System.Collections;
- using System.IO;
+ using System.IO;
+ using System.Text;
using Mono.MonoBASIC;
///
@@ -78,7 +79,6 @@ namespace Mono.Languages
/// Initializes this parser from a file and parses it
///
/// Name of the file to be parsed
- /// Context to output the parsed tree
public int ParseFile(string fileName)
{
// file exceptions must be caught by caller
@@ -93,12 +93,29 @@ namespace Mono.Languages
return parse();
}
+ ///
+ /// Initializes this parser from a file and parses it
+ ///
+ /// Name of the file to be parsed
+ /// Specific encoding to use in parsing
+ public int ParseFile(string fileName, Encoding encoding)
+ {
+ // file exceptions must be caught by caller
+
+ global_errors = 0;
+ name = fileName;
+ // TODO: Encoding switching as needed
+ // We are here forcing StreamReader to assume an specific encoding
+ input = new StreamReader(fileName, encoding);
+ //rc = context;
+ return parse();
+ }
+
///
/// Initializes this parser from a string and parses it
///
/// String to be parsed
/// Name of the source to be parsed (just for error reporting)
- /// Context to output the parsed tree
public int ParseString(string source, string sourceName)
{
global_errors = 0;
@@ -167,41 +184,11 @@ namespace Mono.Languages
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;
}
@@ -209,9 +196,20 @@ namespace Mono.Languages
/// Find the descendant parser that knows how to parse the specified file
/// based on the files extension, and parses it using the chosen parser
///
- /// Name of the file to be parsed
- /// Context to output the parsed tree
+ /// Name of the file to be parsed
+ [Obsolete]
public static int Parse(string fileName)
+ {
+ return Parse(fileName, null);
+ }
+
+ ///
+ /// Find the descendant parser that knows how to parse the specified file
+ /// based on the files extension, and parses it using the chosen parser
+ ///
+ /// Name of the file to be parsed
+ /// Encoding of the file to be parsed
+ public static int Parse(string fileName, Encoding encoding)
{
int errors;
GenericParser parser = GetSpecificParserFor(fileName);
@@ -221,10 +219,13 @@ namespace Mono.Languages
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)
{