| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2015, the Dartino 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 library servicec.scanner; | |
| 6 | |
| 7 import 'package:compiler/src/tokens/token.dart' show | |
| 8 StringToken, | |
| 9 ErrorToken, | |
| 10 KeywordToken, | |
| 11 SymbolToken, | |
| 12 Token, | |
| 13 UnmatchedToken; | |
| 14 | |
| 15 import 'package:compiler/src/tokens/precedence_constants.dart' show | |
| 16 GT_INFO, | |
| 17 EOF_INFO, | |
| 18 IDENTIFIER_INFO, | |
| 19 STRING_INFO; | |
| 20 | |
| 21 import 'package:compiler/src/tokens/precedence.dart' show | |
| 22 PrecedenceInfo; | |
| 23 | |
| 24 import "package:compiler/src/tokens/keyword.dart" show | |
| 25 Keyword; | |
| 26 | |
| 27 import "package:compiler/src/scanner/string_scanner.dart" show | |
| 28 StringScanner; | |
| 29 | |
| 30 import "package:compiler/src/util/characters.dart" show | |
| 31 $LF; | |
| 32 | |
| 33 import "keyword.dart" as own; | |
| 34 | |
| 35 const int LF_TOKEN = $LF; | |
| 36 const PrecedenceInfo LF_INFO = const PrecedenceInfo('<new-line>', 0, LF_TOKEN); | |
| 37 | |
| 38 class Scanner extends StringScanner { | |
| 39 Scanner(String input) | |
| 40 : super.fromString(input); | |
| 41 | |
| 42 void appendKeywordToken(Keyword keyword) { | |
| 43 if (isServicecKeyword(keyword.syntax)) { | |
| 44 super.appendKeywordToken(own.Keyword.keywords[keyword.syntax]); | |
| 45 } else { | |
| 46 super.appendSubstringToken(IDENTIFIER_INFO, | |
| 47 scanOffset - keyword.syntax.length, | |
| 48 true); | |
| 49 } | |
| 50 } | |
| 51 | |
| 52 void appendSubstringToken(PrecedenceInfo info, int start, | |
| 53 bool asciiOnly, [int extraOffset = 0]) { | |
| 54 String syntax = string.substring(start, scanOffset + extraOffset); | |
| 55 if (isServicecKeyword(syntax)) { | |
| 56 Keyword keyword = own.Keyword.keywords[syntax]; | |
| 57 super.appendKeywordToken(keyword); | |
| 58 } else { | |
| 59 super.appendSubstringToken(info, start, asciiOnly, extraOffset); | |
| 60 } | |
| 61 } | |
| 62 | |
| 63 void appendErrorToken(ErrorToken token) { | |
| 64 // Ignore unmatched tokens, since we handle them in a different way. | |
| 65 if (token is! UnmatchedToken) { | |
| 66 super.appendErrorToken(token); | |
| 67 } | |
| 68 } | |
| 69 | |
| 70 void appendGtGt(PrecedenceInfo info) { | |
| 71 // There is no shift operator in the IDL, so treat >> as > >. | |
| 72 appendGt(GT_INFO); | |
| 73 appendGt(GT_INFO); | |
| 74 } | |
| 75 | |
| 76 void appendWhiteSpace(int next) { | |
| 77 super.appendWhiteSpace(next); | |
| 78 if (next == $LF) { | |
| 79 tail.next = new SymbolToken(LF_INFO, stringOffset); | |
| 80 tail = tail.next; | |
| 81 } | |
| 82 } | |
| 83 } | |
| 84 | |
| 85 bool isServicecKeyword(String string) { | |
| 86 return own.Keyword.keywords.containsKey(string); | |
| 87 } | |
| OLD | NEW |