diff options
author | Li Jin <dragon-fly@qq.com> | 2019-09-08 00:28:49 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2019-09-08 00:28:49 +0800 |
commit | fabc309a0a0a6f210a8a7ed8f0d1f8498971f409 (patch) | |
tree | 0187faf6b0caf17d1767b5a01ea174704742ab6f /MoonParser/parser.hpp | |
parent | 5e3d082dd2ea31acf0cc722c19b78aa4ef6e6077 (diff) | |
download | yuescript-fabc309a0a0a6f210a8a7ed8f0d1f8498971f409.tar.gz yuescript-fabc309a0a0a6f210a8a7ed8f0d1f8498971f409.tar.bz2 yuescript-fabc309a0a0a6f210a8a7ed8f0d1f8498971f409.zip |
completing moonscript compiler with c++.
Diffstat (limited to 'MoonParser/parser.hpp')
-rw-r--r-- | MoonParser/parser.hpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/MoonParser/parser.hpp b/MoonParser/parser.hpp index 66d6067..cbabf06 100644 --- a/MoonParser/parser.hpp +++ b/MoonParser/parser.hpp | |||
@@ -16,6 +16,19 @@ | |||
16 | #include <codecvt> | 16 | #include <codecvt> |
17 | #include <locale> | 17 | #include <locale> |
18 | 18 | ||
19 | // const str hash helper functions | ||
20 | inline constexpr std::size_t hash(char const* input) | ||
21 | { | ||
22 | return *input ? *input + 33ull * hash(input + 1) : 5381; | ||
23 | } | ||
24 | inline std::size_t hash(const char* input, int size, int index) | ||
25 | { | ||
26 | return index < size ? input[index] + 33ull * hash(input, size, index + 1) : 5381; | ||
27 | } | ||
28 | inline std::size_t constexpr operator"" _id(const char* s, size_t) | ||
29 | { | ||
30 | return hash(s); | ||
31 | } | ||
19 | 32 | ||
20 | ///type of the parser's input. | 33 | ///type of the parser's input. |
21 | typedef std::basic_string<char32_t> input; | 34 | typedef std::basic_string<char32_t> input; |