| OLD | NEW |
| 1 part of dart; | 1 part of petitparser.dart; |
| 2 | 2 |
| 3 /** | 3 /// Dart grammar. |
| 4 * Dart grammar. | |
| 5 */ | |
| 6 class DartGrammar extends GrammarParser { | 4 class DartGrammar extends GrammarParser { |
| 7 DartGrammar() : super(new DartGrammarDefinition()); | 5 DartGrammar() : super(new DartGrammarDefinition()); |
| 8 } | 6 } |
| 9 | 7 |
| 10 /** | 8 /// Dart grammar definition. |
| 11 * Dart grammar definition. | |
| 12 * | |
| 13 * Adapted from [https://code.google.com/p/dart/source/browse/branches/bleeding_
edge/dart/language/grammar/Dart.g]. | |
| 14 */ | |
| 15 class DartGrammarDefinition extends GrammarDefinition { | 9 class DartGrammarDefinition extends GrammarDefinition { |
| 16 | 10 |
| 17 Parser token(input) { | 11 Parser token(input) { |
| 18 if (input is String) { | 12 if (input is String) { |
| 19 input = input.length == 1 ? char(input) : string(input); | 13 input = input.length == 1 ? char(input) : string(input); |
| 20 } else if (input is Function) { | 14 } else if (input is Function) { |
| 21 input = ref(input); | 15 input = ref(input); |
| 22 } | 16 } |
| 23 if (input is! Parser && input is TrimmingParser) { | 17 if (input is! Parser && input is TrimmingParser) { |
| 24 throw new StateError('Invalid token parser: $input'); | 18 throw new StateError('Invalid token parser: $input'); |
| 25 } | 19 } |
| 26 return input.token().trim(ref(HIDDEN)); | 20 return input.token().trim(ref(HIDDEN_STUFF)); |
| 27 } | 21 } |
| 28 | 22 |
| 29 | 23 |
| 30 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 24 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 31 // for details. All rights reserved. Use of this source code is governed by a | 25 // for details. All rights reserved. Use of this source code is governed by a |
| 32 // BSD-style license that can be found in the LICENSE file. | 26 // BSD-style license that can be found in the LICENSE file. |
| 33 | 27 |
| 34 // ----------------------------------------------------------------- | 28 // ----------------------------------------------------------------- |
| 35 // Keyword definitions. | 29 // Keyword definitions. |
| 36 // ----------------------------------------------------------------- | 30 // ----------------------------------------------------------------- |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 | 133 |
| 140 // A method, operator, or constructor (which all should be followed by | 134 // A method, operator, or constructor (which all should be followed by |
| 141 // a block of code). | 135 // a block of code). |
| 142 methodDeclaration() => | 136 methodDeclaration() => |
| 143 ref(factoryConstructorDeclaration) | 137 ref(factoryConstructorDeclaration) |
| 144 | ref(STATIC) & ref(functionDeclaration) | 138 | ref(STATIC) & ref(functionDeclaration) |
| 145 | ref(specialSignatureDefinition) | 139 | ref(specialSignatureDefinition) |
| 146 | ref(functionDeclaration) & ref(initializers).optional() | 140 | ref(functionDeclaration) & ref(initializers).optional() |
| 147 | ref(namedConstructorDeclaration) & ref(initializers).optional(); | 141 | ref(namedConstructorDeclaration) & ref(initializers).optional(); |
| 148 | 142 |
| 149 // An abstract method/operator, a field, or const constructor (which | 143 // An abstract method/operator, a field, or const constructor (which |
| 150 // all should be followed by a semicolon). | 144 // all should be followed by a semicolon). |
| 151 declaration() => | 145 declaration() => |
| 152 ref(constantConstructorDeclaration) & (ref(redirection) | ref(initialize
rs)).optional() | 146 ref(constantConstructorDeclaration) & (ref(redirection) | ref(initialize
rs)).optional() |
| 153 | ref(functionDeclaration) & ref(redirection) | 147 | ref(functionDeclaration) & ref(redirection) |
| 154 | ref(namedConstructorDeclaration) & ref(redirection) | 148 | ref(namedConstructorDeclaration) & ref(redirection) |
| 155 | ref(ABSTRACT) & ref(specialSignatureDefinition) | 149 | ref(ABSTRACT) & ref(specialSignatureDefinition) |
| 156 | ref(ABSTRACT) & ref(functionDeclaration) | 150 | ref(ABSTRACT) & ref(functionDeclaration) |
| 157 | ref(STATIC) & ref(FINAL) & ref(type).optional() & ref(staticFinalDeclara
tionList) | 151 | ref(STATIC) & ref(FINAL) & ref(type).optional() & ref(staticFinalDeclara
tionList) |
| 158 | ref(STATIC).optional() & ref(constInitializedVariableDeclaration); | 152 | ref(STATIC).optional() & ref(constInitializedVariableDeclaration); |
| 159 | 153 |
| 160 initializers() => ref(token, ':') & ref(superCallOrFieldInitializer) & (ref(to
ken, ',') & ref(superCallOrFieldInitializer)).star(); | 154 initializers() => ref(token, ':') & ref(superCallOrFieldInitializer) & (ref(to
ken, ',') & ref(superCallOrFieldInitializer)).star(); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 | 232 |
| 239 assignmentOperator() => | 233 assignmentOperator() => |
| 240 ref(token, '=') | 234 ref(token, '=') |
| 241 | ref(token, '*=') | 235 | ref(token, '*=') |
| 242 | ref(token, '/=') | 236 | ref(token, '/=') |
| 243 | ref(token, '~/=') | 237 | ref(token, '~/=') |
| 244 | ref(token, '%=') | 238 | ref(token, '%=') |
| 245 | ref(token, '+=') | 239 | ref(token, '+=') |
| 246 | ref(token, '-=') | 240 | ref(token, '-=') |
| 247 | ref(token, '<<=') | 241 | ref(token, '<<=') |
| 248 | ref(token, '>') & ref(token, '>') & ref(token, '>') & ref(token, '=') | 242 | ref(token, '>>>=') |
| 249 | ref(token, '>') & ref(token, '>') & ref(token, '=') | 243 | ref(token, '>>=') |
| 250 | ref(token, '&=') | 244 | ref(token, '&=') |
| 251 | ref(token, '^=') | 245 | ref(token, '^=') |
| 252 | ref(token, '|='); | 246 | ref(token, '|='); |
| 253 | 247 |
| 254 additiveOperator() => | 248 additiveOperator() => |
| 255 ref(token, '+') | 249 ref(token, '+') |
| 256 | ref(token, '-'); | 250 | ref(token, '-'); |
| 257 | 251 |
| 258 incrementOperator() => | 252 incrementOperator() => |
| 259 ref(token, '++') | 253 ref(token, '++') |
| 260 | ref(token, '--'); | 254 | ref(token, '--'); |
| 261 | 255 |
| 262 shiftOperator() => | 256 shiftOperator() => |
| 263 ref(token, '<<') | 257 ref(token, '<<') |
| 264 | ref(token, '>') & ref(token, '>') & ref(token, '>') | 258 | ref(token, '>>>') |
| 265 | ref(token, '>') & ref(token, '>'); | 259 | ref(token, '>>'); |
| 266 | 260 |
| 267 relationalOperator() => | 261 relationalOperator() => |
| 268 ref(token, '>') & ref(token, '=') | 262 ref(token, '>=') |
| 269 | ref(token, '>') | 263 | ref(token, '>') |
| 270 | ref(token, '<=') | 264 | ref(token, '<=') |
| 271 | ref(token, '<'); | 265 | ref(token, '<'); |
| 272 | 266 |
| 273 equalityOperator() => | 267 equalityOperator() => |
| 274 ref(token, '==') | 268 ref(token, '===') |
| 275 | ref(token, '!=') | 269 | ref(token, '!==') |
| 276 | ref(token, '===') | 270 | ref(token, '==') |
| 277 | ref(token, '!=='); | 271 | ref(token, '!='); |
| 278 | 272 |
| 279 bitwiseOperator() => | 273 bitwiseOperator() => |
| 280 ref(token, '&') | 274 ref(token, '&') |
| 281 | ref(token, '^') | 275 | ref(token, '^') |
| 282 | ref(token, '|'); | 276 | ref(token, '|'); |
| 283 | 277 |
| 284 formalParameterList() => | 278 formalParameterList() => |
| 285 ref(token, '(') & ref(namedFormalParameters).optional() & ref(token, ')'
) | 279 ref(token, '(') & ref(namedFormalParameters).optional() & ref(token, ')'
) |
| 286 | ref(token, '(') & ref(normalFormalParameter) & ref(normalFormalParameter
Tail).optional() & ref(token, ')'); | 280 | ref(token, '(') & ref(normalFormalParameter) & ref(normalFormalParameter
Tail).optional() & ref(token, ')'); |
| 287 | 281 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 // We have to introduce a separate rule for 'declared' identifiers to | 314 // We have to introduce a separate rule for 'declared' identifiers to |
| 321 // allow ANTLR to decide if the first identifier we encounter after | 315 // allow ANTLR to decide if the first identifier we encounter after |
| 322 // final is a type or an identifier. Before this change, we used the | 316 // final is a type or an identifier. Before this change, we used the |
| 323 // production 'finalVarOrType identifier' in numerous places. | 317 // production 'finalVarOrType identifier' in numerous places. |
| 324 declaredIdentifier() => | 318 declaredIdentifier() => |
| 325 ref(FINAL) & ref(type).optional() & ref(identifier) | 319 ref(FINAL) & ref(type).optional() & ref(identifier) |
| 326 | ref(VAR) & ref(identifier) | 320 | ref(VAR) & ref(identifier) |
| 327 | ref(type) & ref(identifier) | 321 | ref(type) & ref(identifier) |
| 328 ; | 322 ; |
| 329 | 323 |
| 330 identifier() => ref(token, ref(IDENTIFIER) | 324 identifier() => ref(token, ref(IDENTIFIER)); |
| 331 | ref(ABSTRACT) | |
| 332 | ref(ASSERT) | |
| 333 | ref(CLASS) | |
| 334 | ref(EXTENDS) | |
| 335 | ref(FACTORY) | |
| 336 | ref(GET) | |
| 337 | ref(IMPLEMENTS) | |
| 338 | ref(IMPORT) | |
| 339 | ref(INTERFACE) | |
| 340 | ref(IS) | |
| 341 | ref(LIBRARY) | |
| 342 | ref(NATIVE) | |
| 343 | ref(NEGATE) | |
| 344 | ref(OPERATOR) | |
| 345 | ref(SET) | |
| 346 | ref(SOURCE) | |
| 347 | ref(STATIC) | |
| 348 | ref(TYPEDEF) | |
| 349 ); | |
| 350 | 325 |
| 351 qualified() => | 326 qualified() => |
| 352 ref(identifier) & (ref(token, '.') & ref(identifier)).optional() | 327 ref(identifier) & (ref(token, '.') & ref(identifier)).optional() |
| 353 ; | 328 ; |
| 354 | 329 |
| 355 type() => | 330 type() => |
| 356 ref(qualified) & ref(typeArguments).optional() | 331 ref(qualified) & ref(typeArguments).optional() |
| 357 ; | 332 ; |
| 358 | 333 |
| 359 typeArguments() => | 334 typeArguments() => |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 SINGLE_LINE_COMMENT() => string('//') | 754 SINGLE_LINE_COMMENT() => string('//') |
| 780 & ref(NEWLINE).neg().star() | 755 & ref(NEWLINE).neg().star() |
| 781 & ref(NEWLINE).optional() | 756 & ref(NEWLINE).optional() |
| 782 ; | 757 ; |
| 783 | 758 |
| 784 MULTI_LINE_COMMENT() => string('/*') | 759 MULTI_LINE_COMMENT() => string('/*') |
| 785 & (ref(MULTI_LINE_COMMENT) | string('*/').neg()).star() & string('*/') | 760 & (ref(MULTI_LINE_COMMENT) | string('*/').neg()).star() & string('*/') |
| 786 ; | 761 ; |
| 787 | 762 |
| 788 } | 763 } |
| OLD | NEW |