diff options
Diffstat (limited to 'src/main/java/bjc/rgens/parser/RuleCase.java')
| -rwxr-xr-x[-rw-r--r--] | src/main/java/bjc/rgens/parser/RuleCase.java | 78 |
1 files changed, 22 insertions, 56 deletions
diff --git a/src/main/java/bjc/rgens/parser/RuleCase.java b/src/main/java/bjc/rgens/parser/RuleCase.java index 9c0a856..33aea0c 100644..100755 --- a/src/main/java/bjc/rgens/parser/RuleCase.java +++ b/src/main/java/bjc/rgens/parser/RuleCase.java @@ -13,76 +13,42 @@ import bjc.utils.funcdata.IList; * * @author EVE */ -public class RuleCase { - /** - * The possible types of a case. - * - * @author EVE - */ - public static enum CaseType { - /** A normal case, composed from a list of elements. */ - NORMAL, - /** A case that doesn't insert spaces. */ - SPACEFLATTEN, - /** A case that applies a regex after generation. */ - REGEX - } +public abstract class RuleCase { + public String debugName; - /** The type of this case. */ - public final CaseType type; + public final int serial; - /** - * The list of element values for this case. - * - * <h2>Used For</h2> - * <dl> - * <dt>NORMAL, SPACEFLATTEN</dt> - * <dd>Used as the list of elementList the rule is composed of.</dd> - * </dl> - */ - protected IList<CaseElement> elementList; + private static int nextSerial = 0; - protected RuleCase(CaseType typ) { - type = typ; - } + public Rule belongsTo; + + public IList<CaseElement> elementList; /** * Create a new case of the specified type that takes a element list * parameter. * - * @param typ - * The type of case to create. - * * @param elements * The element list parameter of the case. * - * @throws IllegalArgumentException - * If this type doesn't take a element list parameter. */ - public RuleCase(CaseType typ, IList<CaseElement> elements) { - this(typ); - - switch (typ) { - case NORMAL: - case SPACEFLATTEN: - break; - case REGEX: - throw new IllegalArgumentException("This type requires an element list and a pattern"); - default: - throw new IllegalArgumentException("This type doesn't have a element list parameter"); - } - + protected RuleCase(IList<CaseElement> elements) { elementList = elements; + + serial = nextSerial; + nextSerial += 1; } - /** - * Get the element list value of this type. - * - * @return - * The element list value of this case, or null if this type - * doesn't have one. - */ - public IList<CaseElement> getElements() { - return elementList; + public abstract void generate(GenerationState state); + + public abstract RuleCase withElements(IList<CaseElement> elements); + + public String toString() { + if(debugName != null) { + return String.format("Case %s (#%d) of %s", debugName, serial, belongsTo); + } else { + return String.format("Case #%d of %s", serial, belongsTo, serial, belongsTo); + } } + } |
