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

Side by Side Diff: frog/css/tokenizer_css.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: 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 Tokenizer extends TokenizerBase {
jimhug 2011/11/09 16:04:03 It's weird to me that the file is tokenizer_css bu
terry 2011/11/09 21:56:06 Done.
6 TokenKind cssTokens;
7
8 Tokenizer(SourceFile source, bool skipWhitespace, [int index = 0])
9 : super(source, skipWhitespace, index) {
10 cssTokens = new TokenKind();
11 }
12
13 Token next() {
14 // keep track of our starting position
15 _startIndex = _index;
16
17 if (_interpStack != null && _interpStack.depth == 0) {
nweiz 2011/11/10 00:04:39 Unused code
terry 2011/11/22 16:40:47 I expect to be using this in next checkin. On 2011
18 var istack = _interpStack;
19 _interpStack = _interpStack.pop();
20 /*
21 if (istack.isMultiline) {
22 return finishMultilineStringBody(istack.quote);
23 } else {
24 return finishStringBody(istack.quote);
25 }
26 */
27 }
28
29 int ch;
30 ch = _nextChar();
31 switch(ch) {
32 case 0:
33 return _finishToken(TokenKind.END_OF_FILE);
34 case TokenizerHelpers.WS_SPACE:
35 case TokenizerHelpers.WS_TAB:
36 case TokenizerHelpers.WS_NEWLINE:
37 case TokenizerHelpers.WS_RETURN:
38 return finishWhitespace();
39 case cssTokens.tokens[TokenKind.END_OF_FILE]:
40 return _finishToken(TokenKind.END_OF_FILE);
41 case cssTokens.tokens[TokenKind.AT]:
42 return _finishToken(TokenKind.AT);
43 case cssTokens.tokens[TokenKind.DOT]:
44 return _finishToken(TokenKind.DOT);
45 case cssTokens.tokens[TokenKind.LBRACE]:
46 return _finishToken(TokenKind.LBRACE);
47 case cssTokens.tokens[TokenKind.RBRACE]:
48 return _finishToken(TokenKind.RBRACE);
49 case cssTokens.tokens[TokenKind.HASH]:
50 return _finishToken(TokenKind.HASH);
51 case cssTokens.tokens[TokenKind.COMBINATOR_PLUS]:
52 return _finishToken(TokenKind.COMBINATOR_PLUS);
53 case cssTokens.tokens[TokenKind.COMBINATOR_GREATER]:
54 return _finishToken(TokenKind.COMBINATOR_GREATER);
55 case cssTokens.tokens[TokenKind.COMBINATOR_TILDE]:
56 return _finishToken(TokenKind.COMBINATOR_TILDE);
57 case cssTokens.tokens[TokenKind.ASTERISK]:
58 return _finishToken(TokenKind.ASTERISK);
59 case cssTokens.tokens[TokenKind.NAMESPACE]:
60 return _finishToken(TokenKind.NAMESPACE);
61 case cssTokens.tokens[TokenKind.PSEUDO]:
62 return _finishToken(TokenKind.PSEUDO);
63 case cssTokens.tokens[TokenKind.COMMA]:
64 return _finishToken(TokenKind.COMMA);
65
66 default:
67 if (isIdentifierStart(ch)) {
68 return this.finishIdentifier();
69 } else if (isDigit(ch)) {
70 return this.finishNumber();
71 } else {
72 return _errorToken();
73 }
74 }
75 }
76
77 // TODO(jmesserly): we need a way to emit human readable error messages from
78 // the tokenizer.
79 Token _errorToken() {
80 return _finishToken(TokenKind.ERROR);
81 }
82
83 int getIdentifierKind() {
nweiz 2011/11/10 00:04:39 Not useful, remove
terry 2011/11/22 16:40:47 This will be used real soon with other known ident
84 return TokenKind.IDENTIFIER;
85 }
86 }
87
88 /** Static helper methods. */
89 class TokenizerHelpers {
90 final static int WS_SPACE = 32; // ' '
91 final static int WS_TAB = 9; // '\t'
92 final static int WS_NEWLINE = 10; // '\n'
93 final static int WS_RETURN = 13; // '\r'
94
95 static bool isIdentifierStart(int c) {
96 return ((c >= 97/*a*/ && c <= 122/*z*/) || (c >= 65/*A*/ && c <= 90/*Z*/) || c == 95/*_*/);
nweiz 2011/11/10 00:04:39 Line length (also below)
terry 2011/11/22 16:40:47 Done.
97 }
98
99 static bool isDigit(int c) {
100 return (c >= 48/*0*/ && c <= 57/*9*/);
101 }
102
103 static bool isHexDigit(int c) {
104 return (isDigit(c) || (c >= 97/*a*/ && c <= 102/*f*/) || (c >= 65/*A*/ && c <= 70/*F*/));
105 }
106
107 static bool isWhitespace(int c) {
108 return (c == 32/*' '*/ || c == 9/*'\t'*/ || c == 10/*'\n'*/ || c == 13/*'\r' */);
109 }
110
111 static bool isIdentifierPart(int c) {
112 return (isIdentifierStart(c) || isDigit(c) || c == 45/*-*/);
113 }
114 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698