1 /*******************************************************************************
2 * Copyright (c) 2010 Association for Decentralized Information Management in
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.databoard.parser;
15 * Describes the input token stream.
18 public class Token implements java.io.Serializable {
21 * The version identifier for this Serializable class.
22 * Increment only if the <i>serialized</i> form of the
25 private static final long serialVersionUID = 1L;
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.
34 /** The line number of the first character of this Token. */
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. */
40 /** The column number of the last character of this Token. */
44 * The string image of the token.
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
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.
70 public Token specialToken;
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.
80 public Object getValue() {
85 * No-argument constructor
90 * Constructs a new token for the specified Image.
92 public Token(int kind)
98 * Constructs a new token for the specified Image and Kind.
100 public Token(int kind, String image)
109 public String toString()
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 :
121 * case MyParserConstants.ID : return new IDToken(ofKind, image);
123 * to the following switch statement. Then you can cast matchedToken
124 * variable to the appropriate type and use sit in your lexical actions.
126 public static Token newToken(int ofKind, String image)
130 default : return new Token(ofKind, image);
134 public static Token newToken(int ofKind)
136 return newToken(ofKind, null);
140 /* JavaCC - OriginalChecksum=2dd90d6aa0419b6f776615ee456fe2e2 (do not edit this line) */