1
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
3
* Copyright (C) 1998-2004 Gerwin Klein <lsf@jflex.de> *
4
* All rights reserved. *
6
* This program is free software; you can redistribute it and/or modify *
7
* it under the terms of the GNU General Public License. See the file *
8
* COPYRIGHT for more information. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License along *
16
* with this program; if not, write to the Free Software Foundation, Inc., *
17
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
19
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
21
package weka.core.parser.JFlex;
25
* Encapsulates an action in the specification.
27
* It stores the Java code as String together with a priority (line number in the specification).
29
* @author Gerwin Klein
30
* @version JFlex 1.4.1, $Revision: 1.1 $, $Date: 2008/05/09 09:14:11 $
32
final public class Action {
36
* The Java code this Action represents
41
* The priority (i.e. line number in the specification) of this Action.
46
* True iff the action belongs to an lookahead expresstion
47
* (<code>a/b</code> or <code>r$</code>)
49
private boolean isLookAction;
53
* Creates a new Action object with specified content and line number.
55
* @param content java code
56
* @param priority line number
58
public Action(String content, int priority) {
59
this.content = content.trim();
60
this.priority = priority;
65
* Compares the priority value of this Action with the specified action.
67
* @param other the other Action to compare this Action with.
69
* @return this Action if it has higher priority - the specified one, if not.
71
public Action getHigherPriority(Action other) {
72
if (other == null) return this;
74
// the smaller the number the higher the priority
75
if (other.priority > this.priority)
83
* Returns the String representation of this object.
85
* @return string representation of the action
87
public String toString() {
88
return "Action (priority "+priority+", lookahead "+isLookAction+") :"+Out.NL+content; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
93
* Returns <code>true</code> iff the parameter is an
94
* Action with the same content as this one.
96
* @param a the object to compare this Action with
97
* @return true if the action strings are equal
99
public boolean isEquiv(Action a) {
100
return this == a || this.content.equals(a.content);
105
* Calculate hash value.
107
* @return a hash value for this Action
109
public int hashCode() {
110
return content.hashCode();
115
* Test for equality to another object.
117
* This action equals another object if the other
118
* object is an equivalent action.
120
* @param o the other object.
122
* @see Action#isEquiv(Action)
124
public boolean equals(Object o) {
125
if (o instanceof Action)
126
return isEquiv((Action) o);
132
* Return look ahead flag.
134
* @return true if this actions belongs to a lookahead rule
136
public boolean isLookAction() {
141
* Sets the look ahead flag for this action
143
* @param b set to true if this action belongs to a look ahead rule
145
public void setLookAction(boolean b) {