Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(989)

Unified Diff: pkg/front_end/lib/src/scanner/token.dart

Issue 2758113002: fasta.PrecedenceInfo implement analyzer.TokenType (Closed)
Patch Set: merge Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/front_end/lib/src/fasta/scanner/token.dart ('k') | pkg/front_end/test/precedence_info_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/front_end/lib/src/scanner/token.dart
diff --git a/pkg/front_end/lib/src/scanner/token.dart b/pkg/front_end/lib/src/scanner/token.dart
index d1facd3ba5ee0c5c055949a460887045da59e45d..1ee6255d0fb9ad1129234ce7a83a3ad50ee89936 100644
--- a/pkg/front_end/lib/src/scanner/token.dart
+++ b/pkg/front_end/lib/src/scanner/token.dart
@@ -11,6 +11,7 @@ import 'dart:collection';
import 'package:front_end/src/base/syntactic_entity.dart';
import 'package:front_end/src/scanner/string_utilities.dart';
import 'package:front_end/src/fasta/scanner/keyword.dart' as fasta;
+import 'package:front_end/src/fasta/scanner/precedence.dart' as fasta;
/**
* The opening half of a grouping pair of tokens. This is used for curly
@@ -881,256 +882,186 @@ class TokenClass {
*
* Clients may not extend, implement or mix-in this class.
*/
-class TokenType {
+abstract class TokenType {
/**
* The type of the token that marks the start or end of the input.
*/
- static const TokenType EOF = const _EndOfFileTokenType();
+ static const TokenType EOF = fasta.EOF_INFO;
- static const TokenType DOUBLE = const TokenType._('DOUBLE');
+ static const TokenType DOUBLE = fasta.DOUBLE_INFO;
- static const TokenType HEXADECIMAL = const TokenType._('HEXADECIMAL');
+ static const TokenType HEXADECIMAL = fasta.HEXADECIMAL_INFO;
- static const TokenType IDENTIFIER = const TokenType._('IDENTIFIER');
+ static const TokenType IDENTIFIER = fasta.IDENTIFIER_INFO;
- static const TokenType INT = const TokenType._('INT');
+ static const TokenType INT = fasta.INT_INFO;
- static const TokenType KEYWORD = const TokenType._('KEYWORD');
+ static const TokenType KEYWORD = fasta.KEYWORD_INFO;
static const TokenType MULTI_LINE_COMMENT =
- const TokenType._('MULTI_LINE_COMMENT');
+ const fasta.PrecedenceInfo(null, 'MULTI_LINE_COMMENT', 0, -1);
- static const TokenType SCRIPT_TAG = const TokenType._('SCRIPT_TAG');
+ static const TokenType SCRIPT_TAG = fasta.SCRIPT_INFO;
static const TokenType SINGLE_LINE_COMMENT =
- const TokenType._('SINGLE_LINE_COMMENT');
+ const fasta.PrecedenceInfo(null, 'SINGLE_LINE_COMMENT', 0, -1);
- static const TokenType STRING = const TokenType._('STRING');
+ static const TokenType STRING = fasta.STRING_INFO;
- static const TokenType AMPERSAND =
- const TokenType._('AMPERSAND', TokenClass.BITWISE_AND_OPERATOR, '&');
+ static const TokenType AMPERSAND = fasta.AMPERSAND_INFO;
- static const TokenType AMPERSAND_AMPERSAND = const TokenType._(
- 'AMPERSAND_AMPERSAND', TokenClass.LOGICAL_AND_OPERATOR, '&&');
+ static const TokenType AMPERSAND_AMPERSAND = fasta.AMPERSAND_AMPERSAND_INFO;
- static const TokenType AMPERSAND_AMPERSAND_EQ = const TokenType._(
- 'AMPERSAND_AMPERSAND_EQ', TokenClass.ASSIGNMENT_OPERATOR, '&&=');
+ static const TokenType AMPERSAND_AMPERSAND_EQ =
+ const fasta.PrecedenceInfo('&&=', 'AMPERSAND_AMPERSAND_EQ', 1, -1);
- static const TokenType AMPERSAND_EQ =
- const TokenType._('AMPERSAND_EQ', TokenClass.ASSIGNMENT_OPERATOR, '&=');
+ static const TokenType AMPERSAND_EQ = fasta.AMPERSAND_EQ_INFO;
- static const TokenType AT = const TokenType._('AT', TokenClass.NO_CLASS, '@');
+ static const TokenType AT = fasta.AT_INFO;
- static const TokenType BANG =
- const TokenType._('BANG', TokenClass.UNARY_PREFIX_OPERATOR, '!');
+ static const TokenType BANG = fasta.BANG_INFO;
- static const TokenType BANG_EQ =
- const TokenType._('BANG_EQ', TokenClass.EQUALITY_OPERATOR, '!=');
+ static const TokenType BANG_EQ = fasta.BANG_EQ_INFO;
- static const TokenType BAR =
- const TokenType._('BAR', TokenClass.BITWISE_OR_OPERATOR, '|');
+ static const TokenType BAR = fasta.BAR_INFO;
- static const TokenType BAR_BAR =
- const TokenType._('BAR_BAR', TokenClass.LOGICAL_OR_OPERATOR, '||');
+ static const TokenType BAR_BAR = fasta.BAR_BAR_INFO;
static const TokenType BAR_BAR_EQ =
- const TokenType._('BAR_BAR_EQ', TokenClass.ASSIGNMENT_OPERATOR, '||=');
+ const fasta.PrecedenceInfo('||=', 'BAR_BAR_EQ', 1, -1);
- static const TokenType BAR_EQ =
- const TokenType._('BAR_EQ', TokenClass.ASSIGNMENT_OPERATOR, '|=');
+ static const TokenType BAR_EQ = fasta.BAR_EQ_INFO;
- static const TokenType COLON =
- const TokenType._('COLON', TokenClass.NO_CLASS, ':');
+ static const TokenType COLON = fasta.COLON_INFO;
- static const TokenType COMMA =
- const TokenType._('COMMA', TokenClass.NO_CLASS, ',');
+ static const TokenType COMMA = fasta.COMMA_INFO;
- static const TokenType CARET =
- const TokenType._('CARET', TokenClass.BITWISE_XOR_OPERATOR, '^');
+ static const TokenType CARET = fasta.CARET_INFO;
- static const TokenType CARET_EQ =
- const TokenType._('CARET_EQ', TokenClass.ASSIGNMENT_OPERATOR, '^=');
+ static const TokenType CARET_EQ = fasta.CARET_EQ_INFO;
- static const TokenType CLOSE_CURLY_BRACKET =
- const TokenType._('CLOSE_CURLY_BRACKET', TokenClass.NO_CLASS, '}');
+ static const TokenType CLOSE_CURLY_BRACKET = fasta.CLOSE_CURLY_BRACKET_INFO;
- static const TokenType CLOSE_PAREN =
- const TokenType._('CLOSE_PAREN', TokenClass.NO_CLASS, ')');
+ static const TokenType CLOSE_PAREN = fasta.CLOSE_PAREN_INFO;
- static const TokenType CLOSE_SQUARE_BRACKET =
- const TokenType._('CLOSE_SQUARE_BRACKET', TokenClass.NO_CLASS, ']');
+ static const TokenType CLOSE_SQUARE_BRACKET = fasta.CLOSE_SQUARE_BRACKET_INFO;
- static const TokenType EQ =
- const TokenType._('EQ', TokenClass.ASSIGNMENT_OPERATOR, '=');
+ static const TokenType EQ = fasta.EQ_INFO;
- static const TokenType EQ_EQ =
- const TokenType._('EQ_EQ', TokenClass.EQUALITY_OPERATOR, '==');
+ static const TokenType EQ_EQ = fasta.EQ_EQ_INFO;
- static const TokenType FUNCTION =
- const TokenType._('FUNCTION', TokenClass.NO_CLASS, '=>');
+ static const TokenType FUNCTION = fasta.FUNCTION_INFO;
- static const TokenType GT =
- const TokenType._('GT', TokenClass.RELATIONAL_OPERATOR, '>');
+ static const TokenType GT = fasta.GT_INFO;
- static const TokenType GT_EQ =
- const TokenType._('GT_EQ', TokenClass.RELATIONAL_OPERATOR, '>=');
+ static const TokenType GT_EQ = fasta.GT_EQ_INFO;
- static const TokenType GT_GT =
- const TokenType._('GT_GT', TokenClass.SHIFT_OPERATOR, '>>');
+ static const TokenType GT_GT = fasta.GT_GT_INFO;
- static const TokenType GT_GT_EQ =
- const TokenType._('GT_GT_EQ', TokenClass.ASSIGNMENT_OPERATOR, '>>=');
+ static const TokenType GT_GT_EQ = fasta.GT_GT_EQ_INFO;
- static const TokenType HASH =
- const TokenType._('HASH', TokenClass.NO_CLASS, '#');
+ static const TokenType HASH = fasta.HASH_INFO;
- static const TokenType INDEX =
- const TokenType._('INDEX', TokenClass.NO_CLASS, '[]');
+ static const TokenType INDEX = fasta.INDEX_INFO;
- static const TokenType INDEX_EQ =
- const TokenType._('INDEX_EQ', TokenClass.NO_CLASS, '[]=');
+ static const TokenType INDEX_EQ = fasta.INDEX_EQ_INFO;
- static const TokenType LT =
- const TokenType._('LT', TokenClass.RELATIONAL_OPERATOR, '<');
+ static const TokenType LT = fasta.LT_INFO;
- static const TokenType LT_EQ =
- const TokenType._('LT_EQ', TokenClass.RELATIONAL_OPERATOR, '<=');
+ static const TokenType LT_EQ = fasta.LT_EQ_INFO;
- static const TokenType LT_LT =
- const TokenType._('LT_LT', TokenClass.SHIFT_OPERATOR, '<<');
+ static const TokenType LT_LT = fasta.LT_LT_INFO;
- static const TokenType LT_LT_EQ =
- const TokenType._('LT_LT_EQ', TokenClass.ASSIGNMENT_OPERATOR, '<<=');
+ static const TokenType LT_LT_EQ = fasta.LT_LT_EQ_INFO;
- static const TokenType MINUS =
- const TokenType._('MINUS', TokenClass.ADDITIVE_OPERATOR, '-');
+ static const TokenType MINUS = fasta.MINUS_INFO;
- static const TokenType MINUS_EQ =
- const TokenType._('MINUS_EQ', TokenClass.ASSIGNMENT_OPERATOR, '-=');
+ static const TokenType MINUS_EQ = fasta.MINUS_EQ_INFO;
- static const TokenType MINUS_MINUS =
- const TokenType._('MINUS_MINUS', TokenClass.UNARY_POSTFIX_OPERATOR, '--');
+ static const TokenType MINUS_MINUS = fasta.MINUS_MINUS_INFO;
- static const TokenType OPEN_CURLY_BRACKET =
- const TokenType._('OPEN_CURLY_BRACKET', TokenClass.NO_CLASS, '{');
+ static const TokenType OPEN_CURLY_BRACKET = fasta.OPEN_CURLY_BRACKET_INFO;
- static const TokenType OPEN_PAREN =
- const TokenType._('OPEN_PAREN', TokenClass.UNARY_POSTFIX_OPERATOR, '(');
+ static const TokenType OPEN_PAREN = fasta.OPEN_PAREN_INFO;
- static const TokenType OPEN_SQUARE_BRACKET = const TokenType._(
- 'OPEN_SQUARE_BRACKET', TokenClass.UNARY_POSTFIX_OPERATOR, '[');
+ static const TokenType OPEN_SQUARE_BRACKET = fasta.OPEN_SQUARE_BRACKET_INFO;
- static const TokenType PERCENT =
- const TokenType._('PERCENT', TokenClass.MULTIPLICATIVE_OPERATOR, '%');
+ static const TokenType PERCENT = fasta.PERCENT_INFO;
- static const TokenType PERCENT_EQ =
- const TokenType._('PERCENT_EQ', TokenClass.ASSIGNMENT_OPERATOR, '%=');
+ static const TokenType PERCENT_EQ = fasta.PERCENT_EQ_INFO;
- static const TokenType PERIOD =
- const TokenType._('PERIOD', TokenClass.UNARY_POSTFIX_OPERATOR, '.');
+ static const TokenType PERIOD = fasta.PERIOD_INFO;
- static const TokenType PERIOD_PERIOD =
- const TokenType._('PERIOD_PERIOD', TokenClass.CASCADE_OPERATOR, '..');
+ static const TokenType PERIOD_PERIOD = fasta.PERIOD_PERIOD_INFO;
- static const TokenType PLUS =
- const TokenType._('PLUS', TokenClass.ADDITIVE_OPERATOR, '+');
+ static const TokenType PLUS = fasta.PLUS_INFO;
- static const TokenType PLUS_EQ =
- const TokenType._('PLUS_EQ', TokenClass.ASSIGNMENT_OPERATOR, '+=');
+ static const TokenType PLUS_EQ = fasta.PLUS_EQ_INFO;
- static const TokenType PLUS_PLUS =
- const TokenType._('PLUS_PLUS', TokenClass.UNARY_POSTFIX_OPERATOR, '++');
+ static const TokenType PLUS_PLUS = fasta.PLUS_PLUS_INFO;
- static const TokenType QUESTION =
- const TokenType._('QUESTION', TokenClass.CONDITIONAL_OPERATOR, '?');
+ static const TokenType QUESTION = fasta.QUESTION_INFO;
- static const TokenType QUESTION_PERIOD = const TokenType._(
- 'QUESTION_PERIOD', TokenClass.UNARY_POSTFIX_OPERATOR, '?.');
+ static const TokenType QUESTION_PERIOD = fasta.QUESTION_PERIOD_INFO;
- static const TokenType QUESTION_QUESTION =
- const TokenType._('QUESTION_QUESTION', TokenClass.IF_NULL_OPERATOR, '??');
+ static const TokenType QUESTION_QUESTION = fasta.QUESTION_QUESTION_INFO;
- static const TokenType QUESTION_QUESTION_EQ = const TokenType._(
- 'QUESTION_QUESTION_EQ', TokenClass.ASSIGNMENT_OPERATOR, '??=');
+ static const TokenType QUESTION_QUESTION_EQ = fasta.QUESTION_QUESTION_EQ_INFO;
- static const TokenType SEMICOLON =
- const TokenType._('SEMICOLON', TokenClass.NO_CLASS, ';');
+ static const TokenType SEMICOLON = fasta.SEMICOLON_INFO;
- static const TokenType SLASH =
- const TokenType._('SLASH', TokenClass.MULTIPLICATIVE_OPERATOR, '/');
+ static const TokenType SLASH = fasta.SLASH_INFO;
- static const TokenType SLASH_EQ =
- const TokenType._('SLASH_EQ', TokenClass.ASSIGNMENT_OPERATOR, '/=');
+ static const TokenType SLASH_EQ = fasta.SLASH_EQ_INFO;
- static const TokenType STAR =
- const TokenType._('STAR', TokenClass.MULTIPLICATIVE_OPERATOR, '*');
+ static const TokenType STAR = fasta.STAR_INFO;
- static const TokenType STAR_EQ =
- const TokenType._('STAR_EQ', TokenClass.ASSIGNMENT_OPERATOR, "*=");
+ static const TokenType STAR_EQ = fasta.STAR_EQ_INFO;
- static const TokenType STRING_INTERPOLATION_EXPRESSION = const TokenType._(
- 'STRING_INTERPOLATION_EXPRESSION', TokenClass.NO_CLASS, '\${');
+ static const TokenType STRING_INTERPOLATION_EXPRESSION =
+ fasta.STRING_INTERPOLATION_INFO;
- static const TokenType STRING_INTERPOLATION_IDENTIFIER = const TokenType._(
- 'STRING_INTERPOLATION_IDENTIFIER', TokenClass.NO_CLASS, '\$');
+ static const TokenType STRING_INTERPOLATION_IDENTIFIER =
+ fasta.STRING_INTERPOLATION_IDENTIFIER_INFO;
- static const TokenType TILDE =
- const TokenType._('TILDE', TokenClass.UNARY_PREFIX_OPERATOR, '~');
+ static const TokenType TILDE = fasta.TILDE_INFO;
- static const TokenType TILDE_SLASH = const TokenType._(
- 'TILDE_SLASH', TokenClass.MULTIPLICATIVE_OPERATOR, '~/');
+ static const TokenType TILDE_SLASH = fasta.TILDE_SLASH_INFO;
- static const TokenType TILDE_SLASH_EQ = const TokenType._(
- 'TILDE_SLASH_EQ', TokenClass.ASSIGNMENT_OPERATOR, '~/=');
+ static const TokenType TILDE_SLASH_EQ = fasta.TILDE_SLASH_EQ_INFO;
- static const TokenType BACKPING =
- const TokenType._('BACKPING', TokenClass.NO_CLASS, '`');
+ static const TokenType BACKPING = fasta.BACKPING_INFO;
- static const TokenType BACKSLASH =
- const TokenType._('BACKSLASH', TokenClass.NO_CLASS, '\\');
+ static const TokenType BACKSLASH = fasta.BACKSLASH_INFO;
- static const TokenType PERIOD_PERIOD_PERIOD =
- const TokenType._('PERIOD_PERIOD_PERIOD', TokenClass.NO_CLASS, '...');
+ static const TokenType PERIOD_PERIOD_PERIOD = fasta.PERIOD_PERIOD_PERIOD_INFO;
static const TokenType GENERIC_METHOD_TYPE_LIST =
- const TokenType._('GENERIC_METHOD_TYPE_LIST');
+ const fasta.PrecedenceInfo(null, 'GENERIC_METHOD_TYPE_LIST', 0, -1);
static const TokenType GENERIC_METHOD_TYPE_ASSIGN =
- const TokenType._('GENERIC_METHOD_TYPE_ASSIGN');
-
- /**
- * The class of the token.
- */
- final TokenClass _tokenClass;
+ const fasta.PrecedenceInfo(null, 'GENERIC_METHOD_TYPE_ASSIGN', 0, -1);
/**
* The name of the token type.
*/
- final String name;
+ String get name;
/**
* The lexeme that defines this type of token, or `null` if there is more than
* one possible lexeme for this type of token.
*/
- final String lexeme;
-
- /**
- * Initialize a newly created token type to have the given [name],
- * [_tokenClass] and [lexeme].
- */
- const TokenType._(this.name,
- [this._tokenClass = TokenClass.NO_CLASS, this.lexeme = null]);
+ String get lexeme;
/**
* Return `true` if this type of token represents an additive operator.
*/
- bool get isAdditiveOperator => _tokenClass == TokenClass.ADDITIVE_OPERATOR;
+ bool get isAdditiveOperator;
/**
* Return `true` if this type of token represents an assignment operator.
*/
- bool get isAssignmentOperator =>
- _tokenClass == TokenClass.ASSIGNMENT_OPERATOR;
+ bool get isAssignmentOperator;
/**
* Return `true` if this type of token represents an associative operator. An
@@ -1144,96 +1075,59 @@ class TokenType {
* operators can have an effect because evaluation of the right-hand operand
* is conditional.
*/
- bool get isAssociativeOperator =>
- this == AMPERSAND ||
- this == AMPERSAND_AMPERSAND ||
- this == BAR ||
- this == BAR_BAR ||
- this == CARET ||
- this == PLUS ||
- this == STAR;
+ bool get isAssociativeOperator;
/**
* Return `true` if this type of token represents an equality operator.
*/
- bool get isEqualityOperator => _tokenClass == TokenClass.EQUALITY_OPERATOR;
+ bool get isEqualityOperator;
/**
* Return `true` if this type of token represents an increment operator.
*/
- bool get isIncrementOperator =>
- identical(lexeme, '++') || identical(lexeme, '--');
+ bool get isIncrementOperator;
/**
* Return `true` if this type of token represents a multiplicative operator.
*/
- bool get isMultiplicativeOperator =>
- _tokenClass == TokenClass.MULTIPLICATIVE_OPERATOR;
+ bool get isMultiplicativeOperator;
/**
* Return `true` if this token type represents an operator.
*/
- bool get isOperator =>
- this == INDEX ||
- this == INDEX_EQ ||
- (_tokenClass != TokenClass.NO_CLASS &&
- this != OPEN_PAREN &&
- this != OPEN_SQUARE_BRACKET &&
- this != PERIOD);
+ bool get isOperator;
/**
* Return `true` if this type of token represents a relational operator.
*/
- bool get isRelationalOperator =>
- _tokenClass == TokenClass.RELATIONAL_OPERATOR;
+ bool get isRelationalOperator;
/**
* Return `true` if this type of token represents a shift operator.
*/
- bool get isShiftOperator => _tokenClass == TokenClass.SHIFT_OPERATOR;
+ bool get isShiftOperator;
/**
* Return `true` if this type of token represents a unary postfix operator.
*/
- bool get isUnaryPostfixOperator =>
- _tokenClass == TokenClass.UNARY_POSTFIX_OPERATOR;
+ bool get isUnaryPostfixOperator;
/**
* Return `true` if this type of token represents a unary prefix operator.
*/
- bool get isUnaryPrefixOperator =>
- _tokenClass == TokenClass.UNARY_PREFIX_OPERATOR;
+ bool get isUnaryPrefixOperator;
/**
* Return `true` if this token type represents an operator that can be defined
* by users.
*/
- bool get isUserDefinableOperator =>
- identical(lexeme, '==') ||
- identical(lexeme, '~') ||
- identical(lexeme, '[]') ||
- identical(lexeme, '[]=') ||
- identical(lexeme, '*') ||
- identical(lexeme, '/') ||
- identical(lexeme, '%') ||
- identical(lexeme, '~/') ||
- identical(lexeme, '+') ||
- identical(lexeme, '-') ||
- identical(lexeme, '<<') ||
- identical(lexeme, '>>') ||
- identical(lexeme, '>=') ||
- identical(lexeme, '>') ||
- identical(lexeme, '<=') ||
- identical(lexeme, '<') ||
- identical(lexeme, '&') ||
- identical(lexeme, '^') ||
- identical(lexeme, '|');
+ bool get isUserDefinableOperator;
/**
* Return the precedence of the token, or `0` if the token does not represent
* an operator.
*/
- int get precedence => _tokenClass.precedence;
+ int get precedence;
@override
String toString() => name;
@@ -1270,17 +1164,3 @@ class TokenWithComment extends SimpleToken {
Token copy() =>
new TokenWithComment(type, offset, copyComments(precedingComments));
}
-
-/**
- * A token representing the end (either the head or the tail) of a stream of
- * tokens.
- */
-class _EndOfFileTokenType extends TokenType {
- /**
- * Initialize a newly created token.
- */
- const _EndOfFileTokenType() : super._('EOF', TokenClass.NO_CLASS, '');
-
- @override
- String toString() => '-eof-';
-}
« no previous file with comments | « pkg/front_end/lib/src/fasta/scanner/token.dart ('k') | pkg/front_end/test/precedence_info_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698