mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 15:17:07 +00:00
[parser] Replace isBuiltIn and isPseudo (and implicit isReserved) with explicit enum
Change-Id: I1e77e97989b931160bf98c99272e0a016920b8cf Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/145801 Commit-Queue: Jens Johansen <jensj@google.com> Reviewed-by: Johnni Winther <johnniwinther@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
59e54abb0e
commit
15acf8a51f
2 changed files with 148 additions and 132 deletions
|
@ -3083,8 +3083,7 @@ class Parser {
|
|||
|
||||
bool isReservedKeyword(Token token) {
|
||||
if (!token.isKeyword) return false;
|
||||
Keyword keyword = token.type;
|
||||
return keyword.isReservedWord;
|
||||
return token.type.isReservedWord;
|
||||
}
|
||||
|
||||
bool indicatesMethodOrField(Token token) {
|
||||
|
|
|
@ -119,210 +119,226 @@ class DocumentationCommentToken extends CommentToken {
|
|||
CommentToken copy() => new DocumentationCommentToken(type, _value, offset);
|
||||
}
|
||||
|
||||
enum KeywordStyle {
|
||||
reserved,
|
||||
builtIn,
|
||||
pseudo,
|
||||
}
|
||||
|
||||
/**
|
||||
* The keywords in the Dart programming language.
|
||||
*
|
||||
* Clients may not extend, implement or mix-in this class.
|
||||
*/
|
||||
class Keyword extends TokenType {
|
||||
static const Keyword ABSTRACT =
|
||||
const Keyword("abstract", "ABSTRACT", isBuiltIn: true, isModifier: true);
|
||||
static const Keyword ABSTRACT = const Keyword(
|
||||
"abstract", "ABSTRACT", KeywordStyle.builtIn,
|
||||
isModifier: true);
|
||||
|
||||
static const Keyword AS = const Keyword("as", "AS",
|
||||
precedence: RELATIONAL_PRECEDENCE, isBuiltIn: true);
|
||||
static const Keyword AS = const Keyword("as", "AS", KeywordStyle.builtIn,
|
||||
precedence: RELATIONAL_PRECEDENCE);
|
||||
|
||||
// Reserved Word.
|
||||
static const Keyword ASSERT = const Keyword("assert", "ASSERT");
|
||||
static const Keyword ASSERT =
|
||||
const Keyword("assert", "ASSERT", KeywordStyle.reserved);
|
||||
|
||||
static const Keyword ASYNC = const Keyword("async", "ASYNC", isPseudo: true);
|
||||
static const Keyword ASYNC =
|
||||
const Keyword("async", "ASYNC", KeywordStyle.pseudo);
|
||||
|
||||
static const Keyword AWAIT = const Keyword("await", "AWAIT", isPseudo: true);
|
||||
static const Keyword AWAIT =
|
||||
const Keyword("await", "AWAIT", KeywordStyle.pseudo);
|
||||
|
||||
// Reserved Word.
|
||||
static const Keyword BREAK = const Keyword("break", "BREAK");
|
||||
static const Keyword BREAK =
|
||||
const Keyword("break", "BREAK", KeywordStyle.reserved);
|
||||
|
||||
// Reserved Word.
|
||||
static const Keyword CASE = const Keyword("case", "CASE");
|
||||
static const Keyword CASE =
|
||||
const Keyword("case", "CASE", KeywordStyle.reserved);
|
||||
|
||||
// Reserved Word.
|
||||
static const Keyword CATCH = const Keyword("catch", "CATCH");
|
||||
static const Keyword CATCH =
|
||||
const Keyword("catch", "CATCH", KeywordStyle.reserved);
|
||||
|
||||
// Reserved Word.
|
||||
static const Keyword CLASS =
|
||||
const Keyword("class", "CLASS", isTopLevelKeyword: true);
|
||||
static const Keyword CLASS = const Keyword(
|
||||
"class", "CLASS", KeywordStyle.reserved,
|
||||
isTopLevelKeyword: true);
|
||||
|
||||
// Reserved Word.
|
||||
static const Keyword CONST =
|
||||
const Keyword("const", "CONST", isModifier: true);
|
||||
const Keyword("const", "CONST", KeywordStyle.reserved, isModifier: true);
|
||||
|
||||
// Reserved Word.
|
||||
static const Keyword CONTINUE = const Keyword("continue", "CONTINUE");
|
||||
static const Keyword CONTINUE =
|
||||
const Keyword("continue", "CONTINUE", KeywordStyle.reserved);
|
||||
|
||||
static const Keyword COVARIANT = const Keyword("covariant", "COVARIANT",
|
||||
isBuiltIn: true, isModifier: true);
|
||||
static const Keyword COVARIANT = const Keyword(
|
||||
"covariant", "COVARIANT", KeywordStyle.builtIn,
|
||||
isModifier: true);
|
||||
|
||||
// Reserved Word.
|
||||
static const Keyword DEFAULT = const Keyword("default", "DEFAULT");
|
||||
static const Keyword DEFAULT =
|
||||
const Keyword("default", "DEFAULT", KeywordStyle.reserved);
|
||||
|
||||
static const Keyword DEFERRED =
|
||||
const Keyword("deferred", "DEFERRED", isBuiltIn: true);
|
||||
const Keyword("deferred", "DEFERRED", KeywordStyle.builtIn);
|
||||
|
||||
// Reserved Word.
|
||||
static const Keyword DO = const Keyword("do", "DO");
|
||||
static const Keyword DO = const Keyword("do", "DO", KeywordStyle.reserved);
|
||||
|
||||
static const Keyword DYNAMIC =
|
||||
const Keyword("dynamic", "DYNAMIC", isBuiltIn: true);
|
||||
const Keyword("dynamic", "DYNAMIC", KeywordStyle.builtIn);
|
||||
|
||||
// Reserved Word.
|
||||
static const Keyword ELSE = const Keyword("else", "ELSE");
|
||||
static const Keyword ELSE =
|
||||
const Keyword("else", "ELSE", KeywordStyle.reserved);
|
||||
|
||||
// Reserved Word.
|
||||
static const Keyword ENUM =
|
||||
const Keyword("enum", "ENUM", isTopLevelKeyword: true);
|
||||
static const Keyword ENUM = const Keyword(
|
||||
"enum", "ENUM", KeywordStyle.reserved,
|
||||
isTopLevelKeyword: true);
|
||||
|
||||
static const Keyword EXPORT = const Keyword("export", "EXPORT",
|
||||
isBuiltIn: true, isTopLevelKeyword: true);
|
||||
static const Keyword EXPORT = const Keyword(
|
||||
"export", "EXPORT", KeywordStyle.builtIn,
|
||||
isTopLevelKeyword: true);
|
||||
|
||||
// Reserved Word.
|
||||
static const Keyword EXTENDS = const Keyword("extends", "EXTENDS");
|
||||
static const Keyword EXTENDS =
|
||||
const Keyword("extends", "EXTENDS", KeywordStyle.reserved);
|
||||
|
||||
static const Keyword EXTENSION = const Keyword("extension", "EXTENSION",
|
||||
isBuiltIn: true, isTopLevelKeyword: true);
|
||||
static const Keyword EXTENSION = const Keyword(
|
||||
"extension", "EXTENSION", KeywordStyle.builtIn,
|
||||
isTopLevelKeyword: true);
|
||||
|
||||
static const Keyword EXTERNAL =
|
||||
const Keyword("external", "EXTERNAL", isBuiltIn: true, isModifier: true);
|
||||
static const Keyword EXTERNAL = const Keyword(
|
||||
"external", "EXTERNAL", KeywordStyle.builtIn,
|
||||
isModifier: true);
|
||||
|
||||
static const Keyword FACTORY =
|
||||
const Keyword("factory", "FACTORY", isBuiltIn: true);
|
||||
const Keyword("factory", "FACTORY", KeywordStyle.builtIn);
|
||||
|
||||
// Reserved Word.
|
||||
static const Keyword FALSE = const Keyword("false", "FALSE");
|
||||
static const Keyword FALSE =
|
||||
const Keyword("false", "FALSE", KeywordStyle.reserved);
|
||||
|
||||
// Reserved Word.
|
||||
static const Keyword FINAL =
|
||||
const Keyword("final", "FINAL", isModifier: true);
|
||||
const Keyword("final", "FINAL", KeywordStyle.reserved, isModifier: true);
|
||||
|
||||
// Reserved Word.
|
||||
static const Keyword FINALLY = const Keyword("finally", "FINALLY");
|
||||
static const Keyword FINALLY =
|
||||
const Keyword("finally", "FINALLY", KeywordStyle.reserved);
|
||||
|
||||
// Reserved Word.
|
||||
static const Keyword FOR = const Keyword("for", "FOR");
|
||||
static const Keyword FOR = const Keyword("for", "FOR", KeywordStyle.reserved);
|
||||
|
||||
static const Keyword FUNCTION =
|
||||
const Keyword("Function", "FUNCTION", isPseudo: true);
|
||||
const Keyword("Function", "FUNCTION", KeywordStyle.pseudo);
|
||||
|
||||
static const Keyword GET = const Keyword("get", "GET", isBuiltIn: true);
|
||||
static const Keyword GET = const Keyword("get", "GET", KeywordStyle.builtIn);
|
||||
|
||||
static const Keyword HIDE = const Keyword("hide", "HIDE", isPseudo: true);
|
||||
static const Keyword HIDE =
|
||||
const Keyword("hide", "HIDE", KeywordStyle.pseudo);
|
||||
|
||||
// Reserved Word.
|
||||
static const Keyword IF = const Keyword("if", "IF");
|
||||
static const Keyword IF = const Keyword("if", "IF", KeywordStyle.reserved);
|
||||
|
||||
static const Keyword IMPLEMENTS =
|
||||
const Keyword("implements", "IMPLEMENTS", isBuiltIn: true);
|
||||
const Keyword("implements", "IMPLEMENTS", KeywordStyle.builtIn);
|
||||
|
||||
static const Keyword IMPORT = const Keyword("import", "IMPORT",
|
||||
isBuiltIn: true, isTopLevelKeyword: true);
|
||||
static const Keyword IMPORT = const Keyword(
|
||||
"import", "IMPORT", KeywordStyle.builtIn,
|
||||
isTopLevelKeyword: true);
|
||||
|
||||
// Reserved Word.
|
||||
static const Keyword IN = const Keyword("in", "IN");
|
||||
static const Keyword IN = const Keyword("in", "IN", KeywordStyle.reserved);
|
||||
|
||||
static const Keyword INOUT = const Keyword("inout", "INOUT", isPseudo: true);
|
||||
static const Keyword INOUT =
|
||||
const Keyword("inout", "INOUT", KeywordStyle.pseudo);
|
||||
|
||||
static const Keyword INTERFACE =
|
||||
const Keyword("interface", "INTERFACE", isBuiltIn: true);
|
||||
const Keyword("interface", "INTERFACE", KeywordStyle.builtIn);
|
||||
|
||||
// Reserved Word.
|
||||
static const Keyword IS =
|
||||
const Keyword("is", "IS", precedence: RELATIONAL_PRECEDENCE);
|
||||
static const Keyword IS = const Keyword("is", "IS", KeywordStyle.reserved,
|
||||
precedence: RELATIONAL_PRECEDENCE);
|
||||
|
||||
static const Keyword LATE =
|
||||
const Keyword("late", "LATE", isModifier: true, isBuiltIn: true);
|
||||
const Keyword("late", "LATE", KeywordStyle.builtIn, isModifier: true);
|
||||
|
||||
static const Keyword LIBRARY = const Keyword("library", "LIBRARY",
|
||||
isBuiltIn: true, isTopLevelKeyword: true);
|
||||
static const Keyword LIBRARY = const Keyword(
|
||||
"library", "LIBRARY", KeywordStyle.builtIn,
|
||||
isTopLevelKeyword: true);
|
||||
|
||||
static const Keyword MIXIN =
|
||||
const Keyword("mixin", "MIXIN", isBuiltIn: true, isTopLevelKeyword: true);
|
||||
static const Keyword MIXIN = const Keyword(
|
||||
"mixin", "MIXIN", KeywordStyle.builtIn,
|
||||
isTopLevelKeyword: true);
|
||||
|
||||
static const Keyword NATIVE =
|
||||
const Keyword("native", "NATIVE", isPseudo: true);
|
||||
const Keyword("native", "NATIVE", KeywordStyle.pseudo);
|
||||
|
||||
// Reserved Word.
|
||||
static const Keyword NEW = const Keyword("new", "NEW");
|
||||
static const Keyword NEW = const Keyword("new", "NEW", KeywordStyle.reserved);
|
||||
|
||||
// Reserved Word.
|
||||
static const Keyword NULL = const Keyword("null", "NULL");
|
||||
static const Keyword NULL =
|
||||
const Keyword("null", "NULL", KeywordStyle.reserved);
|
||||
|
||||
static const Keyword OF = const Keyword("of", "OF", isPseudo: true);
|
||||
static const Keyword OF = const Keyword("of", "OF", KeywordStyle.pseudo);
|
||||
|
||||
static const Keyword ON = const Keyword("on", "ON", isPseudo: true);
|
||||
static const Keyword ON = const Keyword("on", "ON", KeywordStyle.pseudo);
|
||||
|
||||
static const Keyword OPERATOR =
|
||||
const Keyword("operator", "OPERATOR", isBuiltIn: true);
|
||||
const Keyword("operator", "OPERATOR", KeywordStyle.builtIn);
|
||||
|
||||
static const Keyword OUT = const Keyword("out", "OUT", isPseudo: true);
|
||||
static const Keyword OUT = const Keyword("out", "OUT", KeywordStyle.pseudo);
|
||||
|
||||
static const Keyword PART =
|
||||
const Keyword("part", "PART", isBuiltIn: true, isTopLevelKeyword: true);
|
||||
static const Keyword PART = const Keyword(
|
||||
"part", "PART", KeywordStyle.builtIn,
|
||||
isTopLevelKeyword: true);
|
||||
|
||||
static const Keyword PATCH = const Keyword("patch", "PATCH", isPseudo: true);
|
||||
static const Keyword PATCH =
|
||||
const Keyword("patch", "PATCH", KeywordStyle.pseudo);
|
||||
|
||||
static const Keyword REQUIRED =
|
||||
const Keyword("required", "REQUIRED", isBuiltIn: true, isModifier: true);
|
||||
static const Keyword REQUIRED = const Keyword(
|
||||
"required", "REQUIRED", KeywordStyle.builtIn,
|
||||
isModifier: true);
|
||||
|
||||
// Reserved Word.
|
||||
static const Keyword RETHROW = const Keyword("rethrow", "RETHROW");
|
||||
static const Keyword RETHROW =
|
||||
const Keyword("rethrow", "RETHROW", KeywordStyle.reserved);
|
||||
|
||||
// Reserved Word.
|
||||
static const Keyword RETURN = const Keyword("return", "RETURN");
|
||||
static const Keyword RETURN =
|
||||
const Keyword("return", "RETURN", KeywordStyle.reserved);
|
||||
|
||||
static const Keyword SET = const Keyword("set", "SET", isBuiltIn: true);
|
||||
static const Keyword SET = const Keyword("set", "SET", KeywordStyle.builtIn);
|
||||
|
||||
static const Keyword SHOW = const Keyword("show", "SHOW", isPseudo: true);
|
||||
static const Keyword SHOW =
|
||||
const Keyword("show", "SHOW", KeywordStyle.pseudo);
|
||||
|
||||
static const Keyword SOURCE =
|
||||
const Keyword("source", "SOURCE", isPseudo: true);
|
||||
const Keyword("source", "SOURCE", KeywordStyle.pseudo);
|
||||
|
||||
static const Keyword STATIC =
|
||||
const Keyword("static", "STATIC", isBuiltIn: true, isModifier: true);
|
||||
const Keyword("static", "STATIC", KeywordStyle.builtIn, isModifier: true);
|
||||
|
||||
// Reserved Word.
|
||||
static const Keyword SUPER = const Keyword("super", "SUPER");
|
||||
static const Keyword SUPER =
|
||||
const Keyword("super", "SUPER", KeywordStyle.reserved);
|
||||
|
||||
// Reserved Word.
|
||||
static const Keyword SWITCH = const Keyword("switch", "SWITCH");
|
||||
static const Keyword SWITCH =
|
||||
const Keyword("switch", "SWITCH", KeywordStyle.reserved);
|
||||
|
||||
static const Keyword SYNC = const Keyword("sync", "SYNC", isPseudo: true);
|
||||
static const Keyword SYNC =
|
||||
const Keyword("sync", "SYNC", KeywordStyle.pseudo);
|
||||
|
||||
// Reserved Word.
|
||||
static const Keyword THIS = const Keyword("this", "THIS");
|
||||
static const Keyword THIS =
|
||||
const Keyword("this", "THIS", KeywordStyle.reserved);
|
||||
|
||||
// Reserved Word.
|
||||
static const Keyword THROW = const Keyword("throw", "THROW");
|
||||
static const Keyword THROW =
|
||||
const Keyword("throw", "THROW", KeywordStyle.reserved);
|
||||
|
||||
// Reserved Word.
|
||||
static const Keyword TRUE = const Keyword("true", "TRUE");
|
||||
static const Keyword TRUE =
|
||||
const Keyword("true", "TRUE", KeywordStyle.reserved);
|
||||
|
||||
// Reserved Word.
|
||||
static const Keyword TRY = const Keyword("try", "TRY");
|
||||
static const Keyword TRY = const Keyword("try", "TRY", KeywordStyle.reserved);
|
||||
|
||||
static const Keyword TYPEDEF = const Keyword("typedef", "TYPEDEF",
|
||||
isBuiltIn: true, isTopLevelKeyword: true);
|
||||
static const Keyword TYPEDEF = const Keyword(
|
||||
"typedef", "TYPEDEF", KeywordStyle.builtIn,
|
||||
isTopLevelKeyword: true);
|
||||
|
||||
// Reserved Word.
|
||||
static const Keyword VAR = const Keyword("var", "VAR", isModifier: true);
|
||||
static const Keyword VAR =
|
||||
const Keyword("var", "VAR", KeywordStyle.reserved, isModifier: true);
|
||||
|
||||
// Reserved Word.
|
||||
static const Keyword VOID = const Keyword("void", "VOID");
|
||||
static const Keyword VOID =
|
||||
const Keyword("void", "VOID", KeywordStyle.reserved);
|
||||
|
||||
// Reserved Word.
|
||||
static const Keyword WHILE = const Keyword("while", "WHILE");
|
||||
static const Keyword WHILE =
|
||||
const Keyword("while", "WHILE", KeywordStyle.reserved);
|
||||
|
||||
// Reserved Word.
|
||||
static const Keyword WITH = const Keyword("with", "WITH");
|
||||
static const Keyword WITH =
|
||||
const Keyword("with", "WITH", KeywordStyle.reserved);
|
||||
|
||||
static const Keyword YIELD = const Keyword("yield", "YIELD", isPseudo: true);
|
||||
static const Keyword YIELD =
|
||||
const Keyword("yield", "YIELD", KeywordStyle.pseudo);
|
||||
|
||||
static const List<Keyword> values = const <Keyword>[
|
||||
ABSTRACT,
|
||||
|
@ -401,30 +417,28 @@ class Keyword extends TokenType {
|
|||
*/
|
||||
static final Map<String, Keyword> keywords = _createKeywordMap();
|
||||
|
||||
/**
|
||||
* A flag indicating whether the keyword is "built-in" identifier.
|
||||
*/
|
||||
@override
|
||||
final bool isBuiltIn;
|
||||
|
||||
@override
|
||||
final bool isPseudo;
|
||||
final KeywordStyle keywordStyle;
|
||||
|
||||
/**
|
||||
* Initialize a newly created keyword.
|
||||
*/
|
||||
const Keyword(String lexeme, String name,
|
||||
{this.isBuiltIn: false,
|
||||
bool isModifier: false,
|
||||
this.isPseudo: false,
|
||||
const Keyword(String lexeme, String name, this.keywordStyle,
|
||||
{bool isModifier: false,
|
||||
bool isTopLevelKeyword: false,
|
||||
int precedence: NO_PRECEDENCE})
|
||||
: super(lexeme, name, precedence, KEYWORD_TOKEN,
|
||||
isModifier: isModifier, isTopLevelKeyword: isTopLevelKeyword);
|
||||
|
||||
@override
|
||||
bool get isBuiltIn => keywordStyle == KeywordStyle.builtIn;
|
||||
|
||||
@override
|
||||
bool get isPseudo => keywordStyle == KeywordStyle.pseudo;
|
||||
|
||||
bool get isBuiltInOrPseudo => isBuiltIn || isPseudo;
|
||||
|
||||
bool get isReservedWord => !isBuiltInOrPseudo;
|
||||
@override
|
||||
bool get isReservedWord => keywordStyle == KeywordStyle.reserved;
|
||||
|
||||
/**
|
||||
* The name of the keyword type.
|
||||
|
@ -1706,6 +1720,9 @@ class TokenType {
|
|||
*/
|
||||
bool get isBuiltIn => false;
|
||||
|
||||
/// A flag indicating whether the keyword is a "reserved word".
|
||||
bool get isReservedWord => false;
|
||||
|
||||
/**
|
||||
* Return `true` if this type of token represents an equality operator.
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue