logo

class

compiler::TokenVal

sys::Obj
  compiler::Location
    compiler::TokenVal
//
// Copyright (c) 2006, Brian Frank and Andy Frank
// Licensed under the Academic Free License version 3.0
//
// History:
//   16 Apr 06  Brian Frank  Creation
//

**
** TokenVal stores an instance of a Token at a specific Location.
**
class TokenVal : Location
{

  new make(Token kind, Obj val := null)
    : super.makeUninit()
  {
    this.kind = kind
    this.val  = val
  }

  override Int hash()
  {
    return kind.hash
  }

  override Bool equals(Obj obj)
  {
    that := obj as TokenVal
    if (that == null) return false
    return (kind === that.kind) && (val == that.val)
  }

  override Str toStr()
  {
    if (kind === Token.identifier) return val.toStr
    return kind.symbol
  }

  Token kind     // enum for Token type
  Obj val        // Str, Int, Float, Duration, or Str[]
  Bool newline   // have we processed one or more newlines since the last token
}