# -*- perl -*-
#
# $Id: Token.pm,v 1.2 1996/06/19 20:26:49 qjb Exp $
# $Source: /home/qjb/source/perl/modules/RCS/Token.pm,v $
# $Author: qjb $
#

require 5.002;
use strict;

package Token;
my $package = "Token";

use qutils qw(:assert_args);

# Field names
my $f_type = "type";
my $f_value = "value";
my $f_lineno = "lineno";

# Static Variables

# Routines

sub new
{
    &assert_args(\@_, ["", "", "", ""], []) if $assert_args;

    my $class = shift;
    my $type = shift;
    my $value = shift;
    my $lineno = shift;

    my $rep = +{$package => {} };

    #
    # WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
    # WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
    # WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
    #
    # Lexer::read_token manually constructs tokens, bypassing this
    # constructor.  It does this for performance reasons.  Be sure to
    # check that code if you ever change the construction of a Token
    # object.
    #

    $rep->{$package}{$f_type} = $type;
    $rep->{$package}{$f_value} = $value;
    $rep->{$package}{$f_lineno} = $lineno;

    bless $rep, $class;
}

sub type
{
    my $rep = shift;
    $rep->{$package}{$f_type};
}

sub value
{
    my $rep = shift;
    $rep->{$package}{$f_value};
}

sub lineno
{
    my $rep = shift;
    $rep->{$package}{$f_lineno};
}

sub unparse
{
    &assert_args(\@_, [$package], []) if $assert_args;
    my $rep = shift;
    my $value = $rep->value();
    $value =~ s/\r/\\r/g;
    $value =~ s/\n/\\n/g;
    sprintf("type: %-12s  line: %-4d  value: |%s|",
	    $rep->type(), $rep->lineno(), $value);
}

1;

#
# END OF Token
#
