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

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: Added Jim's CR comments and updated tests. Created 9 years, 1 month 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 class TokenKind {
6 // Common shared tokens used in TokenizerBase.
7 static final int END_OF_FILE = 0;
8 static final int LPAREN = 1;
9 static final int RPAREN = 2;
10 static final int LBRACK = 3;
11 static final int RBRACK = 4;
12 static final int LBRACE = 5;
13 static final int RBRACE = 6;
14 static final int DOT = 7;
15
16 // Unique tokens for CSS.
17 static final int AT = 8;
18 static final int HASH = 9;
19 static final int COMBINATOR_PLUS = 10;
20 static final int COMBINATOR_GREATER = 11;
21 static final int COMBINATOR_TILDE = 12;
22 static final int ASTERISK = 13;
23 static final int NAMESPACE = 14;
24 static final int PSEUDO = 15;
25 static final int PRIVATE_NAME = 16; // _ prefix private class or id
26 static final int COMMA = 17;
27 static final int SPACE = 18;
28 static final int TAB = 19;
29 static final int NEWLINE = 20;
30 static final int RETURN = 21;
31
32 // WARNING: END_TOKENS must match above token number (last character in our
33 // list). Also add to kindToString function and the constructor
34 // for TokenKind.
35
36 static final int END_TOKENS = 21; // Marker for last token in list
37
38 // Synthesized Tokens (no character associated with TOKEN).
39 // TODO(terry): Possible common names used by both Dart and CSS tokenizers.
40 static final int STRING = 500;
41 static final int STRING_PART = 501;
42 static final int NUMBER = 502;
43 static final int HEX_NUMBER = 503;
44 static final int WHITESPACE = 504;
45 static final int COMMENT = 505;
46 static final int ERROR = 506;
47 static final int INCOMPLETE_STRING = 507;
48 static final int INCOMPLETE_COMMENT = 508;
49 static final int INCOMPLETE_MULTILINE_STRING_DQ = 509;
50 static final int INCOMPLETE_MULTILINE_STRING_SQ = 510;
51 static final int IDENTIFIER = 511;
52
53 // Uniquely synthesized tokens for CSS.
54 static final int SELECTOR_EXPRESSION = 512;
55 static final int COMBINATOR_NONE = 513;
56
57 // Attribute match:
58 static final int INCLUDES_MATCH = 514; // ~=
59 static final int DASH_MATCH = 515; // |=
60 static final int PREFIX_MATCH = 516; // ^=
61 static final int SUFFIX_MATCH = 517; // $=
62 static final int STRING_MATCH = 518; // *=
63 static final int EQUAL_MATCH = 519; // =
64
65 // Simple selector type.
66 static final int CLASS_NAME = 700; // .class
67 static final int ELEMENT_NAME = 701; // tagName
68 static final int HASH_NAME = 702; // #elementId
69 static final int ATTRIBUTE_NAME = 703; // [attrib]
70 static final int PSEUDO_ELEMENT_NAME = 704; // ::pseudoElement
71 static final int PSEUDO_CLASS_NAME = 705; // :pseudoClass
72 static final int NEGATION = 706; // NOT
73
74 List<int> tokens;
75
76 static String kindToString(int kind) {
77 switch(kind) {
78 case TokenKind.END_OF_FILE: return "end of file";
79 case TokenKind.LPAREN: return "(";
80 case TokenKind.RPAREN: return ")";
81 case TokenKind.LBRACK: return "[";
82 case TokenKind.RBRACK: return "[";
83 case TokenKind.LBRACE: return "{";
84 case TokenKind.RBRACE: return "}";
85 case TokenKind.DOT: return ".";
86 case TokenKind.AT: return "@";
87 case TokenKind.HASH: return "#";
88 case TokenKind.COMBINATOR_PLUS: return "+";
89 case TokenKind.COMBINATOR_GREATER: return ">";
90 case TokenKind.COMBINATOR_TILDE: return "~";
91 case TokenKind.ASTERISK: return "*";
92 case TokenKind.NAMESPACE: return "|";
93 case TokenKind.PSEUDO: return ":";
94 case TokenKind.PRIVATE_NAME: return "_";
95 case TokenKind.COMMA: return ",";
96 case TokenKind.SPACE: return " ";
97 case TokenKind.TAB: return "\t";
98 case TokenKind.NEWLINE: return "\n";
99 case TokenKind.RETURN: return "\r";
100
101 default:
102 throw "Unknown TOKEN";
103 }
104 }
105
106 TokenKind() {
107 tokens = [];
108
109 // All tokens must be in TokenKind order.
110 tokens.add(0); // TokenKind.END_OF_FILE
111 tokens.add(TokenKind.kindToString(TokenKind.LPAREN).charCodeAt(0));
112 tokens.add(TokenKind.kindToString(TokenKind.RPAREN).charCodeAt(0));
113 tokens.add(TokenKind.kindToString(TokenKind.LBRACK).charCodeAt(0));
114 tokens.add(TokenKind.kindToString(TokenKind.RBRACK).charCodeAt(0));
115 tokens.add(TokenKind.kindToString(TokenKind.LBRACE).charCodeAt(0));
116 tokens.add(TokenKind.kindToString(TokenKind.RBRACE).charCodeAt(0));
117 tokens.add(TokenKind.kindToString(TokenKind.DOT).charCodeAt(0));
118 tokens.add(TokenKind.kindToString(TokenKind.AT).charCodeAt(0));
119 tokens.add(TokenKind.kindToString(TokenKind.HASH).charCodeAt(0));
120 tokens.add(TokenKind.kindToString(TokenKind.COMBINATOR_PLUS).charCodeAt(0));
121 tokens.add(TokenKind.kindToString(TokenKind.COMBINATOR_GREATER).charCodeAt(0 ));
122 tokens.add(TokenKind.kindToString(TokenKind.COMBINATOR_TILDE).charCodeAt(0)) ;
123 tokens.add(TokenKind.kindToString(TokenKind.ASTERISK).charCodeAt(0));
124 tokens.add(TokenKind.kindToString(TokenKind.NAMESPACE).charCodeAt(0));
125 tokens.add(TokenKind.kindToString(TokenKind.PSEUDO).charCodeAt(0));
126 tokens.add(TokenKind.kindToString(TokenKind.PRIVATE_NAME).charCodeAt(0));
127 tokens.add(TokenKind.kindToString(TokenKind.COMMA).charCodeAt(0));
128 tokens.add(TokenKind.kindToString(TokenKind.SPACE).charCodeAt(0));
129 tokens.add(TokenKind.kindToString(TokenKind.TAB).charCodeAt(0));
130 tokens.add(TokenKind.kindToString(TokenKind.NEWLINE).charCodeAt(0));
131 tokens.add(TokenKind.kindToString(TokenKind.RETURN).charCodeAt(0));
132
133 assert(tokens.length == TokenKind.END_TOKENS);
134 }
135
136 static bool isIdentifier(int kind) {
137 return kind == IDENTIFIER ;
138 }
139 }
OLDNEW
« utils/css/test.dart ('K') | « utils/css/tokenizer.dart ('k') | utils/css/tree.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698