• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2019 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15const TokenType = {
16  kEOF: "end of file",
17  kError: "error",
18
19  kIdentifier: "identifier",
20
21  kIntegerLiteral: "integer_literal",
22  kFloatLiteral: "float_literal",
23  kStringLiteral: "string_literal",
24  kResultId: "result_id",
25
26  kOp: "Op",
27  kEqual: "=",
28  kPipe: "|",
29};
30
31class Token {
32  /**
33   * @param {TokenType} type The type of token
34   * @param {Integer} line The line number this token was on
35   * @param {Any} data Data attached to the token
36   * @param {Integer} bits If the type is a float or integer the bit width
37   */
38  constructor(type, line, data) {
39    this.type_ = type;
40    this.line_ = line;
41    this.data_ = data;
42    this.bits_ = 0;
43  }
44
45  get type() { return this.type_; }
46  get line() { return this.line_; }
47
48  get data() { return this.data_; }
49  set data(val) { this.data_ = val; }
50
51  get bits() { return this.bits_; }
52  set bits(val) { this.bits_ = val; }
53}
54
55export {Token, TokenType};
56