Skip to content

Commit bf545d1

Browse files
committed
Preserve ordering in patterns.
1 parent 8a396ab commit bf545d1

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

TODO.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ Tasks are categorised by importance and marked by difficulty.
1212
- Finish documentation for built-in syntax. \
1313
Some syntax is missing proper [documentation](https://moderocky.gitbook.io/byteskript/). \
1414
Difficulty: trivial
15-
- Make proper handlers for property expressions. \
16-
The current system is inadequate for complex properties.
17-
Difficulty: medium
1815
- Write more comprehensive tests. \
1916
It is important to test all expected behaviour - some syntax are missing full tests. \
2017
It is also important to test forbidden behaviour does *not* work, and proper negative tests are not implemented yet. \
@@ -23,10 +20,6 @@ Tasks are categorised by importance and marked by difficulty.
2320

2421
### Medium Importance
2522

26-
- Create a library for interacting with Java directly. \
27-
This will allow a lot more to be done within scripts, rather than relying on libraries to provide complex
28-
functionality. \
29-
Difficulty: hard
3023
- Create a library for Java GUIs. \
3124
This will probably need to interact with JavaFX. \
3225
This should be handled by somebody with experience using Java front-end. \

src/main/java/org/byteskript/skript/compiler/Pattern.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,29 @@ public class Pattern { // todo remove regex go indexOf impl
2323
private static final char ESCAPE = '\\';
2424

2525
protected final String[] patterns;
26-
protected final Map<java.util.regex.Pattern, String[]> patternMap = new HashMap<>();
26+
protected final PatternMap patternMap = new PatternMap(); // maintains entry order
2727
protected final Library provider;
2828

29+
protected static class PatternMap extends ArrayList<Map.Entry<java.util.regex.Pattern, String[]>> {
30+
public void put(java.util.regex.Pattern pattern, String[] lines) {
31+
add(new AbstractMap.SimpleEntry<>(pattern, lines));
32+
}
33+
34+
public List<java.util.regex.Pattern> keySet() {
35+
final List<java.util.regex.Pattern> list = new ArrayList<>();
36+
for (Map.Entry<java.util.regex.Pattern, String[]> entry : this) {
37+
list.add(entry.getKey());
38+
}
39+
return list;
40+
}
41+
42+
public String[] get(java.util.regex.Pattern pattern) {
43+
for (Map.Entry<java.util.regex.Pattern, String[]> entry : this) {
44+
if (entry.getKey().equals(pattern)) return entry.getValue();
45+
}
46+
return null;
47+
}
48+
}
2949

3050
public Pattern(String[] patterns, Library provider) {
3151
assert patterns != null;

0 commit comments

Comments
 (0)