mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2024-12-22 20:05:31 +00:00
Fixed build errors. Switched to CMake build system completely.
This commit is contained in:
parent
30da6961d4
commit
69ede706f0
@ -1,24 +1,8 @@
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
include_directories(.)
|
||||
add_definitions("-std=c++1y")
|
||||
|
||||
add_executable(peglint lint/peglint.cc lint/server.cc)
|
||||
target_link_libraries(peglint pthread)
|
||||
|
||||
add_executable(test-main test/test.cc)
|
||||
target_link_libraries(test-main pthread)
|
||||
|
||||
add_executable(calc example/calc.cc)
|
||||
target_link_libraries(calc pthread)
|
||||
|
||||
add_executable(calc2 example/calc2.cc)
|
||||
target_link_libraries(calc2 pthread)
|
||||
|
||||
add_executable(calc3 example/calc3.cc)
|
||||
target_link_libraries(calc3 pthread)
|
||||
|
||||
add_executable(pl0 language/pl0/pl0.cc)
|
||||
target_link_libraries(pl0 pthread)
|
||||
|
||||
add_executable(culebra language/culebra/main.cc)
|
||||
target_link_libraries(culebra pthread)
|
||||
add_subdirectory(lint)
|
||||
add_subdirectory(test)
|
||||
add_subdirectory(example)
|
||||
add_subdirectory(language/pl0)
|
||||
add_subdirectory(language/culebra)
|
||||
|
12
example/CMakeLists.txt
Normal file
12
example/CMakeLists.txt
Normal file
@ -0,0 +1,12 @@
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
include_directories(..)
|
||||
add_definitions("-std=c++1y")
|
||||
|
||||
add_executable(calc calc.cc)
|
||||
target_link_libraries(calc pthread)
|
||||
|
||||
add_executable(calc2 calc2.cc)
|
||||
target_link_libraries(calc2 pthread)
|
||||
|
||||
add_executable(calc3 calc3.cc)
|
||||
target_link_libraries(calc3 pthread)
|
@ -1,21 +0,0 @@
|
||||
|
||||
USE_CLANG = 1
|
||||
|
||||
ifdef USE_CLANG
|
||||
CC = clang++
|
||||
CFLAGS = -std=c++1y -stdlib=libc++ -g
|
||||
else
|
||||
CC = g++
|
||||
CFLAGS = -std=c++1y -g
|
||||
endif
|
||||
|
||||
all: calc calc2 calc3
|
||||
|
||||
calc : calc.cc ../peglib.h
|
||||
$(CC) -o calc $(CFLAGS) -I.. calc.cc
|
||||
|
||||
calc2 : calc2.cc ../peglib.h
|
||||
$(CC) -o calc2 $(CFLAGS) -I.. calc2.cc
|
||||
|
||||
calc3 : calc3.cc ../peglib.h
|
||||
$(CC) -o calc3 $(CFLAGS) -I.. calc3.cc
|
@ -141,21 +141,21 @@ struct FunctionValue {
|
||||
};
|
||||
|
||||
struct ObjectValue {
|
||||
ObjectValue() : properties(std::make_shared<std::map<std::string, Symbol>>()) {}
|
||||
bool has(const std::string& name) const;
|
||||
const Value& get(const std::string& name) const;
|
||||
void assign(const std::string& name, const Value& val);
|
||||
void initialize(const std::string& name, const Value& val, bool mut);
|
||||
virtual std::map<std::string, Value>& builtins();
|
||||
|
||||
std::shared_ptr<std::map<std::string, Symbol>> properties =
|
||||
std::make_shared<std::map<std::string, Symbol>>();
|
||||
std::shared_ptr<std::map<std::string, Symbol>> properties;
|
||||
};
|
||||
|
||||
struct ArrayValue : public ObjectValue {
|
||||
ArrayValue() : values(std::make_shared<std::vector<Value>>()) {}
|
||||
std::map<std::string, Value>& builtins() override;
|
||||
|
||||
std::shared_ptr<std::vector<Value>> values =
|
||||
std::make_shared<std::vector<Value>>();
|
||||
std::shared_ptr<std::vector<Value>> values;
|
||||
};
|
||||
|
||||
struct Value
|
||||
|
@ -5,7 +5,6 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
using namespace culebra;
|
||||
using namespace peg;
|
||||
using namespace std;
|
||||
|
||||
@ -28,7 +27,7 @@ bool read_file(const char* path, vector<char>& buff)
|
||||
|
||||
struct CommandLineDebugger
|
||||
{
|
||||
void operator()(const Ast& ast, Environment& env, bool force_to_break) {
|
||||
void operator()(const Ast& ast, culebra::Environment& env, bool force_to_break) {
|
||||
if (quit) {
|
||||
return;
|
||||
}
|
||||
@ -130,7 +129,7 @@ struct CommandLineDebugger
|
||||
}
|
||||
}
|
||||
|
||||
void print(const Ast& ast, Environment& env, const string& symbol) {
|
||||
void print(const Ast& ast, culebra::Environment& env, const string& symbol) {
|
||||
if (symbol.empty()) {
|
||||
print_all(ast, env);
|
||||
} else if (env.has(symbol)) {
|
||||
@ -140,14 +139,14 @@ struct CommandLineDebugger
|
||||
}
|
||||
}
|
||||
|
||||
void print_all(const Ast& ast, Environment& env) {
|
||||
void print_all(const Ast& ast, culebra::Environment& env) {
|
||||
auto node = find_function_node(ast);
|
||||
set<string> references;
|
||||
enum_identifiers(*node, references);
|
||||
for (const auto& symbol: references) {
|
||||
if (env.has(symbol)) {
|
||||
const auto& val = env.get(symbol);
|
||||
if (val.type != Value::Function) {
|
||||
if (val.type != culebra::Value::Function) {
|
||||
cout << symbol << ": " << val.str() << endl;
|
||||
}
|
||||
}
|
||||
@ -212,7 +211,7 @@ struct CommandLineDebugger
|
||||
map<string, vector<size_t>> sources_;
|
||||
};
|
||||
|
||||
int repl(shared_ptr<Environment> env, bool print_ast)
|
||||
int repl(shared_ptr<culebra::Environment> env, bool print_ast)
|
||||
{
|
||||
for (;;) {
|
||||
auto line = linenoise::Readline("cul> ");
|
||||
@ -223,13 +222,13 @@ int repl(shared_ptr<Environment> env, bool print_ast)
|
||||
|
||||
if (!line.empty()) {
|
||||
vector<string> msgs;
|
||||
auto ast = parse("(repl)", line.data(), line.size(), msgs);
|
||||
auto ast = culebra::parse("(repl)", line.data(), line.size(), msgs);
|
||||
if (ast) {
|
||||
if (print_ast) {
|
||||
cout << peg::ast_to_s(ast);
|
||||
}
|
||||
|
||||
Value val;
|
||||
culebra::Value val;
|
||||
if (interpret(ast, env, val, msgs)) {
|
||||
cout << val << endl;
|
||||
linenoise::AddHistory(line.c_str());
|
||||
@ -272,7 +271,7 @@ int main(int argc, const char** argv)
|
||||
}
|
||||
|
||||
try {
|
||||
auto env = make_shared<Environment>();
|
||||
auto env = make_shared<culebra::Environment>();
|
||||
setup_built_in_functions(*env);
|
||||
|
||||
for (auto path: path_list) {
|
||||
@ -283,14 +282,14 @@ int main(int argc, const char** argv)
|
||||
}
|
||||
|
||||
vector<string> msgs;
|
||||
auto ast = parse(path, buff.data(), buff.size(), msgs);
|
||||
auto ast = culebra::parse(path, buff.data(), buff.size(), msgs);
|
||||
if (ast) {
|
||||
if (print_ast) {
|
||||
cout << peg::ast_to_s(ast);
|
||||
}
|
||||
|
||||
Value val;
|
||||
auto dbg = debug ? CommandLineDebugger() : Debugger();
|
||||
culebra::Value val;
|
||||
auto dbg = debug ? CommandLineDebugger() : culebra::Debugger();
|
||||
if (interpret(ast, env, val, msgs, dbg)) {
|
||||
return 0;
|
||||
}
|
||||
|
5
lint/CMakeLists.txt
Normal file
5
lint/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
include_directories(..)
|
||||
add_definitions("-std=c++1y")
|
||||
|
||||
add_executable(peglint peglint.cc server.cc)
|
@ -1,15 +0,0 @@
|
||||
|
||||
USE_CLANG = 1
|
||||
|
||||
ifdef USE_CLANG
|
||||
CC = clang++
|
||||
CFLAGS = -std=c++1y -stdlib=libc++ -g
|
||||
else
|
||||
CC = g++
|
||||
CFLAGS = -std=c++1y -g
|
||||
endif
|
||||
|
||||
all: peglint
|
||||
|
||||
peglint : peglint.cc server.cc ../peglib.h
|
||||
$(CC) -o peglint $(CFLAGS) -I.. peglint.cc server.cc
|
14
peglib.h
14
peglib.h
@ -158,7 +158,7 @@ private:
|
||||
* scope_exit
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
// This is from "http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4189".
|
||||
// This is based on "http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4189".
|
||||
|
||||
template <typename EF>
|
||||
struct scope_exit
|
||||
@ -173,7 +173,7 @@ struct scope_exit
|
||||
rhs.release();
|
||||
}
|
||||
|
||||
~scope_exit() noexcept(noexcept(this->exit_function())) {
|
||||
~scope_exit() noexcept {
|
||||
if (execute_on_destruction) {
|
||||
this->exit_function();
|
||||
}
|
||||
@ -2232,14 +2232,12 @@ void ast_to_s(const std::shared_ptr<T>& ptr, std::string& s, int level = 0) {
|
||||
std::string name;
|
||||
if (ast.name == ast.original_name) {
|
||||
name = ast.name;
|
||||
}
|
||||
else {
|
||||
name = ast.original_name + " (" + ast.name + ")";
|
||||
} else {
|
||||
name = ast.original_name + "[" + ast.name + "]";
|
||||
}
|
||||
if (ast.is_token) {
|
||||
s += "- " + name + "(" + ast.token + ")\n";
|
||||
}
|
||||
else {
|
||||
s += "- " + name + " (" + ast.token + ")\n";
|
||||
} else {
|
||||
s += "+ " + name + "\n";
|
||||
}
|
||||
for (auto node : ast.nodes) {
|
||||
|
6
test/CMakeLists.txt
Normal file
6
test/CMakeLists.txt
Normal file
@ -0,0 +1,6 @@
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
include_directories(..)
|
||||
add_definitions("-std=c++1y")
|
||||
|
||||
add_executable(test-main test.cc)
|
||||
target_link_libraries(test-main pthread)
|
@ -1,16 +0,0 @@
|
||||
|
||||
USE_CLANG = 1
|
||||
|
||||
ifdef USE_CLANG
|
||||
CC = clang++
|
||||
CCFLAGS = -std=c++1y -stdlib=libc++ -g
|
||||
else
|
||||
CC = g++
|
||||
CCFLAGS = -std=c++1y -g
|
||||
endif
|
||||
|
||||
all : test
|
||||
./test
|
||||
|
||||
test : test.cc ../peglib.h
|
||||
$(CC) -o test $(CCFLAGS) -I.. -I. test.cc
|
Loading…
Reference in New Issue
Block a user