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

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: Incorporated Jim's CR 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;
nweiz 2011/11/10 00:04:40 I don't like how some of these token names encode
terry 2011/11/22 16:40:47 You have a valid point I'll clean this up next che
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
28 // WARNING: END_TOKENS must match above token number (last character in our
29 // list). Also add to kindToString function and the constructor
30 // for TokenKind.
31
32 static final int END_TOKENS = 17; // Marker for last token in list
33
34 // Synthesized Tokens (no character associated with TOKEN).
35 // TODO(terry): Possible common names used by both Dart and CSS tokenizers.
36 static final int STRING = 500;
37 static final int STRING_PART = 501;
38 static final int NUMBER = 502;
39 static final int HEX_NUMBER = 503;
40 static final int WHITESPACE = 504;
41 static final int COMMENT = 505;
42 static final int ERROR = 506;
43 static final int INCOMPLETE_STRING = 507;
44 static final int INCOMPLETE_COMMENT = 508;
45 static final int INCOMPLETE_MULTILINE_STRING_DQ = 509;
nweiz 2011/11/10 00:04:40 Unused constants
terry 2011/11/22 16:40:47 I think I'll be using these soon enough. On 2011/1
46 static final int INCOMPLETE_MULTILINE_STRING_SQ = 510;
47 static final int IDENTIFIER = 511;
48
49 // Uniquely synthesized tokens for CSS.
50 static final int SELECTOR_EXPRESSION = 512;
51 static final int COMBINATOR_NONE = 513;
52
53 // Attribute match:
54 static final int INCLUDES_MATCH = 514; // ~=
55 static final int DASH_MATCH = 515; // |=
56 static final int PREFIX_MATCH = 516; // ^=
57 static final int SUFFIX_MATCH = 517; // $=
58 static final int STRING_MATCH = 518; // *=
59 static final int EQUAL_MATCH = 519; // =
60
61 // Simple selector type.
62 static final int CLASS_NAME = 700; // .class
63 static final int ELEMENT_NAME = 701; // tagName
64 static final int HASH_NAME = 702; // #elementId
65 static final int ATTRIBUTE_NAME = 703; // [attrib]
66 static final int PSEUDO_ELEMENT_NAME = 704; // ::pseudoElement
67 static final int PSEUDO_CLASS_NAME = 705; // :pseudoClass
68 static final int NEGATION = 706; // NOT
69
70 List<int> tokens;
71
72 static String kindToString(int kind) {
73 switch(kind) {
74 case TokenKind.END_OF_FILE: return "end of file";
75 case TokenKind.LPAREN: return "(";
76 case TokenKind.RPAREN: return ")";
77 case TokenKind.LBRACK: return "[";
78 case TokenKind.RBRACK: return "[";
79 case TokenKind.LBRACE: return "{";
80 case TokenKind.RBRACE: return "}";
81 case TokenKind.DOT: return ".";
82 case TokenKind.AT: return "@";
83 case TokenKind.HASH: return "#";
84 case TokenKind.COMBINATOR_PLUS: return "+";
85 case TokenKind.COMBINATOR_GREATER: return ">";
86 case TokenKind.COMBINATOR_TILDE: return "~";
87 case TokenKind.ASTERISK: return "*";
88 case TokenKind.NAMESPACE: return "|";
89 case TokenKind.PSEUDO: return ":";
90 case TokenKind.PRIVATE_NAME: return "_";
91 case TokenKind.COMMA: return ",";
92 default:
93 throw "Unknown TOKEN";
94 }
95 }
96
97 TokenKind() {
nweiz 2011/11/10 00:04:40 Why is this a class that gets instantiated? Wouldn
terry 2011/11/22 16:40:47 For now I'm trying to mimic frog w/o the Python cl
98 tokens = [];
99
100 // All tokens must be in TokenKind order.
101 tokens.add(0); // TokenKind.END_OF_FILE
102 tokens.add(TokenKind.kindToString(TokenKind.LPAREN).charCodeAt(0));
103 tokens.add(TokenKind.kindToString(TokenKind.RPAREN).charCodeAt(0));
104 tokens.add(TokenKind.kindToString(TokenKind.LBRACK).charCodeAt(0));
105 tokens.add(TokenKind.kindToString(TokenKind.RBRACK).charCodeAt(0));
106 tokens.add(TokenKind.kindToString(TokenKind.LBRACE).charCodeAt(0));
107 tokens.add(TokenKind.kindToString(TokenKind.RBRACE).charCodeAt(0));
108 tokens.add(TokenKind.kindToString(TokenKind.DOT).charCodeAt(0));
109 tokens.add(TokenKind.kindToString(TokenKind.AT).charCodeAt(0));
110 tokens.add(TokenKind.kindToString(TokenKind.HASH).charCodeAt(0));
111 tokens.add(TokenKind.kindToString(TokenKind.COMBINATOR_PLUS).charCodeAt(0));
112 tokens.add(TokenKind.kindToString(TokenKind.COMBINATOR_GREATER).charCodeAt(0 ));
113 tokens.add(TokenKind.kindToString(TokenKind.COMBINATOR_TILDE).charCodeAt(0)) ;
114 tokens.add(TokenKind.kindToString(TokenKind.ASTERISK).charCodeAt(0));
115 tokens.add(TokenKind.kindToString(TokenKind.NAMESPACE).charCodeAt(0));
116 tokens.add(TokenKind.kindToString(TokenKind.PSEUDO).charCodeAt(0));
117 tokens.add(TokenKind.kindToString(TokenKind.PRIVATE_NAME).charCodeAt(0));
118 tokens.add(TokenKind.kindToString(TokenKind.COMMA).charCodeAt(0));
119
120 assert(tokens.length == TokenKind.END_TOKENS);
121 }
122
123 static bool isIdentifier(int kind) {
124 return kind == IDENTIFIER ;
125 }
126 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698