This commit was manufactured by cvs2svn to create branch 'mono-1-0'.
[mono.git] / mcs / gmcs / cs-tokenizer.cs
index 1c58ecb09c0c74d8c44db780a3e8ef743c3641fb..0fdc84b6ce5fe49dc9c9f9832b9d4ac230b0fd3b 100755 (executable)
@@ -1,3 +1,4 @@
+// -*- coding: dos -*-\r
 //\r
 // cs-tokenizer.cs: The Tokenizer for the C# compiler\r
 //                  This also implements the preprocessor\r
@@ -218,6 +219,7 @@ namespace Mono.CSharp
                {\r
                        keywords = new CharArrayHashtable [64];\r
 \r
+                       AddKeyword ("__arglist", Token.ARGLIST);\r
                        AddKeyword ("abstract", Token.ABSTRACT);\r
                        AddKeyword ("as", Token.AS);\r
                        AddKeyword ("add", Token.ADD);\r
@@ -384,14 +386,29 @@ namespace Mono.CSharp
                        identifiers = null;\r
                }\r
 \r
-               bool is_identifier_start_character (char c)\r
+               static bool is_identifier_start_character (char c)\r
                {\r
                        return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_' || Char.IsLetter (c);\r
                }\r
 \r
-               bool is_identifier_part_character (char c)\r
+               static bool is_identifier_part_character (char c)\r
                {\r
                        return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || (c >= '0' && c <= '9') || Char.IsLetter (c);\r
+               }
+               
+               public static bool IsValidIdentifier (string s)
+               {
+                       if (s == null || s.Length == 0)
+                               return false;
+                       
+                       if (!is_identifier_start_character (s [0]))
+                               return false;
+                       
+                       for (int i = 1; i < s.Length; i ++)
+                               if (! is_identifier_part_character (s [i]))
+                                       return false;
+                       
+                       return true;
                }\r
 \r
                bool parse_less_than ()\r
@@ -1204,8 +1221,13 @@ namespace Mono.CSharp
                                ;\r
                                \r
                        while ((c != -1) && (c != '\n') && (c != ' ') && (c != '\t') && (c != '\r')){\r
-                               static_cmd_arg.Append ((char) c);\r
-                                c = getChar ();\r
+                               if (is_identifier_part_character ((char) c)){\r
+                                       static_cmd_arg.Append ((char) c);\r
+                                       c = getChar ();\r
+                               } else {\r
+                                       putback (c);\r
+                                       break;\r
+                               }\r
                        }\r
 \r
                        cmd = static_cmd_arg.ToString ();\r
@@ -1773,7 +1795,7 @@ namespace Mono.CSharp
                        // Optimization: avoids doing the keyword lookup\r
                        // on uppercase letters and _\r
                        //\r
-                       if (s >= 'a'){\r
+                       if (s >= 'a' || s == '_'){\r
                                int keyword = GetKeyword (id_builder, pos);\r
                                if (keyword != -1 && !quoted)\r
                                return keyword;\r