-
Notifications
You must be signed in to change notification settings - Fork 35
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
0 parents
commit 373a4ff
Showing
27 changed files
with
20,301 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
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,21 @@ | ||
cmake_minimum_required(VERSION 3.22) | ||
project(typescript) | ||
|
||
set(CMAKE_CXX_STANDARD 20) | ||
|
||
set(CMAKE_CXX_FLAGS "-Wall -Wextra -O2") | ||
list(APPEND CMAKE_MODULE_PATH libs/) | ||
|
||
#add_definitions(-DTRACY_ENABLE) | ||
#include_directories(libs/tracy/) | ||
|
||
add_subdirectory(src) | ||
|
||
include_directories(libs) | ||
|
||
add_executable(typescript_main main.cpp) | ||
|
||
target_link_libraries( | ||
typescript_main | ||
typescript | ||
) |
Empty file.
Large diffs are not rendered by default.
Oops, something went wrong.
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,14 @@ | ||
#include <iostream> | ||
#include "src/utf.h" | ||
|
||
int main() { | ||
std::string text = "今天12"; | ||
|
||
for (int i = 0; i < text.length();) { | ||
auto p = ts::charCodeAt(text, i); | ||
std::cout << p.code << std::endl; | ||
i += p.length; | ||
} | ||
|
||
return 0; | ||
} |
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 @@ | ||
cmake_minimum_required(VERSION 3.22) | ||
project(typescript) | ||
|
||
add_definitions(-DTRACY_ENABLE) | ||
|
||
add_subdirectory(tests) | ||
|
||
#add_library(typescript parser.cpp scanner.cpp utf.cpp syntax_cursor.cpp syntax_cursor.h ast.h parser2.h) | ||
add_library(typescript scanner.cpp utf.cpp syntax_cursor.cpp syntax_cursor.h ast.h parser2.h types.cpp factory.h node_test.h) | ||
#add_library(typescript scanner.cpp utf.cpp syntax_cursor.cpp syntax_cursor.h ast.h) |
Large diffs are not rendered by default.
Oops, something went wrong.
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,104 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include <map> | ||
#include <unordered_map> | ||
#include <vector> | ||
#include <functional> | ||
#include <optional> | ||
|
||
namespace ts { | ||
using namespace std; | ||
|
||
inline string trimStringStart(string s) { | ||
while (s.compare(0, 1, " ") == 0) s.erase(s.begin()); | ||
return s; | ||
} | ||
|
||
inline string trimStringEnd(string s) { | ||
while (s.size() > 0 && s.compare(s.size() - 1, 1, " ") == 0) s.erase(s.end() - 1); | ||
return s; | ||
} | ||
|
||
template<typename T> | ||
inline bool some(optional<vector<T>> array, optional<std::function<bool(typename decltype(array)::value_type::value_type)>> predicate) { | ||
//inline bool some(vector<any> array, std::function<void(T)> predicate) { | ||
//inline bool some(optional<vector<T>> array) { | ||
if (array) { | ||
if (predicate) { | ||
for (auto &v: (*array)) { | ||
if ((*predicate)(v)) { | ||
return true; | ||
} | ||
} | ||
} else { | ||
return (*array).size() > 0; | ||
} | ||
} | ||
return false; | ||
}; | ||
|
||
//inline bool some(optional<T> array, std::function<void(typename decltype(data)::value_type::value_type)> predicate) { | ||
template<typename T> | ||
inline bool some(vector<T> array, std::function<bool(typename decltype(array)::value_type)> predicate) { | ||
return some(optional(array), optional(predicate)); | ||
} | ||
|
||
template<typename T> | ||
class LogicalOrReturnLast { | ||
protected: | ||
T value; | ||
public: | ||
LogicalOrReturnLast(T value) : value(value) {} | ||
operator T() { return value; } | ||
LogicalOrReturnLast operator||(LogicalOrReturnLast other) { | ||
if (value) return *this; | ||
|
||
return other; | ||
} | ||
LogicalOrReturnLast operator||(T other) { | ||
if (value) return *this; | ||
|
||
return LogicalOrReturnLast(other); | ||
} | ||
}; | ||
|
||
//template<typename T> | ||
//inline bool some(ts::NodeArray<T> array, std::function<bool(typename decltype(array)::value_type::value_type)> predicate) { | ||
// return some(optional(array.list), optional(predicate)); | ||
//} | ||
|
||
/** | ||
* Filters vector by filter in-place. | ||
*/ | ||
template<typename T, typename Func> | ||
static void remove(vector<T> &vector, const Func &filter) { | ||
auto new_end = remove_if(vector.begin(), vector.end(), filter); | ||
vector.erase(new_end, vector.end()); | ||
}; | ||
|
||
template<typename T> | ||
static void remove(vector<T> &vector, T item) { | ||
vector.erase(remove(vector.begin(), vector.end(), item), vector.end()); | ||
}; | ||
|
||
template<typename T> | ||
static bool has(vector<T> &vector, T item) { | ||
return find(vector.begin(), vector.end(), item) != vector.end(); | ||
}; | ||
|
||
template<typename T> | ||
static bool has(const vector<T> &vector, T item) { | ||
return find(vector.begin(), vector.end(), item) != vector.end(); | ||
}; | ||
|
||
template<typename T, typename U> | ||
static bool has(unordered_map<T, U> &map, T key) { | ||
return map.find(key) != map.end(); | ||
}; | ||
|
||
template<typename T, typename U> | ||
static bool has(map<T, U> &map, T key) { | ||
return map.find(key) != map.end(); | ||
}; | ||
} |
Oops, something went wrong.