Bladeren bron

no more trove dep

Jared 5 jaren geleden
bovenliggende
commit
d756a1e7cb
No account linked to committer's email address

+ 6
- 6
Parser/src/main/java/org/openzen/zenscript/lexer/CompiledDFA.java Bestand weergeven

@@ -1,10 +1,10 @@
1 1
 /* Licensed under GPLv3 - https://opensource.org/licenses/GPL-3.0 */
2 2
 package org.openzen.zenscript.lexer;
3 3
 
4
-import gnu.trove.iterator.TIntIterator;
5
-import gnu.trove.map.hash.TIntIntHashMap;
6 4
 import java.util.ArrayList;
5
+import java.util.Iterator;
7 6
 import java.util.List;
7
+import java.util.Map;
8 8
 
9 9
 /**
10 10
  * Represents a compiled DFA. A compiled DFA has a compact representation and
@@ -32,7 +32,7 @@ public class CompiledDFA<T>
32 32
 		return new NFA<>(regexps, tokens, tokenClass).compile();
33 33
 	}
34 34
 	
35
-    public TIntIntHashMap[] transitions;
35
+    public Map<Integer, Integer>[] transitions;
36 36
     public T[] finals;
37 37
 
38 38
     /**
@@ -47,7 +47,7 @@ public class CompiledDFA<T>
47 47
      * @param transitions transitions graph
48 48
      * @param finals finals
49 49
      */
50
-    public CompiledDFA(TIntIntHashMap[] transitions, T[] finals)
50
+    public CompiledDFA(Map<Integer, Integer>[] transitions, T[] finals)
51 51
 	{
52 52
         this.transitions = transitions;
53 53
         this.finals = finals;
@@ -90,9 +90,9 @@ public class CompiledDFA<T>
90 90
 	{
91 91
         StringBuilder result = new StringBuilder();
92 92
         for (int i = 0; i < transitions.length; i++) {
93
-            TIntIntHashMap map = transitions[i];
93
+            Map<Integer, Integer> map = transitions[i];
94 94
 
95
-            TIntIterator it = map.keySet().iterator();
95
+            Iterator<Integer> it = map.keySet().iterator();
96 96
             while (it.hasNext()) {
97 97
                 int v = it.next();
98 98
                 result.append("edge(");

+ 23
- 21
Parser/src/main/java/org/openzen/zenscript/lexer/DFA.java Bestand weergeven

@@ -1,15 +1,16 @@
1 1
 /* Licensed under GPLv3 - https://opensource.org/licenses/GPL-3.0 */
2 2
 package org.openzen.zenscript.lexer;
3 3
 
4
-import gnu.trove.iterator.TIntIterator;
5
-import gnu.trove.map.hash.TIntIntHashMap;
6
-import gnu.trove.map.hash.TIntObjectHashMap;
7
-import gnu.trove.set.hash.TIntHashSet;
4
+
8 5
 import java.lang.reflect.Array;
9 6
 import java.util.ArrayList;
10 7
 import java.util.HashMap;
8
+import java.util.HashSet;
9
+import java.util.Iterator;
11 10
 import java.util.LinkedList;
11
+import java.util.Map;
12 12
 import java.util.Queue;
13
+import java.util.Set;
13 14
 
14 15
 /**
15 16
  * Implements a DFA. Used as intermediate form when compiling an NFA to a
@@ -56,8 +57,8 @@ public class DFA<T>
56 57
 
57 58
         while (!todo.isEmpty()) {
58 59
             DFAState<T> current = todo.poll();
59
-
60
-            TIntIterator it = current.transitions.keySet().iterator();
60
+    
61
+            Iterator<Integer> it = current.transitions.keySet().iterator();
61 62
             while (it.hasNext()) {
62 63
                 int k = it.next();
63 64
                 DFAState<T> next = current.transitions.get(k);
@@ -70,16 +71,16 @@ public class DFA<T>
70 71
         }
71 72
 
72 73
         /* Compile */
73
-        TIntIntHashMap[] transitions = new TIntIntHashMap[counter];
74
+        Map<Integer, Integer>[] transitions = new HashMap[counter];
74 75
 		@SuppressWarnings("unchecked")
75 76
         T[] finals2 = (T[]) Array.newInstance(tokenClass, counter);
76 77
 		
77 78
         for (DFAState<T> node : nodeList) {
78 79
             int index = nodes.get(node);
79 80
             finals2[index] = node.finalCode;
80
-
81
-            transitions[index] = new TIntIntHashMap();
82
-            TIntIterator it = node.transitions.keySet().iterator();
81
+    
82
+            transitions[index] = new HashMap<>();
83
+            Iterator<Integer> it = node.transitions.keySet().iterator();
83 84
             while (it.hasNext()) {
84 85
                 int k = it.next();
85 86
                 DFAState<T> next = node.transitions.get(k);
@@ -98,13 +99,13 @@ public class DFA<T>
98 99
     public DFA<T> optimize()
99 100
 	{
100 101
         CompiledDFA<T> compiled = compile();
101
-        TIntIntHashMap[] transitions = compiled.transitions;
102
+        Map<Integer, Integer>[] transitions = compiled.transitions;
102 103
         int size = transitions.length;
103 104
 
104 105
         /* Collect all edges and determine alphabet */
105
-        TIntHashSet alphabet = new TIntHashSet();
106
+        Set<Integer> alphabet = new HashSet<>();
106 107
         for (int i = 0; i < size; i++) {
107
-            TIntIterator it = transitions[i].keySet().iterator();
108
+            Iterator<Integer> it = transitions[i].keySet().iterator();
108 109
             while (it.hasNext()) {
109 110
                 int k = it.next();
110 111
                 alphabet.add(k);
@@ -127,7 +128,7 @@ public class DFA<T>
127 128
         boolean changed;
128 129
         do {
129 130
             changed = false;
130
-            TIntIterator ita = alphabet.iterator();
131
+            Iterator<Integer> ita = alphabet.iterator();
131 132
             while (ita.hasNext()) {
132 133
                 int x = ita.next();
133 134
                 for (int i = 0; i < size; i++) {
@@ -146,7 +147,7 @@ public class DFA<T>
146 147
         } while (changed);
147 148
 
148 149
         /* Group nodes */
149
-        TIntObjectHashMap<DFAState<T>> nodeMap = new TIntObjectHashMap<>();
150
+        Map<Integer, DFAState<T>> nodeMap = new HashMap<>();
150 151
         outer: for (int i = 0; i < size; i++) {
151 152
             for (int j = 0; j < size; j++) {
152 153
                 if (!distinguishable[i][j] && nodeMap.containsKey(j)) {
@@ -165,7 +166,7 @@ public class DFA<T>
165 166
         }
166 167
 
167 168
         for (int i = 0; i < compiled.transitions.length; i++) {
168
-            TIntIterator iter = transitions[i].keySet().iterator();
169
+            Iterator<Integer> iter = transitions[i].keySet().iterator();
169 170
             while (iter.hasNext()) {
170 171
                 int k = iter.next();
171 172
 
@@ -182,9 +183,9 @@ public class DFA<T>
182 183
         StringBuilder result = new StringBuilder();
183 184
         CompiledDFA<T> dfs = compile();
184 185
         for (int i = 0; i < dfs.transitions.length; i++) {
185
-            TIntIntHashMap map = dfs.transitions[i];
186
-            
187
-            TIntIterator it = map.keySet().iterator();
186
+            Map<Integer, Integer> map = dfs.transitions[i];
187
+    
188
+            Iterator<Integer> it = map.keySet().iterator();
188 189
             while (it.hasNext()) {
189 190
                 int v = it.next();
190 191
                 result.append("edge(");
@@ -217,14 +218,15 @@ public class DFA<T>
217 218
      */
218 219
     public static class DFAState<T>
219 220
 	{
220
-        private TIntObjectHashMap<DFAState<T>> transitions;
221
+        
222
+        private Map<Integer, DFAState<T>> transitions;
221 223
         private T finalCode = null;
222 224
 
223 225
         /**
224 226
          * Creates a new DFA state.
225 227
          */
226 228
         public DFAState() {
227
-            transitions = new TIntObjectHashMap<>();
229
+            transitions = new HashMap<>();
228 230
         }
229 231
 
230 232
         /**

+ 7
- 7
Parser/src/main/java/org/openzen/zenscript/lexer/NFA.java Bestand weergeven

@@ -1,15 +1,15 @@
1 1
 /* Licensed under GPLv3 - https://opensource.org/licenses/GPL-3.0 */
2 2
 package org.openzen.zenscript.lexer;
3 3
 
4
-import gnu.trove.iterator.TIntIterator;
5
-import gnu.trove.set.hash.TIntHashSet;
6 4
 import java.util.ArrayList;
7 5
 import java.util.Arrays;
8 6
 import java.util.HashMap;
9 7
 import java.util.HashSet;
8
+import java.util.Iterator;
10 9
 import java.util.LinkedList;
11 10
 import java.util.List;
12 11
 import java.util.Queue;
12
+import java.util.Set;
13 13
 
14 14
 /**
15 15
  * Represents an NFA. NFAs can be compiled from a list of regular expressions.
@@ -304,7 +304,7 @@ public class NFA<T extends Comparable<T>>
304 304
             NFAState<T> head = new NFAState<>();
305 305
             NFAState<T> tail = new NFAState<>();
306 306
 
307
-            TIntIterator iter = processCharList(stream).iterator();
307
+            Iterator<Integer> iter = processCharList(stream).iterator();
308 308
             while (iter.hasNext()) {
309 309
                 tail.addTransition(iter.next(), head);
310 310
             }
@@ -325,15 +325,15 @@ public class NFA<T extends Comparable<T>>
325 325
     }
326 326
 
327 327
     /* Processes a character list */
328
-    private TIntHashSet processCharList(CharStream stream)
328
+    private Set<Integer> processCharList(CharStream stream)
329 329
 	{
330 330
         boolean invert = stream.optional('^');
331
-        TIntHashSet base = new TIntHashSet();
331
+        Set<Integer>base = new HashSet();
332 332
         do {
333 333
             processCharPartial(base, stream);
334 334
         } while (!stream.peek(']'));
335 335
         if (invert) {
336
-            TIntHashSet result = new TIntHashSet();
336
+            Set<Integer>result = new HashSet();
337 337
             for (int i = 0; i <= 256; i++) {
338 338
                 if (!base.contains(i)) result.add(i);
339 339
             }
@@ -345,7 +345,7 @@ public class NFA<T extends Comparable<T>>
345 345
 
346 346
     /* Processes a character partial, which can be a single character or a range
347 347
      * of characters. */
348
-    private void processCharPartial(TIntHashSet out, CharStream stream)
348
+    private void processCharPartial(Set<Integer>out, CharStream stream)
349 349
 	{
350 350
         if (stream.optional('.')) {
351 351
             for (int i = 0; i <= 256; i++) {

+ 3
- 2
Parser/src/main/java/org/openzen/zenscript/lexer/TokenParser.java Bestand weergeven

@@ -1,10 +1,11 @@
1 1
 /* Licensed under GPLv3 - https://opensource.org/licenses/GPL-3.0 */
2 2
 package org.openzen.zenscript.lexer;
3 3
 
4
-import java.io.IOException;
5 4
 import org.openzen.zencode.shared.CodePosition;
6 5
 import org.openzen.zencode.shared.SourceFile;
7 6
 
7
+import java.io.IOException;
8
+
8 9
 /**
9 10
  * Represents a token stream. A token stream reads characters from a reader and
10 11
  * presents it as a series of tokens. Can be used to implement LL(*) parsers.
@@ -93,7 +94,7 @@ public class TokenParser<T extends Token<TT>, TT extends TokenType> implements T
93 94
             while (dfa.transitions[state].containsKey(reader.peek())) {
94 95
 				char c = (char) reader.next();
95 96
                 value.append(c);
96
-                state = dfa.transitions[state].get(c);
97
+                state = dfa.transitions[state].get((int)c);
97 98
             }
98 99
 			
99 100
             if (dfa.finals[state] != null) {

+ 0
- 1
common.gradle Bestand weergeven

@@ -16,7 +16,6 @@ repositories {
16 16
 }
17 17
 
18 18
 dependencies {
19
-	compile 'net.sf.trove4j:trove4j:3.0.3'
20 19
 }
21 20
 
22 21
 String mavenArtifactId = name

Laden…
Annuleren
Opslaan