77f7b64611
includeComments option argument added to the ByteArrayScanner. default is false. Test of charOffset, charLength invariants on scanner output added. Calls to beginToken() moved to fix invalid Token.charOffset values for string interpolations. BUG= TEST= Review URL: https://chromiumcodereview.appspot.com//10539021 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@9059 260f80e4-7a28-3924-810f-c04153c831b5
39 lines
1.2 KiB
Dart
39 lines
1.2 KiB
Dart
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
/**
|
|
* Scanner that reads from a byte array and creates tokens that points
|
|
* to the same array.
|
|
*/
|
|
class ByteArrayScanner extends ArrayBasedScanner<ByteString> {
|
|
final List<int> bytes;
|
|
|
|
ByteArrayScanner(List<int> this.bytes, [bool includeComments = false])
|
|
: super(includeComments);
|
|
|
|
int nextByte() => byteAt(++byteOffset);
|
|
|
|
int peek() => byteAt(byteOffset + 1);
|
|
|
|
int byteAt(int index) => bytes[index];
|
|
|
|
AsciiString asciiString(int start, int offset) {
|
|
return AsciiString.of(bytes, start, byteOffset - start + offset);
|
|
}
|
|
|
|
Utf8String utf8String(int start, int offset) {
|
|
return Utf8String.of(bytes, start, byteOffset - start + offset + 1);
|
|
}
|
|
|
|
void appendByteStringToken(PrecedenceInfo info, ByteString value) {
|
|
tail.next = new ByteStringToken(info, value, tokenStart);
|
|
tail = tail.next;
|
|
}
|
|
|
|
// This method should be equivalent to the one in super. However,
|
|
// this is a *HOT* method and Dart VM performs better if it is easy
|
|
// to inline.
|
|
int advance() => bytes[++byteOffset];
|
|
}
|