Skip to content

Commit 483debf

Browse files
authored
Create README.md
1 parent a0a39ab commit 483debf

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

README.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Inscript
2+
A simple, easy and very configurable configuration language.
3+
---
4+
## Default Data Types:
5+
| Data Type | Java | Usage Example |
6+
|-----------|-----------|----------------------------------------------|
7+
| String | String | `'Hello'`, `"Hello"`, `Hello` |
8+
| Boolean | Boolean | `True`, `False`, `true`, `false` |
9+
| Byte | Byte | `13B` |
10+
| Short | Short | `255S` |
11+
| Integer | Integer | `100` |
12+
| Double | Double | `10.5D` |
13+
| Float | Float | `10.00F` |
14+
| Long | Long | `100000L` |
15+
| Character | Character | `'A'C` |
16+
| UUID | UUID | `uuid(4ad4c78c-d4a4-4d25-91cf-4f001efc46c0)` |
17+
---
18+
## Custom Data Types
19+
You can register your own data types and also a custom section parser
20+
Access the ValueRegistry with:
21+
```java
22+
final ValueRegistry registry = ValueRegistry.REGISTRY;
23+
```
24+
After that, we can register a simple data type:
25+
```java
26+
registry.register(BigDecimal.class, InlineValue.<BigDecimal>builder()
27+
.matches(text -> {
28+
try {
29+
new BigDecimal(text);
30+
return true;
31+
} catch (final Exception e) {
32+
return false;
33+
}
34+
})
35+
.deserialize(text -> {
36+
if (!text.startsWith("bigDecimal(") && !text.endsWith(")")) return null;
37+
return new BigDecimal(text.substring(11, text.length() - 1));
38+
})
39+
.serialize(bigDecimal -> "bigDecimal(" + bigDecimal.toString() + ")")
40+
.build()
41+
);
42+
```
43+
You can also make a simple Ticket section or whatever if you like storing stuff without repeating code.
44+
```java
45+
public record Ticket(@NotNull UUID user, long date) {}
46+
47+
registry.register(Ticket.class, InscriptValue.<Ticket>builder()
48+
.serialize((ticket, section) -> {
49+
section.set("user", ticket.user());
50+
section.set("date", ticket.date());
51+
})
52+
.deserialize(section -> {
53+
final Optional<UUID> user = section.get("user", UUID.class);
54+
final Optional<Long> date = section.get("date", Long.class);
55+
56+
if (user.isEmpty() || date.isEmpty()) return null;
57+
return new Ticket(user.get(), date.get());
58+
})
59+
.build()
60+
);
61+
```
62+
And we're done!
63+
---
64+
## Configuring the language
65+
If you want to change stuff like defining a list, or just want to change the indent, you can refer to the InscriptConstants interface.
66+
```java
67+
InscriptConstants.INDENT.set(" "::repeat);
68+
69+
InscriptConstants.LIST_START.set("List(");
70+
InscriptConstants.LIST_END.set(")");
71+
```
72+
---
73+
## Using Inscript
74+
You can load/save contents from/to files, or just load/save contents from/to strings.
75+
If you want to use files, you have to provide a `Path` or a `File`.
76+
```java
77+
final Path path = Path.of(/* ... */);
78+
final Inscript inscript = Inscript.newInscript(path);
79+
```
80+
If you want to use the latter, you don't need to provide anything:
81+
```java
82+
final Inscript inscript = Inscript.emptyInscript();
83+
```
84+
85+
To obtain the inscript editor, you use `Inscript.getEditor()`.
86+
87+
Loading:
88+
1. Files
89+
```java
90+
inscript.loadFromDisk();
91+
```
92+
2. String
93+
```java
94+
inscript.loadFromString("gender = \"male\"")
95+
```
96+
97+
Saving:
98+
1. Files
99+
```java
100+
inscript.saveToDisk();
101+
```
102+
2. String
103+
```java
104+
final String saved = inscript.saveToString()
105+
```

0 commit comments

Comments
 (0)