can compile and windows instructions

This commit is contained in:
SimonFJ20 2023-01-17 15:19:23 +01:00
parent 4e11975a6f
commit 83782004fd
4 changed files with 141 additions and 128 deletions

View File

@ -9,9 +9,20 @@
- Compile `meson compile` - Compile `meson compile`
- Run, `./browser` or `./server` - Run, `./browser` or `./server`
## Toolchain
## Linux
Install clang preferably `clang-15` or `clang-14`;
### Windows
- Install Visual Studio, with `Desktop development with C++` enabled
- Install a newer LLVM
## VS Code development setup ## VS Code development setup
### Install ### Install Linux
- LLVM and clang, `clang-15` recommended, `clang-15` based, check with `clang --version` - LLVM and clang, `clang-15` recommended, `clang-15` based, check with `clang --version`
- [Meson](https://mesonbuild.com/), build system - [Meson](https://mesonbuild.com/), build system
- [Meson VS Code extension](https://marketplace.visualstudio.com/items?itemName=mesonbuild.mesonbuild) - [Meson VS Code extension](https://marketplace.visualstudio.com/items?itemName=mesonbuild.mesonbuild)
@ -19,6 +30,7 @@
- [VSCode - CodeLLDB](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb), debugger - [VSCode - CodeLLDB](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb), debugger
- [VSCode - Better C++ Syntax](https://marketplace.visualstudio.com/items?itemName=jeff-hykin.better-cpp-syntax), syntax higlighting - [VSCode - Better C++ Syntax](https://marketplace.visualstudio.com/items?itemName=jeff-hykin.better-cpp-syntax), syntax higlighting
### Config ### Config
Add these to `settings.json` if necessary Add these to `settings.json` if necessary

View File

@ -339,77 +339,79 @@ auto Lexer::step() noexcept -> void
} }
} }
auto Parser::parse_top_level() noexcept -> Result<std::unique_ptr<Node>, Error> // auto Parser::parse_top_level() noexcept -> Result<std::unique_ptr<Node>,
{ // Error>
if (!lexer.peek()) // {
return Error { lexer.peek().unwrap_error() }; // if (!lexer.peek())
else if (lexer.peek()->type == Tokens::Name) // return Error { lexer.peek().unwrap_error() };
return parse_element(); // else if (lexer.peek()->type == Tokens::Name)
else // return parse_element();
return parse_value(); // else
} // return parse_value();
// }
auto Parser::parse_element() noexcept -> Result<std::unique_ptr<Node>, Error> // auto Parser::parse_element() noexcept -> Result<std::unique_ptr<Node>, Error>
{ // {
auto name = *lexer.peek(); // auto name = *lexer.peek();
auto ids = Element::Ids {}; // auto ids = Element::Ids {};
auto classes = Element::Classes {}; // auto classes = Element::Classes {};
auto properties = Element::Properties {}; // auto properties = Element::Properties {};
auto values = Element::Values {}; // auto values = Element::Values {};
if (auto result = lexer.next(); !result) // if (auto result = lexer.next(); !result)
return Error { result.unwrap_error() }; // return Error { result.unwrap_error() };
return Result<std::unique_ptr<Node>, Error>::create_ok( // return Result<std::unique_ptr<Node>, Error>::create_ok(
std::make_unique<Element>( // std::make_unique<Element>(
Element { std::string { name.value() }, {}, {}, {}, {} })); // Element { std::string { name.value() }, {}, {}, {}, {} }));
} // }
auto Parser::parse_single_line_fields( // auto Parser::parse_single_line_fields(
Element::Initializer& initializer) noexcept -> Result<void, Error> // Element::Initializer& initializer) noexcept -> Result<void, Error>
{ // {
if (lexer.peek()->type == Tokens::Id) { // if (lexer.peek()->type == Tokens::Id) {
initializer.ids.push_back(std::string { lexer.peek()->value() }); // initializer.ids.push_back(std::string { lexer.peek()->value() });
if (auto result = lexer.next(); !result) // if (auto result = lexer.next(); !result)
return Error { result.unwrap_error() }; // return Error { result.unwrap_error() };
// do the rest; // // do the rest;
} else if (lexer.peek()->type == Tokens::Class) { // } else if (lexer.peek()->type == Tokens::Class) {
initializer.classes.push_back(std::string { lexer.peek()->value() }); // initializer.classes.push_back(std::string { lexer.peek()->value() });
if (auto result = lexer.next(); !result) // if (auto result = lexer.next(); !result)
return Error { result.unwrap_error() }; // return Error { result.unwrap_error() };
// do the rest // // do the rest
} else { // } else {
if (auto result = parse_mandatory_same_line_whitespace(); !result) // if (auto result = parse_mandatory_same_line_whitespace(); !result)
return result; // return result;
if (lexer.peek()->type == Tokens::Name) { // if (lexer.peek()->type == Tokens::Name) {
auto key = lexer.peek(); // auto key = lexer.peek();
if (auto result = lexer.next(); !result) // if (auto result = lexer.next(); !result)
return Error { result.unwrap_error() }; // return Error { result.unwrap_error() };
if (auto result = parse_optional_whitespace(); !result) // if (auto result = parse_optional_whitespace(); !result)
return result; // return result;
if (lexer.peek()->type != Tokens::Equal // if (lexer.peek()->type != Tokens::Equal
and lexer.peek()->type != Tokens::Colon) // and lexer.peek()->type != Tokens::Colon)
return Error { // return Error {
fmt::format("expected '=' or ':', got {}", // fmt::format("expected '=' or ':', got {}",
lexer.peek()->to_string()), // lexer.peek()->to_string()),
lexer.peek()->location, // lexer.peek()->location,
}; // };
if (auto result = lexer.next(); !result) // if (auto result = lexer.next(); !result)
return Error { result.unwrap_error() }; // return Error { result.unwrap_error() };
if (auto result = parse_optional_same_line_whitespace(); !result) // if (auto result = parse_optional_same_line_whitespace(); !result)
return result; // return result;
auto value = parse_single_line_value(); // auto value = parse_single_line_value();
if (!value) // if (!value)
return value; // return value;
// do the rest // // do the rest
} else { // } else {
auto value = parse_single_line_value(); // auto value = parse_single_line_value();
if (!value) // if (!value)
return value; // return value;
// do the rest // // do the rest
} // }
} // }
} // return {};
// }
// auto Parser::parse_single_line_field(Element::Initializer& initializer) // auto Parser::parse_single_line_field(Element::Initializer& initializer)
// noexcept // noexcept

View File

@ -201,57 +201,57 @@ struct Bool final : public Node {
auto type() const noexcept -> Nodes override { return Nodes::Bool; } auto type() const noexcept -> Nodes override { return Nodes::Bool; }
}; };
class Parser { // class Parser {
public: // public:
struct Error { // struct Error {
Error(Lexer::Error error) // Error(Lexer::Error error)
: message { std::move(error.message) } // : message { std::move(error.message) }
, location { error.location } // , location { error.location }
{ } // { }
Error(std::string message, Location location) // Error(std::string message, Location location)
: message { std::move(message) } // : message { std::move(message) }
, location { location } // , location { location }
{ } // { }
std::string message; // std::string message;
Location location; // Location location;
}; // };
Parser(Lexer lexer) // Parser(Lexer lexer)
: lexer { std::move(lexer) } // : lexer { std::move(lexer) }
{ } // { }
auto parse_top_level() noexcept -> Result<std::unique_ptr<Node>, Error>; // auto parse_top_level() noexcept -> Result<std::unique_ptr<Node>, Error>;
auto parse_element() noexcept -> Result<std::unique_ptr<Node>, Error>; // auto parse_element() noexcept -> Result<std::unique_ptr<Node>, Error>;
auto parse_element_body(Element::Initializer& initializer) noexcept // auto parse_element_body(Element::Initializer& initializer) noexcept
-> Result<void, Error>; // -> Result<void, Error>;
auto parse_element_fields(Element::Initializer& initializer) noexcept // auto parse_element_fields(Element::Initializer& initializer) noexcept
-> Result<void, Error>; // -> Result<void, Error>;
auto parse_element_field(Element::Initializer& initializer) noexcept // auto parse_element_field(Element::Initializer& initializer) noexcept
-> Result<void, Error>; // -> Result<void, Error>;
auto parse_single_line_fields(Element::Initializer& initializer) noexcept // auto parse_single_line_fields(Element::Initializer& initializer) noexcept
-> Result<void, Error>; // -> Result<void, Error>;
auto parse_element_property() noexcept -> Result<void, Error>; // auto parse_element_property() noexcept -> Result<void, Error>;
auto parse_single_line_value() noexcept -> Result<void, Error>; // auto parse_single_line_value() noexcept -> Result<void, Error>;
auto parse_value() noexcept -> Result<std::unique_ptr<Node>, Error>; // auto parse_value() noexcept -> Result<std::unique_ptr<Node>, Error>;
auto parse_object() noexcept -> Result<void, Error>; // auto parse_object() noexcept -> Result<void, Error>;
auto parse_object_properties() noexcept -> Result<void, Error>; // auto parse_object_properties() noexcept -> Result<void, Error>;
auto parse_object_property() noexcept -> Result<void, Error>; // auto parse_object_property() noexcept -> Result<void, Error>;
auto parse_array() noexcept -> Result<void, Error>; // auto parse_array() noexcept -> Result<void, Error>;
auto parse_array_values() noexcept -> Result<void, Error>; // auto parse_array_values() noexcept -> Result<void, Error>;
auto parse_bool() noexcept -> Result<void, Error>; // auto parse_bool() noexcept -> Result<void, Error>;
auto parse_mandatory_same_line_whitespace() noexcept -> Result<void, Error>; // auto parse_mandatory_same_line_whitespace() noexcept -> Result<void,
auto parse_optional_same_line_whitespace() noexcept -> Result<void, Error>; // Error>; auto parse_optional_same_line_whitespace() noexcept ->
auto parse_mandatory_linebreak() noexcept -> Result<void, Error>; // Result<void, Error>; auto parse_mandatory_linebreak() noexcept ->
auto parse_single_line_whitespace() noexcept -> Result<void, Error>; // Result<void, Error>; auto parse_single_line_whitespace() noexcept ->
auto parse_line_breaker() noexcept -> Result<void, Error>; // Result<void, Error>; auto parse_line_breaker() noexcept -> Result<void,
auto parse_whitespace_and_line_break() noexcept -> Result<void, Error>; // Error>; auto parse_whitespace_and_line_break() noexcept -> Result<void,
auto parse_optional_whitespace() noexcept -> Result<void, Error>; // Error>; auto parse_optional_whitespace() noexcept -> Result<void, Error>;
auto parse_mandatory_whitespace() noexcept -> Result<void, Error>; // auto parse_mandatory_whitespace() noexcept -> Result<void, Error>;
auto parse_singular_whitespace() noexcept -> Result<void, Error>; // auto parse_singular_whitespace() noexcept -> Result<void, Error>;
private: // private:
Lexer lexer; // Lexer lexer;
}; // };
} }

View File

@ -94,16 +94,15 @@ auto main() -> int
tokens.unwrap_error().location.col); tokens.unwrap_error().location.col);
} }
// test fmt::print("browser: hello world!\n");
// fmt::print("browser: hello world!\n"); auto gui = GUI::create().unwrap();
// auto gui = GUI::create().unwrap(); while (true) {
// while (true) { bool should_exit = gui->should_exit();
// bool should_exit = gui->should_exit(); if (should_exit)
// if (should_exit) break;
// break; gui->set_background_color(100, 180, 220);
// gui->set_background_color(100, 180, 220); SDL_Rect rect = { .x = 0, .y = 0, .w = 50, .h = 50 };
// SDL_Rect rect = { .x = 0, .y = 0, .w = 50, .h = 50 }; gui->create_rect(rect, 255, 0, 0);
// gui->create_rect(rect, 255, 0, 0); gui->update_gui();
// gui->update_gui(); }
// }
} }