Skip to content

Commit e735201

Browse files
committed
v2
0 parents  commit e735201

21 files changed

+3957
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Sxf.g4

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 stelixlang
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

stelix/xfile/ISxfBlock.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package stelix.xfile;
2+
3+
import java.util.Collection;
4+
import java.util.List;
5+
6+
public interface ISxfBlock {
7+
8+
}

stelix/xfile/SxfArrayBlock.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package stelix.xfile;
2+
3+
import java.util.ArrayList;
4+
import java.util.HashMap;
5+
import java.util.List;
6+
7+
public class SxfArrayBlock implements ISxfBlock
8+
{
9+
//todo: ? private String[] holderNames;
10+
11+
private List<SxfStruct> elements = new ArrayList<>();
12+
13+
public SxfStruct get(int index) {
14+
return elements.get(index);
15+
}
16+
17+
public void add(SxfStruct element) {
18+
elements.add(element);
19+
}
20+
21+
public boolean isEmpty() {
22+
return elements.isEmpty();
23+
}
24+
25+
public List<SxfStruct> elements() {
26+
return elements;
27+
}
28+
29+
public boolean exists(int index) {
30+
return elements.size() < index;
31+
}
32+
33+
}

stelix/xfile/SxfDataBlock.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package stelix.xfile;
2+
3+
import java.util.Collection;
4+
import java.util.HashMap;
5+
6+
public class SxfDataBlock implements ISxfBlock {
7+
8+
private HashMap<String, ISxfBlock> blocks = new HashMap<>();
9+
private HashMap<String, Object> variables = new HashMap<>();
10+
11+
12+
public <X> X block(String name) {
13+
return (X) blocks.getOrDefault(name, null);
14+
}
15+
16+
public <X> X variable(String name) {
17+
return (X) variables.getOrDefault(name, null);
18+
}
19+
20+
public boolean blockExists(String name) {
21+
return blocks.containsKey(name);
22+
}
23+
24+
public boolean varExists(String name) {
25+
return variables.containsKey(name);
26+
}
27+
28+
public HashMap<String, Object> variables() {
29+
return variables;
30+
}
31+
32+
public HashMap<String, ISxfBlock> blocks() {
33+
return blocks;
34+
}
35+
36+
public void putBlock(String identifier, ISxfBlock block) {
37+
blocks.put(identifier, block);
38+
}
39+
40+
public void putVar(String identifier, Object value) {
41+
variables.put(identifier, value);
42+
}
43+
44+
45+
public SxfArrayBlock arrayBlock(String identifier) {
46+
return block(identifier);
47+
}
48+
49+
public SxfDataBlock dataBlock(String identifier) {
50+
return block(identifier);
51+
}
52+
53+
}

stelix/xfile/SxfFile.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package stelix.xfile;
2+
3+
import stelix.xfile.ISxfBlock;
4+
import stelix.xfile.SxfArrayBlock;
5+
import stelix.xfile.SxfDataBlock;
6+
7+
import java.util.Collection;
8+
import java.util.HashMap;
9+
import java.util.List;
10+
11+
public class SxfFile {
12+
13+
private HashMap<String, ISxfBlock> blocks = new HashMap<>();
14+
15+
public <X> X get(String name) {
16+
return (X) blocks.getOrDefault(name, null);
17+
}
18+
19+
public HashMap<String, ISxfBlock> blocks() {
20+
return blocks;
21+
}
22+
23+
24+
public <X> X block(String identifier) {
25+
return (X) blocks.getOrDefault(identifier, null);
26+
}
27+
28+
public SxfArrayBlock arrayBlock(String identifier) {
29+
return block(identifier);
30+
}
31+
32+
public SxfDataBlock dataBlock(String identifier) {
33+
return block(identifier);
34+
}
35+
36+
public void put(String identifier, ISxfBlock block) {
37+
blocks.put(identifier, block);
38+
}
39+
40+
}

stelix/xfile/SxfStruct.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package stelix.xfile;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class SxfStruct {
7+
8+
private List<Object> elements;
9+
10+
public SxfStruct() {
11+
elements = new ArrayList<>();
12+
}
13+
14+
public void put(Object object) {
15+
elements.add(object);
16+
}
17+
18+
public int size() {
19+
return elements.size();
20+
}
21+
22+
public boolean isEmpty() {
23+
return elements.isEmpty();
24+
}
25+
26+
public List<Object> elements() {
27+
return elements;
28+
}
29+
30+
public <X> X get(int index) {
31+
return (X) elements.get(index);
32+
}
33+
34+
}

stelix/xfile/gen/Sxf.interp

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
token literal names:
2+
null
3+
','
4+
'[]'
5+
'TRUE'
6+
'true'
7+
'FALSE'
8+
'false'
9+
'?'
10+
'.'
11+
'd'
12+
'D'
13+
'f'
14+
'F'
15+
's'
16+
'S'
17+
null
18+
null
19+
'::'
20+
':'
21+
'{'
22+
'}'
23+
'('
24+
')'
25+
'['
26+
']'
27+
'=>'
28+
';'
29+
'\''
30+
'\\'
31+
null
32+
' '
33+
null
34+
'\t'
35+
null
36+
null
37+
null
38+
39+
token symbolic names:
40+
null
41+
null
42+
null
43+
null
44+
null
45+
null
46+
null
47+
null
48+
null
49+
null
50+
null
51+
null
52+
null
53+
null
54+
null
55+
STRING
56+
IDENTIFIER
57+
STATIC
58+
SET
59+
LEFT_CURLY
60+
RIGHT_CURLY
61+
LEFT_PAR
62+
RIGHT_PAR
63+
LEFT_SBRACE
64+
RIGHT_SBRACE
65+
OBJECT_SET
66+
EXECUTE
67+
QUOTE
68+
ESC
69+
NUMBER
70+
WHITESPACE
71+
NEWLINE
72+
TAB
73+
RETURN
74+
BlockComment
75+
SpecialComment
76+
77+
rule names:
78+
file
79+
object
80+
array_object
81+
data_object
82+
array_block
83+
struct_element
84+
struct_elements
85+
data_block
86+
data_block_elemenets
87+
data_block_element
88+
variable
89+
variables
90+
data_types
91+
state_true
92+
state_false
93+
state_null
94+
s_integer
95+
s_double
96+
s_float
97+
s_short
98+
s_string
99+
string_literal
100+
identifier
101+
block_start
102+
block_end
103+
104+
105+
atn:
106+
[3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 3, 37, 190, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 9, 7, 4, 8, 9, 8, 4, 9, 9, 9, 4, 10, 9, 10, 4, 11, 9, 11, 4, 12, 9, 12, 4, 13, 9, 13, 4, 14, 9, 14, 4, 15, 9, 15, 4, 16, 9, 16, 4, 17, 9, 17, 4, 18, 9, 18, 4, 19, 9, 19, 4, 20, 9, 20, 4, 21, 9, 21, 4, 22, 9, 22, 4, 23, 9, 23, 4, 24, 9, 24, 4, 25, 9, 25, 4, 26, 9, 26, 3, 2, 3, 2, 3, 2, 7, 2, 56, 10, 2, 12, 2, 14, 2, 59, 11, 2, 3, 3, 3, 3, 5, 3, 63, 10, 3, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 5, 3, 5, 3, 5, 3, 5, 3, 6, 3, 6, 3, 6, 3, 6, 3, 7, 3, 7, 3, 7, 3, 7, 7, 7, 82, 10, 7, 12, 7, 14, 7, 85, 11, 7, 5, 7, 87, 10, 7, 3, 7, 3, 7, 3, 8, 3, 8, 3, 8, 7, 8, 94, 10, 8, 12, 8, 14, 8, 97, 11, 8, 5, 8, 99, 10, 8, 3, 9, 3, 9, 3, 9, 3, 9, 3, 10, 3, 10, 3, 10, 7, 10, 108, 10, 10, 12, 10, 14, 10, 111, 11, 10, 5, 10, 113, 10, 10, 3, 11, 3, 11, 5, 11, 117, 10, 11, 3, 12, 3, 12, 3, 12, 3, 12, 3, 13, 3, 13, 3, 13, 7, 13, 126, 10, 13, 12, 13, 14, 13, 129, 11, 13, 3, 14, 3, 14, 3, 14, 3, 14, 3, 14, 3, 14, 3, 14, 3, 14, 3, 14, 3, 14, 5, 14, 141, 10, 14, 3, 15, 3, 15, 3, 16, 3, 16, 3, 17, 3, 17, 3, 18, 3, 18, 3, 19, 3, 19, 3, 19, 3, 19, 3, 19, 5, 19, 156, 10, 19, 5, 19, 158, 10, 19, 3, 19, 5, 19, 161, 10, 19, 3, 20, 3, 20, 3, 20, 3, 20, 3, 20, 5, 20, 168, 10, 20, 5, 20, 170, 10, 20, 3, 20, 5, 20, 173, 10, 20, 3, 21, 3, 21, 3, 21, 3, 22, 3, 22, 3, 23, 3, 23, 3, 24, 3, 24, 5, 24, 184, 10, 24, 3, 25, 3, 25, 3, 26, 3, 26, 3, 26, 2, 2, 27, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 2, 9, 3, 2, 5, 6, 3, 2, 7, 8, 3, 2, 11, 12, 3, 2, 13, 14, 3, 2, 15, 16, 4, 2, 21, 21, 23, 23, 4, 2, 22, 22, 24, 24, 2, 190, 2, 52, 3, 2, 2, 2, 4, 62, 3, 2, 2, 2, 6, 64, 3, 2, 2, 2, 8, 69, 3, 2, 2, 2, 10, 73, 3, 2, 2, 2, 12, 77, 3, 2, 2, 2, 14, 98, 3, 2, 2, 2, 16, 100, 3, 2, 2, 2, 18, 112, 3, 2, 2, 2, 20, 116, 3, 2, 2, 2, 22, 118, 3, 2, 2, 2, 24, 122, 3, 2, 2, 2, 26, 140, 3, 2, 2, 2, 28, 142, 3, 2, 2, 2, 30, 144, 3, 2, 2, 2, 32, 146, 3, 2, 2, 2, 34, 148, 3, 2, 2, 2, 36, 150, 3, 2, 2, 2, 38, 162, 3, 2, 2, 2, 40, 174, 3, 2, 2, 2, 42, 177, 3, 2, 2, 2, 44, 179, 3, 2, 2, 2, 46, 183, 3, 2, 2, 2, 48, 185, 3, 2, 2, 2, 50, 187, 3, 2, 2, 2, 52, 57, 5, 4, 3, 2, 53, 54, 7, 3, 2, 2, 54, 56, 5, 4, 3, 2, 55, 53, 3, 2, 2, 2, 56, 59, 3, 2, 2, 2, 57, 55, 3, 2, 2, 2, 57, 58, 3, 2, 2, 2, 58, 3, 3, 2, 2, 2, 59, 57, 3, 2, 2, 2, 60, 63, 5, 8, 5, 2, 61, 63, 5, 6, 4, 2, 62, 60, 3, 2, 2, 2, 62, 61, 3, 2, 2, 2, 63, 5, 3, 2, 2, 2, 64, 65, 5, 46, 24, 2, 65, 66, 7, 4, 2, 2, 66, 67, 7, 27, 2, 2, 67, 68, 5, 10, 6, 2, 68, 7, 3, 2, 2, 2, 69, 70, 5, 46, 24, 2, 70, 71, 7, 27, 2, 2, 71, 72, 5, 16, 9, 2, 72, 9, 3, 2, 2, 2, 73, 74, 5, 48, 25, 2, 74, 75, 5, 14, 8, 2, 75, 76, 5, 50, 26, 2, 76, 11, 3, 2, 2, 2, 77, 86, 7, 25, 2, 2, 78, 83, 5, 26, 14, 2, 79, 80, 7, 3, 2, 2, 80, 82, 5, 26, 14, 2, 81, 79, 3, 2, 2, 2, 82, 85, 3, 2, 2, 2, 83, 81, 3, 2, 2, 2, 83, 84, 3, 2, 2, 2, 84, 87, 3, 2, 2, 2, 85, 83, 3, 2, 2, 2, 86, 78, 3, 2, 2, 2, 86, 87, 3, 2, 2, 2, 87, 88, 3, 2, 2, 2, 88, 89, 7, 26, 2, 2, 89, 13, 3, 2, 2, 2, 90, 95, 5, 12, 7, 2, 91, 92, 7, 3, 2, 2, 92, 94, 5, 12, 7, 2, 93, 91, 3, 2, 2, 2, 94, 97, 3, 2, 2, 2, 95, 93, 3, 2, 2, 2, 95, 96, 3, 2, 2, 2, 96, 99, 3, 2, 2, 2, 97, 95, 3, 2, 2, 2, 98, 90, 3, 2, 2, 2, 98, 99, 3, 2, 2, 2, 99, 15, 3, 2, 2, 2, 100, 101, 5, 48, 25, 2, 101, 102, 5, 18, 10, 2, 102, 103, 5, 50, 26, 2, 103, 17, 3, 2, 2, 2, 104, 109, 5, 20, 11, 2, 105, 106, 7, 3, 2, 2, 106, 108, 5, 20, 11, 2, 107, 105, 3, 2, 2, 2, 108, 111, 3, 2, 2, 2, 109, 107, 3, 2, 2, 2, 109, 110, 3, 2, 2, 2, 110, 113, 3, 2, 2, 2, 111, 109, 3, 2, 2, 2, 112, 104, 3, 2, 2, 2, 112, 113, 3, 2, 2, 2, 113, 19, 3, 2, 2, 2, 114, 117, 5, 22, 12, 2, 115, 117, 5, 4, 3, 2, 116, 114, 3, 2, 2, 2, 116, 115, 3, 2, 2, 2, 117, 21, 3, 2, 2, 2, 118, 119, 5, 46, 24, 2, 119, 120, 7, 20, 2, 2, 120, 121, 5, 26, 14, 2, 121, 23, 3, 2, 2, 2, 122, 127, 5, 22, 12, 2, 123, 124, 7, 3, 2, 2, 124, 126, 5, 22, 12, 2, 125, 123, 3, 2, 2, 2, 126, 129, 3, 2, 2, 2, 127, 125, 3, 2, 2, 2, 127, 128, 3, 2, 2, 2, 128, 25, 3, 2, 2, 2, 129, 127, 3, 2, 2, 2, 130, 141, 5, 28, 15, 2, 131, 141, 5, 30, 16, 2, 132, 141, 5, 42, 22, 2, 133, 141, 5, 34, 18, 2, 134, 141, 5, 40, 21, 2, 135, 141, 5, 38, 20, 2, 136, 141, 5, 36, 19, 2, 137, 141, 5, 12, 7, 2, 138, 141, 5, 16, 9, 2, 139, 141, 5, 32, 17, 2, 140, 130, 3, 2, 2, 2, 140, 131, 3, 2, 2, 2, 140, 132, 3, 2, 2, 2, 140, 133, 3, 2, 2, 2, 140, 134, 3, 2, 2, 2, 140, 135, 3, 2, 2, 2, 140, 136, 3, 2, 2, 2, 140, 137, 3, 2, 2, 2, 140, 138, 3, 2, 2, 2, 140, 139, 3, 2, 2, 2, 141, 27, 3, 2, 2, 2, 142, 143, 9, 2, 2, 2, 143, 29, 3, 2, 2, 2, 144, 145, 9, 3, 2, 2, 145, 31, 3, 2, 2, 2, 146, 147, 7, 9, 2, 2, 147, 33, 3, 2, 2, 2, 148, 149, 7, 31, 2, 2, 149, 35, 3, 2, 2, 2, 150, 160, 7, 31, 2, 2, 151, 152, 7, 10, 2, 2, 152, 157, 7, 31, 2, 2, 153, 158, 7, 11, 2, 2, 154, 156, 7, 12, 2, 2, 155, 154, 3, 2, 2, 2, 155, 156, 3, 2, 2, 2, 156, 158, 3, 2, 2, 2, 157, 153, 3, 2, 2, 2, 157, 155, 3, 2, 2, 2, 158, 161, 3, 2, 2, 2, 159, 161, 9, 4, 2, 2, 160, 151, 3, 2, 2, 2, 160, 159, 3, 2, 2, 2, 161, 37, 3, 2, 2, 2, 162, 172, 7, 31, 2, 2, 163, 164, 7, 10, 2, 2, 164, 169, 7, 31, 2, 2, 165, 170, 7, 13, 2, 2, 166, 168, 7, 14, 2, 2, 167, 166, 3, 2, 2, 2, 167, 168, 3, 2, 2, 2, 168, 170, 3, 2, 2, 2, 169, 165, 3, 2, 2, 2, 169, 167, 3, 2, 2, 2, 170, 173, 3, 2, 2, 2, 171, 173, 9, 5, 2, 2, 172, 163, 3, 2, 2, 2, 172, 171, 3, 2, 2, 2, 173, 39, 3, 2, 2, 2, 174, 175, 7, 31, 2, 2, 175, 176, 9, 6, 2, 2, 176, 41, 3, 2, 2, 2, 177, 178, 5, 44, 23, 2, 178, 43, 3, 2, 2, 2, 179, 180, 7, 17, 2, 2, 180, 45, 3, 2, 2, 2, 181, 184, 7, 18, 2, 2, 182, 184, 5, 44, 23, 2, 183, 181, 3, 2, 2, 2, 183, 182, 3, 2, 2, 2, 184, 47, 3, 2, 2, 2, 185, 186, 9, 7, 2, 2, 186, 49, 3, 2, 2, 2, 187, 188, 9, 8, 2, 2, 188, 51, 3, 2, 2, 2, 20, 57, 62, 83, 86, 95, 98, 109, 112, 116, 127, 140, 155, 157, 160, 167, 169, 172, 183]

stelix/xfile/gen/Sxf.tokens

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
T__0=1
2+
T__1=2
3+
T__2=3
4+
T__3=4
5+
T__4=5
6+
T__5=6
7+
T__6=7
8+
T__7=8
9+
T__8=9
10+
T__9=10
11+
T__10=11
12+
T__11=12
13+
T__12=13
14+
T__13=14
15+
STRING=15
16+
IDENTIFIER=16
17+
STATIC=17
18+
SET=18
19+
LEFT_CURLY=19
20+
RIGHT_CURLY=20
21+
LEFT_PAR=21
22+
RIGHT_PAR=22
23+
LEFT_SBRACE=23
24+
RIGHT_SBRACE=24
25+
OBJECT_SET=25
26+
EXECUTE=26
27+
QUOTE=27
28+
ESC=28
29+
NUMBER=29
30+
WHITESPACE=30
31+
NEWLINE=31
32+
TAB=32
33+
RETURN=33
34+
BlockComment=34
35+
SpecialComment=35
36+
','=1
37+
'[]'=2
38+
'TRUE'=3
39+
'true'=4
40+
'FALSE'=5
41+
'false'=6
42+
'?'=7
43+
'.'=8
44+
'd'=9
45+
'D'=10
46+
'f'=11
47+
'F'=12
48+
's'=13
49+
'S'=14
50+
'::'=17
51+
':'=18
52+
'{'=19
53+
'}'=20
54+
'('=21
55+
')'=22
56+
'['=23
57+
']'=24
58+
'=>'=25
59+
';'=26
60+
'\''=27
61+
'\\'=28
62+
' '=30
63+
'\t'=32

0 commit comments

Comments
 (0)