diff options
| author | bjculkin <bjculkin@mix.wvu.edu> | 2017-03-21 14:04:17 -0400 |
|---|---|---|
| committer | bjculkin <bjculkin@mix.wvu.edu> | 2017-03-21 14:04:17 -0400 |
| commit | e279644fc59f46916c20b0b4f941fd37b4f07675 (patch) | |
| tree | 7782b229f6482039ad0739079807294c14928085 /RGens/src/main/java/bjc/rgens/newparser/CaseElement.java | |
| parent | ba7e0a2c1efe4203f766f3192b8852c3bb7d3369 (diff) | |
Finish basic implementation
This finishes a basic implementation. It now handles literal strings and
rule references, allowing it to handle basic grammars.
Diffstat (limited to 'RGens/src/main/java/bjc/rgens/newparser/CaseElement.java')
| -rw-r--r-- | RGens/src/main/java/bjc/rgens/newparser/CaseElement.java | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/RGens/src/main/java/bjc/rgens/newparser/CaseElement.java b/RGens/src/main/java/bjc/rgens/newparser/CaseElement.java new file mode 100644 index 0000000..fe088b8 --- /dev/null +++ b/RGens/src/main/java/bjc/rgens/newparser/CaseElement.java @@ -0,0 +1,102 @@ +package bjc.rgens.newparser; + +/** + * A element in a rule case. + * + * @author EVE + */ +public class CaseElement { + /** + * The possible types of an element. + * + * @author EVE + * + */ + public static enum ElementType { + /** + * A element that represents a literal string. + */ + LITERAL, + /** + * A element that represents a rule reference. + */ + RULEREF; + } + + /** + * The type of this element. + */ + public final CaseElement.ElementType type; + + /** + * The literal string value of this element. + * + * This means that it is a string whose value should always mean the + * same thing. + * + * <h2>Used For</h2> + * <dl> + * <dt>LITERAL</dt> + * <dd>The string this element represents</dd> + * <dt>RULEREF</dt> + * <dd>The name of the rule this element references</dd> + * </dl> + */ + private String literalVal; + + /** + * Create a new case element. + * + * @param typ + * The type of this element. + * + * @throws IllegalArgumentException + * If the specified type needs parameters. + */ + public CaseElement(CaseElement.ElementType typ) { + switch(typ) { + case LITERAL: + case RULEREF: + throw new IllegalArgumentException("This type requires a string parameter."); + default: + break; + } + type = typ; + } + + /** + * Create a new case element that has a single string value. + * + * @param typ + * The type of this element. + * + * @param val + * The string value of this element. + * + * @throws IllegalArgumentException + * If the specified type doesn't take a single string + * parameter. + */ + public CaseElement(CaseElement.ElementType typ, String val) { + switch(typ) { + case LITERAL: + case RULEREF: + break; + default: + throw new IllegalArgumentException("This type doesn't have a string parameter."); + } + + type = typ; + + literalVal = val; + } + + /** + * Get the literal string value for this element. + * + * @return The literal string value for this element. + */ + public String getLiteral() { + return literalVal; + } +}
\ No newline at end of file |
