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
/// 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
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
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
/// 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
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