2017-09-23 23:43:08 -07:00
|
|
|
package org.nwapw.abacus.lexing.pattern.nodes;
|
2017-07-24 17:42:25 -07:00
|
|
|
|
2017-07-25 22:47:48 -07:00
|
|
|
/**
|
|
|
|
* A node that matches a single value.
|
2017-07-30 21:11:32 -07:00
|
|
|
*
|
2017-07-25 22:47:48 -07:00
|
|
|
* @param <T> the type that's used to tell which pattern this node belongs to.
|
|
|
|
*/
|
2017-07-24 17:42:25 -07:00
|
|
|
public class ValueNode<T> extends PatternNode<T> {
|
|
|
|
|
2017-07-25 22:47:48 -07:00
|
|
|
/**
|
|
|
|
* The value this node matches.
|
|
|
|
*/
|
2017-07-24 17:42:25 -07:00
|
|
|
private char value;
|
|
|
|
|
2017-07-25 22:47:48 -07:00
|
|
|
/**
|
|
|
|
* Creates a new node that matches the given character.
|
2017-07-30 21:11:32 -07:00
|
|
|
*
|
2017-08-05 16:15:30 -07:00
|
|
|
* @param value the character value of the node.
|
2017-07-25 22:47:48 -07:00
|
|
|
*/
|
2017-07-30 21:11:32 -07:00
|
|
|
public ValueNode(char value) {
|
2017-07-24 17:42:25 -07:00
|
|
|
this.value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean matches(char other) {
|
|
|
|
return other == value;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public char range() {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|