3 using System.Globalization;
7 public class EcmaUrlTokenizer : yyParser.yyInput
9 const char EndOfStream = (char)0;
17 public EcmaUrlTokenizer (string input)
22 static bool is_identifier_start_character (char c)
24 return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || Char.IsLetter (c);
27 static bool is_identifier_part_character (char c)
29 if (c >= 'a' && c <= 'z')
32 if (c >= 'A' && c <= 'Z')
35 if (c == '_' || (c >= '0' && c <= '9'))
41 return Char.IsLetter (c) || Char.GetUnicodeCategory (c) == UnicodeCategory.ConnectorPunctuation;
44 public bool advance ()
46 return Peek () != EndOfStream;
55 public Object value ()
62 int token = xtoken ();
63 //Console.WriteLine ("Current token {0} with value {1}", token, val == null ? "(none)" : val.ToString ());
64 if (token == Token.ERROR) {
65 throw new Exception (string.Format ("Error at position {0} parsing url '{0}'", current_pos, input));
67 current_token = token;
74 while (char.IsWhiteSpace (next))
86 return Token.OP_GENERICS_LT;
89 return Token.OP_GENERICS_GT;
91 return Token.OP_GENERICS_BACKTICK;
93 return Token.OP_OPEN_PAREN;
95 return Token.OP_CLOSE_PAREN;
97 return Token.INNER_TYPE_SEPARATOR;
101 return Token.SLASH_SEPARATOR;
103 return Token.OP_ARRAY_OPEN;
105 return Token.OP_ARRAY_CLOSE;
109 return Token.REF_ARG;
111 return Token.OUT_ARG;
113 return Token.EXPLICIT_IMPL_SEP;
115 return TokenizeIdentifierOrNumber (next);
119 int TokenizeIdentifierOrNumber (char current)
121 // We must first return the expression type which is a uppercase letter and a colon
122 if (current_pos < 2) {
127 if (is_identifier_start_character (current) || current == '*') {
129 // identifier length is artificially limited to 1024 bytes by implementations
130 char* pIdent = stackalloc char[512];
135 while ((peek = Peek ()) != EndOfStream && is_identifier_part_character (peek)) {
136 *(pIdent + identCount) = Read ();
141 val = new string ((char*)pIdent, 0, identCount);
142 return Token.IDENTIFIER;
144 } else if (char.IsDigit (current)) {
156 return input[real_current_pos++];
165 return input[real_current_pos];