]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/src/org/simantics/databoard/parser/Token.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / parser / Token.java
1 /*******************************************************************************
2  *  Copyright (c) 2010 Association for Decentralized Information Management in
3  *  Industry THTH ry.
4  *  All rights reserved. This program and the accompanying materials
5  *  are made available under the terms of the Eclipse Public License v1.0
6  *  which accompanies this distribution, and is available at
7  *  http://www.eclipse.org/legal/epl-v10.html
8  *
9  *  Contributors:
10  *      VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.databoard.parser;
13
14 /**
15  * Describes the input token stream.
16  */
17
18 public class Token implements java.io.Serializable {
19
20   /**
21    * The version identifier for this Serializable class.
22    * Increment only if the <i>serialized</i> form of the
23    * class changes.
24    */
25   private static final long serialVersionUID = 1L;
26
27   /**
28    * An integer that describes the kind of this token.  This numbering
29    * system is determined by JavaCCParser, and a table of these numbers is
30    * stored in the file ...Constants.java.
31    */
32   public int kind;
33
34   /** The line number of the first character of this Token. */
35   public int beginLine;
36   /** The column number of the first character of this Token. */
37   public int beginColumn;
38   /** The line number of the last character of this Token. */
39   public int endLine;
40   /** The column number of the last character of this Token. */
41   public int endColumn;
42
43   /**
44    * The string image of the token.
45    */
46   public String image;
47
48   /**
49    * A reference to the next regular (non-special) token from the input
50    * stream.  If this is the last token from the input stream, or if the
51    * token manager has not read tokens beyond this one, this field is
52    * set to null.  This is true only if this token is also a regular
53    * token.  Otherwise, see below for a description of the contents of
54    * this field.
55    */
56   public Token next;
57
58   /**
59    * This field is used to access special tokens that occur prior to this
60    * token, but after the immediately preceding regular (non-special) token.
61    * If there are no such special tokens, this field is set to null.
62    * When there are more than one such special token, this field refers
63    * to the last of these special tokens, which in turn refers to the next
64    * previous special token through its specialToken field, and so on
65    * until the first special token (whose specialToken field is null).
66    * The next fields of special tokens refer to other special tokens that
67    * immediately follow it (without an intervening regular token).  If there
68    * is no such token, this field is null.
69    */
70   public Token specialToken;
71
72   /**
73    * An optional attribute value of the Token.
74    * Tokens which are not used as syntactic sugar will often contain
75    * meaningful values that will be used later on by the compiler or
76    * interpreter. This attribute value is often different from the image.
77    * Any subclass of Token that actually wants to return a non-null value can
78    * override this method as appropriate.
79    */
80   public Object getValue() {
81     return null;
82   }
83
84   /**
85    * No-argument constructor
86    */
87   public Token() {}
88
89   /**
90    * Constructs a new token for the specified Image.
91    */
92   public Token(int kind)
93   {
94     this(kind, null);
95   }
96
97   /**
98    * Constructs a new token for the specified Image and Kind.
99    */
100   public Token(int kind, String image)
101   {
102     this.kind = kind;
103     this.image = image;
104   }
105
106   /**
107    * Returns the image.
108    */
109   public String toString()
110   {
111     return image;
112   }
113
114   /**
115    * Returns a new Token object, by default. However, if you want, you
116    * can create and return subclass objects based on the value of ofKind.
117    * Simply add the cases to the switch for all those special cases.
118    * For example, if you have a subclass of Token called IDToken that
119    * you want to create if ofKind is ID, simply add something like :
120    *
121    *    case MyParserConstants.ID : return new IDToken(ofKind, image);
122    *
123    * to the following switch statement. Then you can cast matchedToken
124    * variable to the appropriate type and use sit in your lexical actions.
125    */
126   public static Token newToken(int ofKind, String image)
127   {
128     switch(ofKind)
129     {
130       default : return new Token(ofKind, image);
131     }
132   }
133
134   public static Token newToken(int ofKind)
135   {
136     return newToken(ofKind, null);
137   }
138
139 }
140 /* JavaCC - OriginalChecksum=2dd90d6aa0419b6f776615ee456fe2e2 (do not edit this line) */