2007-10-17 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / mcs / cs-tokenizer.cs
index e288f8d9dfc330d54839c4a957b3b9e22ce765ec..314ffd245d13e58e424fba998e6a0fa82d672b79 100644 (file)
@@ -38,12 +38,23 @@ namespace Mono.CSharp
                bool handle_get_set = false;
                bool handle_remove_add = false;
                bool handle_assembly = false;
-               bool handle_constraints = false;
+               bool handle_where = false;
                bool handle_typeof = false;
-               bool linq;
+               bool lambda_arguments_parsing;
                Location current_location;
                Location current_comment_location = Location.Null;
-               ArrayList escapedIdentifiers = new ArrayList ();
+               ArrayList escaped_identifiers = new ArrayList ();
+               public int parsing_block;
+
+#if GMCS_SOURCE
+               bool query_parsing;
+#endif
+               
+               static bool IsLinqEnabled {
+                       get {
+                               return RootContext.Version == LanguageVersion.LINQ;
+                       }
+               }
 
                //
                // XML documentation buffer. The save point is used to divide
@@ -54,7 +65,7 @@ namespace Mono.CSharp
                //
                // See comment on XmlCommentState enumeration.
                //
-               XmlCommentState xmlDocState = XmlCommentState.Allowed;
+               XmlCommentState xml_doc_state = XmlCommentState.Allowed;
 
                //
                // Whether tokens have been seen on this line
@@ -68,16 +79,16 @@ namespace Mono.CSharp
                //
                bool any_token_seen = false;
 
-               static Hashtable tokenValues;
+               static Hashtable token_values;
                static readonly char[] simple_whitespaces = new char[] { ' ', '\t' };
 
                private static Hashtable TokenValueName
                {
                        get {
-                               if (tokenValues == null)
-                                       tokenValues = GetTokenValueNameHash ();
+                               if (token_values == null)
+                                       token_values = GetTokenValueNameHash ();
 
-                               return tokenValues;
+                               return token_values;
                        }
                }
 
@@ -121,69 +132,44 @@ namespace Mono.CSharp
                }
 
                public bool PropertyParsing {
-                       get {
-                               return handle_get_set;
-                       }
-
-                       set {
-                               handle_get_set = value;
-                       }
+                       get { return handle_get_set; }
+                       set { handle_get_set = value; }
                 }
 
                public bool AssemblyTargetParsing {
-                       get {
-                               return handle_assembly;
-                       }
-
-                       set {
-                               handle_assembly = value;
-                       }
+                       get { return handle_assembly; }
+                       set { handle_assembly = value; }
                }
 
                public bool EventParsing {
-                       get {
-                               return handle_remove_add;
-                       }
-
-                       set {
-                               handle_remove_add = value;
-                       }
+                       get { return handle_remove_add; }
+                       set { handle_remove_add = value; }
                }
 
                public bool ConstraintsParsing {
-                       get {
-                               return handle_constraints;
-                       }
-
-                       set {
-                               handle_constraints = value;
-                       }
+                       get { return handle_where; }
+                       set { handle_where = value; }
                }
 
                public bool TypeOfParsing {
-                       get {
-                               return handle_typeof;
-                       }
-
-                       set {
-                               handle_typeof = value;
-                       }
+                       get { return handle_typeof; }
+                       set { handle_typeof = value; }
                }
-
+               
                public XmlCommentState doc_state {
-                       get { return xmlDocState; }
+                       get { return xml_doc_state; }
                        set {
                                if (value == XmlCommentState.Allowed) {
                                        check_incorrect_doc_comment ();
                                        reset_doc_comment ();
                                }
-                               xmlDocState = value;
+                               xml_doc_state = value;
                        }
                }
 
                public bool IsEscapedIdentifier (Location loc)
                {
-                       foreach (LocatedToken lt in escapedIdentifiers)
+                       foreach (LocatedToken lt in escaped_identifiers)
                                if (lt.Location.Equals (loc))
                                        return true;
                        return false;
@@ -193,7 +179,7 @@ namespace Mono.CSharp
                // Class variables
                // 
                static CharArrayHashtable[] keywords;
-               static Hashtable keywordStrings = new Hashtable ();
+               static Hashtable keyword_strings;
                static NumberStyles styles;
                static NumberFormatInfo csharp_format_info;
                
@@ -308,8 +294,9 @@ namespace Mono.CSharp
                        position_stack.Pop ();
                }
                
-               static void AddKeyword (string kw, int token) {
-                       keywordStrings.Add (kw, kw);
+               static void AddKeyword (string kw, int token)
+               {
+                       keyword_strings.Add (kw, kw);
                        if (keywords [kw.Length] == null) {
                                keywords [kw.Length] = new CharArrayHashtable (kw.Length);
                        }
@@ -318,6 +305,7 @@ namespace Mono.CSharp
 
                static void InitTokens ()
                {
+                       keyword_strings = new Hashtable ();
                        keywords = new CharArrayHashtable [64];
 
                        AddKeyword ("__arglist", Token.ARGLIST);
@@ -409,15 +397,38 @@ namespace Mono.CSharp
 #endif
                }
 
+#if GMCS_SOURCE
+               public static void InitializeLinqKeywords ()
+               {
+                       AddKeyword ("from", Token.FROM);
+                       AddKeyword ("join", Token.JOIN);
+                       AddKeyword ("on", Token.ON);
+                       AddKeyword ("equals", Token.EQUALS);
+                       AddKeyword ("select", Token.SELECT);
+                       AddKeyword ("group", Token.GROUP);
+                       AddKeyword ("by", Token.BY);
+                       AddKeyword ("let", Token.LET);
+                       AddKeyword ("orderby", Token.ORDERBY);
+                       AddKeyword ("ascending", Token.ASCENDING);
+                       AddKeyword ("descending", Token.DESCENDING);
+                       AddKeyword ("into", Token.INTO);
+               }
+#endif
+
                //
                // Class initializer
                // 
                static Tokenizer ()
+               {
+                       Reset ();
+               }
+
+               public static void Reset ()
                {
                        InitTokens ();
                        csharp_format_info = NumberFormatInfo.InvariantInfo;
                        styles = NumberStyles.Float;
-                       
+
                        string_builder = new System.Text.StringBuilder ();
                }
 
@@ -437,14 +448,51 @@ namespace Mono.CSharp
                        
                        int res = (int) o;
 
-                       if (handle_get_set == false && (res == Token.GET || res == Token.SET))
+                       if (!handle_get_set && (res == Token.GET || res == Token.SET))
                                return -1;
-                       if (handle_remove_add == false && (res == Token.REMOVE || res == Token.ADD))
+                       if (!handle_remove_add && (res == Token.REMOVE || res == Token.ADD))
                                return -1;
-                       if (handle_assembly == false && res == Token.ASSEMBLY)
+                       if (!handle_assembly && res == Token.ASSEMBLY)
                                return -1;
 #if GMCS_SOURCE
-                       if (handle_constraints == false && res == Token.WHERE)
+                       if (IsLinqEnabled) {
+                               //
+                               // A query expression is any expression that starts with `from identifier'
+                               // followed by any token except ; , =
+                               // 
+                               if (!query_parsing && res == Token.FROM) {
+                                       PushPosition ();
+                                       switch (token ()) {
+                                               case Token.IDENTIFIER:
+                                               case Token.INT:
+                                               case Token.BOOL:
+                                               case Token.BYTE:
+                                               case Token.CHAR:
+                                               case Token.DECIMAL:
+                                               case Token.FLOAT:
+                                               case Token.LONG:
+                                               case Token.OBJECT:
+                                               case Token.STRING:
+                                               case Token.UINT:
+                                               case Token.ULONG:
+                                                       int next_token = token ();
+                                                       query_parsing = next_token != Token.SEMICOLON && next_token != Token.COMMA &&
+                                                               next_token != Token.EQUALS;
+                                                       break;
+                                               case Token.VOID:
+                                                       Expression.Error_VoidInvalidInTheContext (Location);
+                                                       break;                                          
+                                       }
+                                       PopPosition ();
+                               }
+
+                               if (!query_parsing && res > Token.QUERY_FIRST_TOKEN && res < Token.QUERY_LAST_TOKEN)
+                                       return -1;
+
+                               return res;
+                       }
+
+                       if (!handle_where && res == Token.WHERE)
                                return -1;
 #endif
                        return res;
@@ -469,7 +517,6 @@ namespace Mono.CSharp
                {
                        this.ref_name = file;
                        this.file_name = file;
-                       linq = RootContext.Version == LanguageVersion.LINQ;
                        reader = input;
                        
                        putback_char = -1;
@@ -502,7 +549,29 @@ namespace Mono.CSharp
 
                public static bool IsKeyword (string s)
                {
-                       return keywordStrings [s] != null;
+                       return keyword_strings [s] != null;
+               }
+
+               //
+               // Tests whether '(' is beggining of lambda parameters
+               //
+               bool IsLambdaOpenParens ()
+               {
+                       int ntoken;
+                       while ((ntoken = xtoken ()) != Token.EOF) {
+                               switch (ntoken) {
+                                       case Token.CLOSE_PARENS:
+                                               return xtoken () == Token.ARROW;
+
+                                       case Token.STAR:
+                                       case Token.SEMICOLON:
+                                       case Token.OPEN_PARENS:
+                                               return false;
+                               }
+                       }
+
+                       Error_TokenExpected (")");
+                       return false;
                }
 
                public static bool IsValidIdentifier (string s)
@@ -520,22 +589,6 @@ namespace Mono.CSharp
                        return true;
                }
 
-               bool parse_generic_dimension (out int dimension)
-               {
-                       dimension = 1;
-
-               again:
-                       int the_token = token ();
-                       if (the_token == Token.OP_GENERICS_GT)
-                               return true;
-                       else if (the_token == Token.COMMA) {
-                               dimension++;
-                               goto again;
-                       }
-
-                       return false;
-               }
-
                bool parse_less_than ()
                {
                start:
@@ -623,6 +676,28 @@ namespace Mono.CSharp
                        else
                                nullable_pos = -1;
                }
+               
+               public bool QueryParsing {
+                       set {
+                               query_parsing = value;
+                       }
+               }               
+               
+               bool parse_generic_dimension (out int dimension)
+               {
+                       dimension = 1;
+
+               again:
+                       int the_token = token ();
+                       if (the_token == Token.OP_GENERICS_GT)
+                               return true;
+                       else if (the_token == Token.COMMA) {
+                               dimension++;
+                               goto again;
+                       }
+
+                       return false;
+               }               
 #endif
                
                public int peek_token ()
@@ -635,142 +710,7 @@ namespace Mono.CSharp
                        
                        return the_token;
                }
-               
-               bool parse_namespace_or_typename (int next)
-               {
-                       if (next == -1)
-                               next = peek_token ();
-                       while (next == Token.IDENTIFIER){
-                               token ();
-                         again:
-                               next = peek_token ();
-                               if (next == Token.DOT || next == Token.DOUBLE_COLON){
-                                       token ();
-                                       next = peek_token ();
-                                       continue;
-                               }
-                               if (next == Token.OP_GENERICS_LT){
-                                       token ();
-                                       if (!parse_less_than ())
-                                               return false;
-                                       goto again;
-                               }
-                               return true;
-                       }
-
-                       return false;
-               }
-
-               bool is_simple_type (int token)
-               {
-                       return  (token == Token.BOOL ||
-                                token == Token.DECIMAL ||
-                                token == Token.SBYTE ||
-                                token == Token.BYTE ||
-                                token == Token.SHORT ||
-                                token == Token.USHORT ||
-                                token == Token.INT ||
-                                token == Token.UINT ||
-                                token == Token.LONG ||
-                                token == Token.ULONG ||
-                                token == Token.CHAR ||
-                                token == Token.FLOAT ||
-                                token == Token.DOUBLE);
-               }
-
-               bool is_builtin_reference_type (int token)
-               {
-                       return (token == Token.OBJECT || token == Token.STRING);
-               }
-
-               bool parse_opt_rank (int next)
-               {
-                       while (true){
-                               if (next != Token.OPEN_BRACKET)
-                                       return true;
-
-                               token ();
-                               while (true){
-                                       next = token ();
-                                       if (next == Token.CLOSE_BRACKET){
-                                               next = peek_token ();
-                                               break;
-                                       }
-                                       if (next == Token.COMMA)
-                                               continue;
                                        
-                                       return false;
-                               }
-                       }
-               }
-                       
-               bool parse_type ()
-               {
-                       int next = peek_token ();
-                       
-                       if (is_simple_type (next)){
-                               token ();
-                               next = peek_token ();
-                               if (next == Token.INTERR)
-                                       token ();
-                               return parse_opt_rank (peek_token ());
-                       }
-                       if (parse_namespace_or_typename (next)){
-                               next = peek_token ();
-                               if (next == Token.INTERR)
-                                       token ();
-                               return parse_opt_rank (peek_token ());
-                       } else if (is_builtin_reference_type (next)){
-                               token ();
-                               return parse_opt_rank (peek_token ());
-                       }
-                       
-                       return false;
-               }
-               
-               //
-               // Invoked after '(' has been seen and tries to parse:
-               // type identifier [, type identifier]*
-               //
-               // if this is the case, instead of returning an
-               // OPEN_PARENS token we return a special token that
-               // triggers lambda parsing.
-               //
-               // This is needed because we can not introduce the
-               // explicitly_typed_lambda_parameter_list after a '(' in the
-               // grammar without introducing reduce/reduce conflicts.
-               //
-               // We need to parse a type and if it is followed by an
-               // identifier, we know it has to be parsed as a lambda
-               // expression.  
-               //
-               // the type expression can be prefixed with `ref' or `out'
-               //
-               public bool parse_lambda_parameters ()
-               {
-                       while (true){
-                               int next = peek_token ();
-
-                               if (next == Token.REF || next == Token.OUT)
-                                       token ();
-                                                
-                               if (parse_type ()){
-                                       next = peek_token ();
-                                       if (next == Token.IDENTIFIER){
-                                               token ();
-                                               next = peek_token ();
-                                               if (next == Token.COMMA){
-                                                       token ();
-                                                       continue;
-                                               }
-                                               if (next == Token.CLOSE_PARENS)
-                                                       return true;
-                                       }
-                               }
-                               return false;
-                       }
-               }
-
                int parsing_generic_less_than = 0;
                
                int is_punct (char c, ref bool doread)
@@ -795,17 +735,16 @@ namespace Mono.CSharp
                        case ']':
                                return Token.CLOSE_BRACKET;
                        case '(':
-                               if (linq){
+                               if (IsLinqEnabled && !lambda_arguments_parsing) {
+                                       lambda_arguments_parsing = true;
                                        PushPosition ();
-                                       bool have_lambda_parameter = parse_lambda_parameters ();
+                                       bool lambda_start = IsLambdaOpenParens ();
                                        PopPosition ();
-                                       
-                                       if (have_lambda_parameter)
+                                       lambda_arguments_parsing = false;
+                                       if (lambda_start)
                                                return Token.OPEN_PARENS_LAMBDA;
-                                       else
-                                               return Token.OPEN_PARENS;
-                               } else
-                                       return Token.OPEN_PARENS;
+                               }
+                               return Token.OPEN_PARENS;
                        case ')': {
                                if (deambiguate_close_parens == 0)
                                        return Token.CLOSE_PARENS;
@@ -837,6 +776,13 @@ namespace Mono.CSharp
                                val = Location;
                                return Token.TILDE;
                        case '?':
+#if GMCS_SOURCE
+                               d = peek_char ();
+                               if (d == '?') {
+                                       get_char ();
+                                       return Token.OP_COALESCING;
+                               }
+#endif
                                return Token.INTERR;
                        }
 #if GMCS_SOURCE
@@ -865,10 +811,10 @@ namespace Mono.CSharp
                                } else
                                        parsing_generic_less_than = 0;
 
-                               d = peekChar ();
+                               d = peek_char ();
                                if (d == '<'){
-                                       getChar ();
-                                       d = peekChar ();
+                                       get_char ();
+                                       d = peek_char ();
 
                                        if (d == '='){
                                                doread = true;
@@ -886,10 +832,10 @@ namespace Mono.CSharp
                                        return Token.OP_GENERICS_GT;
                                }
 
-                               d = peekChar ();
+                               d = peek_char ();
                                if (d == '>'){
-                                       getChar ();
-                                       d = peekChar ();
+                                       get_char ();
+                                       d = peek_char ();
 
                                        if (d == '='){
                                                doread = true;
@@ -903,7 +849,7 @@ namespace Mono.CSharp
                                return Token.OP_GT;
                        }
 #endif
-                       d = peekChar ();
+                       d = peek_char ();
                        if (c == '+'){
                                
                                if (d == '+') {
@@ -955,6 +901,7 @@ namespace Mono.CSharp
                                        val = Location;
                                        return Token.ARROW;
                                }
+
                                return Token.ASSIGN;
                        }
 
@@ -1017,8 +964,8 @@ namespace Mono.CSharp
 #if !GMCS_SOURCE
                        if (c == '<'){
                                if (d == '<'){
-                                       getChar ();
-                                       d = peekChar ();
+                                       get_char ();
+                                       d = peek_char ();
 
                                        if (d == '='){
                                                doread = true;
@@ -1034,8 +981,8 @@ namespace Mono.CSharp
 
                        if (c == '>'){
                                if (d == '>'){
-                                       getChar ();
-                                       d = peekChar ();
+                                       get_char ();
+                                       d = peek_char ();
 
                                        if (d == '='){
                                                doread = true;
@@ -1086,15 +1033,15 @@ namespace Mono.CSharp
                        }
                        
                        //
-                       // We use peekChar2, because decimal_digits needs to do a 
+                       // We use peek_char2, because decimal_digits needs to do a 
                        // 2-character look-ahead (5.ToString for example).
                        //
-                       while ((d = peekChar2 ()) != -1){
+                       while ((d = peek_char2 ()) != -1){
                                if (d >= '0' && d <= '9'){
                                        if (number_pos == max_number_size)
                                                Error_NumericConstantTooLong ();
                                        number_builder [number_pos++] = (char) d;
-                                       getChar ();
+                                       get_char ();
                                        seen_digits = true;
                                } else
                                        break;
@@ -1141,11 +1088,11 @@ namespace Mono.CSharp
                                                if (is_unsigned)
                                                        scanning = false;
                                                is_unsigned = true;
-                                               getChar ();
+                                               get_char ();
                                                break;
 
                                        case 'l':
-                                               if (!is_unsigned && (RootContext.WarningLevel >= 4)){
+                                               if (!is_unsigned){
                                                        //
                                                        // if we have not seen anything in between
                                                        // report this error
@@ -1160,21 +1107,21 @@ namespace Mono.CSharp
                                                if (is_long)
                                                        scanning = false;
                                                is_long = true;
-                                               getChar ();
+                                               get_char ();
                                                break;
 
                                        case 'L': 
                                                if (is_long)
                                                        scanning = false;
                                                is_long = true;
-                                               getChar ();
+                                               get_char ();
                                                break;
                                                
                                        default:
                                                scanning = false;
                                                break;
                                        }
-                                       c = peekChar ();
+                                       c = peek_char ();
                                } while (scanning);
                        }
 
@@ -1291,11 +1238,11 @@ namespace Mono.CSharp
                        int d;
                        ulong ul;
                        
-                       getChar ();
-                       while ((d = peekChar ()) != -1){
+                       get_char ();
+                       while ((d = peek_char ()) != -1){
                                if (is_hex (d)){
                                        number_builder [number_pos++] = (char) d;
-                                       getChar ();
+                                       get_char ();
                                } else
                                        break;
                        }
@@ -1318,7 +1265,7 @@ namespace Mono.CSharp
                                return Token.LITERAL_INTEGER;
                        }
                        
-                       return integer_type_suffix (ul, peekChar ());
+                       return integer_type_suffix (ul, peek_char ());
                }
 
                //
@@ -1333,13 +1280,13 @@ namespace Mono.CSharp
 
                        if (c >= '0' && c <= '9'){
                                if (c == '0'){
-                                       int peek = peekChar ();
+                                       int peek = peek_char ();
 
                                        if (peek == 'x' || peek == 'X')
                                                return handle_hex ();
                                }
                                decimal_digits (c);
-                               c = getChar ();
+                               c = get_char ();
                        }
 
                        //
@@ -1349,7 +1296,7 @@ namespace Mono.CSharp
                        if (c == '.'){
                                if (decimal_digits ('.')){
                                        is_real = true;
-                                       c = getChar ();
+                                       c = get_char ();
                                } else {
                                        putback ('.');
                                        number_pos--;
@@ -1362,7 +1309,7 @@ namespace Mono.CSharp
                                if (number_pos == max_number_size)
                                        Error_NumericConstantTooLong ();
                                number_builder [number_pos++] = 'e';
-                               c = getChar ();
+                               c = get_char ();
                                
                                if (c == '+'){
                                        if (number_pos == max_number_size)
@@ -1381,7 +1328,7 @@ namespace Mono.CSharp
                                }
                                        
                                decimal_digits (c);
-                               c = getChar ();
+                               c = get_char ();
                        }
 
                        type = real_type_suffix (c);
@@ -1412,10 +1359,10 @@ namespace Mono.CSharp
                        int c;
                        int top = count != -1 ? count : 4;
                        
-                       getChar ();
+                       get_char ();
                        error = false;
                        for (i = 0; i < top; i++){
-                               c = getChar ();
+                               c = get_char ();
                                
                                if (c >= '0' && c <= '9')
                                        c = (int) c - (int) '0';
@@ -1430,7 +1377,7 @@ namespace Mono.CSharp
                                
                                total = (total * 16) + c;
                                if (count == -1){
-                                       int p = peekChar ();
+                                       int p = peek_char ();
                                        if (p == -1)
                                                break;
                                        if (!is_hex ((char)p))
@@ -1446,7 +1393,7 @@ namespace Mono.CSharp
                        int d;
                        int v;
 
-                       d = peekChar ();
+                       d = peek_char ();
                        if (c != '\\')
                                return c;
                        
@@ -1492,11 +1439,11 @@ namespace Mono.CSharp
                                Report.Error (1009, Location, "Unrecognized escape sequence `\\{0}'", ((char)d).ToString ());
                                return d;
                        }
-                       getChar ();
+                       get_char ();
                        return v;
                }
 
-               int getChar ()
+               int get_char ()
                {
                        int x;
                        if (putback_char != -1) {
@@ -1515,7 +1462,7 @@ namespace Mono.CSharp
                        return x;
                }
 
-               int peekChar ()
+               int peek_char ()
                {
                        if (putback_char != -1)
                                return putback_char;
@@ -1523,7 +1470,7 @@ namespace Mono.CSharp
                        return putback_char;
                }
 
-               int peekChar2 ()
+               int peek_char2 ()
                {
                        if (putback_char != -1)
                                return putback_char;
@@ -1552,7 +1499,7 @@ namespace Mono.CSharp
 
                public bool advance ()
                {
-                       return peekChar () != -1;
+                       return peek_char () != -1;
                }
 
                public Object Value {
@@ -1648,13 +1595,13 @@ namespace Mono.CSharp
                        static_cmd_arg.Length = 0;
 
                        // skip over white space
-                       while ((c = getChar ()) != -1 && (c != '\n') && ((c == '\r') || (c == ' ') || (c == '\t')))
+                       while ((c = get_char ()) != -1 && (c != '\n') && ((c == '\r') || (c == ' ') || (c == '\t')))
                                ;
                                
                        while ((c != -1) && (c != '\n') && (c != ' ') && (c != '\t') && (c != '\r')){
                                if (is_identifier_part_character ((char) c)){
                                        static_cmd_arg.Append ((char) c);
-                                       c = getChar ();
+                                       c = get_char ();
                                } else {
                                        putback (c);
                                        break;
@@ -1668,7 +1615,7 @@ namespace Mono.CSharp
                        }
 
                        // skip over white space
-                       while ((c = getChar ()) != -1 && (c != '\n') && ((c == '\r') || (c == ' ') || (c == '\t')))
+                       while ((c = get_char ()) != -1 && (c != '\n') && ((c == '\r') || (c == ' ') || (c == '\t')))
                                ;
 
                        if (c == '\n'){
@@ -1683,7 +1630,7 @@ namespace Mono.CSharp
                        static_cmd_arg.Length = 0;
                        static_cmd_arg.Append ((char) c);
                        
-                       while ((c = getChar ()) != -1 && (c != '\n') && (c != '\r')){
+                       while ((c = get_char ()) != -1 && (c != '\n') && (c != '\r')){
                                static_cmd_arg.Append ((char) c);
                        }
 
@@ -2019,6 +1966,11 @@ namespace Mono.CSharp
                                "Unexpected processor directive (" + extra + ")");
                }
 
+               void Error_TokenExpected (string token)
+               {
+                       Report.Error (1026, Location, "Expecting `{0}'", token);
+               }
+
                void Error_TokensSeen ()
                {
                        Report.Error (1032, Location,
@@ -2245,11 +2197,11 @@ namespace Mono.CSharp
                        int c;
                        string_builder.Length = 0;
                                                                
-                       while ((c = getChar ()) != -1){
+                       while ((c = get_char ()) != -1){
                                if (c == '"'){
-                                       if (quoted && peekChar () == '"'){
+                                       if (quoted && peek_char () == '"'){
                                                string_builder.Append ((char) c);
-                                               getChar ();
+                                               get_char ();
                                                continue;
                                        } else {
                                                val = string_builder.ToString ();
@@ -2288,6 +2240,11 @@ namespace Mono.CSharp
                        }
 
                        if (res == Token.PARTIAL) {
+                               if (parsing_block > 0) {
+                                       val = new LocatedToken (Location, "partial");
+                                       return Token.IDENTIFIER;
+                               }
+
                                // Save current position and parse next token.
                                PushPosition ();
 
@@ -2298,8 +2255,12 @@ namespace Mono.CSharp
 
                                PopPosition ();
 
-                               if (ok)
+                               if (ok) {
+                                       if (RootContext.Version == LanguageVersion.ISO_1)
+                                               Report.FeatureIsNotISO1 (Location, "partial types");
+
                                        return res;
+                               }
 
                                if (next_token < Token.LAST_KEYWORD)
                                        Report.Error (267, Location, "The `partial' modifier can be used only immediately before keyword `class', `struct', or `interface'");
@@ -2320,7 +2281,7 @@ namespace Mono.CSharp
 
                        current_location = new Location (ref_line, Col);
 
-                       while ((c = getChar ()) != -1) {
+                       while ((c = get_char ()) != -1) {
                        loop:
                                if (is_identifier_part_character ((char) c)){
                                        if (pos == max_id_size){
@@ -2362,7 +2323,7 @@ namespace Mono.CSharp
                                if (val != null) {
                                        val = new LocatedToken (Location, (string) val);
                                        if (quoted)
-                                               escapedIdentifiers.Add (val);
+                                               escaped_identifiers.Add (val);
                                        return Token.IDENTIFIER;
                                }
                        }
@@ -2387,7 +2348,7 @@ namespace Mono.CSharp
 
                        val = new LocatedToken (Location, (string) val);
                        if (quoted)
-                               escapedIdentifiers.Add (val);
+                               escaped_identifiers.Add (val);
                        return Token.IDENTIFIER;
                }
                
@@ -2400,18 +2361,18 @@ namespace Mono.CSharp
                        // Whether we have seen comments on the current line
                        bool comments_seen = false;
                        val = null;
-                       for (;(c = getChar ()) != -1;) {
+                       for (;(c = get_char ()) != -1;) {
                                if (c == '\t'){
                                        col = ((col + 8) / 8) * 8;
                                        continue;
                                }
                                
-                               if (c == ' ' || c == '\t' || c == '\f' || c == '\v' || c == 0xa0)
+                               if (c == ' ' || c == '\f' || c == '\v' || c == 0xa0 || c == 0)
                                        continue;
 
                                if (c == '\r') {
-                                       if (peekChar () == '\n')
-                                               getChar ();
+                                       if (peek_char () == '\n')
+                                               get_char ();
 
                                        any_token_seen |= tokens_seen;
                                        tokens_seen = false;
@@ -2421,14 +2382,14 @@ namespace Mono.CSharp
 
                                // Handle double-slash comments.
                                if (c == '/'){
-                                       int d = peekChar ();
+                                       int d = peek_char ();
                                
                                        if (d == '/'){
-                                               getChar ();
-                                               if (RootContext.Documentation != null && peekChar () == '/') {
-                                                       getChar ();
+                                               get_char ();
+                                               if (RootContext.Documentation != null && peek_char () == '/') {
+                                                       get_char ();
                                                        // Don't allow ////.
-                                                       if ((d = peekChar ()) != '/') {
+                                                       if ((d = peek_char ()) != '/') {
                                                                update_comment_location ();
                                                                if (doc_state == XmlCommentState.Allowed)
                                                                        handle_one_line_xml_comment ();
@@ -2436,7 +2397,7 @@ namespace Mono.CSharp
                                                                        warn_incorrect_doc_comment ();
                                                        }
                                                }
-                                               while ((d = getChar ()) != -1 && (d != '\n') && d != '\r')
+                                               while ((d = get_char ()) != -1 && (d != '\n') && d != '\r')
                                                        if (d == '\n'){
                                                        }
                                                any_token_seen |= tokens_seen;
@@ -2444,14 +2405,14 @@ namespace Mono.CSharp
                                                comments_seen = false;
                                                continue;
                                        } else if (d == '*'){
-                                               getChar ();
+                                               get_char ();
                                                bool docAppend = false;
-                                               if (RootContext.Documentation != null && peekChar () == '*') {
-                                                       getChar ();
+                                               if (RootContext.Documentation != null && peek_char () == '*') {
+                                                       get_char ();
                                                        update_comment_location ();
                                                        // But when it is /**/, just do nothing.
-                                                       if (peekChar () == '/') {
-                                                               getChar ();
+                                                       if (peek_char () == '/') {
+                                                               get_char ();
                                                                continue;
                                                        }
                                                        if (doc_state == XmlCommentState.Allowed)
@@ -2468,9 +2429,9 @@ namespace Mono.CSharp
 
                                                Location start_location = Location;
 
-                                               while ((d = getChar ()) != -1){
-                                                       if (d == '*' && peekChar () == '/'){
-                                                               getChar ();
+                                               while ((d = get_char ()) != -1){
+                                                       if (d == '*' && peek_char () == '/'){
+                                                               get_char ();
                                                                comments_seen = true;
                                                                break;
                                                        }
@@ -2508,7 +2469,7 @@ namespace Mono.CSharp
                                if ((t = is_punct ((char)c, ref doread)) != Token.ERROR){
                                        tokens_seen = true;
                                        if (doread){
-                                               getChar ();
+                                               get_char ();
                                        }
                                        return t;
                                }
@@ -2528,7 +2489,7 @@ namespace Mono.CSharp
 
                                if (c == '.'){
                                        tokens_seen = true;
-                                       int peek = peekChar ();
+                                       int peek = peek_char ();
                                        if (peek >= '0' && peek <= '9')
                                                return is_number (c);
                                        return Token.DOT;
@@ -2544,7 +2505,7 @@ namespace Mono.CSharp
                                                continue;
 
                                        bool directive_expected = false;
-                                       while ((c = getChar ()) != -1) {
+                                       while ((c = get_char ()) != -1) {
                                                if (col == 1) {
                                                        directive_expected = true;
                                                } else if (!directive_expected) {
@@ -2578,7 +2539,7 @@ namespace Mono.CSharp
                                        return consume_string (false);
 
                                if (c == '\''){
-                                       c = getChar ();
+                                       c = get_char ();
                                        tokens_seen = true;
                                        if (c == '\''){
                                                error_details = "Empty character literal";
@@ -2594,14 +2555,14 @@ namespace Mono.CSharp
                                                return Token.ERROR;
                                        val = new System.Char ();
                                        val = (char) c;
-                                       c = getChar ();
+                                       c = get_char ();
 
                                        if (c != '\''){
                                                error_details = "Too many characters in character literal";
                                                Report.Error (1012, Location, error_details);
 
                                                // Try to recover, read until newline or next "'"
-                                               while ((c = getChar ()) != -1){
+                                               while ((c = get_char ()) != -1){
                                                        if (c == '\n'){
                                                                break;
                                                        }
@@ -2614,7 +2575,7 @@ namespace Mono.CSharp
                                }
                                
                                if (c == '@') {
-                                       c = getChar ();
+                                       c = get_char ();
                                        if (c == '"') {
                                                tokens_seen = true;
                                                return consume_string (true);
@@ -2639,10 +2600,10 @@ namespace Mono.CSharp
                private void handle_one_line_xml_comment ()
                {
                        int c;
-                       while ((c = peekChar ()) == ' ')
-                               getChar (); // skip heading whitespaces.
-                       while ((c = peekChar ()) != -1 && c != '\n' && c != '\r') {
-                               xml_comment_buffer.Append ((char) getChar ());
+                       while ((c = peek_char ()) == ' ')
+                               get_char (); // skip heading whitespaces.
+                       while ((c = peek_char ()) != -1 && c != '\n' && c != '\r') {
+                               xml_comment_buffer.Append ((char) get_char ());
                        }
                        if (c == '\r' || c == '\n')
                                xml_comment_buffer.Append (Environment.NewLine);