All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.gerweck.scala.util.math.HexByteMacros.scala Maven / Gradle / Ivy

The newest version!
package org.gerweck.scala.util.math

import scala.reflect.macros.blackbox.Context

/** Macros for working with hexadecimal byte literals.
  *
  * @author Sarah Gerweck 
  */
private[math] object HexByteMacros {
  /** Macro for hexadecimal byte literals. */
  def hexByte(c: Context)(): c.Expr[Byte] = {
    import c.universe._

    val Apply(_, List(Apply(_, List(Literal(Constant(s: String)))))) = c.prefix.tree
    val byte = Integer.parseInt(s, 16)
    val byteExpr: c.Expr[Int] = c.Expr[Int](Literal(Constant(byte)))
    reify { byteExpr.splice.toByte }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy