()
| 18 | // TODO: Optimize by recursive splitting |
| 19 | |
| 20 | public List<String> scan() throws ScannerException { |
| 21 | |
| 22 | List<String> result = new ArrayList<>(); |
| 23 | |
| 24 | final char [] statementChars = statement.toCharArray(); |
| 25 | |
| 26 | while (index < statementChars.length) { |
| 27 | |
| 28 | char ch = statementChars[index]; |
| 29 | |
| 30 | if (Character.isDigit(ch)) { |
| 31 | result.add(getNextToken(Character::isDigit)); |
| 32 | continue; |
| 33 | } else if (Character.isAlphabetic(ch)) { |
| 34 | result.add(getNextToken(Character::isAlphabetic)); |
| 35 | continue; |
| 36 | } else if (ch == ':' || ch == '(' || ch == ')' || ch == '!' || ch == '\'') { |
| 37 | result.add(String.valueOf(ch)); |
| 38 | } else if (ch == '-') { |
| 39 | result.add(getNextToken("->")); |
| 40 | continue; |
| 41 | } else if (ch == '=') { |
| 42 | result.add(getNextToken("=>")); |
| 43 | continue; |
| 44 | } else if (ch == '>') { |
| 45 | result.add(getNextToken(">>")); |
| 46 | continue; |
| 47 | } else if (ch == '#') { |
| 48 | result.add(String.valueOf(ch)); |
| 49 | result.add(statement.substring(index + 1)); |
| 50 | return result; |
| 51 | } else if (Character.isWhitespace(ch)) { |
| 52 | index++; |
| 53 | continue; |
| 54 | } else { |
| 55 | throw new ScannerException(String.valueOf(ch)); |
| 56 | } |
| 57 | |
| 58 | index++; |
| 59 | } |
| 60 | |
| 61 | return result; |
| 62 | } |
| 63 | |
| 64 | private String getNextToken(String token) throws ScannerException { |
| 65 |
nothing calls this directly
no test coverage detected