-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Queue improvements and sdlang package
- Loading branch information
al1-ce
committed
May 9, 2023
1 parent
657c205
commit 8b49b50
Showing
9 changed files
with
405 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"fileVersion": 1, | ||
"versions": { | ||
"sdlite": "1.1.2", | ||
"taggedalgebraic": "0.11.22" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
/++ | ||
Wrapper for SDLite. | ||
Noticable differences between SDLang and SDLite parser: | ||
- Line breaking is not allowed ("title \", newline, " 'value'") | ||
+/ | ||
module sily.sdlang; | ||
|
||
import sdl = sdlite; | ||
import std.range; | ||
|
||
import taggedalgebraic.taggedunion; | ||
|
||
/++ | ||
Representation of single sdlang node | ||
Example: | ||
--- | ||
// Create SDLNode. SDLNode("name", SDLValue[] values, SDLAttribute[] attributes, SDLNode[] children) | ||
SDLNode node = SDLNode("name", [SDLValue.text("values")], [], []); | ||
// Get name | ||
node.name; | ||
// Get namespace | ||
node.namespace; | ||
// Get/Set qualified name (eq to namespace:name) | ||
node.qualifiedName; | ||
node.qualifiedName = "namespace:name"; | ||
// Get array of values (aka 'node 1 "b" v=2' -> returns 1 "b") | ||
node.values; | ||
// Get array of attributes (aka 'node 1 "b" v=2' -> returns v=2) | ||
node.attributes; | ||
// Get array of children | ||
node.children; | ||
// Gets attribute by qualified name | ||
node.getAttribute("email") | ||
// Gets attribute by qualified name with default value | ||
node.getAttribute("email", SDLValue.text("[email protected]")) | ||
--- | ||
+/ | ||
alias SDLNode = sdl.SDLNode; | ||
|
||
/++ | ||
Value of sdlang node | ||
Example: | ||
--- | ||
// Create new value | ||
SDLValue val = SDLValue.double_(22.5); | ||
// Get value casted to int | ||
val.value!int; | ||
// Check type | ||
val.kind == SDLType.text; | ||
--- | ||
+/ | ||
alias SDLValue = sdl.SDLValue; | ||
|
||
/++ | ||
Attribute of sdlang node (attr="val") | ||
Example: | ||
--- | ||
// Create new attribute | ||
SDLAttribute attr = SDLAttribute("qualifiedName", SDLValue.text("value")); | ||
// Get name | ||
attr.name; | ||
// Get namepsace | ||
attr.namespace; | ||
// Get/Set qualified name (namespace:name) | ||
attr.qualifiedName; | ||
attr.qualifiedName = "namespace:name"; | ||
// Get/Set value | ||
attr.value; | ||
attr.value = SDLValue.text("new value") | ||
--- | ||
+/ | ||
alias SDLAttribute = sdl.SDLAttribute; | ||
|
||
/++ | ||
Alias to SDLValue.Kind. Represents type of SDLValue. | ||
Example: | ||
--- | ||
node.values[0].kind == SDLType.float_; | ||
--- | ||
Defined types: | ||
--- | ||
Void null_; | ||
string text; | ||
immutable(ubyte)[] binary; | ||
int int_; | ||
long long_; | ||
long[2] decimal; | ||
float float_; | ||
double double_; | ||
bool bool_; | ||
SysTime dateTime; | ||
Date date; | ||
Duration duration; | ||
--- | ||
+/ | ||
alias SDLType = sdl.SDLValue.Kind; | ||
|
||
/++ | ||
Parses SDL string into SDLNode[] | ||
Example: | ||
--- | ||
import sily.sdlang; | ||
import std.file; | ||
SDLNode[] arr1 = parseSDL(readText("file.sdl")); | ||
SDLNode[] arr2 = parseSDL("name \"Direct SDLang parsing\" cool=true"); | ||
--- | ||
+/ | ||
SDLNode[] parseSDL(string input) { | ||
SDLNode[] result; | ||
sdl.parseSDLDocument!((n) { result ~= n; })(input, ""); | ||
return result; | ||
} | ||
|
||
private alias generateSDLang = sdl.generateSDLang; | ||
|
||
/++ | ||
Writes SDL data into string | ||
Example: | ||
--- | ||
import sily.sdlang; | ||
import std.file; | ||
SDLNode[] arr1 = parseSDL(readText("file.sdl")); | ||
string out = arr1.generateSDL(); | ||
--- | ||
+/ | ||
string generateSDL(SDLNode[] input) { | ||
auto app = appender!string; | ||
app.generateSDLang(input); | ||
return app.data; | ||
} | ||
|
||
/// Ditto | ||
string generateSDL(SDLNode input) { | ||
auto app = appender!string; | ||
app.generateSDLang(input); | ||
return app.data; | ||
} | ||
|
||
/// Ditto | ||
string generateSDL(SDLValue input) { | ||
auto app = appender!string; | ||
app.generateSDLang(input); | ||
return app.data; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.