diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-04-10 21:39:05 -0400 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-04-10 21:39:05 -0400 |
| commit | 05c17c6e0e8e5e9015da4d1396587c4af0ea09d3 (patch) | |
| tree | 3a2685040342447c22605f4d71b50d3e0fa3d185 /dice-lang/src/main/java/bjc/dicelang/ast/nodes/ILiteralDiceNode.java | |
| parent | bf726639e1bc70b30dc5e5ae2cf349a5bbdfb0ae (diff) | |
Removed old code that wasn't being used
Diffstat (limited to 'dice-lang/src/main/java/bjc/dicelang/ast/nodes/ILiteralDiceNode.java')
| -rw-r--r-- | dice-lang/src/main/java/bjc/dicelang/ast/nodes/ILiteralDiceNode.java | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/dice-lang/src/main/java/bjc/dicelang/ast/nodes/ILiteralDiceNode.java b/dice-lang/src/main/java/bjc/dicelang/ast/nodes/ILiteralDiceNode.java new file mode 100644 index 0000000..b12b516 --- /dev/null +++ b/dice-lang/src/main/java/bjc/dicelang/ast/nodes/ILiteralDiceNode.java @@ -0,0 +1,54 @@ +package bjc.dicelang.ast.nodes; + +import org.apache.commons.lang3.StringUtils; + +/** + * Represents a literal of some type in the AST + * + * @author ben + * + */ +public interface ILiteralDiceNode extends IDiceASTNode { + @Override + default DiceASTType getType() { + return DiceASTType.LITERAL; + } + + @Override + default boolean isOperator() { + return false; + } + + /** + * Get the type of literal this node represents + * + * @return The type of literal this node represents + */ + DiceLiteralType getLiteralType(); + + /** + * Check if a token represents a literal, and if so, what type + * + * @param tok + * The token to check + * @return The type the literal would be if it is one, or null + * otherwise + */ + static DiceLiteralType getLiteralType(String tok) { + if (StringUtils.countMatches(tok, 'c') == 1 + && !tok.equalsIgnoreCase("c")) { + return DiceLiteralType.DICE; + } else if (StringUtils.countMatches(tok, 'd') == 1 + && !tok.equalsIgnoreCase("d")) { + return DiceLiteralType.DICE; + } else { + try { + Integer.parseInt(tok); + return DiceLiteralType.INTEGER; + } catch (@SuppressWarnings("unused") NumberFormatException nfex) { + // We don't care about details + return null; + } + } + } +} |
