summaryrefslogtreecommitdiff
path: root/base/src/bjc/dicelang/Tokenizer.java
diff options
context:
space:
mode:
authorbjculkin <bjculkin@mix.wvu.edu>2018-03-01 19:13:48 -0500
committerbjculkin <bjculkin@mix.wvu.edu>2018-03-01 19:13:48 -0500
commitf9d9bd4bbf7dd6a297e1daf5ee7b4263d706d9cd (patch)
tree75ade2ca798bcdbdd7daf867480378299598581a /base/src/bjc/dicelang/Tokenizer.java
parentb14a399d05fc90d8532cd08d1546e6bf197db10e (diff)
Update
Diffstat (limited to 'base/src/bjc/dicelang/Tokenizer.java')
-rw-r--r--base/src/bjc/dicelang/Tokenizer.java31
1 files changed, 17 insertions, 14 deletions
diff --git a/base/src/bjc/dicelang/Tokenizer.java b/base/src/bjc/dicelang/Tokenizer.java
index 3a6db22..cd732ee 100644
--- a/base/src/bjc/dicelang/Tokenizer.java
+++ b/base/src/bjc/dicelang/Tokenizer.java
@@ -4,13 +4,16 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import bjc.dicelang.dice.DiceBox;
+import bjc.dicelang.tokens.DiceToken;
+import bjc.dicelang.tokens.FloatToken;
+import bjc.dicelang.tokens.Token;
import bjc.utils.funcdata.FunctionalMap;
import bjc.utils.funcdata.IMap;
import bjc.utils.funcutils.StringUtils;
import bjc.utils.parserutils.TokenUtils;
import static bjc.dicelang.Errors.ErrorKey.*;
-import static bjc.dicelang.Token.Type.*;
+import static bjc.dicelang.tokens.Token.Type.*;
/**
* Converts strings into tokens.
@@ -49,16 +52,16 @@ public class Tokenizer {
}
public Token lexToken(final String token, final IMap<String, String> stringLts) {
- if (token.equals("")) {
+ if(token.equals("")) {
return null;
}
Token tk = Token.NIL_TOKEN;
- if (litTokens.containsKey(token)) {
+ if(litTokens.containsKey(token)) {
tk = new Token(litTokens.get(token));
} else {
- switch (token.charAt(0)) {
+ switch(token.charAt(0)) {
case '(':
case ')':
case '[':
@@ -78,9 +81,9 @@ public class Tokenizer {
private static Token tokenizeGrouping(final String token) {
Token tk = Token.NIL_TOKEN;
- if (StringUtils.containsOnly(token, "\\" + token.charAt(0))) {
+ if(StringUtils.containsOnly(token, "\\" + token.charAt(0))) {
/* Handle multiple-grouped delimiters. */
- switch (token.charAt(0)) {
+ switch(token.charAt(0)) {
case '(':
tk = new Token(OPAREN, token.length());
break;
@@ -125,15 +128,15 @@ public class Tokenizer {
String token = rtoken.trim();
- if (TokenUtils.isInt(token)) {
+ if(TokenUtils.isInt(token)) {
tk = new Token(INT_LIT, Long.parseLong(token));
- } else if (hexadecimalMatcher.matcher(token).matches()) {
+ } else if(hexadecimalMatcher.matcher(token).matches()) {
final String newToken = token.substring(0, 1) + token.substring(token.indexOf('x'));
tk = new Token(INT_LIT, Long.parseLong(newToken.substring(2).toUpperCase(), 16));
- } else if (flexadecimalMatcher.matcher(token).matches()) {
+ } else if(flexadecimalMatcher.matcher(token).matches()) {
final int parseBase = Integer.parseInt(token.substring(token.lastIndexOf('B') + 1));
- if (parseBase < Character.MIN_RADIX || parseBase > Character.MAX_RADIX) {
+ if(parseBase < Character.MIN_RADIX || parseBase > Character.MAX_RADIX) {
Errors.inst.printError(EK_TOK_INVBASE, Integer.toString(parseBase));
return Token.NIL_TOKEN;
}
@@ -142,18 +145,18 @@ public class Tokenizer {
try {
tk = new Token(INT_LIT, Long.parseLong(flexNum, parseBase));
- } catch (final NumberFormatException nfex) {
+ } catch(final NumberFormatException nfex) {
Errors.inst.printError(EK_TOK_INVFLEX, flexNum, Integer.toString(parseBase));
return Token.NIL_TOKEN;
}
- } else if (TokenUtils.isDouble(token)) {
+ } else if(TokenUtils.isDouble(token)) {
tk = new FloatToken(Double.parseDouble(token));
- } else if (DiceBox.isValidExpression(token)) {
+ } else if(DiceBox.isValidExpression(token)) {
tk = new DiceToken(DiceBox.parseExpression(token));
} else {
final Matcher stringLit = stringLitMatcher.matcher(token);
- if (stringLit.matches()) {
+ if(stringLit.matches()) {
final int litNum = Integer.parseInt(stringLit.group(1));
eng.addStringLiteral(litNum, stringLts.get(token));