-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
175 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,3 +33,5 @@ | |
|
||
cmake-build-debug/ | ||
.idea/ | ||
build/ | ||
.vscode/ |
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,57 @@ | ||
// | ||
// Created by tate on 17/06/2021. | ||
// | ||
|
||
#ifndef SCL_PARSE_HPP | ||
#define SCL_PARSE_HPP | ||
|
||
#include <optional> | ||
|
||
#include "../../vm/vm.hpp" | ||
#include "../../vm/error.hpp" | ||
|
||
/// Exported native function | ||
static NativeFunction* parse_nfn; | ||
|
||
class XMLParseFn : public NativeFunction { | ||
/// Thrown on invalid XML input | ||
class ParseError : public std::exception { | ||
public: | ||
// Character index | ||
size_t pos; | ||
|
||
// Why it's bad | ||
std::string message; | ||
|
||
ParseError(size_t pos, std::string message): | ||
pos(pos), message(std::move(message)) | ||
{} | ||
}; | ||
|
||
struct Node { | ||
std::string tag; | ||
std::vector<std::variant<Node, std::string>> members; | ||
std::unordered_map<std::string, std::string> attributes; | ||
|
||
Node(std::string tag): tag(std::move(tag)) {} | ||
}; | ||
|
||
|
||
/// Skip whitespaces | ||
static void ws(const std::string& s, size_t& i) { | ||
while (i < s.size() && isspace(s[i])) | ||
if (s[i] != ' ' && s[i] != '\t' && s[i] != '\n' && s[i] != '\r') | ||
return; | ||
else | ||
i++; | ||
} | ||
|
||
static std::optional<Node> parse_xml(std::string& s, size_t& i) { | ||
std::deque<Node> tags; | ||
|
||
ws(s, i); | ||
if (s[i] != '<') { | ||
throw ParseError(i, "expected <"); | ||
} | ||
} | ||
}; |
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,10 @@ | ||
|
||
Node { | ||
tag: string, | ||
children: (Node | string)[], | ||
attributes: { string => string }, | ||
} | ||
|
||
decode(string) => Node | null | ||
encode(Node) => string | ||
|
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,15 @@ | ||
|
||
let s = " abc, 123, you and me " | ||
|
||
print(s.split(',')) | ||
|
||
print("abc,123,you and me".split(',')) | ||
|
||
|
||
print(s = s.trim()) | ||
print(s = s.trim()) | ||
print(s = s.trim()) | ||
print(s = s.trim()) | ||
print(s = s.trim()) | ||
print(s = s.trim()) | ||
print(s = s.trim()) |
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
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