Class AbstractNumericLiteral<T>

java.lang.Object
autumn.lang.compiler.ast.literals.AbstractNumericLiteral<T>
Direct Known Subclasses:
BigDecimalLiteral, BigIntegerLiteral, ByteLiteral, CharLiteral, DoubleLiteral, FloatLiteral, IntLiteral, LongLiteral, ShortLiteral

public abstract class AbstractNumericLiteral<T> extends Object
Instances of this class represent numeric literals in Autumn source-code.
Author:
Mackenzie High
  • Constructor Summary

    Constructors
    Constructor
    Description
    Sole Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    This method determines whether this literal can be converted to a number accurately.
    abstract boolean
    This method determines whether this literal would be recognized by the parser.
    final String
    This method returns the source-code representation of this literal.
    final String
    This method returns the source-code representation of this literal with underscores removed.
    final String
    This method returns a string representation of this literal.
    abstract T
    This method converts this literal to its numeric equivalent.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • AbstractNumericLiteral

      public AbstractNumericLiteral(String source)
      Sole Constructor.
      Parameters:
      source - is this literal as it appeared in the source-code.
      Throws:
      NullPointerException - if source is null.
      IllegalArgumentException - if source.length() equals zero.
  • Method Details

    • value

      public abstract T value()
      This method converts this literal to its numeric equivalent.
      Returns:
      the numeric representation of this literal, or null, if a lossless conversion is not possible.
    • isParsable

      public abstract boolean isParsable()
      This method determines whether this literal would be recognized by the parser.

      Note: Under some circumstances, a literal may be malformed and parse-able.

      Returns:
      true, iff the parser would recognize this literal.
    • source

      public final String source()
      This method returns the source-code representation of this literal.
      Returns:
      this literal, as it appeared in the source code.
    • sourceWithoutUnderscores

      public final String sourceWithoutUnderscores()
      This method returns the source-code representation of this literal with underscores removed.
      Returns:
      this literal, as it appeared in the source code, excluding any underscores.
    • isMalformed

      public final boolean isMalformed()
      This method determines whether this literal can be converted to a number accurately.
      Returns:
      true, if a conversion would lose information.
    • toString

      public final String toString()
      This method returns a string representation of this literal.
      Overrides:
      toString in class Object
      Returns:
      source()