// 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. // TODO(terry): Need to be consistent with tokens either they're ASCII tokens // e.g., ASTERISK or they're CSS e.g., PSEUDO, COMBINATOR_*. class TokenKind { // Common shared tokens used in TokenizerBase. static const int UNUSED = 0; // Unused place holder... static const int END_OF_FILE = 1; static const int LPAREN = 2; // ( static const int RPAREN = 3; // ) static const int LBRACK = 4; // [ static const int RBRACK = 5; // ] static const int LBRACE = 6; // { static const int RBRACE = 7; // } static const int DOT = 8; // . static const int SEMICOLON = 9; // ; static const int SPACE = 10; // space character static const int TAB = 11; // \t static const int NEWLINE = 12; // \n static const int RETURN = 13; // \r static const int COMMA = 14; // , // Unique tokens. static const int LESS_THAN = 15; // < static const int GREATER_THAN = 16; // > static const int SLASH = 17; // / static const int DOLLAR = 18; // $ static const int HASH = 19; // # static const int MINUS = 20; // - static const int EQUAL = 21; // = static const int DOUBLE_QUOTE = 22; // " static const int SINGLE_QUOTE = 23; // ' static const int ASTERISK = 24; // * // WARNING: END_TOKENS must be 1 greater than the last token above (last // character in our list). Also add to kindToString function and the // constructor for TokenKind. static const int END_TOKENS = 25; // Marker for last token in list // Synthesized tokens: static const int END_NO_SCOPE_TAG = 50; // /> static const int START_EXPRESSION = 51; // ${ static const int START_COMMAND = 52; // ${# static const int END_COMMAND = 53; // ${/ static const int EACH_COMMAND = 53; // ${#each list} static const int WITH_COMMAND = 54; // ${#with object} static const int IF_COMMAND = 55; // ${#if (expression)} static const int ELSE_COMMAND = 56; // ${#else} /** [TokenKind] representing integer tokens. */ static const int INTEGER = 60; // TODO(terry): must match base /** [TokenKind] representing hex integer tokens. */ // static const int HEX_INTEGER = 61; // TODO(terry): must match base /** [TokenKind] representing double tokens. */ static const int DOUBLE = 62; // TODO(terry): must match base /** [TokenKind] representing whitespace tokens. */ static const int WHITESPACE = 63; // TODO(terry): must match base /** [TokenKind] representing comment tokens. */ static const int COMMENT = 64; // TODO(terry): must match base /** [TokenKind] representing error tokens. */ static const int ERROR = 65; // TODO(terry): must match base /** [TokenKind] representing incomplete string tokens. */ static const int INCOMPLETE_STRING = 66; // TODO(terry): must match base /** [TokenKind] representing incomplete comment tokens. */ static const int INCOMPLETE_COMMENT = 67; // TODO(terry): must match base // Synthesized Tokens (no character associated with TOKEN). // TODO(terry): Possible common names used by both Dart and CSS tokenizers. static const int ATTR_VALUE = 500; static const int NUMBER = 502; static const int HEX_NUMBER = 503; static const int HTML_COMMENT = 504; // '; case TokenKind.IDENTIFIER: return 'identifier'; case TokenKind.STRING: return 'string'; case TokenKind.STRING_PART: return 'string part'; case TokenKind.TEMPLATE_KEYWORD: return 'template'; default: throw "Unknown TOKEN"; } } TokenKind() { tokens = []; // All tokens must be in TokenKind order. tokens.add(-1); // TokenKind.UNUSED tokens.add(0); // TokenKind.END_OF_FILE match base tokens.add(TokenKind.kindToString(TokenKind.LPAREN).charCodeAt(0)); tokens.add(TokenKind.kindToString(TokenKind.RPAREN).charCodeAt(0)); tokens.add(TokenKind.kindToString(TokenKind.LBRACK).charCodeAt(0)); tokens.add(TokenKind.kindToString(TokenKind.RBRACK).charCodeAt(0)); tokens.add(TokenKind.kindToString(TokenKind.LBRACE).charCodeAt(0)); tokens.add(TokenKind.kindToString(TokenKind.RBRACE).charCodeAt(0)); tokens.add(TokenKind.kindToString(TokenKind.DOT).charCodeAt(0)); tokens.add(TokenKind.kindToString(TokenKind.SEMICOLON).charCodeAt(0)); tokens.add(TokenKind.kindToString(TokenKind.SPACE).charCodeAt(0)); tokens.add(TokenKind.kindToString(TokenKind.TAB).charCodeAt(0)); tokens.add(TokenKind.kindToString(TokenKind.NEWLINE).charCodeAt(0)); tokens.add(TokenKind.kindToString(TokenKind.RETURN).charCodeAt(0)); tokens.add(TokenKind.kindToString(TokenKind.COMMA).charCodeAt(0)); tokens.add(TokenKind.kindToString(TokenKind.LESS_THAN).charCodeAt(0)); tokens.add(TokenKind.kindToString(TokenKind.GREATER_THAN).charCodeAt(0)); tokens.add(TokenKind.kindToString(TokenKind.SLASH).charCodeAt(0)); tokens.add(TokenKind.kindToString(TokenKind.DOLLAR).charCodeAt(0)); tokens.add(TokenKind.kindToString(TokenKind.HASH).charCodeAt(0)); tokens.add(TokenKind.kindToString(TokenKind.MINUS).charCodeAt(0)); tokens.add(TokenKind.kindToString(TokenKind.EQUAL).charCodeAt(0)); tokens.add(TokenKind.kindToString(TokenKind.DOUBLE_QUOTE).charCodeAt(0)); tokens.add(TokenKind.kindToString(TokenKind.SINGLE_QUOTE).charCodeAt(0)); tokens.add(TokenKind.kindToString(TokenKind.ASTERISK).charCodeAt(0)); assert(tokens.length == TokenKind.END_TOKENS); } static bool isIdentifier(int kind) { return kind == IDENTIFIER; } } class NoElementMatchException implements Exception { String _tagName; NoElementMatchException(this._tagName); String get name => _tagName; }