Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: utils/css/tokenkind.dart

Issue 8498020: Beginning of CSS parser using frog parsering infrastructure. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Minor cleanup. Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 // TODO(terry): Need to be consistent with tokens either they're ASCII tokens
6 // e.g., ASTERISK or they're CSS e.g., PSEUDO, COMBINATOR_*.
7 class TokenKind {
8 // Common shared tokens used in TokenizerBase.
9 static final int END_OF_FILE = 0;
10 static final int LPAREN = 1;
11 static final int RPAREN = 2;
12 static final int LBRACK = 3;
13 static final int RBRACK = 4;
14 static final int LBRACE = 5;
15 static final int RBRACE = 6;
16 static final int DOT = 7;
17
18 // Unique tokens for CSS.
19 static final int AT = 8;
20 static final int HASH = 9;
21 static final int COMBINATOR_PLUS = 10;
22 static final int COMBINATOR_GREATER = 11;
23 static final int COMBINATOR_TILDE = 12;
24 static final int ASTERISK = 13;
25 static final int NAMESPACE = 14;
26 static final int PSEUDO = 15;
27 static final int PRIVATE_NAME = 16; // _ prefix private class or id
28 static final int COMMA = 17;
29 static final int SPACE = 18;
30 static final int TAB = 19;
31 static final int NEWLINE = 20;
32 static final int RETURN = 21;
33
34 // WARNING: END_TOKENS must be 1 greater than the last token above (last
35 // character in our list). Also add to kindToString function and the
36 // constructor for TokenKind.
37
38 static final int END_TOKENS = 22; // Marker for last token in list
39
40 // Synthesized Tokens (no character associated with TOKEN).
41 // TODO(terry): Possible common names used by both Dart and CSS tokenizers.
42 static final int STRING = 500;
43 static final int STRING_PART = 501;
44 static final int NUMBER = 502;
45 static final int HEX_NUMBER = 503;
46 static final int WHITESPACE = 504;
47 static final int COMMENT = 505;
48 static final int ERROR = 506;
49 static final int INCOMPLETE_STRING = 507;
50 static final int INCOMPLETE_COMMENT = 508;
51 static final int INCOMPLETE_MULTILINE_STRING_DQ = 509;
52 static final int INCOMPLETE_MULTILINE_STRING_SQ = 510;
53 static final int IDENTIFIER = 511;
54
55 // Uniquely synthesized tokens for CSS.
56 static final int SELECTOR_EXPRESSION = 512;
57 static final int COMBINATOR_NONE = 513;
58 static final int COMBINATOR_DESCENDANT = 514; // Space combinator
59
60 // Attribute match:
61 static final int INCLUDES_MATCH = 515; // ~=
62 static final int DASH_MATCH = 516; // |=
63 static final int PREFIX_MATCH = 517; // ^=
64 static final int SUFFIX_MATCH = 518; // $=
65 static final int STRING_MATCH = 519; // *=
66 static final int EQUAL_MATCH = 520; // =
67
68 // Simple selector type.
69 static final int CLASS_NAME = 700; // .class
70 static final int ELEMENT_NAME = 701; // tagName
71 static final int HASH_NAME = 702; // #elementId
72 static final int ATTRIBUTE_NAME = 703; // [attrib]
73 static final int PSEUDO_ELEMENT_NAME = 704; // ::pseudoElement
74 static final int PSEUDO_CLASS_NAME = 705; // :pseudoClass
75 static final int NEGATION = 706; // NOT
76
77 List<int> tokens;
78
79 static String kindToString(int kind) {
80 switch(kind) {
81 case TokenKind.END_OF_FILE: return "end of file";
82 case TokenKind.LPAREN: return "(";
83 case TokenKind.RPAREN: return ")";
84 case TokenKind.LBRACK: return "[";
85 case TokenKind.RBRACK: return "[";
86 case TokenKind.LBRACE: return "{";
87 case TokenKind.RBRACE: return "}";
88 case TokenKind.DOT: return ".";
89 case TokenKind.AT: return "@";
90 case TokenKind.HASH: return "#";
91 case TokenKind.COMBINATOR_PLUS: return "+";
92 case TokenKind.COMBINATOR_GREATER: return ">";
93 case TokenKind.COMBINATOR_TILDE: return "~";
94 case TokenKind.ASTERISK: return "*";
95 case TokenKind.NAMESPACE: return "|";
96 case TokenKind.PSEUDO: return ":";
97 case TokenKind.PRIVATE_NAME: return "_";
98 case TokenKind.COMMA: return ",";
99 case TokenKind.SPACE: return " ";
100 case TokenKind.TAB: return "\t";
101 case TokenKind.NEWLINE: return "\n";
102 case TokenKind.RETURN: return "\r";
103
104 default:
105 throw "Unknown TOKEN";
106 }
107 }
108
109 TokenKind() {
110 tokens = [];
111
112 // All tokens must be in TokenKind order.
113 tokens.add(0); // TokenKind.END_OF_FILE
114 tokens.add(TokenKind.kindToString(TokenKind.LPAREN).charCodeAt(0));
115 tokens.add(TokenKind.kindToString(TokenKind.RPAREN).charCodeAt(0));
116 tokens.add(TokenKind.kindToString(TokenKind.LBRACK).charCodeAt(0));
117 tokens.add(TokenKind.kindToString(TokenKind.RBRACK).charCodeAt(0));
118 tokens.add(TokenKind.kindToString(TokenKind.LBRACE).charCodeAt(0));
119 tokens.add(TokenKind.kindToString(TokenKind.RBRACE).charCodeAt(0));
120 tokens.add(TokenKind.kindToString(TokenKind.DOT).charCodeAt(0));
121 tokens.add(TokenKind.kindToString(TokenKind.AT).charCodeAt(0));
122 tokens.add(TokenKind.kindToString(TokenKind.HASH).charCodeAt(0));
123 tokens.add(TokenKind.kindToString(TokenKind.COMBINATOR_PLUS).charCodeAt(0));
124 tokens.add(TokenKind.kindToString(TokenKind.COMBINATOR_GREATER).charCodeAt(0 ));
125 tokens.add(TokenKind.kindToString(TokenKind.COMBINATOR_TILDE).charCodeAt(0)) ;
126 tokens.add(TokenKind.kindToString(TokenKind.ASTERISK).charCodeAt(0));
127 tokens.add(TokenKind.kindToString(TokenKind.NAMESPACE).charCodeAt(0));
128 tokens.add(TokenKind.kindToString(TokenKind.PSEUDO).charCodeAt(0));
129 tokens.add(TokenKind.kindToString(TokenKind.PRIVATE_NAME).charCodeAt(0));
130 tokens.add(TokenKind.kindToString(TokenKind.COMMA).charCodeAt(0));
131 tokens.add(TokenKind.kindToString(TokenKind.SPACE).charCodeAt(0));
132 tokens.add(TokenKind.kindToString(TokenKind.TAB).charCodeAt(0));
133 tokens.add(TokenKind.kindToString(TokenKind.NEWLINE).charCodeAt(0));
134 tokens.add(TokenKind.kindToString(TokenKind.RETURN).charCodeAt(0));
135
136 assert(tokens.length == TokenKind.END_TOKENS);
137 }
138
139 static bool isIdentifier(int kind) {
140 return kind == IDENTIFIER ;
141 }
142 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698