From 63390a44ab57983472b87b8869923af02c36b45a Mon Sep 17 00:00:00 2001 From: student Date: Tue, 13 Feb 2018 11:14:30 -0500 Subject: Refactor SCL into its own module --- base/src/bjc/dicelang/scl/SCLToken.java | 92 --------------------------------- 1 file changed, 92 deletions(-) delete mode 100644 base/src/bjc/dicelang/scl/SCLToken.java (limited to 'base/src/bjc/dicelang/scl/SCLToken.java') diff --git a/base/src/bjc/dicelang/scl/SCLToken.java b/base/src/bjc/dicelang/scl/SCLToken.java deleted file mode 100644 index b5dadb0..0000000 --- a/base/src/bjc/dicelang/scl/SCLToken.java +++ /dev/null @@ -1,92 +0,0 @@ -package bjc.dicelang.scl; - -import java.util.HashMap; -import java.util.Map; - -import bjc.dicelang.Errors; -import bjc.utils.parserutils.TokenUtils; - -import static bjc.dicelang.Errors.ErrorKey.EK_SCL_INVTOKEN; - -import static bjc.dicelang.scl.SCLToken.Type.*; - -public class SCLToken { - - public static enum Type { - /* Natural tokens. These come directly from strings */ - ILIT, FLIT, BLIT, SQUOTE, DQUOTE, OBRACKET, OBRACE, SYMBOL, WORD, - - /* Synthetic tokens. These are produced from special tokens. */ - SLIT, WORDS, ARRAY, - } - - public SCLToken.Type type; - - public static SCLToken tokenizeString(final String token) { - if (litTokens.containsKey(token)) { - return new IntSCLToken(litTokens.get(token)); - } else if (token.startsWith("\\")) { - return new SymbolSCLToken(token.substring(1)); - } else if (WordSCLToken.isBuiltinWord(token)) { - return new WordSCLToken(token); - } else if (token.equals("true")) { - return new BooleanSCLToken(true); - } else if (token.equals("false")) { - return new BooleanSCLToken(false); - } else if (TokenUtils.isInt(token)) { - return new IntSCLToken(Long.parseLong(token)); - } else if (TokenUtils.isDouble(token)) { - return new FloatSCLToken(Double.parseDouble(token)); - } else { - Errors.inst.printError(EK_SCL_INVTOKEN, token); - return null; - } - } - - protected static final Map litTokens; - - protected SCLToken() { - - } - - protected SCLToken(Type typ) { - type = typ; - } - - static { - /* Init literal tokens. */ - litTokens = new HashMap<>(); - - litTokens.put("'", SQUOTE); - litTokens.put("\"", DQUOTE); - litTokens.put("[", OBRACKET); - litTokens.put("{", OBRACE); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((type == null) ? 0 : type.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - SCLToken other = (SCLToken) obj; - if (type != other.type) - return false; - return true; - } - - @Override - public String toString() { - return "SCLToken [type=" + type + "]"; - } -} \ No newline at end of file -- cgit v1.2.3