mirror of
https://github.com/dart-lang/sdk
synced 2024-09-20 23:41:18 +00:00
change "deferred" keyword isPseudo --> isBuiltIn
Fix https://github.com/dart-lang/sdk/issues/29069 R=ahe@google.com, paulberry@google.com Review-Url: https://codereview.chromium.org/2769253002 .
This commit is contained in:
parent
0fcb91aa06
commit
05300ea2df
|
@ -72,7 +72,7 @@ class Keyword implements analyzer.Keyword {
|
|||
|
||||
static const ASYNC = const Keyword("async", isPseudo: true);
|
||||
static const AWAIT = const Keyword("await", isPseudo: true);
|
||||
static const DEFERRED = const Keyword("deferred", isPseudo: true);
|
||||
static const DEFERRED = const Keyword("deferred", isBuiltIn: true);
|
||||
static const FUNCTION = const Keyword("Function", isPseudo: true);
|
||||
static const HIDE = const Keyword("hide", isPseudo: true);
|
||||
static const NATIVE = const Keyword("native", isPseudo: true);
|
||||
|
@ -123,6 +123,7 @@ class Keyword implements analyzer.Keyword {
|
|||
ABSTRACT,
|
||||
AS,
|
||||
COVARIANT,
|
||||
DEFERRED,
|
||||
DYNAMIC,
|
||||
EXPORT,
|
||||
EXTERNAL,
|
||||
|
@ -139,7 +140,6 @@ class Keyword implements analyzer.Keyword {
|
|||
// ==== Pseudo
|
||||
ASYNC,
|
||||
AWAIT,
|
||||
DEFERRED,
|
||||
FUNCTION,
|
||||
HIDE,
|
||||
NATIVE,
|
||||
|
@ -178,16 +178,13 @@ class Keyword implements analyzer.Keyword {
|
|||
|
||||
String toString() => syntax;
|
||||
|
||||
/// The term "pseudo-keyword" doesn't exist in the spec, and
|
||||
/// Analyzer and Fasta have different notions of what it means.
|
||||
/// Analyzer's notion of "pseudo-keyword" corresponds with Fasta's
|
||||
/// notion of "built-in keyword".
|
||||
/// Use [isBuiltIn] instead.
|
||||
@override
|
||||
bool get isPseudoKeyword {
|
||||
// The term "pseudo-keyword" doesn't exist in the spec, and
|
||||
// Analyzer and Fasta have different notions of what it means.
|
||||
// Analyzer's notion of "pseudo-keyword" corresponds with Fasta's
|
||||
// notion of "built-in keyword".
|
||||
|
||||
// TODO(danrubel) remove `this == DEFERRED` once dartbug.com/29069 is fixed.
|
||||
return isBuiltIn || this == DEFERRED;
|
||||
}
|
||||
bool get isPseudoKeyword => isBuiltIn;
|
||||
|
||||
@override
|
||||
String get name => syntax.toUpperCase();
|
||||
|
|
|
@ -317,11 +317,7 @@ class KeywordToken extends Token {
|
|||
|
||||
bool get isPseudo => keyword.isPseudo;
|
||||
|
||||
bool get isBuiltInIdentifier {
|
||||
// TODO(ahe): Remove special case for "deferred" once dartbug.com/29069 is
|
||||
// fixed.
|
||||
return keyword.isBuiltIn || identical("deferred", lexeme);
|
||||
}
|
||||
bool get isBuiltInIdentifier => keyword.isBuiltIn;
|
||||
|
||||
String toString() => "KeywordToken($lexeme)";
|
||||
|
||||
|
@ -329,22 +325,12 @@ class KeywordToken extends Token {
|
|||
Token copyWithoutComments() => new KeywordToken(keyword, charOffset);
|
||||
|
||||
@override
|
||||
Object value() {
|
||||
// Analyzer has different set of keyword tokens
|
||||
// TODO(danrubel): Remove special case for "deferred" once dartbug.com/29069
|
||||
// is fixed.
|
||||
return isPseudo && !identical("deferred", lexeme) ? lexeme : keyword;
|
||||
}
|
||||
// Analyzer considers pseudo-keywords to have a different value
|
||||
Object value() => isPseudo ? lexeme : keyword;
|
||||
|
||||
@override
|
||||
analyzer.TokenType get type {
|
||||
// Analyzer considers pseudo-keywords to be identifiers
|
||||
// TODO(danrubel): Remove special case for "deferred" once dartbug.com/29069
|
||||
// is fixed.
|
||||
return isPseudo && !identical("deferred", lexeme)
|
||||
? IDENTIFIER_INFO
|
||||
: KEYWORD_INFO;
|
||||
}
|
||||
// Analyzer considers pseudo-keywords to be identifiers
|
||||
analyzer.TokenType get type => isPseudo ? IDENTIFIER_INFO : KEYWORD_INFO;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -73,32 +73,6 @@ class ScannerTest_RoundTrip extends ScannerTest {
|
|||
// syntax.
|
||||
super.test_comment_generic_method_type_list();
|
||||
}
|
||||
|
||||
void test_pseudo_keywords() {
|
||||
var pseudoAnalyzerKeywords = new Set<Keyword>.from([
|
||||
Keyword.ABSTRACT,
|
||||
Keyword.AS,
|
||||
Keyword.COVARIANT,
|
||||
Keyword.DEFERRED,
|
||||
Keyword.DYNAMIC,
|
||||
Keyword.EXPORT,
|
||||
Keyword.EXTERNAL,
|
||||
Keyword.FACTORY,
|
||||
Keyword.GET,
|
||||
Keyword.IMPLEMENTS,
|
||||
Keyword.IMPORT,
|
||||
Keyword.LIBRARY,
|
||||
Keyword.OPERATOR,
|
||||
Keyword.PART,
|
||||
Keyword.SET,
|
||||
Keyword.STATIC,
|
||||
Keyword.TYPEDEF,
|
||||
]);
|
||||
for (Keyword keyword in Keyword.values) {
|
||||
expect(keyword.isPseudoKeyword, pseudoAnalyzerKeywords.contains(keyword),
|
||||
reason: keyword.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class TestScanner extends analyzer.Scanner {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:front_end/src/fasta/scanner/string_scanner.dart';
|
||||
import 'package:front_end/src/fasta/scanner/keyword.dart' as fasta;
|
||||
import 'package:front_end/src/fasta/scanner/token.dart' as fasta;
|
||||
import 'package:front_end/src/scanner/token.dart';
|
||||
import 'package:front_end/src/scanner/reader.dart' as analyzer;
|
||||
|
@ -154,6 +155,60 @@ class Foo {
|
|||
expect(token.matchesAny([TokenType.AMPERSAND]), false);
|
||||
}
|
||||
|
||||
/// Return all fasta and all analyzer keywords
|
||||
List<Keyword> get _allKeywords =>
|
||||
new List.from(Keyword.values)..addAll(fasta.Keyword.values);
|
||||
|
||||
void test_built_in_keywords() {
|
||||
var builtInKeywords = new Set<Keyword>.from([
|
||||
Keyword.ABSTRACT,
|
||||
Keyword.AS,
|
||||
Keyword.COVARIANT,
|
||||
Keyword.DEFERRED,
|
||||
Keyword.DYNAMIC,
|
||||
Keyword.EXPORT,
|
||||
Keyword.EXTERNAL,
|
||||
Keyword.FACTORY,
|
||||
Keyword.GET,
|
||||
Keyword.IMPLEMENTS,
|
||||
Keyword.IMPORT,
|
||||
Keyword.LIBRARY,
|
||||
Keyword.OPERATOR,
|
||||
Keyword.PART,
|
||||
Keyword.SET,
|
||||
Keyword.STATIC,
|
||||
Keyword.TYPEDEF,
|
||||
]);
|
||||
for (Keyword keyword in _allKeywords) {
|
||||
var isBuiltIn = builtInKeywords.contains(keyword);
|
||||
expect(keyword.isPseudoKeyword, isBuiltIn, reason: keyword.name);
|
||||
expect((keyword as fasta.Keyword).isBuiltIn, isBuiltIn,
|
||||
reason: keyword.name);
|
||||
}
|
||||
}
|
||||
|
||||
void test_pseudo_keywords() {
|
||||
var pseudoKeywords = new Set<Keyword>.from([
|
||||
fasta.Keyword.ASYNC,
|
||||
fasta.Keyword.AWAIT,
|
||||
fasta.Keyword.FUNCTION,
|
||||
fasta.Keyword.HIDE,
|
||||
fasta.Keyword.NATIVE,
|
||||
fasta.Keyword.OF,
|
||||
fasta.Keyword.ON,
|
||||
fasta.Keyword.PATCH,
|
||||
fasta.Keyword.SHOW,
|
||||
fasta.Keyword.SOURCE,
|
||||
fasta.Keyword.SYNC,
|
||||
fasta.Keyword.YIELD,
|
||||
]);
|
||||
for (Keyword keyword in _allKeywords) {
|
||||
var isPseudo = pseudoKeywords.contains(keyword);
|
||||
expect((keyword as fasta.Keyword).isPseudo, isPseudo,
|
||||
reason: keyword.name);
|
||||
}
|
||||
}
|
||||
|
||||
void test_value() {
|
||||
var scanner = new StringScanner('true & "home"', includeComments: true);
|
||||
var token = scanner.tokenize();
|
||||
|
@ -166,7 +221,6 @@ class Foo {
|
|||
expect(token.value(), '&');
|
||||
// String tokens
|
||||
token = token.next;
|
||||
print('String token :: ${token.runtimeType}');
|
||||
expect(token.lexeme, '"home"');
|
||||
expect(token.value(), '"home"');
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue