| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 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 | 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 class ArrayBasedScanner<S extends SourceString> extends AbstractScanner<S> { | 5 class ArrayBasedScanner<S extends SourceString> extends AbstractScanner<S> { |
| 6 int get charOffset => byteOffset + extraCharOffset; | 6 int get charOffset => byteOffset + extraCharOffset; |
| 7 final Token tokens; | 7 final Token tokens; |
| 8 Token tail; | 8 Token tail; |
| 9 int tokenStart; | 9 int tokenStart; |
| 10 int byteOffset; | 10 int byteOffset; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 tail.next = new KeywordToken(keyword, tokenStart); | 57 tail.next = new KeywordToken(keyword, tokenStart); |
| 58 tail = tail.next; | 58 tail = tail.next; |
| 59 } | 59 } |
| 60 | 60 |
| 61 void appendEofToken() { | 61 void appendEofToken() { |
| 62 tail.next = new Token(EOF_INFO, charOffset); | 62 tail.next = new Token(EOF_INFO, charOffset); |
| 63 tail = tail.next; | 63 tail = tail.next; |
| 64 // EOF points to itself so there's always infinite look-ahead. | 64 // EOF points to itself so there's always infinite look-ahead. |
| 65 tail.next = tail; | 65 tail.next = tail; |
| 66 discardOpenLt(); | 66 discardOpenLt(); |
| 67 if (!groupingStack.isEmpty()) { | 67 while (!groupingStack.isEmpty()) { |
| 68 BeginGroupToken begin = groupingStack.head; | 68 BeginGroupToken begin = groupingStack.head; |
| 69 throw new MalformedInputException('Unbalanced ${begin.stringValue}', | 69 begin.endGroup = tail; |
| 70 begin); | 70 groupingStack = groupingStack.tail; |
| 71 } | 71 } |
| 72 } | 72 } |
| 73 | 73 |
| 74 void beginToken() { | 74 void beginToken() { |
| 75 tokenStart = charOffset; | 75 tokenStart = charOffset; |
| 76 } | 76 } |
| 77 | 77 |
| 78 Token firstToken() { | 78 Token firstToken() { |
| 79 return tokens.next; | 79 return tokens.next; |
| 80 } | 80 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 104 appendStringToken(info, value); | 104 appendStringToken(info, value); |
| 105 discardOpenLt(); | 105 discardOpenLt(); |
| 106 if (groupingStack.isEmpty()) { | 106 if (groupingStack.isEmpty()) { |
| 107 return advance(); | 107 return advance(); |
| 108 } | 108 } |
| 109 BeginGroupToken begin = groupingStack.head; | 109 BeginGroupToken begin = groupingStack.head; |
| 110 if (begin.kind !== openKind) { | 110 if (begin.kind !== openKind) { |
| 111 if (openKind !== OPEN_CURLY_BRACKET_TOKEN || | 111 if (openKind !== OPEN_CURLY_BRACKET_TOKEN || |
| 112 begin.kind !== STRING_INTERPOLATION_TOKEN) { | 112 begin.kind !== STRING_INTERPOLATION_TOKEN) { |
| 113 // Not ending string interpolation. | 113 // Not ending string interpolation. |
| 114 throw new MalformedInputException('Unmatched ${begin.stringValue}', | 114 return error(new SourceString('Unmatched ${begin.stringValue}')); |
| 115 begin); | |
| 116 } | 115 } |
| 117 // We're ending an interpolated expression. | 116 // We're ending an interpolated expression. |
| 118 begin.endGroup = tail; | 117 begin.endGroup = tail; |
| 119 groupingStack = groupingStack.tail; | 118 groupingStack = groupingStack.tail; |
| 120 // Using "start-of-text" to signal that we're back in string | 119 // Using "start-of-text" to signal that we're back in string |
| 121 // scanning mode. | 120 // scanning mode. |
| 122 return $STX; | 121 return $STX; |
| 123 } | 122 } |
| 124 begin.endGroup = tail; | 123 begin.endGroup = tail; |
| 125 groupingStack = groupingStack.tail; | 124 groupingStack = groupingStack.tail; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 | 172 |
| 174 void discardOpenLt() { | 173 void discardOpenLt() { |
| 175 while (!groupingStack.isEmpty() && groupingStack.head.kind === LT_TOKEN) { | 174 while (!groupingStack.isEmpty() && groupingStack.head.kind === LT_TOKEN) { |
| 176 groupingStack = groupingStack.tail; | 175 groupingStack = groupingStack.tail; |
| 177 } | 176 } |
| 178 } | 177 } |
| 179 | 178 |
| 180 // TODO(ahe): make class abstract instead of adding an abstract method. | 179 // TODO(ahe): make class abstract instead of adding an abstract method. |
| 181 abstract peek(); | 180 abstract peek(); |
| 182 } | 181 } |
| OLD | NEW |