MCPcopy Create free account
hub / github.com/DGVPSH/SlackOpen / TokenParser

Class TokenParser

src/main/java/net/optifine/expr/TokenParser.java:10–72  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8import java.util.List;
9
10public class TokenParser
11{
12 public static Token[] parse(String str) throws IOException, ParseException
13 {
14 Reader reader = new StringReader(str);
15 PushbackReader pushbackreader = new PushbackReader(reader);
16 List<Token> list = new ArrayList();
17
18 while (true)
19 {
20 int i = pushbackreader.read();
21
22 if (i < 0)
23 {
24 Token[] atoken = (Token[])((Token[])list.toArray(new Token[list.size()]));
25 return atoken;
26 }
27
28 char c0 = (char)i;
29
30 if (!Character.isWhitespace(c0))
31 {
32 TokenType tokentype = TokenType.getTypeByFirstChar(c0);
33
34 if (tokentype == null)
35 {
36 throw new ParseException("Invalid character: \'" + c0 + "\', in: " + str);
37 }
38
39 Token token = readToken(c0, tokentype, pushbackreader);
40 list.add(token);
41 }
42 }
43 }
44
45 private static Token readToken(char chFirst, TokenType type, PushbackReader pr) throws IOException
46 {
47 StringBuffer stringbuffer = new StringBuffer();
48 stringbuffer.append(chFirst);
49
50 while (true)
51 {
52 int i = pr.read();
53
54 if (i < 0)
55 {
56 break;
57 }
58
59 char c0 = (char)i;
60
61 if (!type.hasCharNext(c0))
62 {
63 pr.unread(c0);
64 break;
65 }
66
67 stringbuffer.append(c0);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected