Keyword.java
/*
** Module : Keyword.java
** Abstract : encapsulates a language keyword
**
** Copyright (c) 2004-2017, Golden Code Development Corporation.
**
** -#- -I- --Date-- -T- --JPRM-- ----------------Description-----------------
** 001 GES 20041105 ADD @18645 First version implementing a bean-like
** interface. Only designed to contain some
** data, there is no processing being done.
** 002 GES 20041116 CHG @18646 Added generic support for containing an
** arbitrary object reference to user-specified
** data.
*/
/*
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU Affero General Public License as
** published by the Free Software Foundation, either version 3 of the
** License, or (at your option) any later version.
**
** 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. See the
** GNU Affero General Public License for more details.
**
** You may find a copy of the GNU Affero GPL version 3 at the following
** location: https://www.gnu.org/licenses/agpl-3.0.en.html
**
** Additional terms under GNU Affero GPL version 3 section 7:
**
** Under Section 7 of the GNU Affero GPL version 3, the following additional
** terms apply to the works covered under the License. These additional terms
** are non-permissive additional terms allowed under Section 7 of the GNU
** Affero GPL version 3 and may not be removed by you.
**
** 0. Attribution Requirement.
**
** You must preserve all legal notices or author attributions in the covered
** work or Appropriate Legal Notices displayed by works containing the covered
** work. You may not remove from the covered work any author or developer
** credit already included within the covered work.
**
** 1. No License To Use Trademarks.
**
** This license does not grant any license or rights to use the trademarks
** Golden Code, FWD, any Golden Code or FWD logo, or any other trademarks
** of Golden Code Development Corporation. You are not authorized to use the
** name Golden Code, FWD, or the names of any author or contributor, for
** publicity purposes without written authorization.
**
** 2. No Misrepresentation of Affiliation.
**
** You may not represent yourself as Golden Code Development Corporation or FWD.
**
** You may not represent yourself for publicity purposes as associated with
** Golden Code Development Corporation, FWD, or any author or contributor to
** the covered work, without written authorization.
**
** 3. No Misrepresentation of Source or Origin.
**
** You may not represent the covered work as solely your work. All modified
** versions of the covered work must be marked in a reasonable way to make it
** clear that the modified work is not originating from Golden Code Development
** Corporation or FWD. All modified versions must contain the notices of
** attribution required in this license.
*/
package com.goldencode.p2j.uast;
/**
* Encapsulates all data associated with a language keyword. Instances of
* this class can be stored in a dictionary of type
* <code>KeywordDictionary</code>. This class provides sufficient data about
* the keyword to implement reserved/unreserved keywords and matching on a
* set of valid keyword abbreviations.
* <p>
* The interface is designed to provide data access and the class does not
* implement any real function other than the storage and retrieval of
* the associated data members.
*
* @author GES
* @version 1.0.1
*/
public class Keyword
{
/** Full, literal text form of the keyword. */
private String fullText;
/**
* Minimum number of characters needed to match the keyword. Must be
* a non-negative integer. If set to 0, this disables abbreviation
* processing. Otherwise, it specifies the number of leftmost characters
* that must be an identical match to match this keyword.
*/
private int minChars;
/**
* The integer token type associated with this keyword in the Parser
* and Lexer. This usually will correspond to an "imaginary" token
* created in a tokens {} clause for ANTLR.
*/
private int tokenType;
/** The keyword is a reserved keyword in the source language. */
private boolean reserved;
/**
* Arbitrary user-specified data to be associated with this keyword.
* This data is not used or modified in any way, but is simply provided
* to the caller upon request.
*/
private Object extra;
/**
* Constructs a keyword with the minimum number of valid fields.
*
* @param text
* Full text form of the keyword.
* @param min
* Minimum number of leftmost characters which will still match
* the full text. Set to 0 to disable abbreviation support.
* @param type
* Constant representing the Lexer or Parser token type
* associated with this keyword.
* @param reserved
* If true, this keyword is a reserved keyword and may not be
* used in user-defined symbols. If false, this is an
* unreserved keyword.
*/
public Keyword(String text,
int min,
int type,
boolean reserved)
{
fullText = text;
minChars = min;
tokenType = type;
this.reserved = reserved;
}
/**
* Constructs a keyword with all possible fields.
*
* @param text
* Full text form of the keyword.
* @param min
* Minimum number of leftmost characters which will still match
* the full text. Set to 0 to disable abbreviation support.
* @param type
* Constant representing the Lexer or Parser token type
* associated with this keyword.
* @param reserved
* If true, this keyword is a reserved keyword and may not be
* used in user-defined symbols. If false, this is an
* unreserved keyword.
* @param extra
* User-defined object that is associated with this keyword. This
* object is stored but not altered in any way.
*/
public Keyword(String text,
int min,
int type,
boolean reserved,
Object extra)
{
fullText = text;
minChars = min;
tokenType = type;
this.reserved = reserved;
this.extra = extra;
}
/**
* Converts a <code>Keyword</code> object into a <code>String</code>
* representation.
*
* @see java.lang.Object#toString
*/
public String toString()
{
return new String("'" +
fullText +
"' minChars = " +
minChars +
"; tokenType = " +
tokenType +
"; reserved = " +
reserved);
}
/**
* Returns the full text of the keyword.
*
* @return Full text of the keyword.
*/
public String getFullText()
{
return fullText;
}
/**
* Sets the full text of the keyword.
*
* @param text
* The text to seet as the keyword's full text.
*/
public void setFullText(String text)
{
fullText = text;
}
/**
* Returns the minimum number of characters used in abbreviations.
*
* @return Minimum number of left-most characters that still is a match.
*/
public int getMinChars()
{
return minChars;
}
/**
* Sets the minimum number of characters used in abbreviations.
*
* @param min
* Minimum number of left-most characters that still is a match.
*/
public void setMinChars(int min)
{
minChars = min;
}
/**
* Returns the token type associated with this keyword by the Lexer and
* Parser.
*
* @return The token type.
*/
public int getTokenType()
{
return tokenType;
}
/**
* Sets the token type associated with this keyword by the Lexer and
* Parser.
*
* @param type
* The token type.
*/
public void setTokenType(int type)
{
tokenType = type;
}
/**
* Returns the reserved keyword status of this keyword.
*
* @return The keyword's reserved status.
*/
public boolean isReserved()
{
return reserved;
}
/**
* Sets the reserved keyword status of this keyword.
*
* @param reserved
* The keyword's reserved status.
*/
public void setReserved(boolean reserved)
{
this.reserved = reserved;
}
/**
* Returns the user-defined object associated with this keyword.
*
* @return User-defined object.
*/
public Object getExtra()
{
return extra;
}
/**
* Sets the user-defined object associated with this keyword.
*
* @param extra
* User-defined object.
*/
public void setExtra(Object extra)
{
this.extra = extra;
}
}