001: package org.ofbiz.rules.parse.tokens;
002:
003: import java.util.*;
004: import org.ofbiz.rules.parse.*;
005:
006: /**
007: * <p><b>Title:</b> Symbol
008: * <p><b>Description:</b> None
009: * <p>Copyright (c) 1999 Steven J. Metsker.
010: * <p>Copyright (c) 2001 The Open For Business Project - www.ofbiz.org
011: *
012: * <p>Permission is hereby granted, free of charge, to any person obtaining a
013: * copy of this software and associated documentation files (the "Software"),
014: * to deal in the Software without restriction, including without limitation
015: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
016: * and/or sell copies of the Software, and to permit persons to whom the
017: * Software is furnished to do so, subject to the following conditions:
018: *
019: * <p>The above copyright notice and this permission notice shall be included
020: * in all copies or substantial portions of the Software.
021: *
022: * <p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
023: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
024: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
025: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
026: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
027: * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
028: * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
029: *
030: * <br>
031: * A Symbol matches a specific sequence, such as
032: * <code><</code>, or <code><=</code> that a tokenizer
033: * returns as a symbol.
034: *
035: * @author Steven J. Metsker
036: * @version 1.0
037: */
038: public class Symbol extends Terminal {
039:
040: /**
041: * the literal to match
042: */
043: protected Token symbol;
044:
045: /**
046: * Constructs a symbol that will match the specified char.
047: *
048: * @param char the character to match. The char must be
049: * one that the tokenizer will return as a
050: * symbol token. This typically includes most
051: * characters except letters and digits.
052: *
053: * @return a symbol that will match the specified char
054: */
055: public Symbol(char c) {
056: this (String.valueOf(c));
057: }
058:
059: /**
060: * Constructs a symbol that will match the specified sequence
061: * of characters.
062: *
063: * @param String the characters to match. The characters
064: * must be a sequence that the tokenizer will
065: * return as a symbol token, such as
066: * <code><=</code>.
067: *
068: * @return a Symbol that will match the specified sequence
069: * of characters
070: */
071: public Symbol(String s) {
072: symbol = new Token(Token.TT_SYMBOL, s, 0);
073: }
074:
075: /**
076: * Returns true if the symbol this object represents equals an
077: * assembly's next element.
078: *
079: * @param object an element from an assembly
080: *
081: * @return true, if the specified symbol equals the next
082: * token from an assembly
083: */
084: protected boolean qualifies(Object o) {
085: return symbol.equals((Token) o);
086: }
087:
088: /**
089: * Returns a textual description of this parser.
090: *
091: * @param vector a list of parsers already printed in
092: * this description
093: *
094: * @return string a textual description of this parser
095: *
096: * @see Parser#toString()
097: */
098: public String unvisitedString(List visited) {
099: return symbol.toString();
100: }
101: }
|