Home | History | Annotate | Download | only in SlimParsing
      1 /*
      2  * [The "BSD license"]
      3  * Copyright (c) 2011 Terence Parr
      4  * All rights reserved.
      5  *
      6  * Conversion to C#:
      7  * Copyright (c) 2011 Sam Harwell, Pixel Mine, Inc.
      8  * All rights reserved.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. The name of the author may not be used to endorse or promote products
     19  *    derived from this software without specific prior written permission.
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 namespace Antlr.Runtime
     34 {
     35     using System;
     36     using System.Runtime.InteropServices;
     37 
     38     [StructLayout( LayoutKind.Sequential, Pack = 2 )]
     39     public struct SlimToken
     40         : IToken
     41     {
     42         private short _type;
     43         private short _channel;
     44         private short _startIndex;
     45         private short _stopIndex;
     46 
     47         public SlimToken(int type)
     48             : this()
     49         {
     50             _type = (short)type;
     51         }
     52 
     53         #region IToken Members
     54 
     55         string IToken.Text
     56         {
     57             get
     58             {
     59                 return string.Empty;
     60             }
     61             set
     62             {
     63             }
     64         }
     65 
     66         public int Type
     67         {
     68             get
     69             {
     70                 return _type;
     71             }
     72             set
     73             {
     74                 _type = (short)value;
     75             }
     76         }
     77 
     78         int IToken.Line
     79         {
     80             get
     81             {
     82                 return 0;
     83             }
     84             set
     85             {
     86             }
     87         }
     88 
     89         int IToken.CharPositionInLine
     90         {
     91             get
     92             {
     93                 return 0;
     94             }
     95             set
     96             {
     97             }
     98         }
     99 
    100         public int Channel
    101         {
    102             get
    103             {
    104                 return _channel;
    105             }
    106             set
    107             {
    108                 _channel = (short)value;
    109             }
    110         }
    111 
    112         public int StartIndex
    113         {
    114             get
    115             {
    116                 return _startIndex;
    117             }
    118             set
    119             {
    120                 _startIndex = (short)value;
    121             }
    122         }
    123 
    124         public int StopIndex
    125         {
    126             get
    127             {
    128                 return _stopIndex;
    129             }
    130             set
    131             {
    132                 _stopIndex = (short)value;
    133             }
    134         }
    135 
    136         int IToken.TokenIndex
    137         {
    138             get
    139             {
    140                 return 0;
    141             }
    142             set
    143             {
    144             }
    145         }
    146 
    147         ICharStream IToken.InputStream
    148         {
    149             get
    150             {
    151                 return null;
    152             }
    153             set
    154             {
    155             }
    156         }
    157 
    158         #endregion
    159     }
    160 }
    161