logo
class

compiler::TokenVal

sys::Obj
  compiler::Location
    compiler::TokenVal
  1  //
  2  // Copyright (c) 2006, Brian Frank and Andy Frank
  3  // Licensed under the Academic Free License version 3.0
  4  //
  5  // History:
  6  //   16 Apr 06  Brian Frank  Creation
  7  //
  8  
  9  **
 10  ** TokenVal stores an instance of a Token at a specific Location.
 11  **
 12  class TokenVal : Location
 13  {
 14  
 15    new make(Token kind, Obj val := null)
 16      : super.makeUninit()
 17    {
 18      this.kind = kind
 19      this.val  = val
 20    }
 21  
 22    override Int hash()
 23    {
 24      return kind.hash
 25    }
 26  
 27    override Bool equals(Obj obj)
 28    {
 29      that := obj as TokenVal
 30      if (that == null) return false
 31      return (kind === that.kind) && (val == that.val)
 32    }
 33  
 34    override Str toStr()
 35    {
 36      if (kind === Token.identifier) return val.toStr
 37      return kind.symbol
 38    }
 39  
 40    Token kind     // enum for Token type
 41    Obj val        // Str, Int, Float, Duration, or Str[]
 42    Bool newline   // have we processed one or more newlines since the last token
 43  }