// ---------------------------------------------------------------------------
// - Lexical.hpp                                                             -
// - aleph engine - lexical name class definition                            -
// ---------------------------------------------------------------------------
// - This program is free software;  you can redistribute it  and/or  modify -
// - it provided that this copyright notice is kept intact.                  -
// -                                                                         -
// - This program  is  distributed in  the hope  that it will be useful, but -
// - without  any  warranty;  without  even   the   implied    warranty   of -
// - merchantability or fitness for a particular purpose.  In no event shall -
// - the copyright holder be liable for any  direct, indirect, incidental or -
// - special damages arising in any way out of the use of this software.     -
// ---------------------------------------------------------------------------
// - copyright (c) 1999-2003 amaury darsch                                   -
// ---------------------------------------------------------------------------

#ifndef  ALEPH_LEXICAL_HPP
#define  ALEPH_LEXICAL_HPP

#ifndef  ALEPH_STRING_HPP
#include "String.hpp"
#endif

namespace aleph {

  /// The Lexical class is a simple class which holds a lexical name. Such
  /// object is generated by the aleph lexical analyzer. The object is
  /// constructed by name. Static methods are available to check for the
  /// name character syntax.
  /// @author amaury darsch

  class Lexical : public Literal {
  private:
    /// the lexical name
    String d_name;
    /// the lexical quark
    long   d_quark;
    /// the line number
    long d_lnum;

  public:
    /// create an empty lexical
    Lexical (void);

    /// create a new lexical with a name
    /// @param name the lexical name
    Lexical (const String& name);

    /// create a new lexical with a name and a line number
    /// @param name the lexical name
    /// @param line the line number
    Lexical (const String& name, const long lnum);

    /// copy constructor for this lexical
    /// @param that the lexical to copy
    Lexical (const Lexical& that);

    /// @return the class name
    String repr (void) const;

    /// @return a literal representation of this lexical
    String toliteral (void) const {
      return d_name;
    }

    /// @return a string representation of this lexical
    String tostring (void) const {
      return d_name;
    }

    /// @return a clone of this lexical
    Object* clone (void) const;

    /// @return the lexical serial code
    t_byte serialid (void) const;

    /// serialize this lexical to an output stream
    /// @param os the output stream to write
    void wrstream (class Output& os) const;

    /// deserialize a lexical from an input stream
    /// @param is the input steam to read in
    void rdstream (class Input& is);

    /// @return the lexical line number
    long getlnum (void) const {
      return d_lnum;
    }

    /// @return the lexical quark
    long toquark (void) const {
      return d_quark;
    }
    
    /// @return true if the lexical is the nil string
    bool isnil (void) const;

    /// @return true if the character is a valid lexical one
    static bool valid (const char c);

    /// @return true if the lexical name is a valid one
    static bool valid (const String& name);

    /// generate a new lexical
    /// @param argv the argument vector
    static Object* mknew (Vector* argv);

    /// set this lexical as a const symbol
    /// @param robj   the current runnable
    /// @param nset   the current nameset
    /// @param object the object to set
    Object* cdef (Runnable* robj, Nameset* nset, Object* object);

    /// set this lexical with an object
    /// @param robj   the current runnable
    /// @param nset   the current nameset
    /// @param object the object to set
    Object* vdef (Runnable* robj, Nameset* nset, Object* object);

    /// evaluate this lexical name in the current nameset
    /// @param robj   the current runnable
    /// @param nset   the current nameset
    Object* eval (Runnable* robj, Nameset* nset);

    /// apply this lexical with a set of arguments and a quark
    /// @param robj   the current runnable
    /// @param nset   the current nameset    
    /// @param quark  the quark to apply these arguments
    /// @param argv   the arguments to apply
    Object* apply (Runnable* robj, Nameset* nset, const long quark,
		   Vector* argv);

  private:
    // make the assignment operator private
    Lexical& operator = (const Lexical&);
  };
}

#endif
