OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library polymer_expressions.tokenizer; | 5 library polymer_expressions.tokenizer; |
6 | 6 |
7 const int _TAB = 9; | 7 const int _TAB = 9; |
8 const int _LF = 10; | 8 const int _LF = 10; |
9 const int _VTAB = 11; | 9 const int _VTAB = 11; |
10 const int _FF = 12; | 10 const int _FF = 12; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 | 52 |
53 const _OPERATORS = const [_PLUS, _MINUS, _STAR, _SLASH, _BANG, _AMPERSAND, | 53 const _OPERATORS = const [_PLUS, _MINUS, _STAR, _SLASH, _BANG, _AMPERSAND, |
54 _PERCENT, _LT, _EQ, _GT, _QUESTION, _CARET, _BAR]; | 54 _PERCENT, _LT, _EQ, _GT, _QUESTION, _CARET, _BAR]; |
55 | 55 |
56 const _GROUPERS = const [_OPEN_PAREN, _CLOSE_PAREN, | 56 const _GROUPERS = const [_OPEN_PAREN, _CLOSE_PAREN, |
57 _OPEN_SQUARE_BRACKET, _CLOSE_SQUARE_BRACKET, | 57 _OPEN_SQUARE_BRACKET, _CLOSE_SQUARE_BRACKET, |
58 _OPEN_CURLY_BRACKET, _CLOSE_CURLY_BRACKET]; | 58 _OPEN_CURLY_BRACKET, _CLOSE_CURLY_BRACKET]; |
59 | 59 |
60 const _TWO_CHAR_OPS = const ['==', '!=', '<=', '>=', '||', '&&']; | 60 const _TWO_CHAR_OPS = const ['==', '!=', '<=', '>=', '||', '&&']; |
61 | 61 |
62 const _KEYWORDS = const ['in', 'this']; | 62 const KEYWORDS = const ['as', 'in', 'this']; |
63 | 63 |
64 const _PRECEDENCE = const { | 64 const _PRECEDENCE = const { |
65 '!': 0, | 65 '!': 0, |
66 ':': 0, | 66 ':': 0, |
67 ',': 0, | 67 ',': 0, |
68 ')': 0, | 68 ')': 0, |
69 ']': 0, | 69 ']': 0, |
70 '}': 0, // ? | 70 '}': 0, // ? |
71 '?': 1, | 71 '?': 1, |
72 '||': 2, | 72 '||': 2, |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 _sb.clear(); | 211 _sb.clear(); |
212 _advance(); | 212 _advance(); |
213 } | 213 } |
214 | 214 |
215 tokenizeIdentifierOrKeyword() { | 215 tokenizeIdentifierOrKeyword() { |
216 while (_next != null && isIdentifier(_next)) { | 216 while (_next != null && isIdentifier(_next)) { |
217 _sb.writeCharCode(_next); | 217 _sb.writeCharCode(_next); |
218 _advance(); | 218 _advance(); |
219 } | 219 } |
220 var value = _sb.toString(); | 220 var value = _sb.toString(); |
221 if (_KEYWORDS.contains(value)) { | 221 if (KEYWORDS.contains(value)) { |
222 _tokens.add(new Token(KEYWORD_TOKEN, value)); | 222 _tokens.add(new Token(KEYWORD_TOKEN, value)); |
223 } else { | 223 } else { |
224 _tokens.add(new Token(IDENTIFIER_TOKEN, value)); | 224 _tokens.add(new Token(IDENTIFIER_TOKEN, value)); |
225 } | 225 } |
226 _sb.clear(); | 226 _sb.clear(); |
227 } | 227 } |
228 | 228 |
229 tokenizeNumber() { | 229 tokenizeNumber() { |
230 while (_next != null && isNumber(_next)) { | 230 while (_next != null && isNumber(_next)) { |
231 _sb.writeCharCode(_next); | 231 _sb.writeCharCode(_next); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 _tokens.add(new Token(GROUPER_TOKEN, value, _PRECEDENCE[value])); | 292 _tokens.add(new Token(GROUPER_TOKEN, value, _PRECEDENCE[value])); |
293 _advance(); | 293 _advance(); |
294 } | 294 } |
295 } | 295 } |
296 | 296 |
297 class ParseException implements Exception { | 297 class ParseException implements Exception { |
298 final String message; | 298 final String message; |
299 ParseException(this.message); | 299 ParseException(this.message); |
300 String toString() => "ParseException: $message"; | 300 String toString() => "ParseException: $message"; |
301 } | 301 } |
OLD | NEW |